Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1646953 > unrolled thread
| Started by | "Gustavo A. R. Silva" <garsilva@embeddedor.com> |
|---|---|
| First post | 2017-05-22 16:10 +0200 |
| Last post | 2017-05-22 17:00 +0200 |
| Articles | 6 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH] kernel: bpf: remove dead code "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-05-22 16:10 +0200
Re: [PATCH] kernel: bpf: remove dead code David Miller <davem@davemloft.net> - 2017-05-22 16:40 +0200
Re: [PATCH] kernel: bpf: remove dead code Daniel Borkmann <daniel@iogearbox.net> - 2017-05-22 17:00 +0200
Re: [PATCH] kernel: bpf: remove dead code David Miller <davem@davemloft.net> - 2017-05-22 18:30 +0200
Re: [PATCH] kernel: bpf: remove dead code Daniel Borkmann <daniel@iogearbox.net> - 2017-05-22 19:10 +0200
Re: [PATCH] kernel: bpf: remove dead code "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-05-22 17:00 +0200
| From | "Gustavo A. R. Silva" <garsilva@embeddedor.com> |
|---|---|
| Date | 2017-05-22 16:10 +0200 |
| Subject | [PATCH] kernel: bpf: remove dead code |
| Message-ID | <tJWc4-6Hl-67@gated-at.bofh.it> |
Execution cannot reach NET_IP_ALIGN inside the following statement:
ip_align = strict ? 2 : NET_IP_ALIGN
Addresses-Coverity-ID: 1409762
Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---
NOTE: variable ip_align could also be removed and use value 2 directly.
kernel/bpf/verifier.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 1eddb71..94f6e46 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -812,7 +812,7 @@ static int check_pkt_ptr_alignment(const struct bpf_reg_state *reg,
* we force this to 2 which is universally what architectures use
* when they don't set CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS.
*/
- ip_align = strict ? 2 : NET_IP_ALIGN;
+ ip_align = 2;
if ((ip_align + reg_off + off) % size != 0) {
verbose("misaligned packet access off %d+%d+%d size %d\n",
ip_align, reg_off, off, size);
--
2.5.0
[toc] | [next] | [standalone]
| From | David Miller <davem@davemloft.net> |
|---|---|
| Date | 2017-05-22 16:40 +0200 |
| Message-ID | <tJWF4-6Ra-25@gated-at.bofh.it> |
| In reply to | #1646953 |
From: "Gustavo A. R. Silva" <garsilva@embeddedor.com> Date: Mon, 22 May 2017 09:07:46 -0500 > Execution cannot reach NET_IP_ALIGN inside the following statement: > ip_align = strict ? 2 : NET_IP_ALIGN > > Addresses-Coverity-ID: 1409762 > Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com> > --- > NOTE: variable ip_align could also be removed and use value 2 directly. Incorrect. Some platforms define NET_IP_ALIGN to zero, so the code must remain as is.
[toc] | [prev] | [next] | [standalone]
| From | Daniel Borkmann <daniel@iogearbox.net> |
|---|---|
| Date | 2017-05-22 17:00 +0200 |
| Message-ID | <tJWYq-6XB-17@gated-at.bofh.it> |
| In reply to | #1646990 |
On 05/22/2017 04:38 PM, David Miller wrote:
> From: "Gustavo A. R. Silva" <garsilva@embeddedor.com>
> Date: Mon, 22 May 2017 09:07:46 -0500
>
>> Execution cannot reach NET_IP_ALIGN inside the following statement:
>> ip_align = strict ? 2 : NET_IP_ALIGN
>>
>> Addresses-Coverity-ID: 1409762
>> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
>> ---
>> NOTE: variable ip_align could also be removed and use value 2 directly.
>
> Incorrect.
>
> Some platforms define NET_IP_ALIGN to zero, so the code must remain
> as is.
In the check_pkt_ptr_alignment(), when !strict you would already
return earlier from that function.
So, above test in ip_align will always give 2, meaning technically
the patch is correct, although hard-coded value less clean.
Perhaps something like the below to keep intentions more clear (and
it will get resolved during compile time anyway ...):
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index a098d95..3cf1d60 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -2297,8 +2297,10 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
* Since this trade off varies between architectures, we allow NET_IP_ALIGN
* to be overridden.
*/
+#define NET_IP_ALIGN_DEFAULT 2
+
#ifndef NET_IP_ALIGN
-#define NET_IP_ALIGN 2
+#define NET_IP_ALIGN NET_IP_ALIGN_DEFAULT
#endif
/*
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 1eddb71..61f6aaa 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -812,7 +812,7 @@ static int check_pkt_ptr_alignment(const struct bpf_reg_state *reg,
* we force this to 2 which is universally what architectures use
* when they don't set CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS.
*/
- ip_align = strict ? 2 : NET_IP_ALIGN;
+ ip_align = NET_IP_ALIGN ? : NET_IP_ALIGN_DEFAULT;
if ((ip_align + reg_off + off) % size != 0) {
verbose("misaligned packet access off %d+%d+%d size %d\n",
ip_align, reg_off, off, size);
[toc] | [prev] | [next] | [standalone]
| From | David Miller <davem@davemloft.net> |
|---|---|
| Date | 2017-05-22 18:30 +0200 |
| Message-ID | <tJYnx-80c-53@gated-at.bofh.it> |
| In reply to | #1647017 |
From: Daniel Borkmann <daniel@iogearbox.net>
Date: Mon, 22 May 2017 16:52:24 +0200
> On 05/22/2017 04:38 PM, David Miller wrote:
>> From: "Gustavo A. R. Silva" <garsilva@embeddedor.com>
>> Date: Mon, 22 May 2017 09:07:46 -0500
>>
>>> Execution cannot reach NET_IP_ALIGN inside the following statement:
>>> ip_align = strict ? 2 : NET_IP_ALIGN
>>>
>>> Addresses-Coverity-ID: 1409762
>>> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
>>> ---
>>> NOTE: variable ip_align could also be removed and use value 2
>>> directly.
>>
>> Incorrect.
>>
>> Some platforms define NET_IP_ALIGN to zero, so the code must remain
>> as is.
>
> In the check_pkt_ptr_alignment(), when !strict you would already
> return earlier from that function.
>
> So, above test in ip_align will always give 2, meaning technically
> the patch is correct, although hard-coded value less clean.
>
> Perhaps something like the below to keep intentions more clear (and
> it will get resolved during compile time anyway ...):
Ok I understand the issue now. Thanks for explaining.
I guess a hard-coded value of 2 and an adjusted comment above the
assignment of ip_align is the way to go.
I'll push the following, thanks everyone:
====================
net: Make IP alignment calulations clearer.
The assignmnet:
ip_align = strict ? 2 : NET_IP_ALIGN;
in compare_pkt_ptr_alignment() trips up Coverity because we can only
get to this code when strict is true, therefore ip_align will always
be 2 regardless of NET_IP_ALIGN's value.
So just assign directly to '2' and explain the situation in the
comment above.
Reported-by: "Gustavo A. R. Silva" <garsilva@embeddedor.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
---
kernel/bpf/verifier.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 1eddb71..c72cd41 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -808,11 +808,15 @@ static int check_pkt_ptr_alignment(const struct bpf_reg_state *reg,
reg_off += reg->aux_off;
}
- /* skb->data is NET_IP_ALIGN-ed, but for strict alignment checking
- * we force this to 2 which is universally what architectures use
- * when they don't set CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS.
+ /* For platforms that do not have a Kconfig enabling
+ * CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS the value of
+ * NET_IP_ALIGN is universally set to '2'. And on platforms
+ * that do set CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS, we get
+ * to this code only in strict mode where we want to emulate
+ * the NET_IP_ALIGN==2 checking. Therefore use an
+ * unconditional IP align value of '2'.
*/
- ip_align = strict ? 2 : NET_IP_ALIGN;
+ ip_align = 2;
if ((ip_align + reg_off + off) % size != 0) {
verbose("misaligned packet access off %d+%d+%d size %d\n",
ip_align, reg_off, off, size);
--
2.4.11
[toc] | [prev] | [next] | [standalone]
| From | Daniel Borkmann <daniel@iogearbox.net> |
|---|---|
| Date | 2017-05-22 19:10 +0200 |
| Message-ID | <tJZ0e-8sT-23@gated-at.bofh.it> |
| In reply to | #1647123 |
On 05/22/2017 06:27 PM, David Miller wrote: [...] > Ok I understand the issue now. Thanks for explaining. > > I guess a hard-coded value of 2 and an adjusted comment above the > assignment of ip_align is the way to go. > > I'll push the following, thanks everyone: > > ==================== > net: Make IP alignment calulations clearer. > > The assignmnet: > > ip_align = strict ? 2 : NET_IP_ALIGN; > > in compare_pkt_ptr_alignment() trips up Coverity because we can only > get to this code when strict is true, therefore ip_align will always > be 2 regardless of NET_IP_ALIGN's value. > > So just assign directly to '2' and explain the situation in the > comment above. > > Reported-by: "Gustavo A. R. Silva" <garsilva@embeddedor.com> > Signed-off-by: David S. Miller <davem@davemloft.net> Yeah, that's fine, thanks! Acked-by: Daniel Borkmann <daniel@iogearbox.net>
[toc] | [prev] | [next] | [standalone]
| From | "Gustavo A. R. Silva" <garsilva@embeddedor.com> |
|---|---|
| Date | 2017-05-22 17:00 +0200 |
| Message-ID | <tJWYq-6XB-19@gated-at.bofh.it> |
| In reply to | #1646990 |
Hi David, Quoting David Miller <davem@davemloft.net>: > From: "Gustavo A. R. Silva" <garsilva@embeddedor.com> > Date: Mon, 22 May 2017 09:07:46 -0500 > >> Execution cannot reach NET_IP_ALIGN inside the following statement: >> ip_align = strict ? 2 : NET_IP_ALIGN >> >> Addresses-Coverity-ID: 1409762 >> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com> >> --- >> NOTE: variable ip_align could also be removed and use value 2 directly. > > Incorrect. > > Some platforms define NET_IP_ALIGN to zero, so the code must remain > as is. The following piece of code at kernel/bpf/verifier.c:798 is preventing value NET_IP_ALIGN to be stored in variable ip_align when _strict_ is false: 798 if (!strict || size == 1) 799 return 0; Thanks -- Gustavo A. R. Silva
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web