Skip to content

Commit 61d52f6

Browse files
azeemshaikh38gregkh
authored andcommitted
usbip: usbip_host: Replace strlcpy with strscpy
strlcpy() reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy(). Direct replacement is safe here since return value of -errno is used to check for truncation instead of sizeof(dest). [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy [2] KSPP#89 Signed-off-by: Azeem Shaikh <azeemshaikh38@gmail.com> Reviewed-by: Kees Cook <keescook@chromium.org> Acked-by: Shuah Khan <skhan@linuxfoundation.org> Message-ID: <20230615180504.401169-1-azeemshaikh38@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c0aabed commit 61d52f6

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

drivers/usb/usbip/stub_main.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,13 @@ static ssize_t match_busid_show(struct device_driver *drv, char *buf)
167167
static ssize_t match_busid_store(struct device_driver *dev, const char *buf,
168168
size_t count)
169169
{
170-
int len;
171170
char busid[BUSID_SIZE];
172171

173172
if (count < 5)
174173
return -EINVAL;
175174

176175
/* busid needs to include \0 termination */
177-
len = strlcpy(busid, buf + 4, BUSID_SIZE);
178-
if (sizeof(busid) <= len)
176+
if (strscpy(busid, buf + 4, BUSID_SIZE) < 0)
179177
return -EINVAL;
180178

181179
if (!strncmp(buf, "add ", 4)) {

0 commit comments

Comments
 (0)