Return-Path: Received: from fldsmtpe03.verizon.com ([140.108.26.142]:57302 "EHLO fldsmtpe03.verizon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753558AbdJGWi1 (ORCPT ); Sat, 7 Oct 2017 18:38:27 -0400 From: "Levin, Alexander (Sasha Levin)" Cc: Seth Forshee , "Eric W. Biederman" , "Levin, Alexander (Sasha Levin)" To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" Subject: [PATCH review for 4.9 40/50] vfs: open() with O_CREAT should not create inodes with unknown ids Date: Sat, 7 Oct 2017 22:36:55 +0000 Message-ID: <20171007223636.24797-40-alexander.levin@verizon.com> References: <20171007223636.24797-1-alexander.levin@verizon.com> In-Reply-To: <20171007223636.24797-1-alexander.levin@verizon.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: Seth Forshee [ Upstream commit 1328c727004d432bbdfba0ffa02a166df04c7305 ] may_create() rejects creation of inodes with ids which lack a mapping into s_user_ns. However for O_CREAT may_o_create() is is used instead. Add a similar check there. Fixes: 036d523641c6 ("vfs: Don't create inodes with a uid or gid unknown to= the vfs") Signed-off-by: Seth Forshee Signed-off-by: "Eric W. Biederman" Signed-off-by: Sasha Levin --- fs/namei.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/namei.c b/fs/namei.c index 66209f720146..e7d125c23aa6 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -2971,10 +2971,16 @@ static inline int open_to_namei_flags(int flag) =20 static int may_o_create(const struct path *dir, struct dentry *dentry, umo= de_t mode) { + struct user_namespace *s_user_ns; int error =3D security_path_mknod(dir, dentry, mode, 0); if (error) return error; =20 + s_user_ns =3D dir->dentry->d_sb->s_user_ns; + if (!kuid_has_mapping(s_user_ns, current_fsuid()) || + !kgid_has_mapping(s_user_ns, current_fsgid())) + return -EOVERFLOW; + error =3D inode_permission(dir->dentry->d_inode, MAY_WRITE | MAY_EXEC); if (error) return error; --=20 2.11.0