Skip to content

Commit 2a79289

Browse files
Patrick Caulfeldteigland
authored andcommitted
dlm: Sanity check namelen before copying it
The 32/64 compatibility code in the DLM does not check the validity of the lock name length passed into it, so it can easily overwrite memory if the value is rubbish (as early versions of libdlm can cause with unlock calls, it doesn't zero the field). This patch restricts the length of the name to the amount of data actually passed into the call. Signed-off-by: Patrick Caulfield <pcaulfie@redhat.com> Signed-off-by: David Teigland <teigland@redhat.com>
1 parent 85f0379 commit 2a79289

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

‎fs/dlm/user.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ struct dlm_lock_result32 {
8282
};
8383

8484
static void compat_input(struct dlm_write_request *kb,
85-
struct dlm_write_request32 *kb32)
85+
struct dlm_write_request32 *kb32,
86+
int max_namelen)
8687
{
8788
kb->version[0] = kb32->version[0];
8889
kb->version[1] = kb32->version[1];
@@ -112,7 +113,11 @@ 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-
memcpy(kb->i.lock.name, kb32->i.lock.name, kb->i.lock.namelen);
116+
if (kb->i.lock.namelen <= max_namelen)
117+
memcpy(kb->i.lock.name, kb32->i.lock.name,
118+
kb->i.lock.namelen);
119+
else
120+
kb->i.lock.namelen = max_namelen;
116121
}
117122
}
118123

@@ -529,7 +534,8 @@ static ssize_t device_write(struct file *file, const char __user *buf,
529534

530535
if (proc)
531536
set_bit(DLM_PROC_FLAGS_COMPAT, &proc->flags);
532-
compat_input(kbuf, k32buf);
537+
compat_input(kbuf, k32buf,
538+
count - sizeof(struct dlm_write_request32));
533539
kfree(k32buf);
534540
}
535541
#endif

0 commit comments

Comments
 (0)