Skip to content

Commit 1404297

Browse files
keestorvalds
authored andcommitted
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: Kees 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: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent ef95159 commit 1404297

File tree

5 files changed

+24
-54
lines changed

5 files changed

+24
-54
lines changed

drivers/net/wireless/marvell/mwifiex/debugfs.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -880,14 +880,12 @@ mwifiex_reset_write(struct file *file,
880880
{
881881
struct mwifiex_private *priv = file->private_data;
882882
struct mwifiex_adapter *adapter = priv->adapter;
883-
char cmd;
884883
bool result;
884+
int rc;
885885

886-
if (copy_from_user(&cmd, ubuf, sizeof(cmd)))
887-
return -EFAULT;
888-
889-
if (strtobool(&cmd, &result))
890-
return -EINVAL;
886+
rc = kstrtobool_from_user(ubuf, count, &result);
887+
if (rc)
888+
return rc;
891889

892890
if (!result)
893891
return -EINVAL;

fs/cifs/cifs_debug.c

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -255,19 +255,15 @@ static const struct file_operations cifs_debug_data_proc_fops = {
255255
static ssize_t cifs_stats_proc_write(struct file *file,
256256
const char __user *buffer, size_t count, loff_t *ppos)
257257
{
258-
char c;
259258
bool bv;
260259
int rc;
261260
struct list_head *tmp1, *tmp2, *tmp3;
262261
struct TCP_Server_Info *server;
263262
struct cifs_ses *ses;
264263
struct cifs_tcon *tcon;
265264

266-
rc = get_user(c, buffer);
267-
if (rc)
268-
return rc;
269-
270-
if (strtobool(&c, &bv) == 0) {
265+
rc = kstrtobool_from_user(buffer, count, &bv);
266+
if (rc == 0) {
271267
#ifdef CONFIG_CIFS_STATS2
272268
atomic_set(&totBufAllocCount, 0);
273269
atomic_set(&totSmBufAllocCount, 0);
@@ -290,6 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
290286
}
291287
}
292288
spin_unlock(&cifs_tcp_ses_lock);
289+
} else {
290+
return rc;
293291
}
294292

295293
return count;
@@ -433,17 +431,17 @@ static int cifsFYI_proc_open(struct inode *inode, struct file *file)
433431
static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
434432
size_t count, loff_t *ppos)
435433
{
436-
char c;
434+
char c[2] = { '\0' };
437435
bool bv;
438436
int rc;
439437

440-
rc = get_user(c, buffer);
438+
rc = get_user(c[0], buffer);
441439
if (rc)
442440
return rc;
443-
if (strtobool(&c, &bv) == 0)
441+
if (strtobool(c, &bv) == 0)
444442
cifsFYI = bv;
445-
else if ((c > '1') && (c <= '9'))
446-
cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */
443+
else if ((c[0] > '1') && (c[0] <= '9'))
444+
cifsFYI = (int) (c[0] - '0'); /* see cifs_debug.h for meanings */
447445

448446
return count;
449447
}
@@ -471,20 +469,12 @@ static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
471469
static ssize_t cifs_linux_ext_proc_write(struct file *file,
472470
const char __user *buffer, size_t count, loff_t *ppos)
473471
{
474-
char c;
475-
bool bv;
476472
int rc;
477473

478-
rc = get_user(c, buffer);
474+
rc = kstrtobool_from_user(buffer, count, &linuxExtEnabled);
479475
if (rc)
480476
return rc;
481477

482-
rc = strtobool(&c, &bv);
483-
if (rc)
484-
return rc;
485-
486-
linuxExtEnabled = bv;
487-
488478
return count;
489479
}
490480

@@ -511,20 +501,12 @@ static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
511501
static ssize_t cifs_lookup_cache_proc_write(struct file *file,
512502
const char __user *buffer, size_t count, loff_t *ppos)
513503
{
514-
char c;
515-
bool bv;
516504
int rc;
517505

518-
rc = get_user(c, buffer);
506+
rc = kstrtobool_from_user(buffer, count, &lookupCacheEnabled);
519507
if (rc)
520508
return rc;
521509

522-
rc = strtobool(&c, &bv);
523-
if (rc)
524-
return rc;
525-
526-
lookupCacheEnabled = bv;
527-
528510
return count;
529511
}
530512

@@ -551,20 +533,12 @@ static int traceSMB_proc_open(struct inode *inode, struct file *file)
551533
static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
552534
size_t count, loff_t *ppos)
553535
{
554-
char c;
555-
bool bv;
556536
int rc;
557537

558-
rc = get_user(c, buffer);
538+
rc = kstrtobool_from_user(buffer, count, &traceSMB);
559539
if (rc)
560540
return rc;
561541

562-
rc = strtobool(&c, &bv);
563-
if (rc)
564-
return rc;
565-
566-
traceSMB = bv;
567-
568542
return count;
569543
}
570544

@@ -622,7 +596,6 @@ static ssize_t cifs_security_flags_proc_write(struct file *file,
622596
int rc;
623597
unsigned int flags;
624598
char flags_string[12];
625-
char c;
626599
bool bv;
627600

628601
if ((count < 1) || (count > 11))
@@ -635,11 +608,10 @@ static ssize_t cifs_security_flags_proc_write(struct file *file,
635608

636609
if (count < 3) {
637610
/* single char or single char followed by null */
638-
c = flags_string[0];
639-
if (strtobool(&c, &bv) == 0) {
611+
if (strtobool(flags_string, &bv) == 0) {
640612
global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF;
641613
return count;
642-
} else if (!isdigit(c)) {
614+
} else if (!isdigit(flags_string[0])) {
643615
cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
644616
flags_string);
645617
return -EINVAL;

fs/cifs/cifs_debug.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
void cifs_dump_mem(char *label, void *data, int length);
2626
void cifs_dump_detail(void *);
2727
void cifs_dump_mids(struct TCP_Server_Info *);
28-
extern int traceSMB; /* flag which enables the function below */
28+
extern bool traceSMB; /* flag which enables the function below */
2929
void dump_smb(void *, int);
3030
#define CIFS_INFO 0x01
3131
#define CIFS_RC 0x02

fs/cifs/cifsfs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@
5454
#endif
5555

5656
int cifsFYI = 0;
57-
int traceSMB = 0;
57+
bool traceSMB;
5858
bool enable_oplocks = true;
59-
unsigned int linuxExtEnabled = 1;
60-
unsigned int lookupCacheEnabled = 1;
59+
bool linuxExtEnabled = true;
60+
bool lookupCacheEnabled = true;
6161
unsigned int global_secflags = CIFSSEC_DEF;
6262
/* unsigned int ntlmv2_support = 0; */
6363
unsigned int sign_CIFS_PDUs = 1;

fs/cifs/cifsglob.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,11 +1596,11 @@ GLOBAL_EXTERN atomic_t midCount;
15961596

15971597
/* Misc globals */
15981598
GLOBAL_EXTERN bool enable_oplocks; /* enable or disable oplocks */
1599-
GLOBAL_EXTERN unsigned int lookupCacheEnabled;
1599+
GLOBAL_EXTERN bool lookupCacheEnabled;
16001600
GLOBAL_EXTERN unsigned int global_secflags; /* if on, session setup sent
16011601
with more secure ntlmssp2 challenge/resp */
16021602
GLOBAL_EXTERN unsigned int sign_CIFS_PDUs; /* enable smb packet signing */
1603-
GLOBAL_EXTERN unsigned int linuxExtEnabled;/*enable Linux/Unix CIFS extensions*/
1603+
GLOBAL_EXTERN bool linuxExtEnabled;/*enable Linux/Unix CIFS extensions*/
16041604
GLOBAL_EXTERN unsigned int CIFSMaxBufSize; /* max size not including hdr */
16051605
GLOBAL_EXTERN unsigned int cifs_min_rcv; /* min size of big ntwrk buf pool */
16061606
GLOBAL_EXTERN unsigned int cifs_min_small; /* min size of small buf pool */

0 commit comments

Comments
 (0)