All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Theodore Ts'o" <tytso@mit.edu>
To: Rob Landley <rob@landley.net>
Cc: Denys Vlasenko <vda.linux@googlemail.com>,
	David Howells <dhowells@redhat.com>,
	Linux API <linux-api@vger.kernel.org>
Subject: Re: lsattr: incorrect size for ioctl result
Date: Mon, 28 Jun 2021 12:33:03 -0400	[thread overview]
Message-ID: <YNn5v7CTRsDo1mDO@mit.edu> (raw)
In-Reply-To: <9acca2fa-eaef-1a0b-ac72-6b0eab3d8a45@landley.net>

On Fri, Jun 25, 2021 at 04:01:27AM -0500, Rob Landley wrote:
> > No. The above is a lie.
> 
> --- a/include/uapi/linux/fs.h
> +++ b/include/uapi/linux/fs.h
> @@ -203,8 +203,8 @@ struct fsxattr {
> 
>  #define        FS_IOC_GETFLAGS                 _IOR('f', 1, long)
>  #define        FS_IOC_SETFLAGS                 _IOW('f', 2, long)
> -#define        FS_IOC_GETVERSION               _IOR('v', 1, long)
> -#define        FS_IOC_SETVERSION               _IOW('v', 2, long)
> +#define        FS_IOC_GETVERSION               _IOR('v', 1, unsigned int)
> +#define        FS_IOC_SETVERSION               _IOW('v', 2, unsigned int)
>  #define FS_IOC_FIEMAP                  _IOWR('f', 11, struct fiemap)
>  #define FS_IOC32_GETFLAGS              _IOR('f', 1, int)
>  #define FS_IOC32_SETFLAGS              _IOW('f', 2, int)

The problem is that there are a large number of userspace programs
which are using _IOR('v', 1, long) (the codepoint for
FS_IOC_GETVERSION for decades), but are expecting the kernel to fill
in an int.

We could do something like this:

#define        FS_IOC_GETVERSION               _IOR('v', 1, int)
#define        FS_IOC_GETVERSION_OLD           _IOR('v', 1, long)

But the key is that we keep support for the codepoint of _IOR('v', 1,
long) essentially forever, or we will break userspace binary
compatibility, which is verboten.

We also need to be a bit careful when we make these sorts of changes
of #defines, so we don't break kernel code like this: 

long ext2_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
	/* These are just misnamed, they actually get/put from/to user an int */
	switch (cmd) {
	case EXT2_IOC32_GETFLAGS:
		cmd = EXT2_IOC_GETFLAGS;
		break;
	case EXT2_IOC32_SETFLAGS:
		cmd = EXT2_IOC_SETFLAGS;
		break;
	case EXT2_IOC32_GETVERSION:
		cmd = EXT2_IOC_GETVERSION;
		break;
	case EXT2_IOC32_SETVERSION:
		cmd = EXT2_IOC_SETVERSION;
		break;
	default:
		return -ENOIOCTLCMD;
	}
	return ext2_ioctl(file, cmd, (unsigned long) compat_ptr(arg));
}

(This is from 4.4's fs/ext2/ioct.c; the point is if we want to "fix"
the definition of *_IOC_GETFLAGS because of a pearl clutching fit that
even though the code point is _IOR('v', 1, long), we're reading and
writing an int, we need to be careful and check all of the kernel
codepaths that refer to IOC_{GET,SET}{FLAGS,VERSION}.

> Which raises the question "why is there an IOC32 version of this when it was
> never NOT 32 bit" and "does GETFLAGS have the same problem"? (Haven't looked...)

Probably because the people who added the IOC32 versions didn't
understand this at the time?  :-)

					- Ted

  parent reply	other threads:[~2021-06-28 16:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAK1hOcO3qHFO6QOkpjnC_A4LVhwed02XxCYZvEn+8t+HnyGjZA@mail.gmail.com>
     [not found] ` <b1b801af-d309-829e-fd48-6487661df809@landley.net>
     [not found]   ` <CAK1hOcMh3RK_Nd_=W-RgqhMZJh-OGY9qMDfxpALZHpxwriHgAA@mail.gmail.com>
2021-06-25  9:01     ` lsattr: incorrect size for ioctl result Rob Landley
2021-06-25 12:14       ` Denys Vlasenko
2021-06-28 16:33       ` Theodore Ts'o [this message]
2021-06-28 19:35         ` Rob Landley
2021-06-29 15:24           ` Theodore Ts'o
2021-06-29 21:04             ` Darrick J. Wong
2021-06-30  3:57               ` Theodore Ts'o
2021-06-30 18:30               ` Rob Landley

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=YNn5v7CTRsDo1mDO@mit.edu \
    --to=tytso@mit.edu \
    --cc=dhowells@redhat.com \
    --cc=linux-api@vger.kernel.org \
    --cc=rob@landley.net \
    --cc=vda.linux@googlemail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.