Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

kmihelich
Copy link

packet: fix race condition in packet_set_ring

When packet_set_ring creates a ring buffer it will initialize a
struct timer_list if the packet version is TPACKET_V3. This value
can then be raced by a different thread calling setsockopt to
set the version to TPACKET_V1 before packet_set_ring has finished.

This leads to a use-after-free on a function pointer in the
struct timer_list when the socket is closed as the previously
initialized timer will not be deleted.

The bug is fixed by taking lock_sock(sk) in packet_setsockopt when
changing the packet version while also taking the lock at the start
of packet_set_ring.

Fixes: f6fb8f1 ("af-packet: TPACKET_V3 flexible buffer implementation.")
Signed-off-by: Philip Pettersson [email protected]
Signed-off-by: Eric Dumazet [email protected]
Signed-off-by: David S. Miller [email protected]

When packet_set_ring creates a ring buffer it will initialize a
struct timer_list if the packet version is TPACKET_V3. This value
can then be raced by a different thread calling setsockopt to
set the version to TPACKET_V1 before packet_set_ring has finished.

This leads to a use-after-free on a function pointer in the
struct timer_list when the socket is closed as the previously
initialized timer will not be deleted.

The bug is fixed by taking lock_sock(sk) in packet_setsockopt when
changing the packet version while also taking the lock at the start
of packet_set_ring.

Fixes: f6fb8f1 ("af-packet: TPACKET_V3 flexible buffer implementation.")
Signed-off-by: Philip Pettersson <[email protected]>
Signed-off-by: Eric Dumazet <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
@mdrjr mdrjr merged commit a063880 into hardkernel:odroidc2-3.14.y Jan 5, 2017
mdrjr pushed a commit that referenced this pull request Aug 14, 2023
[ 1240eb9 ]

In case of error when adding a new rule that refers to an anonymous set,
deactivate expressions via NFT_TRANS_PREPARE state, not NFT_TRANS_RELEASE.
Thus, the lookup expression marks anonymous sets as inactive in the next
generation to ensure it is not reachable in this transaction anymore and
decrement the set refcount as introduced by c1592a8 ("netfilter:
nf_tables: deactivate anonymous set from preparation phase"). The abort
step takes care of undoing the anonymous set.

This is also consistent with rule deletion, where NFT_TRANS_PREPARE is
used. Note that this error path is exercised in the preparation step of
the commit protocol. This patch replaces nf_tables_rule_release() by the
deactivate and destroy calls, this time with NFT_TRANS_PREPARE.

Due to this incorrect error handling, it is possible to access a
dangling pointer to the anonymous set that remains in the transaction
list.

[1009.379054] BUG: KASAN: use-after-free in nft_set_lookup_global+0x147/0x1a0 [nf_tables]
[1009.379106] Read of size 8 at addr ffff88816c4c8020 by task nft-rule-add/137110
[1009.379116] CPU: 7 PID: 137110 Comm: nft-rule-add Not tainted 6.4.0-rc4+ #256
[1009.379128] Call Trace:
[1009.379132]  <TASK>
[1009.379135]  dump_stack_lvl+0x33/0x50
[1009.379146]  ? nft_set_lookup_global+0x147/0x1a0 [nf_tables]
[1009.379191]  print_address_description.constprop.0+0x27/0x300
[1009.379201]  kasan_report+0x107/0x120
[1009.379210]  ? nft_set_lookup_global+0x147/0x1a0 [nf_tables]
[1009.379255]  nft_set_lookup_global+0x147/0x1a0 [nf_tables]
[1009.379302]  nft_lookup_init+0xa5/0x270 [nf_tables]
[1009.379350]  nf_tables_newrule+0x698/0xe50 [nf_tables]
[1009.379397]  ? nf_tables_rule_release+0xe0/0xe0 [nf_tables]
[1009.379441]  ? kasan_unpoison+0x23/0x50
[1009.379450]  nfnetlink_rcv_batch+0x97c/0xd90 [nfnetlink]
[1009.379470]  ? nfnetlink_rcv_msg+0x480/0x480 [nfnetlink]
[1009.379485]  ? __alloc_skb+0xb8/0x1e0
[1009.379493]  ? __alloc_skb+0xb8/0x1e0
[1009.379502]  ? entry_SYSCALL_64_after_hwframe+0x46/0xb0
[1009.379509]  ? unwind_get_return_address+0x2a/0x40
[1009.379517]  ? write_profile+0xc0/0xc0
[1009.379524]  ? avc_lookup+0x8f/0xc0
[1009.379532]  ? __rcu_read_unlock+0x43/0x60

Fixes: 958bee1 ("netfilter: nf_tables: use new transaction infrastructure to handle sets")
Signed-off-by: Pablo Neira Ayuso <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
hardkernel pushed a commit that referenced this pull request May 21, 2025
PD#SWPL-116004
PD#SWPL-157951
PD#SWPL-168212
PD#SWPL-169271

Problem:
1.squashfs don't handle bad block
2.partition size returned from mtdblock
is incorrect
3.mtdblock io performance
4.mtdblock report partition size wrong when meet bad block
5.wrong poniter reference is used in container_of()

Solution:
1.mtdblock handle bad block
2.fix mtdblock size
3.mtd disk block size set to mtd writesize
4.correct the decrease size when meet bad block
5.fix the wrong poniter reference

Verify:
s4_aq2432
AT301_962D4-K35(1.5G) #256
C3_C308L_AW419_SOCKET_V01_R05
s1a_bg201

Change-Id: Icbaec2b6679727ebe0d12fd92bf4d21cc4d5f3fe
Signed-off-by: Feng Chen <[email protected]>
Signed-off-by: zhikui.cui <[email protected]>
Signed-off-by: Liang Yang <[email protected]>
hardkernel pushed a commit that referenced this pull request May 21, 2025
PD#SWPL-120491
PD#SWPL-129754
PD#SWPL-155674

Problem:
1.wrong select onfi mode
2.erase flash error during OTA upgrade
3.strncmp can't match full id 01h,DCh,00h,05h,04h(S34ML04G300BHI00)
and 01h,DCh,00h,1Ah,00h(S34ML04G300TFI000)

Solution:
1.get onfi mode from id table
2.change the check way of badblock
3.use memcmp to compare ID memory instead strncmp

Verify:
1-2:s4
3:AT301_T962D4-K35E(1.5G) #256

Change-Id: Ie747ceb95f1045c2acaaf2afb6862c9b05d36d8b
Signed-off-by: Bichao Zheng <[email protected]>
Signed-off-by: zhikui.cui <[email protected]>
hardkernel pushed a commit that referenced this pull request May 21, 2025
PD#SWPL-116004
PD#SWPL-157951
PD#SWPL-168212
PD#SWPL-169271

Problem:
1.squashfs don't handle bad block
2.partition size returned from mtdblock
is incorrect
3.mtdblock io performance
4.mtdblock report partition size wrong when meet bad block
5.wrong poniter reference is used in container_of()

Solution:
1.mtdblock handle bad block
2.fix mtdblock size
3.mtd disk block size set to mtd writesize
4.correct the decrease size when meet bad block
5.fix the wrong poniter reference

Verify:
s4_aq2432
AT301_962D4-K35(1.5G) #256
C3_C308L_AW419_SOCKET_V01_R05
s1a_bg201

Change-Id: Icbaec2b6679727ebe0d12fd92bf4d21cc4d5f3fe
Signed-off-by: Feng Chen <[email protected]>
Signed-off-by: zhikui.cui <[email protected]>
Signed-off-by: Liang Yang <[email protected]>
hardkernel pushed a commit that referenced this pull request May 21, 2025
PD#SWPL-120491
PD#SWPL-129754
PD#SWPL-155674
PD#SWPL-183416

Problem:
1.wrong select onfi mode
2.erase flash error during OTA upgrade
3.strncmp can't match full id 01h,DCh,00h,05h,04h(S34ML04G300BHI00)
and 01h,DCh,00h,1Ah,00h(S34ML04G300TFI000)
4.mtd_device_parse_register panic when parse_mtd_partitions return -EPROBE_DEFER

Solution:
1.get onfi mode from id table
2.change the check way of badblock
3.use memcmp to compare ID memory instead strncmp
4.nvmem_unregister otp_user_nvmem/otp_factory_nvmem if them existing

Verify:
1-2:s4
3:AT301_T962D4-K35E(1.5G) #256
4:BR309-T950D5_SOCKET #48

Change-Id: Ie747ceb95f1045c2acaaf2afb6862c9b05d36d8b
Signed-off-by: Bichao Zheng <[email protected]>
Signed-off-by: zhikui.cui <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants