Return-Path: Received: from mail-co1nam03on0133.outbound.protection.outlook.com ([104.47.40.133]:16069 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1032410AbeCAPeM (ORCPT ); Thu, 1 Mar 2018 10:34:12 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Eric Biggers , Trond Myklebust , Sasha Levin Subject: [added to the 4.1 stable tree] NFS: reject request for id_legacy key without auxdata Date: Thu, 1 Mar 2018 15:26:04 +0000 Message-ID: <20180301152116.1486-329-alexander.levin@microsoft.com> References: <20180301152116.1486-1-alexander.levin@microsoft.com> In-Reply-To: <20180301152116.1486-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Eric Biggers This patch has been added to the 4.1 stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ Upstream commit 49686cbbb3ebafe42e63868222f269d8053ead00 ] 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: # v3.4+ Signed-off-by: Eric Biggers Signed-off-by: Trond Myklebust Signed-off-by: Sasha Levin --- fs/nfs/nfs4idmap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/nfs/nfs4idmap.c b/fs/nfs/nfs4idmap.c index 2e1737c40a29..27c4970ed32f 100644 --- a/fs/nfs/nfs4idmap.c +++ b/fs/nfs/nfs4idmap.c @@ -582,9 +582,13 @@ static int nfs_idmap_legacy_upcall(struct key_construc= tion *cons, struct idmap_msg *im; struct idmap *idmap =3D (struct idmap *)aux; struct key *key =3D cons->key; - int ret =3D -ENOMEM; + int ret =3D -ENOKEY; + + if (!aux) + goto out1; =20 /* msg and im are freed in idmap_pipe_destroy_msg */ + ret =3D -ENOMEM; data =3D kzalloc(sizeof(*data), GFP_KERNEL); if (!data) goto out1; --=20 2.14.1