public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	stsp <stsp2@yandex.ru>,
	linux-serial@vger.kernel.org,
	Linux kernel <linux-kernel@vger.kernel.org>
Subject: Re: [regression] ENOTTY returned for tty fds
Date: Wed, 31 Jul 2024 18:12:11 +0200	[thread overview]
Message-ID: <ZqpiWy81owgsdscR@hovoldconsulting.com> (raw)
In-Reply-To: <2024073111-probe-endanger-cc8c@gregkh>

[ For some reason I never received Herbert's replies so I didn't see
  them until today. ]

On Wed, Jul 31, 2024 at 12:25:43PM +0200, Greg Kroah-Hartman wrote:
> On Wed, Jul 24, 2024 at 06:58:22PM +0800, Herbert Xu wrote:
> > On Wed, Jul 24, 2024 at 06:53:00PM +0800, Herbert Xu wrote:
> > > On Wed, Jul 24, 2024 at 12:15:39PM +0200, Greg KH wrote:
> > > >
> > > > -ENOTTY is the documented result of invalid ioctl arguments sent, I am
> > > > pretty sure POSIX requires this somewhere.  So this was fixing a
> > > > requirement here...
> > > 
> > > POSIX does not specify this at all:
> > > 
> > > https://pubs.opengroup.org/onlinepubs/9699919799/functions/ioctl.html
> > 
> > In fact it says:
> > 
> > If an underlying device driver detects an error, then ioctl() shall fail if:
> > 
> > [EINVAL]
> > The request or arg argument is not valid for this device.
> > 
> > [ENOTTY]
> > The file associated with the fildes argument is not a STREAMS device that accepts control functions.
> > 
> > Of course this is all moot since POSIX only specifies ioctl(2)
> > for STREAMS devices, but this patch in question is literally
> > going against the woring here.
> 
> That's going to be going against a lot of existing kernel code then.
> -ENOTTY is the default action of almost all ioctl handlers when the
> command is not a valid one, sorry.

This has been discussed at length before, and Linus made it clear that
ENOTTY is the right errno for unsupported ioctls, for example, here:

	https://lore.kernel.org/lkml/BANLkTi=6W0quy1M71UapwKDe97E67b4EiA@mail.gmail.com/

The tty code has been returning this since 2012 and commit bbb63c514a34
("drivers:tty:fix up ENOIOCTLCMD error handling") except for a few cases
that were missed and that I fixed up in 2021.

If this breaks real applications me may need to revert to EINVAL for the
affected ioctls however. Apparently, dosemu hasn't been
updated since 2013, but it looks like it indeed expects EINVAL for
unsupported TIOCMBIC.

Johan

      reply	other threads:[~2024-07-31 16:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <b6f4aa5c-10ba-411b-994b-6dbed2bf63db@yandex.ru>
     [not found] ` <2024072452-pegboard-undying-4245@gregkh>
2024-07-24  8:07   ` [regression] ENOTTY returned for tty fds stsp
2024-07-24  9:08     ` Greg KH
2024-07-24  9:55       ` stsp
2024-07-24 10:15         ` Greg KH
2024-07-24 10:53           ` Herbert Xu
2024-07-24 10:58             ` Herbert Xu
2024-07-31 10:25               ` Greg KH
2024-07-31 16:12                 ` Johan Hovold [this message]

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=ZqpiWy81owgsdscR@hovoldconsulting.com \
    --to=johan@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=stsp2@yandex.ru \
    --cc=torvalds@linux-foundation.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