[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <dae5886a8b3b4d9f869e4f8ab3cefa96@AcuMS.aculab.com>
Date: Wed, 19 Jul 2023 13:10:03 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Alexei Starovoitov' <alexei.starovoitov@...il.com>, "davem@...emloft.net"
<davem@...emloft.net>
CC: "kuba@...nel.org" <kuba@...nel.org>, "edumazet@...gle.com"
<edumazet@...gle.com>, "pabeni@...hat.com" <pabeni@...hat.com>,
"daniel@...earbox.net" <daniel@...earbox.net>, "andrii@...nel.org"
<andrii@...nel.org>, "netdev@...r.kernel.org" <netdev@...r.kernel.org>,
"bpf@...r.kernel.org" <bpf@...r.kernel.org>, "kernel-team@...com"
<kernel-team@...com>
Subject: RE: [PATCH bpf-next] bpf, net: Introduce skb_pointer_if_linear().
From: Alexei Starovoitov
> Sent: 19 July 2023 00:40
>
> Network drivers always call skb_header_pointer() with non-null buffer.
> Remove !buffer check to prevent accidental misuse of skb_header_pointer().
> Introduce skb_pointer_if_linear() instead.
>
...
> +static inline void * __must_check
> +skb_pointer_if_linear(const struct sk_buff *skb, int offset, int len)
> +{
> + if (likely(skb_headlen(skb) - offset >= len))
> + return skb->data + offset;
> + return NULL;
> +}
Shouldn't both 'offset' and 'len' be 'unsigned int' ?
The check should probably be written:
offset + len <= skb_headlen(skb)
so that it fails if 'offset' is also large.
(Provided 'offset + len' itself doesn't wrap.)
I've swapped the order because I prefer conditional to be
if (variable op constant)
and in this case skb_headlen() is the more constant value.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists