linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
To: Miklos Szeredi <miklos-sUDqSbJrdHQHWmgEVkV9KA@public.gmane.org>,
	Alexander Viro
	<viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
Cc: linux-fsdevel
	<linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	fuse-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org,
	linux-kernel
	<linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	Richard Hansen <rhansen-ATUMkS0HV+5AfugRpC6u6w@public.gmane.org>
Subject: [PATCH v2] fuse: Fix IOC_[GS]ET{FLAGS, VERSION} argument size brokenness.
Date: Fri, 20 Dec 2013 15:35:34 -0800	[thread overview]
Message-ID: <20131220233534.GC10192@birch.djwong.org> (raw)
In-Reply-To: <20131219232739.GA10192-PTl6brltDGh4DFYR7WNSRA@public.gmane.org>

The IOC_[GS]ETFLAGS and IOC_[GS]ETVERSION ioctls, despite being
defined to take a "long" parameter, actually take "int" parameters.
FUSE unfortunately assumed that the ioctl definitions never lie, and
transfers a long's worth of data in and out of userspace, which causes
stack smashing in chattr, and other bugs elsewhere.

So, special-case this in FUSE so that we don't crash userland.

v2: Do the same for the IOC_[GS]ETVERSION ioctls, as Richard Hansen
    points out.

Signed-off-by: Darrick J. Wong <darrick.wong-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
---
 fs/fuse/file.c |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 7e70506..f8766ab 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -2385,6 +2385,22 @@ long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
 		iov->iov_base = (void __user *)arg;
 		iov->iov_len = _IOC_SIZE(cmd);
 
+		/*
+		 * The IOC_[GS]ETFLAGS and IOC_[GS]ETVERSION ioctls take int
+		 * parameters even though the ioctl definition specifies long.
+		 * Userland has been expecting int for ages (and chattr
+		 * segfaults on FUSE filesystems), so special case that here.
+		 * The IOC32 variants were declared with int, so they don't
+		 * need this correction.
+		 */
+		switch (cmd) {
+		case FS_IOC_GETFLAGS:
+		case FS_IOC_SETFLAGS:
+		case FS_IOC_GETVERSION:
+		case FS_IOC_SETVERSION:
+			iov->iov_len = sizeof(int);
+		}
+
 		if (_IOC_DIR(cmd) & _IOC_WRITE) {
 			in_iov = iov;
 			in_iovs = 1;

------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk

  parent reply	other threads:[~2013-12-20 23:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-19 23:27 [PATCH] fuse: Fix IOC_[GS]ETFLAGS argument size brokenness Darrick J. Wong
2013-12-20  6:19 ` Richard Hansen
     [not found]   ` <52B3E16F.7070409-ATUMkS0HV+5AfugRpC6u6w@public.gmane.org>
2013-12-20 23:10     ` Darrick J. Wong
2013-12-20 16:48 ` Richard Hansen
     [not found] ` <20131219232739.GA10192-PTl6brltDGh4DFYR7WNSRA@public.gmane.org>
2013-12-20 23:35   ` Darrick J. Wong [this message]
2013-12-21  2:09     ` [PATCH v2] fuse: Fix IOC_[GS]ET{FLAGS,VERSION} " Andreas Dilger
2013-12-21  2:45       ` Darrick J. Wong
2014-01-06 17:50     ` [fuse-devel] [PATCH v2] fuse: Fix IOC_[GS]ET{FLAGS, VERSION} " Miklos Szeredi
2014-01-07  1:34       ` Darrick J. Wong

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=20131220233534.GC10192@birch.djwong.org \
    --to=darrick.wong-qhclzuegtsvqt0dzr+alfa@public.gmane.org \
    --cc=fuse-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    --cc=linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=miklos-sUDqSbJrdHQHWmgEVkV9KA@public.gmane.org \
    --cc=rhansen-ATUMkS0HV+5AfugRpC6u6w@public.gmane.org \
    --cc=viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn@public.gmane.org \
    /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).