linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: demiobenour@gmail.com
To: Alexander Viro <viro@zeniv.linux.org.uk>,
	linux-fsdevel@vger.kernel.org (open list:FILESYSTEMS (VFS and
	infrastructure)), linux-kernel@vger.kernel.org (open list)
Cc: "Demi M. Obenour" <demiobenour@gmail.com>
Subject: [PATCH 4/4] Return -EINVAL if userspace passes bogus flags to open()
Date: Tue, 12 Feb 2019 09:54:47 -0500	[thread overview]
Message-ID: <20190212145450.2200-4-demiobenour@gmail.com> (raw)
In-Reply-To: <20190212145450.2200-1-demiobenour@gmail.com>

From: "Demi M. Obenour" <demiobenour@gmail.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


  parent reply	other threads:[~2019-02-12 14:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-12 14:54 [PATCH 1/4] Add path resolution flag LOOKUP_NEVER_FOLLOW demiobenour
2019-02-12 14:54 ` [PATCH 2/4] Expose O_PATHSTATIC to userspace demiobenour
2019-02-12 20:18   ` Andreas Dilger
2019-02-12 22:41     ` Demi M. Obenour
2019-02-12 14:54 ` [PATCH 3/4] Add AT_PATHSTATIC to linkat() demiobenour
2019-02-12 14:54 ` demiobenour [this message]
2019-02-12 20:38   ` [PATCH 4/4] Return -EINVAL if userspace passes bogus flags to open() Al Viro
2019-02-12 23:00     ` Demi M. Obenour

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190212145450.2200-4-demiobenour@gmail.com \
    --to=demiobenour@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).