Skip to content

Commit 9804501

Browse files
YueHaibingdavem330
authored andcommitted
appletalk: Fix potential NULL pointer dereference in unregister_snap_client
register_snap_client may return NULL, all the callers check it, but only print a warning. This will result in NULL pointer dereference in unregister_snap_client and other places. It has always been used like this since v2.6 Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: YueHaibing <yuehaibing@huawei.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f261c4e commit 9804501

3 files changed

Lines changed: 25 additions & 12 deletions

File tree

‎include/linux/atalk.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static __inline__ struct elapaarp *aarp_hdr(struct sk_buff *skb)
108108
#define AARP_RESOLVE_TIME (10 * HZ)
109109

110110
extern struct datalink_proto *ddp_dl, *aarp_dl;
111-
extern void aarp_proto_init(void);
111+
extern int aarp_proto_init(void);
112112

113113
/* Inter module exports */
114114

‎net/appletalk/aarp.c‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -879,15 +879,24 @@ static struct notifier_block aarp_notifier = {
879879

880880
static unsigned char aarp_snap_id[] = { 0x00, 0x00, 0x00, 0x80, 0xF3 };
881881

882-
void __init aarp_proto_init(void)
882+
int __init aarp_proto_init(void)
883883
{
884+
int rc;
885+
884886
aarp_dl = register_snap_client(aarp_snap_id, aarp_rcv);
885-
if (!aarp_dl)
887+
if (!aarp_dl) {
886888
printk(KERN_CRIT "Unable to register AARP with SNAP.\n");
889+
return -ENOMEM;
890+
}
887891
timer_setup(&aarp_timer, aarp_expire_timeout, 0);
888892
aarp_timer.expires = jiffies + sysctl_aarp_expiry_time;
889893
add_timer(&aarp_timer);
890-
register_netdevice_notifier(&aarp_notifier);
894+
rc = register_netdevice_notifier(&aarp_notifier);
895+
if (rc) {
896+
del_timer_sync(&aarp_timer);
897+
unregister_snap_client(aarp_dl);
898+
}
899+
return rc;
891900
}
892901

893902
/* Remove the AARP entries associated with a device. */

‎net/appletalk/ddp.c‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,9 +1904,6 @@ static unsigned char ddp_snap_id[] = { 0x08, 0x00, 0x07, 0x80, 0x9B };
19041904
EXPORT_SYMBOL(atrtr_get_dev);
19051905
EXPORT_SYMBOL(atalk_find_dev_addr);
19061906

1907-
static const char atalk_err_snap[] __initconst =
1908-
KERN_CRIT "Unable to register DDP with SNAP.\n";
1909-
19101907
/* Called by proto.c on kernel start up */
19111908
static int __init atalk_init(void)
19121909
{
@@ -1921,17 +1918,22 @@ static int __init atalk_init(void)
19211918
goto out_proto;
19221919

19231920
ddp_dl = register_snap_client(ddp_snap_id, atalk_rcv);
1924-
if (!ddp_dl)
1925-
printk(atalk_err_snap);
1921+
if (!ddp_dl) {
1922+
pr_crit("Unable to register DDP with SNAP.\n");
1923+
goto out_sock;
1924+
}
19261925

19271926
dev_add_pack(&ltalk_packet_type);
19281927
dev_add_pack(&ppptalk_packet_type);
19291928

19301929
rc = register_netdevice_notifier(&ddp_notifier);
19311930
if (rc)
1932-
goto out_sock;
1931+
goto out_snap;
1932+
1933+
rc = aarp_proto_init();
1934+
if (rc)
1935+
goto out_dev;
19331936

1934-
aarp_proto_init();
19351937
rc = atalk_proc_init();
19361938
if (rc)
19371939
goto out_aarp;
@@ -1945,11 +1947,13 @@ static int __init atalk_init(void)
19451947
atalk_proc_exit();
19461948
out_aarp:
19471949
aarp_cleanup_module();
1950+
out_dev:
19481951
unregister_netdevice_notifier(&ddp_notifier);
1949-
out_sock:
1952+
out_snap:
19501953
dev_remove_pack(&ppptalk_packet_type);
19511954
dev_remove_pack(&ltalk_packet_type);
19521955
unregister_snap_client(ddp_dl);
1956+
out_sock:
19531957
sock_unregister(PF_APPLETALK);
19541958
out_proto:
19551959
proto_unregister(&ddp_proto);

0 commit comments

Comments
 (0)