diff options
author | Eric Biggers <ebiggers@google.com> | 2018-01-19 18:15:34 -0500 |
---|---|---|
committer | Trond Myklebust <trondmy@gmail.com> | 2018-01-22 10:05:11 -0500 |
commit | 49686cbbb3ebafe42e63868222f269d8053ead00 (patch) | |
tree | 4b3cbd32a2650de894100c554a75d4010edbfe20 | |
parent | cbebc6ef4fc830f4040d4140bf53484812d5d5d9 (diff) |
NFS: reject request for id_legacy key without auxdata
nfs_idmap_legacy_upcall() is supposed to be called with 'aux' pointing
to a 'struct idmap', via the call to request_key_with_auxdata() in
nfs_idmap_request_key().
However it can also be reached via the request_key() system call in
which case 'aux' will be NULL, causing a NULL pointer dereference in
nfs_idmap_prepare_pipe_upcall(), assuming that the key description is
valid enough to get that far.
Fix this by making nfs_idmap_legacy_upcall() negate the key if no
auxdata is provided.
As usual, this bug was found by syzkaller. A simple reproducer using
the command-line keyctl program is:
keyctl request2 id_legacy uid:0 '' @s
Fixes: 57e62324e469 ("NFS: Store the legacy idmapper result in the keyring")
Reported-by: syzbot+5dfdbcf7b3eb5912abbb@syzkaller.appspotmail.com
Cc: <stable@vger.kernel.org> # v3.4+
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Trond Myklebust <trondmy@gmail.com>
-rw-r--r-- | fs/nfs/nfs4idmap.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/fs/nfs/nfs4idmap.c b/fs/nfs/nfs4idmap.c index 30426c1a1bbd..22dc30a679a0 100644 --- a/fs/nfs/nfs4idmap.c +++ b/fs/nfs/nfs4idmap.c | |||
@@ -568,9 +568,13 @@ static int nfs_idmap_legacy_upcall(struct key_construction *cons, | |||
568 | struct idmap_msg *im; | 568 | struct idmap_msg *im; |
569 | struct idmap *idmap = (struct idmap *)aux; | 569 | struct idmap *idmap = (struct idmap *)aux; |
570 | struct key *key = cons->key; | 570 | struct key *key = cons->key; |
571 | int ret = -ENOMEM; | 571 | int ret = -ENOKEY; |
572 | |||
573 | if (!aux) | ||
574 | goto out1; | ||
572 | 575 | ||
573 | /* msg and im are freed in idmap_pipe_destroy_msg */ | 576 | /* msg and im are freed in idmap_pipe_destroy_msg */ |
577 | ret = -ENOMEM; | ||
574 | data = kzalloc(sizeof(*data), GFP_KERNEL); | 578 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
575 | if (!data) | 579 | if (!data) |
576 | goto out1; | 580 | goto out1; |