From: Gaurav Singh <gaurav1086@gmail.com>
To: gaurav1086@gmail.com, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Jesper Dangaard Brouer <hawk@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
Yonghong Song <yhs@fb.com>, Andrii Nakryiko <andriin@fb.com>,
KP Singh <kpsingh@chromium.org>,
netdev@vger.kernel.org (open list:XDP (eXpress Data Path)),
bpf@vger.kernel.org (open list:XDP (eXpress Data Path)),
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH] xdp_rxq_info_user: Add null check after malloc
Date: Tue, 9 Jun 2020 23:01:36 -0400 [thread overview]
Message-ID: <20200610030145.17263-1-gaurav1086@gmail.com> (raw)
Signed-off-by: Gaurav Singh <gaurav1086@gmail.com>
The memset call is made right after malloc call which
can return a NULL pointer upon failure causing a
segmentation fault. Fix this by adding a null check
right after malloc() and then do memset().
---
samples/bpf/xdp_rxq_info_user.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/samples/bpf/xdp_rxq_info_user.c b/samples/bpf/xdp_rxq_info_user.c
index 4fe47502ebed..2d03c84a4cca 100644
--- a/samples/bpf/xdp_rxq_info_user.c
+++ b/samples/bpf/xdp_rxq_info_user.c
@@ -202,11 +202,11 @@ static struct datarec *alloc_record_per_cpu(void)
size = sizeof(struct datarec) * nr_cpus;
array = malloc(size);
- memset(array, 0, size);
if (!array) {
fprintf(stderr, "Mem alloc error (nr_cpus:%u)\n", nr_cpus);
exit(EXIT_FAIL_MEM);
}
+ memset(array, 0, size);
return array;
}
@@ -218,11 +218,11 @@ static struct record *alloc_record_per_rxq(void)
size = sizeof(struct record) * nr_rxqs;
array = malloc(size);
- memset(array, 0, size);
if (!array) {
fprintf(stderr, "Mem alloc error (nr_rxqs:%u)\n", nr_rxqs);
exit(EXIT_FAIL_MEM);
}
+ memset(array, 0, size);
return array;
}
@@ -233,11 +233,11 @@ static struct stats_record *alloc_stats_record(void)
int i;
rec = malloc(sizeof(*rec));
- memset(rec, 0, sizeof(*rec));
if (!rec) {
fprintf(stderr, "Mem alloc error\n");
exit(EXIT_FAIL_MEM);
}
+ memset(rec, 0, sizeof(*rec));
rec->rxq = alloc_record_per_rxq();
for (i = 0; i < nr_rxqs; i++)
rec->rxq[i].cpu = alloc_record_per_cpu();
--
2.17.1
next reply other threads:[~2020-06-10 3:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-10 3:01 Gaurav Singh [this message]
2020-06-11 14:12 ` Daniel Borkmann
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=20200610030145.17263-1-gaurav1086@gmail.com \
--to=gaurav1086@gmail.com \
--cc=andriin@fb.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=hawk@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@chromium.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=songliubraving@fb.com \
--cc=yhs@fb.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®