Skip to contentSkip to conversation

KEYS: Miscellaneous fixes

GIT PULL David Howells 2 participants 6 messages Dec 10, 2013 – Dec 18, 2013

lore
Share & tools
lore
#0 lore raw

Hi Linus,

Could you pull the following fixes for the keyring stuff. They break down into five sets:

(1) A patch to error handling in the big_key type for huge payloads. If the payload is larger than the "low limit" and the backing store allocation fails, then big_key_instantiate() doesn't clear the payload pointers in the key, assuming them to have been previously cleared - but only one of them is.

Unfortunately, the garbage collector still calls big_key_destroy() when sees one of the pointers with a weird value in it (and not NULL) which it then tries to clean up.

(2) Three patches to fix the keyring type:

(a) A patch to fix the hash function to correctly divide keyrings off from keys in the topology of the tree inside the associative array. This is only a problem if searching through nested keyrings - and only if the hash function incorrectly puts the a keyring outside of the 0 branch of the root node.

(b) A patch to fix keyrings' use of the associative array. The __key_link_begin() function initially passes a NULL key pointer to assoc_array_insert() on the basis that it's holding a place in the tree whilst it does more allocation and stuff.

This is only a problem when a node contains 16 keys that match at that level and we want to add an also matching 17th. This should easily be manufactured with a keyring full of keyrings (without chucking any other sort of key into the mix) - except for (a) above which makes it on average adding the 65th keyring.

(c) A patch to fix searching down through nested keyrings, where any keyring in the set has more than 16 keyrings and none of the first keyrings we look through has a match (before the tree iteration needs to step to a more distal node).

Test in keyutils test suite:

http://git.kernel.org/cgit/linux/kernel/git/dhowells/keyutils.git/commit/?id=8b4ae963ed92523aea18dfbb8cab3f4979e13bd1

(3) A patch to fix the big_key type's use of a shmem file as its backing store causing audit messages and LSM check failures. This is done by setting S_PRIVATE on the file to avoid LSM checks on the file (access to the shmem file goes through the keyctl() interface and so is gated by the LSM that way).

This isn't normally a problem if a key is used by the context that generated it - and it's currently only used by libkrb5.

Test in keyutils test suite:

http://git.kernel.org/cgit/linux/kernel/git/dhowells/keyutils.git/commit/?id=d9a53cbab42c293962f2f78f7190253fc73bd32e

(4) A patch to add a generated file to .gitignore.

(5) A patch to fix the alignment of the system certificate data such that it it works on S390. As I understand it, on the S390 arch, symbols must be 2-byte aligned because loading the address discards the least-significant bit.

David
---
The following changes since commit af91706d5ddecb4a9858cca9e90d463037cfd498:

ima: store address of template_fmt_copy in a pointer before calling strsep (2013-11-30 13:09:53 +1100)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git tags/keys-devel-20131210

for you to fetch changes up to 62226983da070f7e51068ec2e3a4da34672964c7:

KEYS: correct alignment of system_certificate_list content in assembly file (2013-12-10 18:25:28 +0000)

----------------------------------------------------------------
(from the branch description for keys-devel local branch)

Keyrings development
Keyrings fixes 2013-12-10

----------------------------------------------------------------
David Howells (4):
KEYS: Pre-clear struct key on allocation
KEYS: Fix the keyring hash function
KEYS: Fix multiple key add into associative array
KEYS: Fix searching of nested keyrings

Eric Paris (1):
security: shmem: implement kernel private shmem inodes

Hendrik Brueckner (1):
KEYS: correct alignment of system_certificate_list content in assembly file

Rusty Russell (1):
Ignore generated file kernel/x509_certificate_list

 Documentation/assoc_array.txt |  6 +++---
 include/linux/assoc_array.h   |  6 +++---
 include/linux/shmem_fs.h      |  2 ++
 kernel/.gitignore             |  1 +
 kernel/system_certificates.S  | 14 ++++++++++++--
 kernel/system_keyring.c       |  4 ++--
 lib/assoc_array.c             |  4 ++--
 mm/shmem.c                    | 36 +++++++++++++++++++++++++++++-------
 security/keys/big_key.c       |  2 +-
 security/keys/key.c           |  8 +-------
 security/keys/keyring.c       | 17 ++++++++---------
 11 files changed, 64 insertions(+), 36 deletions(-)
#1 lore raw
Quoted 2 lines · David Howells

Could you pull the following fixes for the keyring stuff.

Pulled. However, I notice that the following issue remains with module key signing, and I *think* it was introduced in the -rc1 pull:

- start with clean kernel sources

- build kernel ("make -j16" or whatever after doing your config)

- build kernel again ("make -j" - nothing has changed):

...
X.509 certificate list changed
CERTS kernel/x509_certificate_list
- Including cert /home/torvalds/v2.6/linux/signing_key.x509
AS kernel/system_certificates.o
LD kernel/built-in.o
...

which causes it to relink the kernel.

- build kernel yet again, and now finally it doesn't build/link anything.

So some rule for the certificate list seems to be broken. I'm pretty sure this didn't happen in 3.12. Any ideas?

Linus

#2 lore raw
Quoted 5 lines · Linus Torvalds
Quoted 1 line

Could you pull the following fixes for the keyring stuff.

Pulled. However, I notice that the following issue remains with module key signing, and I *think* it was introduced in the -rc1 pull:

Quoted 8 lines

- start with clean kernel sources

- build kernel ("make -j16" or whatever after doing your config)

- build kernel again ("make -j" - nothing has changed):

...
X.509 certificate list changed

Hmmm... I don't see this.

Are you using O= on the make command line? Do you have any extra certificates?

David

#3 lore raw
Quoted 6 lines · David Howells
Quoted 4 lines

- build kernel again ("make -j" - nothing has changed):

...
X.509 certificate list changed

Hmmm... I don't see this.

I take that back. I do, but only on the first rebuild. The problem appears to be that kernel/Makefile does not predict the path of kernel/.x509.list when it does not exist yet.

David

#4 lore raw
In reply to Linus Torvalds
Quoted 2 lines · Linus Torvalds

Pulled. However, I notice that the following issue remains with module key signing, and I *think* it was introduced in the -rc1 pull:

I posted four patches on Friday. Does:

[PATCH 1/4] X.509: Fix certificate gathering

fix your problem?

David

#5 lore raw
In reply to Linus Torvalds
Quoted 19 lines · Linus Torvalds
Quoted 1 line

Could you pull the following fixes for the keyring stuff.

Pulled. However, I notice that the following issue remains with module key signing, and I *think* it was introduced in the -rc1 pull:

- start with clean kernel sources

- build kernel ("make -j16" or whatever after doing your config)

- build kernel again ("make -j" - nothing has changed):

...
X.509 certificate list changed
CERTS kernel/x509_certificate_list
- Including cert /home/torvalds/v2.6/linux/signing_key.x509
AS kernel/system_certificates.o
LD kernel/built-in.o
...

Quoted 6 lines

which causes it to relink the kernel.

- build kernel yet again, and now finally it doesn't build/link anything.

So some rule for the certificate list seems to be broken. I'm pretty sure this didn't happen in 3.12. Any ideas?

Is this fixed by the attached patch?

David
---
Fix the gathering of certificates from both the source tree and the build tree to correctly calculate the pathnames of all the certificates.

The problem was that if the default generated cert, signing_key.x509, didn't exist then it would not have a path attached and if it did, it would have a path attached.

This means that the contents of kernel/.x509.list would change between the first compilation in a directory and the second. After the second it would remain stable because the signing_key.x509 file exists.

The consequence was that the kernel would get relinked unconditionally on the second recompilation. The second recompilation would also show something like this:

X.509 certificate list changed
CERTS kernel/x509_certificate_list
- Including cert /home/torvalds/v2.6/linux/signing_key.x509
AS kernel/system_certificates.o
LD kernel/built-in.o

which is why the relink would happen.

Unfortunately, it isn't a simple matter of just sticking a path on the front of the filename of the certificate in the build directory as make can't then work out how to build it.

So the path has to be prepended to the name for sorting and duplicate elimination and then removed for the make rule if it is in the build tree.

---

 kernel/Makefile |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/Makefile +3 -2
index bbaf7d59c1bb..c23bb0b30293 100644
@@ -137,9 +137,10 @@ $(obj)/timeconst.h: $(obj)/hz.bc $(src)/timeconst.bc FORCE
 ###############################################################################
 ifeq ($(CONFIG_SYSTEM_TRUSTED_KEYRING),y)
 X509_CERTIFICATES-y := $(wildcard *.x509) $(wildcard $(srctree)/*.x509)
-X509_CERTIFICATES-$(CONFIG_MODULE_SIG) += signing_key.x509
-X509_CERTIFICATES := $(sort $(foreach CERT,$(X509_CERTIFICATES-y), \
+X509_CERTIFICATES-$(CONFIG_MODULE_SIG) += $(objtree)/signing_key.x509
+X509_CERTIFICATES-raw := $(sort $(foreach CERT,$(X509_CERTIFICATES-y), \
 				$(or $(realpath $(CERT)),$(CERT))))
+X509_CERTIFICATES := $(subst $(realpath $(objtree))/,,$(X509_CERTIFICATES-raw))
 
 ifeq ($(X509_CERTIFICATES),)
 $(warning *** No X.509 certificates found ***)