[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20230421175223.77692-1-kuniyu@amazon.com>
Date: Fri, 21 Apr 2023 10:52:23 -0700
From: Kuniyuki Iwashima <kuniyu@...zon.com>
To: <johannes@...solutions.net>
CC: <bspencer@...ckberry.com>, <christophe-h.ricard@...com>,
<davem@...emloft.net>, <dsahern@...il.com>, <edumazet@...gle.com>,
<kaber@...sh.net>, <kuba@...nel.org>, <kuni1840@...il.com>,
<kuniyu@...zon.com>, <netdev@...r.kernel.org>, <pabeni@...hat.com>,
<pablo@...filter.org>
Subject: Re: [PATCH v2 net] netlink: Use copy_to_user() for optval in netlink_getsockopt().
From: Johannes Berg <johannes@...solutions.net>
Date: Fri, 21 Apr 2023 09:56:37 +0200
> On Thu, 2023-04-20 at 23:33 +0000, Kuniyuki Iwashima wrote:
> > Brad Spencer provided a detailed report [0] that when calling getsockopt()
> > for AF_NETLINK, some SOL_NETLINK options set only 1 byte even though such
> > options require more than int as length.
>
> Nit: not "more than" but "at least" (and sizeof(int), I guess).
Will change in v3.
>
> > The options return a flag value that fits into 1 byte, but such behaviour
> > confuses users who do not initialise the variable before calling
> > getsockopt() and do not strictly check the returned value as char.
> >
> > Currently, netlink_getsockopt() uses put_user() to copy data to optlen and
> > optval, but put_user() casts the data based on the pointer, char *optval.
> > As a result, only 1 byte is set to optval.
>
> Maybe as a future thing, we should make the getsockopt method prototype
> have void here, so this kind of thing becomes a compilation error? That
> affects a fair number I guess, though I can't think of any socket
> options that really _should_ be just a char, so if it fails anywhere
> that might uncover additional bugs (and potentially avoid future ones)?
Ah, cool, we can uncover the same issue easily by doing so and
fix it unless the handler accepts char.
Thanks!
Powered by blists - more mailing lists