[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAKgT0UdyykQL-BidjaNpjX99FwJTxET51U29q4_CDqmABUuVbw@mail.gmail.com>
Date: Fri, 2 Jun 2023 09:01:34 -0700
From: Alexander Duyck <alexander.duyck@...il.com>
To: Andrew Lunn <andrew@...n.ch>
Cc: Ding Hui <dinghui@...gfor.com.cn>, davem@...emloft.net, edumazet@...gle.com,
kuba@...nel.org, pabeni@...hat.com, netdev@...r.kernel.org,
linux-kernel@...r.kernel.org, pengdonglin@...gfor.com.cn,
huangcun@...gfor.com.cn
Subject: Re: [PATCH net-next] net: ethtool: Fix out-of-bounds copy to user
On Fri, Jun 2, 2023 at 8:42 AM Andrew Lunn <andrew@...n.ch> wrote:
>
> > > Also, RTNL should be held during the time both calls are made into the
> > > driver. So nothing from userspace should be able to get in the middle
> > > of these calls to change the number of queues.
> > >
> >
> > The RTNL lock is already be held during every each ioctl in dev_ethtool().
> >
> > rtnl_lock();
> > rc = __dev_ethtool(net, ifr, useraddr, ethcmd, state);
> > rtnl_unlock();
>
> Yes, exactly. So the kernel should be safe from buffer overruns.
>
> Userspace will not get more than it asked for. It might get less, and
> it could be different to the previous calls. But i'm not aware of
> anything which says anything about the consistency between different
> invocations of ethtool -S.
The problem is the userspace allocation ends up requiring we make two
calls into the stack. So it takes the lock once to get the count,
performs the allocation, and then calls into ethtool again taking the
lock and by then the value may have changed.
Within each call it is held the entire time, but the userspace has to
make two calls. So in between the two the number of rings could
potentially change.
What this change is essentially doing is clamping the copied data to
the lesser of the current value versus the value when the userspace
was allocated. However I am wondering now if we shouldn't just update
the size value and return that as some sort of error for the userspace
to potentially reallocate and repeat until it has the right size.
Powered by blists - more mailing lists