Skip to content

Commit cb79f19

Browse files
Al Viroteigland
authored andcommitted
dlm: dlm/user.c input validation fixes
a) in device_write(): add sentinel NUL byte, making sure that lspace.name will be NUL-terminated b) in compat_input() be keep it simple about the amounts of data we are copying. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: David Teigland <teigland@redhat.com>
1 parent 043b19c commit cb79f19

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

‎fs/dlm/user.c‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ struct dlm_lock_result32 {
8282

8383
static void compat_input(struct dlm_write_request *kb,
8484
struct dlm_write_request32 *kb32,
85-
int max_namelen)
85+
size_t count)
8686
{
8787
kb->version[0] = kb32->version[0];
8888
kb->version[1] = kb32->version[1];
@@ -94,7 +94,8 @@ static void compat_input(struct dlm_write_request *kb,
9494
kb->cmd == DLM_USER_REMOVE_LOCKSPACE) {
9595
kb->i.lspace.flags = kb32->i.lspace.flags;
9696
kb->i.lspace.minor = kb32->i.lspace.minor;
97-
strcpy(kb->i.lspace.name, kb32->i.lspace.name);
97+
memcpy(kb->i.lspace.name, kb32->i.lspace.name, count -
98+
offsetof(struct dlm_write_request32, i.lspace.name));
9899
} else if (kb->cmd == DLM_USER_PURGE) {
99100
kb->i.purge.nodeid = kb32->i.purge.nodeid;
100101
kb->i.purge.pid = kb32->i.purge.pid;
@@ -112,11 +113,8 @@ static void compat_input(struct dlm_write_request *kb,
112113
kb->i.lock.bastaddr = (void *)(long)kb32->i.lock.bastaddr;
113114
kb->i.lock.lksb = (void *)(long)kb32->i.lock.lksb;
114115
memcpy(kb->i.lock.lvb, kb32->i.lock.lvb, DLM_USER_LVB_LEN);
115-
if (kb->i.lock.namelen <= max_namelen)
116-
memcpy(kb->i.lock.name, kb32->i.lock.name,
117-
kb->i.lock.namelen);
118-
else
119-
kb->i.lock.namelen = max_namelen;
116+
memcpy(kb->i.lock.name, kb32->i.lock.name, count -
117+
offsetof(struct dlm_write_request32, i.lock.name));
120118
}
121119
}
122120

@@ -508,7 +506,7 @@ static ssize_t device_write(struct file *file, const char __user *buf,
508506
#endif
509507
return -EINVAL;
510508

511-
kbuf = kmalloc(count, GFP_KERNEL);
509+
kbuf = kzalloc(count + 1, GFP_KERNEL);
512510
if (!kbuf)
513511
return -ENOMEM;
514512

@@ -526,15 +524,14 @@ static ssize_t device_write(struct file *file, const char __user *buf,
526524
if (!kbuf->is64bit) {
527525
struct dlm_write_request32 *k32buf;
528526
k32buf = (struct dlm_write_request32 *)kbuf;
529-
kbuf = kmalloc(count + (sizeof(struct dlm_write_request) -
527+
kbuf = kmalloc(count + 1 + (sizeof(struct dlm_write_request) -
530528
sizeof(struct dlm_write_request32)), GFP_KERNEL);
531529
if (!kbuf)
532530
return -ENOMEM;
533531

534532
if (proc)
535533
set_bit(DLM_PROC_FLAGS_COMPAT, &proc->flags);
536-
compat_input(kbuf, k32buf,
537-
count - sizeof(struct dlm_write_request32));
534+
compat_input(kbuf, k32buf, count + 1);
538535
kfree(k32buf);
539536
}
540537
#endif

0 commit comments

Comments
 (0)