Skip to content

Commit dcae905

Browse files
Dan Carpenterholtmann
authored andcommitted
Bluetooth: hidp: NUL terminate a string in the compat ioctl
This change is similar to commit a1616a5 ("Bluetooth: hidp: fix buffer overflow") but for the compat ioctl. We take a string from the user and forgot to ensure that it's NUL terminated. I have also changed the strncpy() in to strscpy() in hidp_setup_hid(). The difference is the strncpy() doesn't necessarily NUL terminate the destination string. Either change would fix the problem but it's nice to take a belt and suspenders approach and do both. Signed-off-by: Dan Carpenter <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]>
1 parent 44d34af commit dcae905

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

net/bluetooth/hidp/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ static int hidp_setup_hid(struct hidp_session *session,
775775
hid->version = req->version;
776776
hid->country = req->country;
777777

778-
strncpy(hid->name, req->name, sizeof(hid->name));
778+
strscpy(hid->name, req->name, sizeof(hid->name));
779779

780780
snprintf(hid->phys, sizeof(hid->phys), "%pMR",
781781
&l2cap_pi(session->ctrl_sock->sk)->chan->src);

net/bluetooth/hidp/sock.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ static int hidp_sock_compat_ioctl(struct socket *sock, unsigned int cmd, unsigne
192192
ca.version = ca32.version;
193193
ca.flags = ca32.flags;
194194
ca.idle_to = ca32.idle_to;
195+
ca32.name[sizeof(ca32.name) - 1] = '\0';
195196
memcpy(ca.name, ca32.name, 128);
196197

197198
csock = sockfd_lookup(ca.ctrl_sock, &err);

0 commit comments

Comments
 (0)