diff mbox

kernel: bpf: remove dead code

Message ID 20170522140746.GA10113@embeddedgus
State Rejected, archived
Delegated to: David Miller
Headers show

Commit Message

Gustavo A. R. Silva May 22, 2017, 2:07 p.m. UTC
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(-)

Comments

David Miller May 22, 2017, 2:38 p.m. UTC | #1
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.
Gustavo A. R. Silva May 22, 2017, 2:51 p.m. UTC | #2
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
diff mbox

Patch

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