
KASAN report this: BUG: KASAN: use-after-free in pde_subdir_find+0x12d/0x150 fs/proc/generic.c:71 Read of size 8 at addr ffff8881f41fe5b0 by task syz-executor.0/2806 CPU: 0 PID: 2806 Comm: syz-executor.0 Not tainted 5.0.0-rc7+ #45 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014 Call Trace: __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0xfa/0x1ce lib/dump_stack.c:113 print_address_description+0x65/0x270 mm/kasan/report.c:187 kasan_report+0x149/0x18d mm/kasan/report.c:317 pde_subdir_find+0x12d/0x150 fs/proc/generic.c:71 remove_proc_entry+0xe8/0x420 fs/proc/generic.c:667 atalk_proc_exit+0x18/0x820 [appletalk] atalk_exit+0xf/0x5a [appletalk] __do_sys_delete_module kernel/module.c:1018 [inline] __se_sys_delete_module kernel/module.c:961 [inline] __x64_sys_delete_module+0x3dc/0x5e0 kernel/module.c:961 do_syscall_64+0x147/0x600 arch/x86/entry/common.c:290 entry_SYSCALL_64_after_hwframe+0x49/0xbe RIP: 0033:0x462e99 Code: f7 d8 64 89 02 b8 ff ff ff ff c3 66 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 bc ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007fb2de6b9c58 EFLAGS: 00000246 ORIG_RAX: 00000000000000b0 RAX: ffffffffffffffda RBX: 000000000073bf00 RCX: 0000000000462e99 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 00000000200001c0 RBP: 0000000000000002 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 00007fb2de6ba6bc R13: 00000000004bccaa R14: 00000000006f6bc8 R15: 00000000ffffffff Allocated by task 2806: set_track mm/kasan/common.c:85 [inline] __kasan_kmalloc.constprop.3+0xa0/0xd0 mm/kasan/common.c:496 slab_post_alloc_hook mm/slab.h:444 [inline] slab_alloc_node mm/slub.c:2739 [inline] slab_alloc mm/slub.c:2747 [inline] kmem_cache_alloc+0xcf/0x250 mm/slub.c:2752 kmem_cache_zalloc include/linux/slab.h:730 [inline] __proc_create+0x30f/0xa20 fs/proc/generic.c:408 proc_mkdir_data+0x47/0x190 fs/proc/generic.c:469 0xffffffffc10c01bb 0xffffffffc10c0166 do_one_initcall+0xfa/0x5ca init/main.c:887 do_init_module+0x204/0x5f6 kernel/module.c:3460 load_module+0x66b2/0x8570 kernel/module.c:3808 __do_sys_finit_module+0x238/0x2a0 kernel/module.c:3902 do_syscall_64+0x147/0x600 arch/x86/entry/common.c:290 entry_SYSCALL_64_after_hwframe+0x49/0xbe Freed by task 2806: set_track mm/kasan/common.c:85 [inline] __kasan_slab_free+0x130/0x180 mm/kasan/common.c:458 slab_free_hook mm/slub.c:1409 [inline] slab_free_freelist_hook mm/slub.c:1436 [inline] slab_free mm/slub.c:2986 [inline] kmem_cache_free+0xa6/0x2a0 mm/slub.c:3002 pde_put+0x6e/0x80 fs/proc/generic.c:647 remove_proc_entry+0x1d3/0x420 fs/proc/generic.c:684 0xffffffffc10c031c 0xffffffffc10c0166 do_one_initcall+0xfa/0x5ca init/main.c:887 do_init_module+0x204/0x5f6 kernel/module.c:3460 load_module+0x66b2/0x8570 kernel/module.c:3808 __do_sys_finit_module+0x238/0x2a0 kernel/module.c:3902 do_syscall_64+0x147/0x600 arch/x86/entry/common.c:290 entry_SYSCALL_64_after_hwframe+0x49/0xbe The buggy address belongs to the object at ffff8881f41fe500 which belongs to the cache proc_dir_entry of size 256 The buggy address is located 176 bytes inside of 256-byte region [ffff8881f41fe500, ffff8881f41fe600) The buggy address belongs to the page: page:ffffea0007d07f80 count:1 mapcount:0 mapping:ffff8881f6e69a00 index:0x0 flags: 0x2fffc0000000200(slab) raw: 02fffc0000000200 dead000000000100 dead000000000200 ffff8881f6e69a00 raw: 0000000000000000 00000000800c000c 00000001ffffffff 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff8881f41fe480: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc ffff8881f41fe500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb >ffff8881f41fe580: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ^ ffff8881f41fe600: fc fc fc fc fc fc fc fc fb fb fb fb fb fb fb fb ffff8881f41fe680: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb It should check the return value of atalk_proc_init fails, otherwise atalk_exit will trgger use-after-free in pde_subdir_find while unload the module.This patch fix error cleanup path of atalk_init Reported-by: Hulk Robot <hulkci@huawei.com> Signed-off-by: YueHaibing <yuehaibing@huawei.com> Signed-off-by: David S. Miller <davem@davemloft.net>
177 lines
4.4 KiB
C
177 lines
4.4 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef __LINUX_ATALK_H__
|
|
#define __LINUX_ATALK_H__
|
|
|
|
|
|
#include <net/sock.h>
|
|
#include <uapi/linux/atalk.h>
|
|
|
|
struct atalk_route {
|
|
struct net_device *dev;
|
|
struct atalk_addr target;
|
|
struct atalk_addr gateway;
|
|
int flags;
|
|
struct atalk_route *next;
|
|
};
|
|
|
|
/**
|
|
* struct atalk_iface - AppleTalk Interface
|
|
* @dev - Network device associated with this interface
|
|
* @address - Our address
|
|
* @status - What are we doing?
|
|
* @nets - Associated direct netrange
|
|
* @next - next element in the list of interfaces
|
|
*/
|
|
struct atalk_iface {
|
|
struct net_device *dev;
|
|
struct atalk_addr address;
|
|
int status;
|
|
#define ATIF_PROBE 1 /* Probing for an address */
|
|
#define ATIF_PROBE_FAIL 2 /* Probe collided */
|
|
struct atalk_netrange nets;
|
|
struct atalk_iface *next;
|
|
};
|
|
|
|
struct atalk_sock {
|
|
/* struct sock has to be the first member of atalk_sock */
|
|
struct sock sk;
|
|
__be16 dest_net;
|
|
__be16 src_net;
|
|
unsigned char dest_node;
|
|
unsigned char src_node;
|
|
unsigned char dest_port;
|
|
unsigned char src_port;
|
|
};
|
|
|
|
static inline struct atalk_sock *at_sk(struct sock *sk)
|
|
{
|
|
return (struct atalk_sock *)sk;
|
|
}
|
|
|
|
struct ddpehdr {
|
|
__be16 deh_len_hops; /* lower 10 bits are length, next 4 - hops */
|
|
__be16 deh_sum;
|
|
__be16 deh_dnet;
|
|
__be16 deh_snet;
|
|
__u8 deh_dnode;
|
|
__u8 deh_snode;
|
|
__u8 deh_dport;
|
|
__u8 deh_sport;
|
|
/* And netatalk apps expect to stick the type in themselves */
|
|
};
|
|
|
|
static __inline__ struct ddpehdr *ddp_hdr(struct sk_buff *skb)
|
|
{
|
|
return (struct ddpehdr *)skb_transport_header(skb);
|
|
}
|
|
|
|
/* AppleTalk AARP headers */
|
|
struct elapaarp {
|
|
__be16 hw_type;
|
|
#define AARP_HW_TYPE_ETHERNET 1
|
|
#define AARP_HW_TYPE_TOKENRING 2
|
|
__be16 pa_type;
|
|
__u8 hw_len;
|
|
__u8 pa_len;
|
|
#define AARP_PA_ALEN 4
|
|
__be16 function;
|
|
#define AARP_REQUEST 1
|
|
#define AARP_REPLY 2
|
|
#define AARP_PROBE 3
|
|
__u8 hw_src[ETH_ALEN];
|
|
__u8 pa_src_zero;
|
|
__be16 pa_src_net;
|
|
__u8 pa_src_node;
|
|
__u8 hw_dst[ETH_ALEN];
|
|
__u8 pa_dst_zero;
|
|
__be16 pa_dst_net;
|
|
__u8 pa_dst_node;
|
|
} __attribute__ ((packed));
|
|
|
|
static __inline__ struct elapaarp *aarp_hdr(struct sk_buff *skb)
|
|
{
|
|
return (struct elapaarp *)skb_transport_header(skb);
|
|
}
|
|
|
|
/* Not specified - how long till we drop a resolved entry */
|
|
#define AARP_EXPIRY_TIME (5 * 60 * HZ)
|
|
/* Size of hash table */
|
|
#define AARP_HASH_SIZE 16
|
|
/* Fast retransmission timer when resolving */
|
|
#define AARP_TICK_TIME (HZ / 5)
|
|
/* Send 10 requests then give up (2 seconds) */
|
|
#define AARP_RETRANSMIT_LIMIT 10
|
|
/*
|
|
* Some value bigger than total retransmit time + a bit for last reply to
|
|
* appear and to stop continual requests
|
|
*/
|
|
#define AARP_RESOLVE_TIME (10 * HZ)
|
|
|
|
extern struct datalink_proto *ddp_dl, *aarp_dl;
|
|
extern void aarp_proto_init(void);
|
|
|
|
/* Inter module exports */
|
|
|
|
/* Give a device find its atif control structure */
|
|
#if IS_ENABLED(CONFIG_IRDA) || IS_ENABLED(CONFIG_ATALK)
|
|
static inline struct atalk_iface *atalk_find_dev(struct net_device *dev)
|
|
{
|
|
return dev->atalk_ptr;
|
|
}
|
|
#endif
|
|
|
|
extern struct atalk_addr *atalk_find_dev_addr(struct net_device *dev);
|
|
extern struct net_device *atrtr_get_dev(struct atalk_addr *sa);
|
|
extern int aarp_send_ddp(struct net_device *dev,
|
|
struct sk_buff *skb,
|
|
struct atalk_addr *sa, void *hwaddr);
|
|
extern void aarp_device_down(struct net_device *dev);
|
|
extern void aarp_probe_network(struct atalk_iface *atif);
|
|
extern int aarp_proxy_probe_network(struct atalk_iface *atif,
|
|
struct atalk_addr *sa);
|
|
extern void aarp_proxy_remove(struct net_device *dev,
|
|
struct atalk_addr *sa);
|
|
|
|
extern void aarp_cleanup_module(void);
|
|
|
|
extern struct hlist_head atalk_sockets;
|
|
extern rwlock_t atalk_sockets_lock;
|
|
|
|
extern struct atalk_route *atalk_routes;
|
|
extern rwlock_t atalk_routes_lock;
|
|
|
|
extern struct atalk_iface *atalk_interfaces;
|
|
extern rwlock_t atalk_interfaces_lock;
|
|
|
|
extern struct atalk_route atrtr_default;
|
|
|
|
struct aarp_iter_state {
|
|
int bucket;
|
|
struct aarp_entry **table;
|
|
};
|
|
|
|
extern const struct seq_operations aarp_seq_ops;
|
|
|
|
extern int sysctl_aarp_expiry_time;
|
|
extern int sysctl_aarp_tick_time;
|
|
extern int sysctl_aarp_retransmit_limit;
|
|
extern int sysctl_aarp_resolve_time;
|
|
|
|
#ifdef CONFIG_SYSCTL
|
|
extern int atalk_register_sysctl(void);
|
|
extern void atalk_unregister_sysctl(void);
|
|
#else
|
|
#define atalk_register_sysctl() do { } while(0)
|
|
#define atalk_unregister_sysctl() do { } while(0)
|
|
#endif
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
extern int atalk_proc_init(void);
|
|
extern void atalk_proc_exit(void);
|
|
#else
|
|
#define atalk_proc_init() ({ 0; })
|
|
#define atalk_proc_exit() do { } while(0)
|
|
#endif /* CONFIG_PROC_FS */
|
|
|
|
#endif /* __LINUX_ATALK_H__ */
|