Skip to contentSkip to conversation

tools/libbpf: signedness bug in btf_dedup_ref_type()

PATCH Superseded Dan Carpenter 6 participants 10 messages Feb 28, 2019 – Mar 1, 2019

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/libbpf: signedness bug in btf_dedup_ref_type()

The "ref_type_id" variable needs to be signed for the error handling to work.

Fixes d5caef5b5655 ("btf: add BTF types deduplication algorithm")

---
This goes through the BPF tree probably, although it does apply to net-next.

 tools/lib/bpf/btf.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/lib/bpf/btf.c +2 -1
index 68b50e9bbde1..8faed5386124 100644
@@ -2326,7 +2326,8 @@ static int btf_dedup_ref_type(struct btf_dedup *d, __u32 type_id)
 	struct btf_type *t, *cand;
 	/* if we don't find equivalent type, then we are representative type */
 	__u32 new_id = type_id;
-	__u32 h, ref_type_id;
+	__u32 h;
+	int ref_type_id;
 
 	if (d->map[type_id] = BTF_IN_PROGRESS_ID)
 		return -ELOOP;
Signature · 1 line
2.17.1
#1 lore raw

DQoNCk9uIDIvMjcvMTkgOTo0NiBQTSwgRGFuIENhcnBlbnRlciB3cm90ZToNCj4gVGhlICJyZWZf dHlwZV9pZCIgdmFyaWFibGUgbmVlZHMgdG8gYmUgc2lnbmVkIGZvciB0aGUgZXJyb3IgaGFuZGxp bmcNCj4gdG8gd29yay4NCj4gDQo+IEZpeGVzOiBkNWNhZWY1YjU2NTUgKCJidGY6IGFkZCBCVEYg dHlwZXMgZGVkdXBsaWNhdGlvbiBhbGdvcml0aG0iKQ0KPiBTaWduZWQtb2ZmLWJ5OiBEYW4gQ2Fy cGVudGVyIDxkYW4uY2FycGVudGVyQG9yYWNsZS5jb20+DQo+IC0tLQ0KPiBUaGlzIGdvZXMgdGhy b3VnaCB0aGUgQlBGIHRyZWUgcHJvYmFibHksIGFsdGhvdWdoIGl0IGRvZXMgYXBwbHkgdG8NCj4g bmV0LW5leHQuDQo+IA0KPiAgIHRvb2xzL2xpYi9icGY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be signed for the error handling to work.

Fixes d5caef5b5655 ("btf: add BTF types deduplication algorithm")

---
This goes through the BPF tree probably, although it does apply to net-next.

  tools/lib/bpf/btf.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
tools/lib/bpf/btf.c +0 -0
index 68b50e9bbde1..8faed5386124 100644

tools/lib/bpf/btf.c static int btf_dedup_ref_type(struct btf_dedup *d, __u32 type_id) · line 2329

Quoted 5 lines
tools/lib/bpf/btf.c +1 -1
@@ -2326,7 +2326,8 @@ static int btf_dedup_ref_type(struct btf_dedup *d, __u32 type_id)
  	struct btf_type *t, *cand;
  	/* if we don't find equivalent type, then we are representative type */
  	__u32 new_id = type_id;
-	__u32 h, ref_type_id;
+	__u32 h; > +	int ref_type_id;

nit. Maybe you can change to

Quoted 4 lines
	int ref_type_id;
	__u32 h;

to maintain kernel declaration reverse christmas tree convention?

Yes. Thanks. Let me resend.

regards,
dan carpenter

#3 lore raw
Quoted 34 lines · Dan Carpenter
Quoted 27 lines · Yonghong Song
Quoted 17 lines · Dan Carpenter

The "ref_type_id" variable needs to be signed for the error handling to work.

Fixes d5caef5b5655 ("btf: add BTF types deduplication algorithm")

---
This goes through the BPF tree probably, although it does apply to net-next.

  tools/lib/bpf/btf.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
tools/lib/bpf/btf.c +0 -0
index 68b50e9bbde1..8faed5386124 100644

tools/lib/bpf/btf.c static int btf_dedup_ref_type(struct btf_dedup *d, __u32 type_id) · line 2329

Quoted 5 lines
tools/lib/bpf/btf.c +1 -1
@@ -2326,7 +2326,8 @@ static int btf_dedup_ref_type(struct btf_dedup *d, __u32 type_id)
    struct btf_type *t, *cand;
    /* if we don't find equivalent type, then we are representative type */
    __u32 new_id = type_id;
-   __u32 h, ref_type_id;
+   __u32 h; > +    int ref_type_id;

nit. Maybe you can change to

Quoted 4 lines
      int ref_type_id;
      __u32 h;

to maintain kernel declaration reverse christmas tree convention?

Quoted 2 lines

Yes. Thanks. Let me resend.

Thanks for catching and fixing this! With Yonghong's suggestion, you can add:

Quoted 3 lines

regards,
dan carpenter

#4 lore raw

PATCH v2 1/1 tools/libbpf: signedness bug in btf_dedup_ref_type()

In reply to Yonghong Song

The "ref_type_id" variable needs to be signed for the error handling to work.

Fixes d5caef5b5655 ("btf: add BTF types deduplication algorithm")

---
v2: Use reverse Christmas tree style

This goes through the BPF tree probably, although it does apply to net-next.

 drivers/infiniband/ulp/iser/iscsi_iser.h | 2 +-
 tools/lib/bpf/btf.c                      | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/infiniband/ulp/iser/iscsi_iser.h +1 -1
index 120b40829560..ee7d3f6a666e 100644
@@ -197,7 +197,7 @@ struct iser_data_buf {
 	struct scatterlist *sg;
 	int                size;
 	unsigned long      data_len;
-	unsigned int       dma_nents;
+	int		   dma_nents;
 };
 
 /* fwd declarations */
tools/lib/bpf/btf.c +2 -1
index 68b50e9bbde1..00a2f06e38fd 100644
@@ -2326,7 +2326,8 @@ static int btf_dedup_ref_type(struct btf_dedup *d, __u32 type_id)
 	struct btf_type *t, *cand;
 	/* if we don't find equivalent type, then we are representative type */
 	__u32 new_id = type_id;
-	__u32 h, ref_type_id;
+	int ref_type_id;
+	__u32 h;
 
 	if (d->map[type_id] = BTF_IN_PROGRESS_ID)
 		return -ELOOP;
Signature · 1 line
2.17.1
#5 lore raw

Em Thu, Feb 28, 2019 at 08:50:35PM +0300, Dan Carpenter escreveu:

Quoted 2 lines

The "ref_type_id" variable needs to be signed for the error handling to work.

Does the infiniband signedness change comes as a bonus? :-)

- Arnaldo

Quoted 42 lines
Fixes d5caef5b5655 ("btf: add BTF types deduplication algorithm")

---
v2: Use reverse Christmas tree style

This goes through the BPF tree probably, although it does apply to net-next.

 drivers/infiniband/ulp/iser/iscsi_iser.h | 2 +-
 tools/lib/bpf/btf.c                      | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/infiniband/ulp/iser/iscsi_iser.h +1 -1
index 120b40829560..ee7d3f6a666e 100644
@@ -197,7 +197,7 @@ struct iser_data_buf {
 	struct scatterlist *sg;
 	int                size;
 	unsigned long      data_len;
-	unsigned int       dma_nents;
+	int		   dma_nents;
 };
 
 /* fwd declarations */
tools/lib/bpf/btf.c +2 -1
index 68b50e9bbde1..00a2f06e38fd 100644
@@ -2326,7 +2326,8 @@ static int btf_dedup_ref_type(struct btf_dedup *d, __u32 type_id)
 	struct btf_type *t, *cand;
 	/* if we don't find equivalent type, then we are representative type */
 	__u32 new_id = type_id;
-	__u32 h, ref_type_id;
+	int ref_type_id;
+	__u32 h;
 
 	if (d->map[type_id] = BTF_IN_PROGRESS_ID)
 		return -ELOOP;
Signature · 1 line
2.17.1
Signature · 1 line
- Arnaldo
#6 lore raw
Quoted 6 lines · Arnaldo Carvalho de Melo

Em Thu, Feb 28, 2019 at 08:50:35PM +0300, Dan Carpenter escreveu:

Quoted 2 lines

The "ref_type_id" variable needs to be signed for the error handling to work.

Does the infiniband signedness change comes as a bonus? :-)

Oh wow... :P

Let me resend v3.

regards,
dan carpenter

#7 lore raw

PATCH v3 1/1 tools/libbpf: signedness bug in btf_dedup_ref_type()

In reply to Yonghong Song

The "ref_type_id" variable needs to be signed for the error handling to work.

Fixes d5caef5b5655 ("btf: add BTF types deduplication algorithm")

---
v2: Use reverse Christmas tree style
v3: Remove the bonus fix.

This goes through the BPF tree probably, although it does apply to net-next.

 tools/lib/bpf/btf.c                      | 3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
tools/lib/bpf/btf.c +2 -1
index 68b50e9bbde1..00a2f06e38fd 100644
@@ -2326,7 +2326,8 @@ static int btf_dedup_ref_type(struct btf_dedup *d, __u32 type_id)
 	struct btf_type *t, *cand;
 	/* if we don't find equivalent type, then we are representative type */
 	__u32 new_id = type_id;
-	__u32 h, ref_type_id;
+	int ref_type_id;
+	__u32 h;
 
 	if (d->map[type_id] = BTF_IN_PROGRESS_ID)
 		return -ELOOP;
Signature · 1 line
2.17.1
Acked-by on v3 1/1
#8 lore raw
Quoted 10 lines · Dan Carpenter

The "ref_type_id" variable needs to be signed for the error handling to work.

Fixes d5caef5b5655 ("btf: add BTF types deduplication algorithm")
Quoted 26 lines

---
v2: Use reverse Christmas tree style
v3: Remove the bonus fix.

This goes through the BPF tree probably, although it does apply to net-next.

tools/lib/bpf/btf.c | 3 ++-

1 files changed, 2 insertions(+), 1 deletions(-)
tools/lib/bpf/btf.c +2 -1
index 68b50e9bbde1..00a2f06e38fd 100644
@@ -2326,7 +2326,8 @@ static int btf_dedup_ref_type(struct btf_dedup *d, __u32 type_id)
 	struct btf_type *t, *cand;
 	/* if we don't find equivalent type, then we are representative type */
 	__u32 new_id = type_id;
-	__u32 h, ref_type_id;
+	int ref_type_id;
+	__u32 h;
 
 	if (d->map[type_id] == BTF_IN_PROGRESS_ID)
 		return -ELOOP;
Signature · 1 line
2.17.1