All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Abeni <pabeni@redhat.com>
To: Eric Dumazet <eric.dumazet@gmail.com>,
	"David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>
Cc: netdev <netdev@vger.kernel.org>, Eric Dumazet <edumazet@google.com>
Subject: Re: [PATCH net-next] net: warn if mac header was not set
Date: Tue, 21 Jun 2022 11:21:28 +0200	[thread overview]
Message-ID: <58f36d9554cb3dd19d52373f9496cd230ed48423.camel@redhat.com> (raw)
In-Reply-To: <20220620093017.3366713-1-eric.dumazet@gmail.com>

Hello,

On Mon, 2022-06-20 at 02:30 -0700, Eric Dumazet wrote:
> From: Eric Dumazet <edumazet@google.com>
> 
> Make sure skb_mac_header(), skb_mac_offset() and skb_mac_header_len() uses
> are not fooled if the mac header has not been set.
> 
> These checks are enabled if CONFIG_DEBUG_NET=y
> 
> This commit will likely expose existing bugs in linux networking stacks.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> ---
>  include/linux/skbuff.h | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
> index 82edf0359ab32d0d7cd583676b38d569ce0b24cc..cd4a8268894acce4bde16dc0fedb7eb13706f515 100644
> --- a/include/linux/skbuff.h
> +++ b/include/linux/skbuff.h
> @@ -2763,8 +2763,14 @@ static inline void skb_set_network_header(struct sk_buff *skb, const int offset)
>  	skb->network_header += offset;
>  }
>  
> +static inline int skb_mac_header_was_set(const struct sk_buff *skb)
> +{
> +	return skb->mac_header != (typeof(skb->mac_header))~0U;
> +}
> +
>  static inline unsigned char *skb_mac_header(const struct sk_buff *skb)
>  {
> +	DEBUG_NET_WARN_ON_ONCE(!skb_mac_header_was_set(skb));
>  	return skb->head + skb->mac_header;
>  }
>  
> @@ -2775,14 +2781,10 @@ static inline int skb_mac_offset(const struct sk_buff *skb)
>  
>  static inline u32 skb_mac_header_len(const struct sk_buff *skb)
>  {
> +	DEBUG_NET_WARN_ON_ONCE(!skb_mac_header_was_set(skb));

The patch LGTM. 

I'm wondering if it's worthy adding similar debug checks for network
and transport offset (with more patches). e.g. still in
skb_mac_header_len():

	DEBUG_NET_WARN_ON_ONCE(skb->network_header < skb->mac_header);

Thanks!

Paolo


  reply	other threads:[~2022-06-21  9:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-20  9:30 [PATCH net-next] net: warn if mac header was not set Eric Dumazet
2022-06-21  9:21 ` Paolo Abeni [this message]
2022-06-21  9:40 ` patchwork-bot+netdevbpf

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=58f36d9554cb3dd19d52373f9496cd230ed48423.camel@redhat.com \
    --to=pabeni@redhat.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=eric.dumazet@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.