Skip to content

Commit 95e8e7e

Browse files
azeemsgooglegregkh
authored andcommitted
vt: Replace strlcpy with strscpy
strlcpy() reads the entire source buffer first and returns the size of the source string, not the destination string, which can be accidentally misused [1]. The copy_to_user() call uses @len returned from strlcpy() directly without checking its value. This could potentially lead to read overflow. There is no existing bug since @len is always guaranteed to be greater than hardcoded strings in @func_table[kb_func]. But as written it is very fragile and specifically uses a strlcpy() result without sanity checking and using it to copy to userspace. In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy(). [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy [2] KSPP/linux#89 Signed-off-by: Azeem Shaikh <[email protected]> Reviewed-by: Justin Stitt <[email protected]> Reviewed-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 29bff58 commit 95e8e7e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

drivers/tty/vt/keyboard.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,12 +2079,15 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
20792079
return -ENOMEM;
20802080

20812081
spin_lock_irqsave(&func_buf_lock, flags);
2082-
len = strlcpy(kbs, func_table[kb_func] ? : "", len);
2082+
len = strscpy(kbs, func_table[kb_func] ? : "", len);
20832083
spin_unlock_irqrestore(&func_buf_lock, flags);
20842084

2085+
if (len < 0) {
2086+
ret = -ENOSPC;
2087+
break;
2088+
}
20852089
ret = copy_to_user(user_kdgkb->kb_string, kbs, len + 1) ?
20862090
-EFAULT : 0;
2087-
20882091
break;
20892092
}
20902093
case KDSKBSENT:

0 commit comments

Comments
 (0)