From: Tobias Klauser <tklauser@distanz.ch>
To: "David S. Miller" <davem@davemloft.net>,
Daniel Borkmann <dborkman@redhat.com>,
Alexei Starovoitov <ast@plumgrid.com>
Cc: netdev@vger.kernel.org
Subject: [PATCH] net: filter: Use kcalloc/kmalloc_array to allocate arrays
Date: Tue, 24 Jun 2014 15:33:22 +0200 [thread overview]
Message-ID: <1403616802-25743-3-git-send-email-tklauser@distanz.ch> (raw)
In-Reply-To: <1403616802-25743-1-git-send-email-tklauser@distanz.ch>
Use kcalloc/kmalloc_array to make it clear we're allocating arrays. No
integer overflow can actually happen here, since len/flen is guaranteed
to be less than BPF_MAXINSNS (4096). However, this changed makes sure
we're not going to get one if BPF_MAXINSNS were ever increased.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
---
net/core/filter.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/core/filter.c b/net/core/filter.c
index ed8d929..e44c1c4 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -844,7 +844,7 @@ int sk_convert_filter(struct sock_filter *prog, int len,
return -EINVAL;
if (new_prog) {
- addrs = kzalloc(len * sizeof(*addrs), GFP_KERNEL);
+ addrs = kcalloc(len, sizeof(*addrs), GFP_KERNEL);
if (!addrs)
return -ENOMEM;
}
@@ -1101,7 +1101,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)
BUILD_BUG_ON(BPF_MEMWORDS > 16);
- masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
+ masks = kmalloc_array(flen, sizeof(*masks), GFP_KERNEL);
if (!masks)
return -ENOMEM;
--
1.7.9.5
next prev parent reply other threads:[~2014-06-24 13:34 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-24 13:33 [PATCH] trivial: net: filter: Fix typo in comment Tobias Klauser
2014-06-24 13:33 ` [PATCH] trivial: net: filter: Change kerneldoc parameter order Tobias Klauser
2014-06-24 13:42 ` Daniel Borkmann
2014-06-24 15:02 ` Alexei Starovoitov
2014-06-25 23:39 ` David Miller
2014-06-24 13:33 ` Tobias Klauser [this message]
2014-06-24 13:47 ` [PATCH] net: filter: Use kcalloc/kmalloc_array to allocate arrays Daniel Borkmann
2014-06-24 15:03 ` Alexei Starovoitov
2014-06-25 23:40 ` David Miller
2014-06-24 13:41 ` [PATCH] trivial: net: filter: Fix typo in comment Daniel Borkmann
2014-06-24 15:01 ` Alexei Starovoitov
2014-06-25 23:39 ` David Miller
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=1403616802-25743-3-git-send-email-tklauser@distanz.ch \
--to=tklauser@distanz.ch \
--cc=ast@plumgrid.com \
--cc=davem@davemloft.net \
--cc=dborkman@redhat.com \
--cc=netdev@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).