cred: Reject inodes with invalid ids in set_create_file_as()
authorSeth Forshee <seth.forshee@canonical.com>
Tue, 30 Aug 2016 04:35:01 +0000 (00:35 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 15 Sep 2016 06:27:49 +0000 (08:27 +0200)
[ Upstream commit 5f65e5ca286126a60f62c8421b77c2018a482b8a ]

Using INVALID_[UG]ID for the LSM file creation context doesn't
make sense, so return an error if the inode passed to
set_create_file_as() has an invalid id.

Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
Acked-by: Serge Hallyn <serge.hallyn@canonical.com>
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
kernel/cred.c

index 71179a09c1d6a3240fd9c1a4ead58d89646da24e..ff8606f77d901d4ed1201d35d35feaa5066821e3 100644 (file)
@@ -689,6 +689,8 @@ EXPORT_SYMBOL(set_security_override_from_ctx);
  */
 int set_create_files_as(struct cred *new, struct inode *inode)
 {
+       if (!uid_valid(inode->i_uid) || !gid_valid(inode->i_gid))
+               return -EINVAL;
        new->fsuid = inode->i_uid;
        new->fsgid = inode->i_gid;
        return security_kernel_create_files_as(new, inode);