* [PATCH net] net: core: sock: add AF_PACKET unsupported binding error
@ 2024-07-11 13:48 Szpetkowski, Grzegorz
2024-07-11 17:41 ` Kuniyuki Iwashima
0 siblings, 1 reply; 3+ messages in thread
From: Szpetkowski, Grzegorz @ 2024-07-11 13:48 UTC (permalink / raw)
To: netdev@vger.kernel.org
Hi All,
Currently, when setsockopt() API with SO_BINDTODEVICE option is
called over a raw packet socket, then although the function doesn't
return an error, the socket is not bound to a specific interface.
The limitation itself is explicitly stated in man 7 socket, particularly
that SO_BINDTODEVICE is "not supported for packet sockets".
The patch below is to align the API, so that it does return failure in
case of a packet socket.
Signed-off-by: Grzegorz Szpetkowski grzegorz.szpetkowski@intel.com
---
net/core/sock.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/net/core/sock.c b/net/core/sock.c
index 100e975073ca..1b77241ac1f7 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -639,6 +639,11 @@ static int sock_bindtoindex_locked(struct sock *sk, int ifindex)
if (ifindex < 0)
goto out;
+ /* Not supported for packet sockets, use bind() instead */
+ ret = -EOPNOTSUPP;
+ if (sk->sk_family == PF_PACKET)
+ goto out;
+
/* Paired with all READ_ONCE() done locklessly. */
WRITE_ONCE(sk->sk_bound_dev_if, ifindex);
--
2.39.2
---------------------------------------------------------------------
Intel Technology Poland sp. z o.o.
ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN.
Spolka oswiadcza, ze posiada status duzego przedsiebiorcy w rozumieniu ustawy z dnia 8 marca 2013 r. o przeciwdzialaniu nadmiernym opoznieniom w transakcjach handlowych.
Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek przegladanie lub rozpowszechnianie jest zabronione.
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by others is strictly prohibited.
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net] net: core: sock: add AF_PACKET unsupported binding error
2024-07-11 13:48 [PATCH net] net: core: sock: add AF_PACKET unsupported binding error Szpetkowski, Grzegorz
@ 2024-07-11 17:41 ` Kuniyuki Iwashima
2024-07-12 14:54 ` Willem de Bruijn
0 siblings, 1 reply; 3+ messages in thread
From: Kuniyuki Iwashima @ 2024-07-11 17:41 UTC (permalink / raw)
To: grzegorz.szpetkowski; +Cc: netdev, kuniyu
From: "Szpetkowski, Grzegorz" <grzegorz.szpetkowski@intel.com>
Date: Thu, 11 Jul 2024 13:48:07 +0000
> Hi All,
>
> Currently, when setsockopt() API with SO_BINDTODEVICE option is
> called over a raw packet socket, then although the function doesn't
> return an error, the socket is not bound to a specific interface.
>
> The limitation itself is explicitly stated in man 7 socket, particularly
> that SO_BINDTODEVICE is "not supported for packet sockets".
>
> The patch below is to align the API, so that it does return failure in
> case of a packet socket.
SO_XXX is generic options and can be set to any socket (except for
SO_ZEROCOPY due to MSG_ZEROCOPY, see 76851d1212c11), and whether it's
really used or not depends on each socket implementation.
Otherwise, we need this kind of change for all socket options and
families.
>
> Signed-off-by: Grzegorz Szpetkowski grzegorz.szpetkowski@intel.com
> ---
> net/core/sock.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/net/core/sock.c b/net/core/sock.c
> index 100e975073ca..1b77241ac1f7 100644
> --- a/net/core/sock.c
> +++ b/net/core/sock.c
> @@ -639,6 +639,11 @@ static int sock_bindtoindex_locked(struct sock *sk, int ifindex)
> if (ifindex < 0)
> goto out;
>
> + /* Not supported for packet sockets, use bind() instead */
> + ret = -EOPNOTSUPP;
> + if (sk->sk_family == PF_PACKET)
> + goto out;
> +
> /* Paired with all READ_ONCE() done locklessly. */
> WRITE_ONCE(sk->sk_bound_dev_if, ifindex);
>
> --
> 2.39.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net] net: core: sock: add AF_PACKET unsupported binding error
2024-07-11 17:41 ` Kuniyuki Iwashima
@ 2024-07-12 14:54 ` Willem de Bruijn
0 siblings, 0 replies; 3+ messages in thread
From: Willem de Bruijn @ 2024-07-12 14:54 UTC (permalink / raw)
To: Kuniyuki Iwashima, grzegorz.szpetkowski; +Cc: netdev, kuniyu
Kuniyuki Iwashima wrote:
> From: "Szpetkowski, Grzegorz" <grzegorz.szpetkowski@intel.com>
> Date: Thu, 11 Jul 2024 13:48:07 +0000
> > Hi All,
> >
> > Currently, when setsockopt() API with SO_BINDTODEVICE option is
> > called over a raw packet socket, then although the function doesn't
> > return an error, the socket is not bound to a specific interface.
> >
> > The limitation itself is explicitly stated in man 7 socket, particularly
> > that SO_BINDTODEVICE is "not supported for packet sockets".
> >
> > The patch below is to align the API, so that it does return failure in
> > case of a packet socket.
>
> SO_XXX is generic options and can be set to any socket (except for
> SO_ZEROCOPY due to MSG_ZEROCOPY, see 76851d1212c11), and whether it's
> really used or not depends on each socket implementation.
>
> Otherwise, we need this kind of change for all socket options and
> families.
Making this change now might also break applications that
set it even though it is a noop for them.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-07-12 14:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-11 13:48 [PATCH net] net: core: sock: add AF_PACKET unsupported binding error Szpetkowski, Grzegorz
2024-07-11 17:41 ` Kuniyuki Iwashima
2024-07-12 14:54 ` Willem de Bruijn
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox