From: Xi Wang <xi.wang@gmail.com>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Tom Herbert <therbert@google.com>,
"David S. Miller" <davem@davemloft.net>,
netdev@vger.kernel.org
Subject: [PATCH v2] rps: fix insufficient bounds checking in store_rps_dev_flow_table_cnt()
Date: Thu, 22 Dec 2011 18:35:22 -0500 [thread overview]
Message-ID: <4EF3BEBA.4040402@gmail.com> (raw)
In-Reply-To: <1324493459-19764-1-git-send-email-xi.wang@gmail.com>
Setting a large rps_flow_cnt like (1 << 30) on 32-bit platform will
cause a kernel oops due to insufficient bounds checking.
if (count > 1<<30) {
/* Enforce a limit to prevent overflow */
return -EINVAL;
}
count = roundup_pow_of_two(count);
table = vmalloc(RPS_DEV_FLOW_TABLE_SIZE(count));
Note that the macro RPS_DEV_FLOW_TABLE_SIZE(count) is defined as:
... + (count * sizeof(struct rps_dev_flow))
where sizeof(struct rps_dev_flow) is 8. (1 << 30) * 8 will overflow
32 bits.
This patch replaces the magic number (1 << 30) with a symbolic bound.
Suggested-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: Xi Wang <xi.wang@gmail.com>
---
net/core/net-sysfs.c | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index c71c434..385aefe 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -665,11 +665,14 @@ static ssize_t store_rps_dev_flow_table_cnt(struct netdev_rx_queue *queue,
if (count) {
int i;
- if (count > 1<<30) {
+ if (count > INT_MAX)
+ return -EINVAL;
+ count = roundup_pow_of_two(count);
+ if (count > (ULONG_MAX - sizeof(struct rps_dev_flow_table))
+ / sizeof(struct rps_dev_flow)) {
/* Enforce a limit to prevent overflow */
return -EINVAL;
}
- count = roundup_pow_of_two(count);
table = vmalloc(RPS_DEV_FLOW_TABLE_SIZE(count));
if (!table)
return -ENOMEM;
--
1.7.5.4
next prev parent reply other threads:[~2011-12-22 23:35 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-21 18:50 [PATCH] rps: fix insufficient bounds checking in store_rps_dev_flow_table_cnt() Xi Wang
2011-12-21 19:22 ` Eric Dumazet
2011-12-21 19:41 ` David Miller
2011-12-21 23:41 ` Xi Wang
2011-12-22 23:35 ` Xi Wang [this message]
2011-12-23 3:37 ` [PATCH v2] " David Miller
2011-12-23 4:10 ` Eric Dumazet
2011-12-23 4:44 ` Xi Wang
2011-12-23 4:53 ` Eric Dumazet
2011-12-23 5:10 ` Xi Wang
2011-12-23 5:16 ` Eric Dumazet
2011-12-23 5:35 ` Eric Dumazet
2011-12-23 5:56 ` Xi Wang
2011-12-23 13:06 ` Eric Dumazet
2011-12-23 14:30 ` Xi Wang
2011-12-23 14:53 ` Eric Dumazet
2011-12-23 15:07 ` Xi Wang
2011-12-24 16:56 ` [PATCH net-next] rfs: better sizing of dev_flow_table Eric Dumazet
2011-12-24 21:19 ` David Miller
2011-12-23 5:49 ` [PATCH v2] rps: fix insufficient bounds checking in store_rps_dev_flow_table_cnt() Xi Wang
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=4EF3BEBA.4040402@gmail.com \
--to=xi.wang@gmail.com \
--cc=davem@davemloft.net \
--cc=eric.dumazet@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=therbert@google.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;
as well as URLs for NNTP newsgroup(s).