Skip to contentSkip to conversation

tty: synclink_gt: Fix null-pointer-dereference in slgt_clean()

PATCH In review Zheyu Ma 2 participants 3 messages Apr 10, 2022 – Apr 11, 2022 TTY layer and serial drivers

lore
Share & tools
lore

Zheyu Ma

author
#0 lore raw

PATCH 1/1 tty: synclink_gt: Fix null-pointer-dereference in slgt_clean()

When the driver fails at alloc_hdlcdev(), and then we remove the driver module, we will get the following splat:

[   25.065966] general protection fault, probably for non-canonical address 0xdffffc0000000182: 0000 [#1] PREEMPT SMP KASAN PTI
[   25.066914] KASAN: null-ptr-deref in range [0x0000000000000c10-0x0000000000000c17]
[   25.069262] RIP: 0010:detach_hdlc_protocol+0x2a/0x3e0
[   25.077709] Call Trace:
[   25.077924]  <TASK>
[   25.078108]  unregister_hdlc_device+0x16/0x30
[   25.078481]  slgt_cleanup+0x157/0x9f0 [synclink_gt]

Fix this by checking whether the 'info->netdev' is a null pointer first.

---
 drivers/tty/synclink_gt.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/tty/synclink_gt.c +2 -0
index 25c558e65ece..9bc2a9265277 100644
@@ -1746,6 +1746,8 @@ static int hdlcdev_init(struct slgt_info *info)
  */
 static void hdlcdev_exit(struct slgt_info *info)
 {
+	if (!info->netdev)
+		return;
 	unregister_hdlc_device(info->netdev);
 	free_netdev(info->netdev);
 	info->netdev = NULL;
Signature · 1 line
2.25.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Zheyu Ma

When the driver fails at alloc_hdlcdev(), and then we remove the driver module, we will get the following splat:

[   25.065966] general protection fault, probably for non-canonical address 0xdffffc0000000182: 0000 [#1] PREEMPT SMP KASAN PTI
[   25.066914] KASAN: null-ptr-deref in range [0x0000000000000c10-0x0000000000000c17]
[   25.069262] RIP: 0010:detach_hdlc_protocol+0x2a/0x3e0
[   25.077709] Call Trace:
[   25.077924]  <TASK>
[   25.078108]  unregister_hdlc_device+0x16/0x30
[   25.078481]  slgt_cleanup+0x157/0x9f0 [synclink_gt]
Quoted 1 line

Fix this by checking whether the 'info->netdev' is a null pointer first.

Hi,

LGTM

Out of curiosity, do you use the driver, or you only do some static analysis?

Quoted 18 lines
---
  drivers/tty/synclink_gt.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/tty/synclink_gt.c +2 -0
index 25c558e65ece..9bc2a9265277 100644
@@ -1746,6 +1746,8 @@ static int hdlcdev_init(struct slgt_info *info)
   */
  static void hdlcdev_exit(struct slgt_info *info)
  {
+	if (!info->netdev)
+		return;
  	unregister_hdlc_device(info->netdev);
  	free_netdev(info->netdev);
  	info->netdev = NULL;
Signature · 2 lines
js
suse labs
author
#2 lore raw
Quoted 15 lines · Jiri Slaby
Quoted 11 lines · Zheyu Ma

When the driver fails at alloc_hdlcdev(), and then we remove the driver module, we will get the following splat:

[   25.065966] general protection fault, probably for non-canonical address 0xdffffc0000000182: 0000 [#1] PREEMPT SMP KASAN PTI
[   25.066914] KASAN: null-ptr-deref in range [0x0000000000000c10-0x0000000000000c17]
[   25.069262] RIP: 0010:detach_hdlc_protocol+0x2a/0x3e0
[   25.077709] Call Trace:
[   25.077924]  <TASK>
[   25.078108]  unregister_hdlc_device+0x16/0x30
[   25.078481]  slgt_cleanup+0x157/0x9f0 [synclink_gt]
Quoted 1 line

Fix this by checking whether the 'info->netdev' is a null pointer first.

Quoted 8 lines

Hi,

LGTM

Out of curiosity, do you use the driver, or you only do some static analysis?

In fact, neither. I test the driver via fuzzing in a simulated environment.

Zheyu Ma