diff mbox series

[net] net: core: sock: add AF_PACKET unsupported binding error

Message ID CY5PR11MB6186C896926FDA33E99BD82081A52@CY5PR11MB6186.namprd11.prod.outlook.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net] net: core: sock: add AF_PACKET unsupported binding error | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present fail Series targets non-next tree, but doesn't contain any Fixes tags
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 833 this patch: 833
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers fail 3 maintainers not CCed: kuba@kernel.org edumazet@google.com pabeni@redhat.com
netdev/build_clang success Errors and warnings before: 835 this patch: 835
netdev/verify_signedoff fail author Signed-off-by missing
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 839 this patch: 839
netdev/checkpatch fail ERROR: Unrecognized email address: 'Grzegorz Szpetkowski grzegorz.szpetkowski@intel.com'
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 9 this patch: 9
netdev/source_inline success Was 0 now: 0
netdev/contest fail net-next-2024-07-11--15-00 (tests: 693)

Commit Message

Szpetkowski, Grzegorz July 11, 2024, 1:48 p.m. UTC
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(+)

Comments

Kuniyuki Iwashima July 11, 2024, 5:41 p.m. UTC | #1
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
Willem de Bruijn July 12, 2024, 2:54 p.m. UTC | #2
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.
diff mbox series

Patch

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