Commit c617651
committed
tun: avoid double free in tun_free_netdev
jira VULN-8777
cve CVE-2022-4744
commit-author George Kennedy <george.kennedy@oracle.com>
commit 158b515
upstream-diff Content is the same as the upstream patch except
s/dev->tstats/tun->pcpu_stats/g becuase the switch to
tstats (497a575 "tun: switch to net core provided
statistics counters") isn't in this kernel.
This matches how this change was backported to 4.19.y.
Avoid double free in tun_free_netdev() by moving the
dev->tstats and tun->security allocs to a new ndo_init routine
(tun_net_init()) that will be called by register_netdevice().
ndo_init is paired with the desctructor (tun_free_netdev()),
so if there's an error in register_netdevice() the destructor
will handle the frees.
BUG: KASAN: double-free or invalid-free in selinux_tun_dev_free_security+0x1a/0x20 security/selinux/hooks.c:5605
CPU: 0 PID: 25750 Comm: syz-executor416 Not tainted 5.16.0-rc2-syzk #1
Hardware name: Red Hat KVM, BIOS
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0x89/0xb5 lib/dump_stack.c:106
print_address_description.constprop.9+0x28/0x160 mm/kasan/report.c:247
kasan_report_invalid_free+0x55/0x80 mm/kasan/report.c:372
____kasan_slab_free mm/kasan/common.c:346 [inline]
__kasan_slab_free+0x107/0x120 mm/kasan/common.c:374
kasan_slab_free include/linux/kasan.h:235 [inline]
slab_free_hook mm/slub.c:1723 [inline]
slab_free_freelist_hook mm/slub.c:1749 [inline]
slab_free mm/slub.c:3513 [inline]
kfree+0xac/0x2d0 mm/slub.c:4561
selinux_tun_dev_free_security+0x1a/0x20 security/selinux/hooks.c:5605
security_tun_dev_free_security+0x4f/0x90 security/security.c:2342
tun_free_netdev+0xe6/0x150 drivers/net/tun.c:2215
netdev_run_todo+0x4df/0x840 net/core/dev.c:10627
rtnl_unlock+0x13/0x20 net/core/rtnetlink.c:112
__tun_chr_ioctl+0x80c/0x2870 drivers/net/tun.c:3302
tun_chr_ioctl+0x2f/0x40 drivers/net/tun.c:3311
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:874 [inline]
__se_sys_ioctl fs/ioctl.c:860 [inline]
__x64_sys_ioctl+0x19d/0x220 fs/ioctl.c:860
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x3a/0x80 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x44/0xae
Reported-by: syzkaller <syzkaller@googlegroups.com>
Signed-off-by: George Kennedy <george.kennedy@oracle.com>
Suggested-by: Jakub Kicinski <kuba@kernel.org>
Link: https://lore.kernel.org/r/1639679132-19884-1-git-send-email-george.kennedy@oracle.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
(cherry picked from commit 158b515)
Signed-off-by: Brett Mastbergen <bmastbergen@ciq.com>1 parent 2d31b60 commit c617651
1 file changed
+59
-60
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
251 | 251 | | |
252 | 252 | | |
253 | 253 | | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
254 | 257 | | |
255 | 258 | | |
256 | 259 | | |
257 | 260 | | |
258 | 261 | | |
259 | 262 | | |
260 | 263 | | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
261 | 267 | | |
262 | 268 | | |
263 | 269 | | |
| |||
996 | 1002 | | |
997 | 1003 | | |
998 | 1004 | | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
999 | 1048 | | |
1000 | 1049 | | |
1001 | 1050 | | |
| |||
1274 | 1323 | | |
1275 | 1324 | | |
1276 | 1325 | | |
| 1326 | + | |
1277 | 1327 | | |
1278 | 1328 | | |
1279 | 1329 | | |
| |||
1360 | 1410 | | |
1361 | 1411 | | |
1362 | 1412 | | |
| 1413 | + | |
1363 | 1414 | | |
1364 | 1415 | | |
1365 | 1416 | | |
| |||
1403 | 1454 | | |
1404 | 1455 | | |
1405 | 1456 | | |
1406 | | - | |
| 1457 | + | |
1407 | 1458 | | |
1408 | 1459 | | |
1409 | 1460 | | |
| |||
2324 | 2375 | | |
2325 | 2376 | | |
2326 | 2377 | | |
2327 | | - | |
2328 | 2378 | | |
2329 | | - | |
2330 | | - | |
2331 | | - | |
2332 | | - | |
2333 | | - | |
2334 | 2379 | | |
2335 | 2380 | | |
2336 | 2381 | | |
| |||
2825 | 2870 | | |
2826 | 2871 | | |
2827 | 2872 | | |
2828 | | - | |
2829 | | - | |
2830 | | - | |
2831 | 2873 | | |
2832 | 2874 | | |
2833 | 2875 | | |
| |||
2846 | 2888 | | |
2847 | 2889 | | |
2848 | 2890 | | |
2849 | | - | |
2850 | | - | |
2851 | | - | |
2852 | | - | |
2853 | | - | |
2854 | | - | |
2855 | | - | |
2856 | | - | |
2857 | | - | |
2858 | | - | |
2859 | | - | |
2860 | | - | |
2861 | | - | |
2862 | | - | |
2863 | | - | |
2864 | | - | |
2865 | | - | |
2866 | | - | |
2867 | | - | |
2868 | | - | |
2869 | | - | |
2870 | | - | |
| 2891 | + | |
| 2892 | + | |
2871 | 2893 | | |
2872 | | - | |
2873 | | - | |
2874 | | - | |
2875 | | - | |
2876 | | - | |
2877 | | - | |
2878 | | - | |
2879 | | - | |
| 2894 | + | |
2880 | 2895 | | |
2881 | 2896 | | |
2882 | | - | |
2883 | | - | |
| 2897 | + | |
| 2898 | + | |
| 2899 | + | |
| 2900 | + | |
2884 | 2901 | | |
2885 | 2902 | | |
2886 | 2903 | | |
| |||
2899 | 2916 | | |
2900 | 2917 | | |
2901 | 2918 | | |
2902 | | - | |
2903 | | - | |
2904 | | - | |
2905 | | - | |
2906 | | - | |
2907 | | - | |
2908 | | - | |
2909 | | - | |
2910 | | - | |
2911 | | - | |
2912 | | - | |
2913 | | - | |
2914 | | - | |
2915 | | - | |
2916 | | - | |
2917 | | - | |
2918 | | - | |
2919 | | - | |
2920 | 2919 | | |
2921 | 2920 | | |
2922 | 2921 | | |
| |||
0 commit comments