netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tools/bpftool: silence a static check warning
@ 2018-01-15  8:15 Dan Carpenter
  2018-01-15 10:35 ` Daniel Borkmann
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2018-01-15  8:15 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann; +Cc: netdev, kernel-janitors

There is a static checker warning that proglen has an upper bound but no
lower bound.  The allocation will just fail harmlessly so it's not a big
deal.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/tools/bpf/bpf_jit_disasm.c b/tools/bpf/bpf_jit_disasm.c
index 30044bc4f389..2d7bb5dc0b8c 100644
--- a/tools/bpf/bpf_jit_disasm.c
+++ b/tools/bpf/bpf_jit_disasm.c
@@ -205,7 +205,7 @@ static uint8_t *get_last_jit_image(char *haystack, size_t hlen,
 		regfree(&regex);
 		return NULL;
 	}
-	if (proglen > 1000000) {
+	if (proglen < 0 || proglen > 1000000) {
 		printf("proglen of %d too big, stopping\n", proglen);
 		return NULL;
 	}

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] tools/bpftool: silence a static check warning
  2018-01-15  8:15 [PATCH] tools/bpftool: silence a static check warning Dan Carpenter
@ 2018-01-15 10:35 ` Daniel Borkmann
  2018-01-18  9:35   ` [PATCH v2] tools/bpftool: silence a static checker warning Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Borkmann @ 2018-01-15 10:35 UTC (permalink / raw)
  To: Dan Carpenter, Alexei Starovoitov; +Cc: netdev, kernel-janitors

Hi Dan,

On 01/15/2018 09:15 AM, Dan Carpenter wrote:
> There is a static checker warning that proglen has an upper bound but no
> lower bound.  The allocation will just fail harmlessly so it's not a big
> deal.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> diff --git a/tools/bpf/bpf_jit_disasm.c b/tools/bpf/bpf_jit_disasm.c
> index 30044bc4f389..2d7bb5dc0b8c 100644
> --- a/tools/bpf/bpf_jit_disasm.c
> +++ b/tools/bpf/bpf_jit_disasm.c
> @@ -205,7 +205,7 @@ static uint8_t *get_last_jit_image(char *haystack, size_t hlen,
>  		regfree(&regex);
>  		return NULL;
>  	}
> -	if (proglen > 1000000) {
> +	if (proglen < 0 || proglen > 1000000) {

Could you just change proglen into unsigned? It's parsing the bpf_jit_dump()
and there we use proglen=%u anyway.

>  		printf("proglen of %d too big, stopping\n", proglen);
>  		return NULL;
>  	}
> 

Thanks,
Daniel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] tools/bpftool: silence a static checker warning
  2018-01-15 10:35 ` Daniel Borkmann
@ 2018-01-18  9:35   ` Dan Carpenter
  2018-01-18 21:23     ` Daniel Borkmann
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2018-01-18  9:35 UTC (permalink / raw)
  To: Alexei Starovoitov; +Cc: Daniel Borkmann, netdev, kernel-janitors

There is a static checker warning that "proglen" has an upper bound but
no lower bound.  The allocation will just fail harmlessly so it's not a
big deal.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2: change the type to unsigned instead of checking for negatives

diff --git a/tools/bpf/bpf_jit_disasm.c b/tools/bpf/bpf_jit_disasm.c
index 30044bc4f389..58c2bab4ef6e 100644
--- a/tools/bpf/bpf_jit_disasm.c
+++ b/tools/bpf/bpf_jit_disasm.c
@@ -172,7 +172,8 @@ static uint8_t *get_last_jit_image(char *haystack, size_t hlen,
 {
 	char *ptr, *pptr, *tmp;
 	off_t off = 0;
-	int ret, flen, proglen, pass, ulen = 0;
+	unsigned int proglen;
+	int ret, flen, pass, ulen = 0;
 	regmatch_t pmatch[1];
 	unsigned long base;
 	regex_t regex;
@@ -199,7 +200,7 @@ static uint8_t *get_last_jit_image(char *haystack, size_t hlen,
 	}
 
 	ptr = haystack + off - (pmatch[0].rm_eo - pmatch[0].rm_so);
-	ret = sscanf(ptr, "flen=%d proglen=%d pass=%d image=%lx",
+	ret = sscanf(ptr, "flen=%d proglen=%u pass=%d image=%lx",
 		     &flen, &proglen, &pass, &base);
 	if (ret != 4) {
 		regfree(&regex);
@@ -239,7 +240,7 @@ static uint8_t *get_last_jit_image(char *haystack, size_t hlen,
 	}
 
 	assert(ulen == proglen);
-	printf("%d bytes emitted from JIT compiler (pass:%d, flen:%d)\n",
+	printf("%u bytes emitted from JIT compiler (pass:%d, flen:%d)\n",
 	       proglen, pass, flen);
 	printf("%lx + <x>:\n", base);
 

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] tools/bpftool: silence a static checker warning
  2018-01-18  9:35   ` [PATCH v2] tools/bpftool: silence a static checker warning Dan Carpenter
@ 2018-01-18 21:23     ` Daniel Borkmann
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Borkmann @ 2018-01-18 21:23 UTC (permalink / raw)
  To: Dan Carpenter, Alexei Starovoitov; +Cc: netdev, kernel-janitors

On 01/18/2018 10:35 AM, Dan Carpenter wrote:
> There is a static checker warning that "proglen" has an upper bound but
> no lower bound.  The allocation will just fail harmlessly so it's not a
> big deal.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Applied to bpf-next, thanks Dan! (I changed the prefix from 'tools/bpftool'
into 'tools/bpf_jit_disasm' since it's not touching bpftool here.)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-01-18 21:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-15  8:15 [PATCH] tools/bpftool: silence a static check warning Dan Carpenter
2018-01-15 10:35 ` Daniel Borkmann
2018-01-18  9:35   ` [PATCH v2] tools/bpftool: silence a static checker warning Dan Carpenter
2018-01-18 21:23     ` Daniel Borkmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).