selftests/bpf: Add test for bpf_timer overwriting crash
Subsystems (9)
Sasha Levin
maintainerPATCH 1/11 selftests/bpf: Add test for bpf_timer overwriting crash
From: Kumar Kartikeya Dwivedi <[email protected]>
[ Upstream commit a7e75016a0753c24d6c995bc02501ae35368e333 ]
Add a test that validates that timer value is not overwritten when doing a copy_map_value call in the kernel. Without the prior fix, this test triggers a crash.
--- .../selftests/bpf/prog_tests/timer_crash.c | 32 +++++++++++ .../testing/selftests/bpf/progs/timer_crash.c | 54 +++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/timer_crash.c create mode 100644 tools/testing/selftests/bpf/progs/timer_crash.c
tools/testing/selftests/bpf/prog_tests/timer_crash.c new file +32 -0
@@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <test_progs.h> +#include "timer_crash.skel.h" + +enum { +MODE_ARRAY , +MODE_HASH , +}; + +static void test_timer_crash_mode (int mode) +{ +struct timer_crash *skel; + + skel =timer_crash__open_and_load (); +if (!ASSERT_OK_PTR (skel,"timer_crash__open_and_load" )) +return ; + skel->bss->pid =getpid (); + skel->bss->crash_map = mode; +if (!ASSERT_OK (timer_crash__attach (skel),"timer_crash__attach" )) + goto end; +usleep (1 ); +end: +timer_crash__destroy (skel); +} + +void test_timer_crash (void ) +{ +if (test__start_subtest ("array" )) +test_timer_crash_mode (MODE_ARRAY ); +if (test__start_subtest ("hash" )) +test_timer_crash_mode (MODE_HASH ); +}
tools/testing/selftests/bpf/progs/timer_crash.c new file +54 -0
54 lines not on this page · raw message
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 2/11 KVM: Fix lockdep false negative during host resume
From: Wanpeng Li <[email protected]>
[ Upstream commit 4cb9a998b1ce25fad74a82f5a5c45a4ef40de337 ]
I saw the below splatting after the host suspended and resumed.
WARNING: CPU: 0 PID: 2943 at kvm/arch/x86/kvm/../../../virt/kvm/kvm_main.c:5531 kvm_resume+0x2c/0x30 [kvm]
CPU: 0 PID: 2943 Comm: step_after_susp Tainted: G W IOE 5.17.0-rc3+ #4
RIP: 0010:kvm_resume+0x2c/0x30 [kvm]
Call Trace:
<TASK>
syscore_resume+0x90/0x340
suspend_devices_and_enter+0xaee/0xe90
pm_suspend.cold+0x36b/0x3c2
state_store+0x82/0xf0
kernfs_fop_write_iter+0x1b6/0x260
new_sync_write+0x258/0x370
vfs_write+0x33f/0x510
ksys_write+0xc9/0x160
do_syscall_64+0x3b/0xc0
entry_SYSCALL_64_after_hwframe+0x44/0xaelockdep_is_held() can return -1 when lockdep is disabled which triggers this warning. Let's use lockdep_assert_not_held() which can detect incorrect calls while holding a lock and it also avoids false negatives when lockdep is disabled.
Message-Id: <[email protected]>
--- virt/kvm/kvm_main.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
virt/kvm/kvm_main.c +1 -3
@@ -4427,9 +4427,7 @@ static int kvm_suspend(void)static void kvm_resume (void ) {if (kvm_usage_count) { -#ifdef CONFIG_LOCKDEP -WARN_ON (lockdep_is_held (&kvm_count_lock)); -#endif +lockdep_assert_not_held (&kvm_count_lock);hardware_enable_nolock (NULL ); } }
Signature · 1 line
2.34.1
Re: [PATCH AUTOSEL 5.4 02/11] KVM: Fix lockdep false negative during host resume
Quoted 40 lines · Sasha Levin
From: Wanpeng Li <[email protected]>
[ Upstream commit
4cb9a998b1ce25fad74a82f5a5c45a4ef40de337]I saw the below splatting after the host suspended and resumed.
WARNING: CPU: 0 PID: 2943 at kvm/arch/x86/kvm/../../../virt/kvm/kvm_main.c:5531 kvm_resume+0x2c/0x30 [kvm] CPU: 0 PID: 2943 Comm: step_after_susp Tainted: G W IOE 5.17.0-rc3+ #4 RIP: 0010:kvm_resume+0x2c/0x30 [kvm] Call Trace: <TASK> syscore_resume+0x90/0x340 suspend_devices_and_enter+0xaee/0xe90 pm_suspend.cold+0x36b/0x3c2 state_store+0x82/0xf0 kernfs_fop_write_iter+0x1b6/0x260 new_sync_write+0x258/0x370 vfs_write+0x33f/0x510 ksys_write+0xc9/0x160 do_syscall_64+0x3b/0xc0 entry_SYSCALL_64_after_hwframe+0x44/0xae
lockdep_is_held()can return -1 when lockdep is disabled which triggers this warning. Let's uselockdep_assert_not_held()which can detect incorrect calls while holding a lock and it also avoids false negatives when lockdep is disabled.Signed-off-by Wanpeng Li <[email protected]>Message-Id: <[email protected]>
Signed-off-by Paolo Bonzini <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- virt/kvm/kvm_main.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)virt/kvm/kvm_main.c +0
-0
virt/kvm/kvm_main.c static int kvm_suspend(void) · line 4433
Quoted 10 lines
virt/kvm/kvm_main.c +1
-3@@ -4427,9 +4427,7 @@ static int kvm_suspend(void)static void kvm_resume (void ) {if (kvm_usage_count) { -#ifdef CONFIG_LOCKDEP -WARN_ON (lockdep_is_held (&kvm_count_lock)); -#endif +lockdep_assert_not_held (&kvm_count_lock);hardware_enable_nolock (NULL ); } }
Sasha Levin
maintainerPATCH 3/11 net-sysfs: add check for netdevice being present to speed_show
In reply to Sasha LevinFrom: suresh kumar <[email protected]>
[ Upstream commit 4224cfd7fb6523f7a9d1c8bb91bb5df1e38eb624 ]
When bringing down the netdevice or system shutdown, a panic can be triggered while accessing the sysfs path because the device is already removed.
[ 755.549084] mlx5_core 0000:12:00.1: Shutdown was called
[ 756.404455] mlx5_core 0000:12:00.0: Shutdown was called
...
[ 757.937260] BUG: unable to handle kernel NULL pointer dereference at (null)
[ 758.031397] IP: [<ffffffff8ee11acb>] dma_pool_alloc+0x1ab/0x280 crash> bt
...
PID: 12649 TASK: ffff8924108f2100 CPU: 1 COMMAND: "amsd"
...
#9 [ffff89240e1a38b0] page_fault at ffffffff8f38c778
[exception RIP: dma_pool_alloc+0x1ab]
RIP: ffffffff8ee11acb RSP: ffff89240e1a3968 RFLAGS: 00010046
RAX: 0000000000000246 RBX: ffff89243d874100 RCX: 0000000000001000
RDX: 0000000000000000 RSI: 0000000000000246 RDI: ffff89243d874090
RBP: ffff89240e1a39c0 R8: 000000000001f080 R9: ffff8905ffc03c00
R10: ffffffffc04680d4 R11: ffffffff8edde9fd R12: 00000000000080d0
R13: ffff89243d874090 R14: ffff89243d874080 R15: 0000000000000000
ORIG_RAX: ffffffffffffffff CS: 0010 SS: 0018
#10 [ffff89240e1a39c8] mlx5_alloc_cmd_msg at ffffffffc04680f3 [mlx5_core]
#11 [ffff89240e1a3a18] cmd_exec at ffffffffc046ad62 [mlx5_core]
#12 [ffff89240e1a3ab8] mlx5_cmd_exec at ffffffffc046b4fb [mlx5_core]
#13 [ffff89240e1a3ae8] mlx5_core_access_reg at ffffffffc0475434 [mlx5_core]
#14 [ffff89240e1a3b40] mlx5e_get_fec_caps at ffffffffc04a7348 [mlx5_core]
#15 [ffff89240e1a3bb0] get_fec_supported_advertised at ffffffffc04992bf [mlx5_core]
#16 [ffff89240e1a3c08] mlx5e_get_link_ksettings at ffffffffc049ab36 [mlx5_core]
#17 [ffff89240e1a3ce8] __ethtool_get_link_ksettings at ffffffff8f25db46
#18 [ffff89240e1a3d48] speed_show at ffffffff8f277208
#19 [ffff89240e1a3dd8] dev_attr_show at ffffffff8f0b70e3
#20 [ffff89240e1a3df8] sysfs_kf_seq_show at ffffffff8eedbedf
#21 [ffff89240e1a3e18] kernfs_seq_show at ffffffff8eeda596
#22 [ffff89240e1a3e28] seq_read at ffffffff8ee76d10
#23 [ffff89240e1a3e98] kernfs_fop_read at ffffffff8eedaef5
#24 [ffff89240e1a3ed8] vfs_read at ffffffff8ee4e3ff
#25 [ffff89240e1a3f08] sys_read at ffffffff8ee4f27f
#26 [ffff89240e1a3f50] system_call_fastpath at ffffffff8f395f92
crash> net_device.state ffff89443b0c0000
state = 0x5 (__LINK_STATE_START| __LINK_STATE_NOCARRIER)To prevent this scenario, we also make sure that the netdevice is present.
--- net/core/net-sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/net-sysfs.c +1 -1
@@ -212,7 +212,7 @@ static ssize_t speed_show(struct device *dev,if (!rtnl_trylock ())return restart_syscall (); -if (netif_running (netdev)) { +if (netif_running (netdev) &&netif_device_present (netdev)) {struct ethtool_link_ksettings cmd;if (!__ethtool_get_link_ksettings (netdev, &cmd))
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 4/11 sr9700: sanity check for packet length
In reply to Sasha LevinFrom: Oliver Neukum <[email protected]>
[ Upstream commit e9da0b56fe27206b49f39805f7dcda8a89379062 ]
A malicious device can leak heap data to user space providing bogus frame lengths. Introduce a sanity check.
--- drivers/net/usb/sr9700.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/usb/sr9700.c +1 -1
@@ -410,7 +410,7 @@ static int sr9700_rx_fixup(struct usbnet *dev, struct sk_buff *skb)/* ignore the CRC length */ len = (skb->data[1 ] | (skb->data[2 ] <<8 )) -4 ; -if (len >ETH_FRAME_LEN ) +if (len >ETH_FRAME_LEN || len > skb->len)return 0 ;/* the last packet of current skb */
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 5/11 gpio: Return EPROBE_DEFER if gc->to_irq is NULL
In reply to Sasha LevinFrom: Shreeya Patel <[email protected]>
[ Upstream commit ae42f9288846353982e2eab181fb41e7fd8bf60f ]
We are racing the registering of .to_irq when probing the i2c driver. This results in random failure of touchscreen devices.
Following explains the race condition better.
[gpio driver] gpio driver registers gpio chip [gpio consumer] gpio is acquired
[gpio consumer] gpiod_to_irq() fails with -ENXIO [gpio driver] gpio driver registers irqchip gpiod_to_irq works at this point, but -ENXIO is fatal
We could see the following errors in dmesg logs when gc->to_irq is NULL
[2.101857] i2c_hid i2c-FTS3528:00: HID over i2c has not been provided an Int IRQ [2.101953] i2c_hid: probe of i2c-FTS3528:00 failed with error -22
To avoid this situation, defer probing until to_irq is registered. Returning -EPROBE_DEFER would be the first step towards avoiding the failure of devices due to the race in registration of .to_irq. Final solution to this issue would be to avoid using gc irq members until they are fully initialized.
This issue has been reported many times in past and people have been using workarounds like changing the pinctrl_amd to built-in instead of loading it as a module or by adding a softdep for pinctrl_amd into the config file.
--- drivers/gpio/gpiolib.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/gpio/gpiolib.c +10 -0
@@ -3860,6 +3860,16 @@ int gpiod_to_irq(const struct gpio_desc *desc)return retirq; } +#ifdef CONFIG_GPIOLIB_IRQCHIP +if (gc->irq.chip) { +/* +* Avoid race condition with other code, which tries to lookup +* an IRQ before the irqchip has been properly registered, +* i.e. while gpiochip is still being brought up. +*/ +return -EPROBE_DEFER ; + } +#endif return -ENXIO ; }EXPORT_SYMBOL_GPL (gpiod_to_irq);
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 6/11 Revert "xen-netback: remove 'hotplug-status' once it has served its purpose"
In reply to Sasha LevinFrom: Marek Marczykowski-Górecki <[email protected]>
[ Upstream commit 0f4558ae91870692ce7f509c31c9d6ee721d8cdc ]
This reverts commit 1f2565780e9b7218cf92c7630130e82dcc0fe9c2.
The 'hotplug-status' node should not be removed as long as the vif device remains configured. Otherwise the xen-netback would wait for re-running the network script even if it was already called (in case of the frontent re-connecting). But also, it _should_ be removed when the vif device is destroyed (for example when unbinding the driver) - otherwise hotplug script would not configure the device whenever it re-appear.
Moving removal of the 'hotplug-status' node was a workaround for nothing calling network script after xen-netback module is reloaded. But when vif interface is re-created (on xen-netback unbind/bind for example), the script should be called, regardless of who does that - currently this case is not handled by the toolstack, and requires manual script call. Keeping hotplug-status=connected to skip the call is wrong and leads to not configured interface.
More discussion at
https://lore.kernel.org/xen-devel/[email protected]/T/#u
--- drivers/net/xen-netback/xenbus.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/xen-netback/xenbus.c +1 -0
@@ -435,6 +435,7 @@ static void backend_disconnect(struct backend_info *be)unsigned int queue_index;xen_unregister_watchers (vif); +xenbus_rm (XBT_NIL , be->dev->nodename,"hotplug-status" );#ifdef CONFIG_DEBUG_FS xenvif_debugfs_delif (vif);#endif /* CONFIG_DEBUG_FS */
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 7/11 Revert "xen-netback: Check for hotplug-status existence before watching"
In reply to Sasha LevinFrom: Marek Marczykowski-Górecki <[email protected]>
[ Upstream commit e8240addd0a3919e0fd7436416afe9aa6429c484 ]
This reverts commit 2afeec08ab5c86ae21952151f726bfe184f6b23d.
The reasoning in the commit was wrong - the code expected to setup the watch even if 'hotplug-status' didn't exist. In fact, it relied on the watch being fired the first time - to check if maybe 'hotplug-status' is already set to 'connected'. Not registering a watch for non-existing path (which is the case if hotplug script hasn't been executed yet), made the backend not waiting for the hotplug script to execute. This in turns, made the netfront think the interface is fully operational, while in fact it was not (the vif interface on xen-netback side might not be configured yet).
This was a workaround for 'hotplug-status' erroneously being removed. But since that is reverted now, the workaround is not necessary either.
More discussion at
https://lore.kernel.org/xen-devel/[email protected]/T/#u
--- drivers/net/xen-netback/xenbus.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/net/xen-netback/xenbus.c +4 -8
@@ -980,15 +980,11 @@ static void connect(struct backend_info *be)xenvif_carrier_on (be->vif);unregister_hotplug_status_watch (be); -if (xenbus_exists (XBT_NIL , dev->nodename,"hotplug-status" )) { - err =xenbus_watch_pathfmt (dev, &be->hotplug_status_watch, -NULL , hotplug_status_changed, -"%s/%s" , dev->nodename, -"hotplug-status" ); -if (err) - goto err; + err =xenbus_watch_pathfmt (dev, &be->hotplug_status_watch,NULL , + hotplug_status_changed, +"%s/%s" , dev->nodename,"hotplug-status" ); +if (!err) be->have_hotplug_status_watch =1 ; - }netif_tx_wake_all_queues (be->vif->dev);
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 8/11 ipv6: prevent a possible race condition with lifetimes
In reply to Sasha LevinFrom: Niels Dossche <[email protected]>
[ Upstream commit 6c0d8833a605e195ae219b5042577ce52bf71fff ]
valid_lft, prefered_lft and tstamp are always accessed under the lock "lock" in other places. Reading these without taking the lock may result in inconsistencies regarding the calculation of the valid and preferred variables since decisions are taken on these fields for those variables.
--- net/ipv6/addrconf.c | 2 ++ 1 file changed, 2 insertions(+)
net/ipv6/addrconf.c +2 -0
@@ -4924,6 +4924,7 @@ static int inet6_fill_ifaddr(struct sk_buff *skb, struct inet6_ifaddr *ifa, nla_put_s32(skb, IFA_TARGET_NETNSID, args->netnsid)) goto error; +spin_lock_bh (&ifa->lock);if (!((ifa->flags&IFA_F_PERMANENT ) && (ifa->prefered_lft ==INFINITY_LIFE_TIME ))) { preferred = ifa->prefered_lft;
@@ -4945,6 +4946,7 @@ static int inet6_fill_ifaddr(struct sk_buff *skb, struct inet6_ifaddr *ifa, preferred =INFINITY_LIFE_TIME ; valid =INFINITY_LIFE_TIME ; } +spin_unlock_bh (&ifa->lock);if (!ipv6_addr_any (&ifa->peer_addr)) { if (nla_put_in6_addr(skb, IFA_LOCAL, &ifa->addr) < 0 ||
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 9/11 tracing: Ensure trace buffer is at least 4096 bytes large
In reply to Sasha LevinFrom: Sven Schnelle <[email protected]>
[ Upstream commit 7acf3a127bb7c65ff39099afd78960e77b2ca5de ]
Booting the kernel with 'trace_buf_size=1' give a warning at boot during the ftrace selftests:
[ 0.892809] Running postponed tracer tests: [ 0.892893] Testing tracer function: [ 0.901899] Callback from call_rcu_tasks_trace() invoked. [ 0.983829] Callback from call_rcu_tasks_rude() invoked. [ 1.072003] .. bad ring buffer .. corrupted trace buffer .. [ 1.091944] Callback from call_rcu_tasks() invoked. [ 1.097695] PASSED [ 1.097701] Testing dynamic ftrace: .. filter failed count=0 ..FAILED! [ 1.353474] ------------[ cut here ]------------ [ 1.353478] WARNING: CPU: 0 PID: 1 at kernel/trace/trace.c:1951 run_tracer_selftest+0x13c/0x1b0
Therefore enforce a minimum of 4096 bytes to make the selftest pass.
--- kernel/trace/trace.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
kernel/trace/trace.c +6 -4
@@ -1305,10 +1305,12 @@ static int __init set_buf_size(char *str)if (!str)return 0 ; buf_size =memparse (str, &str); -/* nr_entries can not be zero */ -if (buf_size ==0 ) -return 0 ; - trace_buf_size = buf_size; +/* +* nr_entries can not be zero and the startup +* tests require some buffer space. Therefore +* ensure we have at least 4096 bytes of buffer. +*/ + trace_buf_size =max (4096UL , buf_size);return 1 ; }__setup ("trace_buf_size=" , set_buf_size);
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 10/11 selftest/vm: fix map_fixed_noreplace test failure
In reply to Sasha LevinFrom: "Aneesh Kumar K.V" <[email protected]>
[ Upstream commit f39c58008dee7ab5fc94c3f1995a21e886801df0 ]
On the latest RHEL the test fails due to executable mapped at 256MB address
# ./map_fixed_noreplace
mmap() @ 0x10000000-0x10050000 p=0xffffffffffffffff result=File exists
10000000-10010000 r-xp 00000000 fd:04 34905657 /root/rpmbuild/BUILD/kernel-5.14.0-56.el9/linux-5.14.0-56.el9.ppc64le/tools/testing/selftests/vm/map_fixed_noreplace
10010000-10020000 r--p 00000000 fd:04 34905657 /root/rpmbuild/BUILD/kernel-5.14.0-56.el9/linux-5.14.0-56.el9.ppc64le/tools/testing/selftests/vm/map_fixed_noreplace
10020000-10030000 rw-p 00010000 fd:04 34905657 /root/rpmbuild/BUILD/kernel-5.14.0-56.el9/linux-5.14.0-56.el9.ppc64le/tools/testing/selftests/vm/map_fixed_noreplace
10029b90000-10029bc0000 rw-p 00000000 00:00 0 [heap]
7fffbb510000-7fffbb750000 r-xp 00000000 fd:04 24534 /usr/lib64/libc.so.6
7fffbb750000-7fffbb760000 r--p 00230000 fd:04 24534 /usr/lib64/libc.so.6
7fffbb760000-7fffbb770000 rw-p 00240000 fd:04 24534 /usr/lib64/libc.so.6
7fffbb780000-7fffbb7a0000 r--p 00000000 00:00 0 [vvar]
7fffbb7a0000-7fffbb7b0000 r-xp 00000000 00:00 0 [vdso]
7fffbb7b0000-7fffbb800000 r-xp 00000000 fd:04 24514 /usr/lib64/ld64.so.2
7fffbb800000-7fffbb810000 r--p 00040000 fd:04 24514 /usr/lib64/ld64.so.2
7fffbb810000-7fffbb820000 rw-p 00050000 fd:04 24514 /usr/lib64/ld64.so.2
7fffd93f0000-7fffd9420000 rw-p 00000000 00:00 0 [stack]
Error: couldn't map the space we need for the testFix this by finding a free address using mmap instead of hardcoding BASE_ADDRESS.
--- .../selftests/vm/map_fixed_noreplace.c | 49 ++++++++++++++----- 1 file changed, 37 insertions(+), 12 deletions(-)
tools/testing/selftests/vm/map_fixed_noreplace.c +37 -12
@@ -17,9 +17,6 @@#define MAP_FIXED_NOREPLACE 0x100000#endif -#define BASE_ADDRESS (256ul * 1024 * 1024) - -static void dump_maps (void ) {char cmd[32 ];
@@ -28,18 +25,46 @@ static void dump_maps(void)system (cmd); } +static unsigned long find_base_addr (unsigned long size) +{ +void *addr; +unsigned long flags; + + flags =MAP_PRIVATE |MAP_ANONYMOUS ; + addr =mmap (NULL , size,PROT_NONE , flags,-1 ,0 ); +if (addr ==MAP_FAILED ) { +printf ("Error: couldn't map the space we need for the test\n" ); +return 0 ; + } + +if (munmap (addr, size) !=0 ) { +printf ("Error: couldn't map the space we need for the test\n" ); +return 0 ; + } +return (unsigned long )addr; +} +int main (void ) { +unsigned long base_addr;unsigned long flags, addr, size, page_size;char *p; page_size =sysconf (_SC_PAGE_SIZE); +//let's find a base addr that is free before we start the tests + size =5 * page_size; + base_addr =find_base_addr (size); +if (!base_addr) { +printf ("Error: couldn't map the space we need for the test\n" ); +return 1 ; + } + flags =MAP_PRIVATE |MAP_ANONYMOUS |MAP_FIXED_NOREPLACE ;// Check we can map all the areas we need below errno =0 ; - addr =BASE_ADDRESS ; + addr = base_addr; size =5 * page_size; p =mmap ((void *)addr, size,PROT_NONE , flags,-1 ,0 );
@@ -60,7 +85,7 @@ int main(void)printf ("unmap() successful\n" ); errno =0 ; - addr =BASE_ADDRESS + page_size; + addr = base_addr + page_size; size =3 * page_size; p =mmap ((void *)addr, size,PROT_NONE , flags,-1 ,0 );printf ("mmap() @ 0x%lx-0x%lx p=%p result=%m\n" , addr, addr + size, p);
@@ -80,7 +105,7 @@ int main(void)* +4 | free | new */ errno =0 ; - addr =BASE_ADDRESS ; + addr = base_addr; size =5 * page_size; p =mmap ((void *)addr, size,PROT_NONE , flags,-1 ,0 );printf ("mmap() @ 0x%lx-0x%lx p=%p result=%m\n" , addr, addr + size, p);
@@ -101,7 +126,7 @@ int main(void)* +4 | free | */ errno =0 ; - addr =BASE_ADDRESS + (2 * page_size); + addr = base_addr + (2 * page_size); size = page_size; p =mmap ((void *)addr, size,PROT_NONE , flags,-1 ,0 );printf ("mmap() @ 0x%lx-0x%lx p=%p result=%m\n" , addr, addr + size, p);
@@ -121,7 +146,7 @@ int main(void)* +4 | free | new */ errno =0 ; - addr =BASE_ADDRESS + (3 * page_size); + addr = base_addr + (3 * page_size); size =2 * page_size; p =mmap ((void *)addr, size,PROT_NONE , flags,-1 ,0 );printf ("mmap() @ 0x%lx-0x%lx p=%p result=%m\n" , addr, addr + size, p);
@@ -141,7 +166,7 @@ int main(void)* +4 | free | */ errno =0 ; - addr =BASE_ADDRESS ; + addr = base_addr; size =2 * page_size; p =mmap ((void *)addr, size,PROT_NONE , flags,-1 ,0 );printf ("mmap() @ 0x%lx-0x%lx p=%p result=%m\n" , addr, addr + size, p);
@@ -161,7 +186,7 @@ int main(void)* +4 | free | */ errno =0 ; - addr =BASE_ADDRESS ; + addr = base_addr; size = page_size; p =mmap ((void *)addr, size,PROT_NONE , flags,-1 ,0 );printf ("mmap() @ 0x%lx-0x%lx p=%p result=%m\n" , addr, addr + size, p);
@@ -181,7 +206,7 @@ int main(void)* +4 | free | new */ errno =0 ; - addr =BASE_ADDRESS + (4 * page_size); + addr = base_addr + (4 * page_size); size = page_size; p =mmap ((void *)addr, size,PROT_NONE , flags,-1 ,0 );printf ("mmap() @ 0x%lx-0x%lx p=%p result=%m\n" , addr, addr + size, p);
@@ -192,7 +217,7 @@ int main(void)return 1 ; } - addr =BASE_ADDRESS ; + addr = base_addr; size =5 * page_size;if (munmap ((void *)addr, size) !=0 ) {dump_maps ();
Signature · 1 line
2.34.1
Sasha Levin
maintainerPATCH 11/11 selftests/memfd: clean up mapping in mfd_fail_write
In reply to Sasha LevinFrom: Mike Kravetz <[email protected]>
[ Upstream commit fda153c89af344d21df281009a9d046cf587ea0f ]
Running the memfd script ./run_hugetlbfs_test.sh will often end in error as follows:
memfd-hugetlb: CREATE
memfd-hugetlb: BASIC
memfd-hugetlb: SEAL-WRITE
memfd-hugetlb: SEAL-FUTURE-WRITE
memfd-hugetlb: SEAL-SHRINK fallocate(ALLOC) failed: No space left on device
./run_hugetlbfs_test.sh: line 60: 166855 Aborted (core dumped) ./memfd_test hugetlbfs
opening: ./mnt/memfd
fuse: DONE
If no hugetlb pages have been preallocated, run_hugetlbfs_test.sh will allocate 'just enough' pages to run the test. In the SEAL-FUTURE-WRITE test the mfd_fail_write routine maps the file, but does not unmap. As a result, two hugetlb pages remain reserved for the mapping. When the fallocate call in the SEAL-SHRINK test attempts allocate all hugetlb pages, it is short by the two reserved pages.
Fix by making sure to unmap in mfd_fail_write.
--- tools/testing/selftests/memfd/memfd_test.c | 1 + 1 file changed, 1 insertion(+)
tools/testing/selftests/memfd/memfd_test.c +1 -0
@@ -421,6 +421,7 @@ static void mfd_fail_write(int fd)printf ("mmap()+mprotect() didn't fail as expected\n" );abort (); } +munmap (p, mfd_def_size); }/* verify PUNCH_HOLE fails */
Signature · 1 line
2.34.1