From: Dan Carpenter <dan.carpenter@oracle.com>
To: kernel-janitors@vger.kernel.org
Subject: [patch 2/2] Staging: silicom: use kstrtoint_from_user()
Date: Fri, 14 Sep 2012 08:11:35 +0000 [thread overview]
Message-ID: <20120914081135.GA11315@elgon.mountain> (raw)
The main problem with the hand rolled code was that there weren't any
range checks so you could corrupt memory by writing too much data to
the proc file.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/drivers/staging/silicom/bp_mod.c b/drivers/staging/silicom/bp_mod.c
index 1b3f5e7..f138d29 100644
--- a/drivers/staging/silicom/bp_mod.c
+++ b/drivers/staging/silicom/bp_mod.c
@@ -8071,20 +8071,13 @@ int
set_bypass_wd_pfs(struct file *file, const char *buffer,
unsigned long count, void *data)
{
-
- char kbuf[256];
bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
+ int timeout;
+ int ret;
- unsigned int timeout = 0;
- char *timeout_ptr = kbuf;
-
- if (copy_from_user(&kbuf, buffer, count)) {
- return -1;
- }
-
- timeout_ptr = kbuf;
- timeout = atoi(&timeout_ptr);
-
+ ret = kstrtoint_from_user(buffer, count, 10, &timeout);
+ if (ret)
+ return ret;
set_bypass_wd_fn(pbp_device_block, timeout);
return count;
@@ -8712,18 +8705,13 @@ int
set_wd_autoreset_pfs(struct file *file, const char *buffer,
unsigned long count, void *data)
{
- char kbuf[256];
bpctl_dev_t *pbp_device_block = (bpctl_dev_t *) data;
- u32 timeout = 0;
- char *timeout_ptr = kbuf;
-
- if (copy_from_user(&kbuf, buffer, count)) {
- return -1;
- }
-
- timeout_ptr = kbuf;
- timeout = atoi(&timeout_ptr);
+ int timeout;
+ int ret;
+ ret = kstrtoint_from_user(buffer, count, 10, &timeout);
+ if (ret)
+ return ret;
set_wd_autoreset_fn(pbp_device_block, timeout);
return count;
reply other threads:[~2012-09-14 8:11 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20120914081135.GA11315@elgon.mountain \
--to=dan.carpenter@oracle.com \
--cc=kernel-janitors@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