All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <error27@gmail.com>
To: memxor@gmail.com
Cc: bpf@vger.kernel.org
Subject: [bug report] bpf: Refactor map->off_arr handling
Date: Tue, 15 Nov 2022 16:04:43 +0300	[thread overview]
Message-ID: <Y3OOa77Sn6GnyLvB@kili> (raw)

Hello Kumar Kartikeya Dwivedi,

The patch f71b2f64177a: "bpf: Refactor map->off_arr handling" from
Nov 4, 2022, leads to the following Smatch static checker warning:

	kernel/bpf/btf.c:3597 btf_parse_field_offs()
	warn: potential pointer math issue ('off' is a 32 bit pointer)

kernel/bpf/btf.c
    3580 struct btf_field_offs *btf_parse_field_offs(struct btf_record *rec)
    3581 {
    3582         struct btf_field_offs *foffs;
    3583         u32 i, *off;
    3584         u8 *sz;
    3585 
    3586         BUILD_BUG_ON(ARRAY_SIZE(foffs->field_off) != ARRAY_SIZE(foffs->field_sz));
    3587         if (IS_ERR_OR_NULL(rec) || WARN_ON_ONCE(rec->cnt > sizeof(foffs->field_off)))
                                                                    ^^^^^^^^^^^^^^^^^^^^^^^^
s/sizeof/ARRAY_SIZE/

    3588                 return NULL;
    3589 
    3590         foffs = kzalloc(sizeof(*foffs), GFP_KERNEL | __GFP_NOWARN);
    3591         if (!foffs)
    3592                 return ERR_PTR(-ENOMEM);
    3593 
    3594         off = foffs->field_off;
    3595         sz = foffs->field_sz;
    3596         for (i = 0; i < rec->cnt; i++) {
--> 3597                 off[i] = rec->fields[i].offset;
    3598                 sz[i] = btf_field_type_size(rec->fields[i].type);
    3599         }
    3600         foffs->cnt = rec->cnt;
    3601 
    3602         if (foffs->cnt == 1)
    3603                 return foffs;
    3604         sort_r(foffs->field_off, foffs->cnt, sizeof(foffs->field_off[0]),
    3605                btf_field_offs_cmp, btf_field_offs_swap, foffs);
    3606         return foffs;
    3607 }

regards,
dan carpenter

             reply	other threads:[~2022-11-15 13:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-15 13:04 Dan Carpenter [this message]
2022-11-15 16:45 ` [bug report] bpf: Refactor map->off_arr handling Kumar Kartikeya Dwivedi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y3OOa77Sn6GnyLvB@kili \
    --to=error27@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=memxor@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.