Commit 1404297e authored by Kees Cook's avatar Kees Cook Committed by Linus Torvalds

lib: update single-char callers of strtobool()

Some callers of strtobool() were passing a pointer to unterminated
strings.  In preparation of adding multi-character processing to
kstrtobool(), update the callers to not pass single-character pointers,
and switch to using the new kstrtobool_from_user() helper where
possible.
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Cc: Amitkumar Karwar <akarwar@marvell.com>
Cc: Nishant Sarmukadam <nishants@marvell.com>
Cc: Kalle Valo <kvalo@codeaurora.org>
Cc: Steve French <sfrench@samba.org>
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Joe Perches <joe@perches.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent ef951599
...@@ -880,14 +880,12 @@ mwifiex_reset_write(struct file *file, ...@@ -880,14 +880,12 @@ mwifiex_reset_write(struct file *file,
{ {
struct mwifiex_private *priv = file->private_data; struct mwifiex_private *priv = file->private_data;
struct mwifiex_adapter *adapter = priv->adapter; struct mwifiex_adapter *adapter = priv->adapter;
char cmd;
bool result; bool result;
int rc;
if (copy_from_user(&cmd, ubuf, sizeof(cmd))) rc = kstrtobool_from_user(ubuf, count, &result);
return -EFAULT; if (rc)
return rc;
if (strtobool(&cmd, &result))
return -EINVAL;
if (!result) if (!result)
return -EINVAL; return -EINVAL;
......
...@@ -255,7 +255,6 @@ static const struct file_operations cifs_debug_data_proc_fops = { ...@@ -255,7 +255,6 @@ static const struct file_operations cifs_debug_data_proc_fops = {
static ssize_t cifs_stats_proc_write(struct file *file, static ssize_t cifs_stats_proc_write(struct file *file,
const char __user *buffer, size_t count, loff_t *ppos) const char __user *buffer, size_t count, loff_t *ppos)
{ {
char c;
bool bv; bool bv;
int rc; int rc;
struct list_head *tmp1, *tmp2, *tmp3; struct list_head *tmp1, *tmp2, *tmp3;
...@@ -263,11 +262,8 @@ static ssize_t cifs_stats_proc_write(struct file *file, ...@@ -263,11 +262,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
struct cifs_ses *ses; struct cifs_ses *ses;
struct cifs_tcon *tcon; struct cifs_tcon *tcon;
rc = get_user(c, buffer); rc = kstrtobool_from_user(buffer, count, &bv);
if (rc) if (rc == 0) {
return rc;
if (strtobool(&c, &bv) == 0) {
#ifdef CONFIG_CIFS_STATS2 #ifdef CONFIG_CIFS_STATS2
atomic_set(&totBufAllocCount, 0); atomic_set(&totBufAllocCount, 0);
atomic_set(&totSmBufAllocCount, 0); atomic_set(&totSmBufAllocCount, 0);
...@@ -290,6 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file, ...@@ -290,6 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
} }
} }
spin_unlock(&cifs_tcp_ses_lock); spin_unlock(&cifs_tcp_ses_lock);
} else {
return rc;
} }
return count; return count;
...@@ -433,17 +431,17 @@ static int cifsFYI_proc_open(struct inode *inode, struct file *file) ...@@ -433,17 +431,17 @@ static int cifsFYI_proc_open(struct inode *inode, struct file *file)
static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer, static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
char c; char c[2] = { '\0' };
bool bv; bool bv;
int rc; int rc;
rc = get_user(c, buffer); rc = get_user(c[0], buffer);
if (rc) if (rc)
return rc; return rc;
if (strtobool(&c, &bv) == 0) if (strtobool(c, &bv) == 0)
cifsFYI = bv; cifsFYI = bv;
else if ((c > '1') && (c <= '9')) else if ((c[0] > '1') && (c[0] <= '9'))
cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */ cifsFYI = (int) (c[0] - '0'); /* see cifs_debug.h for meanings */
return count; return count;
} }
...@@ -471,20 +469,12 @@ static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file) ...@@ -471,20 +469,12 @@ static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
static ssize_t cifs_linux_ext_proc_write(struct file *file, static ssize_t cifs_linux_ext_proc_write(struct file *file,
const char __user *buffer, size_t count, loff_t *ppos) const char __user *buffer, size_t count, loff_t *ppos)
{ {
char c;
bool bv;
int rc; int rc;
rc = get_user(c, buffer); rc = kstrtobool_from_user(buffer, count, &linuxExtEnabled);
if (rc) if (rc)
return rc; return rc;
rc = strtobool(&c, &bv);
if (rc)
return rc;
linuxExtEnabled = bv;
return count; return count;
} }
...@@ -511,20 +501,12 @@ static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file) ...@@ -511,20 +501,12 @@ static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
static ssize_t cifs_lookup_cache_proc_write(struct file *file, static ssize_t cifs_lookup_cache_proc_write(struct file *file,
const char __user *buffer, size_t count, loff_t *ppos) const char __user *buffer, size_t count, loff_t *ppos)
{ {
char c;
bool bv;
int rc; int rc;
rc = get_user(c, buffer); rc = kstrtobool_from_user(buffer, count, &lookupCacheEnabled);
if (rc) if (rc)
return rc; return rc;
rc = strtobool(&c, &bv);
if (rc)
return rc;
lookupCacheEnabled = bv;
return count; return count;
} }
...@@ -551,20 +533,12 @@ static int traceSMB_proc_open(struct inode *inode, struct file *file) ...@@ -551,20 +533,12 @@ static int traceSMB_proc_open(struct inode *inode, struct file *file)
static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer, static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
char c;
bool bv;
int rc; int rc;
rc = get_user(c, buffer); rc = kstrtobool_from_user(buffer, count, &traceSMB);
if (rc) if (rc)
return rc; return rc;
rc = strtobool(&c, &bv);
if (rc)
return rc;
traceSMB = bv;
return count; return count;
} }
...@@ -622,7 +596,6 @@ static ssize_t cifs_security_flags_proc_write(struct file *file, ...@@ -622,7 +596,6 @@ static ssize_t cifs_security_flags_proc_write(struct file *file,
int rc; int rc;
unsigned int flags; unsigned int flags;
char flags_string[12]; char flags_string[12];
char c;
bool bv; bool bv;
if ((count < 1) || (count > 11)) if ((count < 1) || (count > 11))
...@@ -635,11 +608,10 @@ static ssize_t cifs_security_flags_proc_write(struct file *file, ...@@ -635,11 +608,10 @@ static ssize_t cifs_security_flags_proc_write(struct file *file,
if (count < 3) { if (count < 3) {
/* single char or single char followed by null */ /* single char or single char followed by null */
c = flags_string[0]; if (strtobool(flags_string, &bv) == 0) {
if (strtobool(&c, &bv) == 0) {
global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF; global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF;
return count; return count;
} else if (!isdigit(c)) { } else if (!isdigit(flags_string[0])) {
cifs_dbg(VFS, "Invalid SecurityFlags: %s\n", cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
flags_string); flags_string);
return -EINVAL; return -EINVAL;
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
void cifs_dump_mem(char *label, void *data, int length); void cifs_dump_mem(char *label, void *data, int length);
void cifs_dump_detail(void *); void cifs_dump_detail(void *);
void cifs_dump_mids(struct TCP_Server_Info *); void cifs_dump_mids(struct TCP_Server_Info *);
extern int traceSMB; /* flag which enables the function below */ extern bool traceSMB; /* flag which enables the function below */
void dump_smb(void *, int); void dump_smb(void *, int);
#define CIFS_INFO 0x01 #define CIFS_INFO 0x01
#define CIFS_RC 0x02 #define CIFS_RC 0x02
......
...@@ -54,10 +54,10 @@ ...@@ -54,10 +54,10 @@
#endif #endif
int cifsFYI = 0; int cifsFYI = 0;
int traceSMB = 0; bool traceSMB;
bool enable_oplocks = true; bool enable_oplocks = true;
unsigned int linuxExtEnabled = 1; bool linuxExtEnabled = true;
unsigned int lookupCacheEnabled = 1; bool lookupCacheEnabled = true;
unsigned int global_secflags = CIFSSEC_DEF; unsigned int global_secflags = CIFSSEC_DEF;
/* unsigned int ntlmv2_support = 0; */ /* unsigned int ntlmv2_support = 0; */
unsigned int sign_CIFS_PDUs = 1; unsigned int sign_CIFS_PDUs = 1;
......
...@@ -1596,11 +1596,11 @@ GLOBAL_EXTERN atomic_t midCount; ...@@ -1596,11 +1596,11 @@ GLOBAL_EXTERN atomic_t midCount;
/* Misc globals */ /* Misc globals */
GLOBAL_EXTERN bool enable_oplocks; /* enable or disable oplocks */ GLOBAL_EXTERN bool enable_oplocks; /* enable or disable oplocks */
GLOBAL_EXTERN unsigned int lookupCacheEnabled; GLOBAL_EXTERN bool lookupCacheEnabled;
GLOBAL_EXTERN unsigned int global_secflags; /* if on, session setup sent GLOBAL_EXTERN unsigned int global_secflags; /* if on, session setup sent
with more secure ntlmssp2 challenge/resp */ with more secure ntlmssp2 challenge/resp */
GLOBAL_EXTERN unsigned int sign_CIFS_PDUs; /* enable smb packet signing */ GLOBAL_EXTERN unsigned int sign_CIFS_PDUs; /* enable smb packet signing */
GLOBAL_EXTERN unsigned int linuxExtEnabled;/*enable Linux/Unix CIFS extensions*/ GLOBAL_EXTERN bool linuxExtEnabled;/*enable Linux/Unix CIFS extensions*/
GLOBAL_EXTERN unsigned int CIFSMaxBufSize; /* max size not including hdr */ GLOBAL_EXTERN unsigned int CIFSMaxBufSize; /* max size not including hdr */
GLOBAL_EXTERN unsigned int cifs_min_rcv; /* min size of big ntwrk buf pool */ GLOBAL_EXTERN unsigned int cifs_min_rcv; /* min size of big ntwrk buf pool */
GLOBAL_EXTERN unsigned int cifs_min_small; /* min size of small buf pool */ GLOBAL_EXTERN unsigned int cifs_min_small; /* min size of small buf pool */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment