linux-ppp.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: Linux FS-devel Mailing List <linux-fsdevel@vger.kernel.org>,
	y2038 Mailman List <y2038@lists.linaro.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Paul Mackerras <paulus@samba.org>,
	"David S. Miller" <davem@davemloft.net>,
	Michal Ostrowski <mostrows@earthlink.net>,
	Dmitry Kozlov <xeb@mail.ru>, James Chapman <jchapman@katalix.com>,
	linux-ppp@vger.kernel.org, Networking <netdev@vger.kernel.org>
Subject: Re: [PATCH v3 02/26] compat_ioctl: move simple ppp command handling into driver
Date: Thu, 18 Apr 2019 15:14:21 +0000	[thread overview]
Message-ID: <CAK8P3a06NdTDVpDn-KWmdc4_562Ge=hYe2Zw39mx5s0FP+KD6Q@mail.gmail.com> (raw)
In-Reply-To: <20190417235300.GB2217@ZenIV.linux.org.uk>

On Thu, Apr 18, 2019 at 1:53 AM Al Viro <viro@zeniv.linux.org.uk> wrote:
> On Thu, Apr 18, 2019 at 12:03:07AM +0200, Arnd Bergmann wrote:
> > On Wed, Apr 17, 2019 at 11:13 PM Al Viro <viro@zeniv.linux.org.uk> wrote:
> > >
> > > On Tue, Apr 16, 2019 at 10:19:40PM +0200, Arnd Bergmann wrote:
> > > > diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
> > > > index c708400fff4a..04252c3492ee 100644
_ptr(arg) to ppp_ioctl() and be done with that
> > > }
> > >
> > > with BPF-related bits (both compat and native) taken to e.g. net/core/bpf-ppp.c,
> > > picked by both generic and isdn?  IDGI...
> >
> > I was trying to unify the native and compat code paths as much
> > as possible here. Handling the four PPPIO*32 commands in
> > compat_ppp_ioctl would either require duplicating large chunks
> > of ppp_ioctl, or keeping the extra compat_alloc_user_space()
> > copy from the existing implementation.
> >
> > I'll try to come up with a different way to structure the patches.
>
> Huh?  Instead of
>         case PPPIOCSCOMPRESS:
>                 err = ppp_set_compress(ppp, arg);
>                 break;
> in native, have
>         struct ppp_option_data data;
> ...
>         case PPPIOCSCOMPRESS:
>                 if (copy_from_user(&data, argp, sizeof(data)))
>                         err = -EFAULT;
>                 else
>                         err = ppp_set_compress(ppp, &data);
>                 break;

Right, I ended up with something similar before I saw your message.

> in native and similar in compat, with get_bpf_ppp() replaced
> with call of compat_get_bpf_ppp() and ioctl numbers obviously
> adjusted.  All there is to it...  Helpers obviously shared
> with isdn and yes, all crap gone from fs/compat_ioctl.c...

I would still leave the ISDN side alone, aside from adding
the 64-bit time_t support.

> Why would you want to duplicate large chunks of anything?
> The above is not even compile-tested, but...  I can put
> together a patch if you wish.  Or am I missing something
> here?

I expected that the ppp_compat_ioctl() function would end up
fairly complex, to duplicate the logic before the switch()/case.

What I have now is

static long ppp_compat_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
{
        struct ppp_file *pf;
        struct ppp *ppp;
        int err = -ENOIOCTLCMD;
        struct ppp_option_data32 data32;
        struct ppp_option_data data;
        void __user *argp = compat_ptr(arg);

        mutex_lock(&ppp_mutex);

        pf = file->private_data;
        if (!pf || pf->kind != INTERFACE)
                goto out;

        ppp = PF_TO_PPP(pf);
        switch (cmd) {
        case PPPIOCSCOMPRESS32:
                if (copy_from_user(&data32, argp, sizeof(data32))) {
                        err = -EFAULT;
                        goto out;
                }

                data.ptr = compat_ptr(data32.ptr);
                data.length = data32.length;
                data.transmit = data32.transmit;

                err = ppp_set_compress(ppp, &data);
                break;

#ifdef CONFIG_PPP_FILTER
        case PPPIOCSPASS32:
                err = compat_get_sock_fprog(&uprog, argp);
                if (err)
                        break;
                err = ppp_set_filter(ppp, &uprog, &ppp->pass_filter);
                break;

        case PPPIOCSACTIVE32:
                err = compat_get_sock_fprog(&uprog, argp);
                if (err)
                        break;
                err = ppp_set_filter(ppp, &uprog, &ppp->active_filter);
                break;
#endif /* CONFIG_PPP_FILTER */

        default:
                break;
        }

out:
        mutex_unlock(&ppp_mutex);

        if (err = -ENOIOCTLCMD)
                err = ppp_ioctl(file, cmd, (unsigned long)compat_ptr(arg));

        return err;
}

Which doesn't look nearly as bad as I had feared, but still is
a larger change to the existing code than what I had before,
so there is a bigger risk that I screwed up somewhere new.

       Arnd

  parent reply	other threads:[~2019-04-18 15:14 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-16 20:19 [PATCH v3 00/26] compat_ioctl: cleanups Arnd Bergmann
2019-04-16 20:19 ` [PATCH v3 02/26] compat_ioctl: move simple ppp command handling into driver Arnd Bergmann
2019-04-17 21:13   ` Al Viro
2019-04-17 22:03     ` Arnd Bergmann
2019-04-17 23:53       ` Al Viro
2019-04-18  5:57         ` Al Viro
2019-04-18 15:14         ` Arnd Bergmann [this message]
2019-04-16 20:19 ` [PATCH v3 04/26] compat_ioctl: move PPPIOCSCOMPRESS32 to ppp-generic.c Arnd Bergmann
2019-04-17 21:16   ` Al Viro
2019-04-17 21:44     ` Arnd Bergmann
2019-04-16 20:19 ` [PATCH v3 05/26] compat_ioctl: move PPPIOCSPASS32/PPPIOCSACTIVE32 to ppp_generic.c Arnd Bergmann
2019-04-16 20:19 ` [PATCH v3 06/26] compat_ioctl: handle PPPIOCGIDLE for 64-bit time_t Arnd Bergmann
2019-04-16 22:33 ` [PATCH v3 00/26] compat_ioctl: cleanups Douglas Gilbert

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='CAK8P3a06NdTDVpDn-KWmdc4_562Ge=hYe2Zw39mx5s0FP+KD6Q@mail.gmail.com' \
    --to=arnd@arndb.de \
    --cc=davem@davemloft.net \
    --cc=jchapman@katalix.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-ppp@vger.kernel.org \
    --cc=mostrows@earthlink.net \
    --cc=netdev@vger.kernel.org \
    --cc=paulus@samba.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=xeb@mail.ru \
    --cc=y2038@lists.linaro.org \
    --subject='Re: [PATCH v3 02/26] compat_ioctl: move simple ppp command handling into driver' \
    /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

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).