[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190212145450.2200-4-demiobenour@gmail.com>
Date: Tue, 12 Feb 2019 09:54:47 -0500
From: demiobenour@...il.com
To: Alexander Viro <viro@...iv.linux.org.uk>,
linux-fsdevel@...r.kernel.org (open list:FILESYSTEMS (VFS and
infrastructure)), linux-kernel@...r.kernel.org (open list)
Cc: "Demi M. Obenour" <demiobenour@...il.com>
Subject: [PATCH 4/4] Return -EINVAL if userspace passes bogus flags to open()
From: "Demi M. Obenour" <demiobenour@...il.com>
While testing the O_PATHSTATIC patch, I discovered that Linux does not
return any error if an invalid flag is passed to open(2). This prevents
adding new flags without a (minor) risk of breaking userspace.
Therefore, add a check for invalid flags, and return -EINVAL if any are
found.
---
fs/open.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/fs/open.c b/fs/open.c
index 717afa8179c0..eeaa2eeb342a 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -1074,6 +1074,13 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
if (fd)
return fd;
+ /*
+ * Enforce that open flags are valid, to ensure that new flags can be
+ * added later.
+ */
+ if (unlikely(flags & ~VALID_OPEN_FLAGS))
+ return -EINVAL;
+
tmp = getname(filename);
if (IS_ERR(tmp))
return PTR_ERR(tmp);
--
2.20.1
Powered by blists - more mailing lists