7.1.5-rc1 review
Subsystems (15)
Greg Kroah-Hartman
maintainerPATCH 1627/2077 mfd: sm501: Fix reference leak on failed device registration
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
commit 8c2f0b42fc252e1bf1c7746447091a468e784ca1 upstream.
When platform_device_register() fails in sm501_register_device(), the embedded struct device in pdev has already been initialized by device_initialize(), but the failure path only reports the error and returns without dropping the device reference for the current platform device:
sm501_register_device()
-> platform_device_register(pdev)
-> device_initialize(&pdev->dev)
-> setup_pdev_dma_masks(pdev)
-> platform_device_add(pdev)This leads to a reference leak when platform_device_register() fails. Fix this by calling platform_device_put() before returning the error.
The issue was identified by a static analysis tool I developed and confirmed by manual review.
--- drivers/mfd/sm501.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mfd/sm501.c +3 -1
@@ -704,9 +704,11 @@ static int sm501_register_device(structif (ret >=0 ) {dev_dbg (sm->dev,"registered %s\n" , pdev->name);list_add_tail (&smdev->list, &sm->devices); - }else + }else {dev_err (sm->dev,"error registering %s (%d)\n" , pdev->name, ret); +platform_device_put (pdev); + }return ret; }
Greg Kroah-Hartman
maintainerPATCH 1628/2077 tools/power/x86/intel-speed-select: Harden daemon pidfile open
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ali Ahmet MEMIS <[email protected]>
commit 607af438e6430893a822964c841a1994b33acccc upstream.
Avoid symlink-based pidfile clobbering by opening the pidfile with O_NOFOLLOW and validating it with fstat() before locking/writing.
The daemon currently uses a fixed pidfile path under /tmp. A local unprivileged user can pre-create a symlink at that path and cause a root-run daemon instance to write into an attacker-chosen file.
--- tools/power/x86/intel-speed-select/isst-daemon.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
tools/power/x86/intel-speed-select/isst-daemon.c +8 -1
@@ -148,6 +148,7 @@ static void daemonize(char *rundir, char {int pid, sid, i;char str[10 ]; +struct stat st;struct sigaction sig_actions;sigset_t sig_set;int ret;
@@ -200,11 +201,17 @@ static void daemonize(char *rundir, charif (ret ==-1 )exit (EXIT_FAILURE ); - pid_file_handle =open (pidfile,O_RDWR |O_CREAT ,0600 ); + pid_file_handle =open (pidfile,O_RDWR |O_CREAT |O_NOFOLLOW ,0600 );if (pid_file_handle ==-1 ) {/* Couldn't open lock file */ exit (1 ); } + +if (fstat (pid_file_handle, &st) ==-1 ) +exit (1 ); + +if (!S_ISREG (st.st_mode)) +exit (1 );/* Try to lock file */ #ifdef LOCKF_SUPPORT if (lockf (pid_file_handle,F_TLOCK ,0 ) ==-1 ) {
Greg Kroah-Hartman
maintainerPATCH 1629/2077 x86/video: Only fall back to vga_default_device() without screen info
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mario Limonciello <[email protected]>
commit 596b3678326d3d1aed7c19423b6746f1ce09688a upstream.
Some multi GPU systems may have a VGA compatible device, but that might not be used for display. If due to enumeration order this device is found before the one actually used for display then multiple devices may show the boot_display attribute, confusing userspace.
When screen info is valid, use it exclusively to find the primary device so that only the device backing the framebuffer is reported. Only when no framebuffer has been set up does it make sense to fall back to the default VGA device. This ensures at most one primary graphics device, preferably the one with the framebuffer.
--- arch/x86/video/video-common.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
arch/x86/video/video-common.c +14 -9
@@ -43,21 +43,26 @@ bool video_is_primary_device(struct deviif (!pci_is_display (pdev))return false; -if (pdev ==vga_default_device ()) -return true; -#ifdef CONFIG_SCREEN_INFO numres =screen_info_resources (si, res,ARRAY_SIZE (res)); -for (i =0 ; i < numres; ++i) { -if (!(res[i].flags &IORESOURCE_MEM )) -continue ; +if (numres >0 ) { +for (i =0 ; i < numres; ++i) { +if (!(res[i].flags &IORESOURCE_MEM )) +continue ; + +if (pci_find_resource (pdev, &res[i])) +return true; + } -if (pci_find_resource (pdev, &res[i])) -return true; +return false; }#endif -return false; +/* +* No framebuffer was set up by the firmware/bootloader, so fall back +* to the default VGA device. +*/ +return pdev ==vga_default_device (); }EXPORT_SYMBOL (video_is_primary_device);
Greg Kroah-Hartman
maintainerPATCH 1630/2077 x86/virt/sev: Revert "Drop WBINVD before setting MSR_AMD64_SYSCFG_SNP_EN"
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tycho Andersen (AMD) <[email protected]>
commit 4c2509f3b79756679a02bea649c6a7501b58f52c upstream.
Revert
99cf1fb58e68 ("x86/virt/sev: Drop WBINVD before setting MSR_AMD64_SYSCFG_SNP_EN").
Section 8.8 of the SNP spec says:
Before invoking SNP_INIT_EX with INIT_RMP set to 1, software must ensure that no CPUs contain dirty cache lines for the memory containing the RMP.
Cachelines can be moved from cache to cache in a dirty state. The wbinvd_on_all_cpus() before SNP_INIT_EX flushes the caches for each CPU, but if the IPIs for WBINVD race with this dirty cacheline movement, it is possible that they may not get flushed, violating the firmware requirement.
Doing wbinvd_on_all_cpus() before setting SNPEn is safer since the RMP table is not yet in use.
[ Heroically bisected by Srikanth. ]
[ bp: Massage commit message. ]
--- arch/x86/virt/svm/sev.c | 2 ++ 1 file changed, 2 insertions(+)
arch/x86/virt/svm/sev.c +2 -0
@@ -527,6 +527,8 @@ void snp_prepare(void)cpus_read_lock (); +wbinvd_on_all_cpus (); +/* * MtrrFixDramModEn is not shared between threads on a core, * therefore it must be set on all CPUs prior to enabling SNP.
Greg Kroah-Hartman
maintainerPATCH 1631/2077 x86/boot: Validate console=uart8250 baud rate to fix early boot hang
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
commit ffa0aa5b625fe0bed7463ac613f8b06676ff4542 upstream.
When the baud rate is empty, 0, invalid, or overflows to 0 when stored as an int, the system will hang during early boot because of a division by zero in early_serial_init().
Fall back to DEFAULT_BAUD when the resulting baud rate is 0 to prevent an early system hang.
--- arch/x86/boot/early_serial_console.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
arch/x86/boot/early_serial_console.c +7 -4
@@ -117,7 +117,7 @@ static unsigned int probe_baud(int port)static void parse_console_uart8250 (void ) {char optstr[64 ], *options; -int baud =DEFAULT_BAUD ; +int baud;int port =0 ;/*
@@ -136,10 +136,13 @@ static void parse_console_uart8250(void)else return ; -if (options && (options[0 ] ==',' )) - baud =simple_strtoull (options +1 , &options,0 ); -else +if (options && (options[0 ] ==',' )) { + baud =simple_strtoull (options +1 ,NULL ,0 ); +if (!baud) + baud =DEFAULT_BAUD ; + }else { baud =probe_baud (port); + }if (port)early_serial_init (port, baud);
Greg Kroah-Hartman
maintainerPATCH 1632/2077 x86/boot: Reject too long acpi_rsdp= values
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
commit d130041a7b96f79cd4c7079a6c2431a6db4c9619 upstream.
cmdline_find_option() returns the full length of the parsed acpi_rsdp= value. get_cmdline_acpi_rsdp() then silently truncates values which do not fit in the val[] buffer.
Prevent boot_kstrtoul() from parsing a truncated value and then the kernel from silently using the wrong RSDP address, see discussion in Link:.
Issue a warning so that the user is aware that s/he supplied a malformed value and can get feedback instead of silent crashes.
[ bp: Make commit message more precise. ]
--- arch/x86/boot/compressed/acpi.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/x86/boot/compressed/acpi.c +6 -1
@@ -184,10 +184,15 @@ static unsigned long get_cmdline_acpi_rschar val[MAX_ADDR_LEN ] = { };int ret; - ret =cmdline_find_option ("acpi_rsdp" , val,MAX_ADDR_LEN ); + ret =cmdline_find_option ("acpi_rsdp" , val,sizeof (val));if (ret <0 )return 0 ; +if (ret >=sizeof (val)) { +warn ("acpi_rsdp= value too long; ignoring" ); +return 0 ; + } +if (boot_kstrtoul (val,16 , &addr))return 0 ;#endif
Greg Kroah-Hartman
maintainerPATCH 1633/2077 perf/x86/amd/brs: Fix kernel address leakage
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sandipan Das <[email protected]>
commit 47915e855fb38b42133e31ba917d99565f862154 upstream.
A user-only branch stack can contain branches that originate from the kernel. As a result, kernel addresses are exposed to user space even when PERF_SAMPLE_BRANCH_USER is requested. On AMD processors supporting X86_FEATURE_BRS (Zen 3 only), perf can still report entries such as SYSRET/interrupt returns for which the branch-from addresses are in the kernel.
E.g.
$ perf record -j any,u -c 4000 -e branch-brs -o - -- \
perf bench syscall basic --loop 1000 | \
perf script -i - -F brstack|tr ' ' '\n'| \
grep -E '0x[89a-f][0-9a-f]{15}' ...
0xffffffff810001c4/0x72e2e32955eb/-/-/-/0//-
0xffffffff810001c4/0x72e2d94a9821/-/-/-/0//-
0xffffffff810001c4/0x72e2d94ffa1b/-/-/-/0//-
...
BRS provides no hardware branch filtering, so privilege level filtering is performed entirely in software. However, amd_brs_match_plm() only validates the branch-to address against the requested privilege levels. For branches from the kernel to user space, the branch-from address is left unchecked and is leaked. Extend the software filter to also validate the branch-from address, so that any branch record whose branch-from address is in the kernel is dropped when PERF_SAMPLE_BRANCH_USER is requested.
--- arch/x86/events/amd/brs.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
arch/x86/events/amd/brs.c +5 -5
@@ -259,13 +259,13 @@ void amd_brs_disable_all(void)amd_brs_disable (); } -static bool amd_brs_match_plm (struct perf_event *event,u64 to) +static bool amd_brs_match_plm (struct perf_event *event,u64 from,u64 to) {int type = event->attr.branch_sample_type;int plm_k =PERF_SAMPLE_BRANCH_KERNEL |PERF_SAMPLE_BRANCH_HV ;int plm_u =PERF_SAMPLE_BRANCH_USER ; -if (!(type & plm_k) &&kernel_ip (to)) +if (!(type & plm_k) && (kernel_ip (to) ||kernel_ip (from)))return 0 ;if (!(type & plm_u) && !kernel_ip (to))
@@ -338,11 +338,11 @@ void amd_brs_drain(void)*/ to = (u64)(((s64 )to << shift) >> shift); -if (!amd_brs_match_plm (event, to)) -continue ; -rdmsrq (brs_from (brs_idx), from); +if (!amd_brs_match_plm (event, from, to)) +continue ; +perf_clear_branch_entry_bitfields (br+nr); br[nr].from = from;
Greg Kroah-Hartman
maintainerPATCH 1634/2077 perf/x86/amd/lbr: Fix kernel address leakage
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sandipan Das <[email protected]>
commit 2a892294b83f541115c94b0bb637f39bef187657 upstream.
A user-only branch stack can contain branches that originate from the kernel. As a result, kernel addresses are exposed to user space even when PERF_SAMPLE_BRANCH_USER is requested. On AMD processors supporting X86_FEATURE_AMD_LBR_V2, perf can still report SYSRET/ERET entries for which the branch-from addresses are in the kernel.
E.g.
$ perf record -e cycles -o - -j any,save_type,u -- \
perf bench syscall basic --loop 1000 | \
perf script -i - -F brstack|tr ' ' '\n'| \
grep -E '0x[89a-f][0-9a-f]{15}' ...
0xffffffff81001268/0x717a90a38f1a/M/-/-/0/ERET/NON_SPEC_CORRECT_PATH 0xffffffff81001268/0x717a90a39157/M/-/-/0/ERET/NON_SPEC_CORRECT_PATH 0xffffffff81001268/0x717a90a2c628/M/-/-/0/ERET/NON_SPEC_CORRECT_PATH 0xffffffff81001268/0x717a90a41b60/M/-/-/0/ERET/NON_SPEC_CORRECT_PATH 0xffffffff81001268/0x717a90a260db/M/-/-/0/ERET/NON_SPEC_CORRECT_PATH 0xffffffff81001268/0x717a90a260db/M/-/-/0/ERET/NON_SPEC_CORRECT_PATH 0xffffffff81001268/0x717a8bef1c30/M/-/-/0/ERET/NON_SPEC_CORRECT_PATH 0xffffffff81001268/0x717a8e4d3c90/M/-/-/0/ERET/NON_SPEC_CORRECT_PATH
...
The reason is that the hardware filter only considers the privilege level applicable to the branch target. Extend software filtering to also validate the branch-from addresses against br_sel, so that any branch record whose branch-from address is in the kernel is dropped when PERF_SAMPLE_BRANCH_USER is requested.
--- arch/x86/events/amd/lbr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/events/amd/lbr.c +2 -1
@@ -125,7 +125,8 @@ static void amd_pmu_lbr_filter(void) }/* If type does not correspond, then discard */ -if (type ==X86_BR_NONE || (br_sel & type) != type) { +if (type ==X86_BR_NONE || (br_sel & type) != type || + (!(br_sel &X86_BR_KERNEL ) &&kernel_ip (cpuc->lbr_entries[i].from))) { cpuc->lbr_entries[i].from =0 ;/* mark invalid */ compress = true; }
Greg Kroah-Hartman
maintainerPATCH 1635/2077 cpufreq: schedutil: Fix uncleared need_freq_update on the .adjust_perf() path
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhongqiu Han <[email protected]>
commit 9ef450ca74e43dacf9a2a15db7a851052c78dcf0 upstream.
The need_freq_update flag makes sugov_should_update_freq() return true regardless of the rate_limit_us throttling, and is cleared in sugov_update_next_freq(). sugov_update_single_freq() and sugov_update_shared() go through that helper, so the flag does not persist there.
However, sugov_update_single_perf(), used by drivers implementing the .adjust_perf() callback (e.g. intel_pstate or amd-pstate in passive mode) calls cpufreq_driver_adjust_perf() directly and never goes through sugov_update_next_freq(), so the need_freq_update flag is not cleared in that path.
Before commit 75da043d8f88 ("cpufreq/sched: Set need_freq_update in ignore_dl_rate_limit()"), this was effectively harmless because sugov_should_update_freq() still honored the rate limit even when need_freq_update was set. After that change, the flag forces sugov_should_update_freq() to always return true, so once set, it stays effective indefinitely on the .adjust_perf() path.
As a result, cpufreq_driver_adjust_perf() gets called on every scheduler utilization update (with the runqueue lock held) rather than being throttled by rate_limit_us, even if the driver itself may skip redundant hardware updates.
Clear need_freq_update at the end of the adjust_perf path as well.
--- kernel/sched/cpufreq_schedutil.c | 1 + 1 file changed, 1 insertion(+)
kernel/sched/cpufreq_schedutil.c +1 -0
@@ -486,6 +486,7 @@ static void sugov_update_single_perf(strcpufreq_driver_adjust_perf (sg_policy->policy, sg_cpu->bw_min, sg_cpu->util, max_cap); + sg_policy->need_freq_update = false; sg_policy->last_freq_update_time = time; }
Greg Kroah-Hartman
maintainerPATCH 1636/2077 cpufreq: intel_pstate: Set non-turbo capacity to HWP_GUARANTEED_PERF()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
commit 27d80e0f8b8dff97503fc0061754b1d3800cb961 upstream.
Setting cpu->capacity_perf to cpu->pstate.max_pstate_physical in the "no turbo" case is inconsistent with what happens elsewhere in the driver and causes arch_scale_cpu_capacity() to be incorrect. It also skews arch_scale_freq_capacity() which ends up differing from 1024 for the guaranteed P-state.
Address that by setting capacity_perf to HWP_GUARANTEED_PERF() in the "no turbo" case.
--- drivers/cpufreq/intel_pstate.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/cpufreq/intel_pstate.c +4 -2
@@ -1058,12 +1058,14 @@ static void hybrid_clear_cpu_capacity(unstatic void hybrid_get_capacity_perf (struct cpudata *cpu) { +u64 hwp_cap =READ_ONCE (cpu->hwp_cap_cached); +if (READ_ONCE (global.no_turbo)) { - cpu->capacity_perf = cpu->pstate.max_pstate_physical; + cpu->capacity_perf =HWP_GUARANTEED_PERF (hwp_cap);return ; } - cpu->capacity_perf =HWP_HIGHEST_PERF (READ_ONCE (cpu->hwp_cap_cached)); + cpu->capacity_perf =HWP_HIGHEST_PERF (hwp_cap); }static void hybrid_set_capacity_of_cpus (void )
Greg Kroah-Hartman
maintainerPATCH 1637/2077 s390/perf_cpum_cf: Add missing array_index_nospec() to __hw_perf_event_init()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sumanth Korikkar <[email protected]>
commit 49145bce539117db4b6e9e83c0e5ef528e361050 upstream.
ev variable is userspace controlled via event->attr.config and used as an array index after bounds checking, but without speculation barriers.
Add the missing array_index_nospec() call to prevent speculative execution.
--- arch/s390/kernel/perf_cpum_cf.c | 3 +++ 1 file changed, 3 insertions(+)
arch/s390/kernel/perf_cpum_cf.c +3 -0
@@ -15,6 +15,7 @@#include <linux/init.h> #include <linux/miscdevice.h> #include <linux/perf_event.h> +#include <linux/nospec.h> #include <asm/cpu_mf.h> #include <asm/hwctrset.h>
@@ -768,6 +769,7 @@ static int __hw_perf_event_init(struct pif (!is_userspace_event (ev)) {if (ev >=ARRAY_SIZE (cpumf_generic_events_user))return -EOPNOTSUPP ; + ev =array_index_nospec (ev,ARRAY_SIZE (cpumf_generic_events_user)); ev = cpumf_generic_events_user[ev]; } }else if (!attr->exclude_kernel && attr->exclude_user) {
@@ -778,6 +780,7 @@ static int __hw_perf_event_init(struct pif (!is_userspace_event (ev)) {if (ev >=ARRAY_SIZE (cpumf_generic_events_basic))return -EOPNOTSUPP ; + ev =array_index_nospec (ev,ARRAY_SIZE (cpumf_generic_events_basic)); ev = cpumf_generic_events_basic[ev]; } }
Greg Kroah-Hartman
maintainerPATCH 1638/2077 batman-adv: gw: acquire ethernet header only after skb realloc
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 77880a3be88d378d60cc1e8f8ec70430e2ed0518 upstream.
The pskb_may_pull() called by batadv_get_vid() could reallocate the buffer behind the skb. Variables which were pointing to the old buffer need to be reassigned to avoid an use-after-free.
--- net/batman-adv/gateway_client.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/batman-adv/gateway_client.c +2 -1
@@ -683,12 +683,13 @@ bool batadv_gw_out_of_range(struct batadstruct batadv_gw_node *gw_node =NULL ;struct batadv_gw_node *curr_gw =NULL ;struct batadv_neigh_ifinfo *curr_ifinfo, *old_ifinfo; -struct ethhdr *ethhdr = (struct ethhdr *)skb->data; +struct ethhdr *ethhdr;bool out_of_range = false;u8 curr_tq_avg;unsigned short vid; vid =batadv_get_vid (skb,0 ); + ethhdr = (struct ethhdr *)skb->data;if (is_multicast_ether_addr (ethhdr->h_dest)) goto out;
Greg Kroah-Hartman
maintainerPATCH 1639/2077 batman-adv: retrieve ethhdr after potential skb realloc on RX
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 035e1fed892d3d06002a73ff73668f618a514644 upstream.
pskb_may_pull() in batadv_interface_rx() could reallocate the buffer behind the skb. Variables which were pointing to the old buffer need to be reassigned to avoid an use-after-free.
This was done correctly for the VLAN header but missed for the ethernet header which is later used for the TT and AP isolation handling.
--- net/batman-adv/mesh-interface.c | 1 + 1 file changed, 1 insertion(+)
net/batman-adv/mesh-interface.c +1 -0
@@ -432,6 +432,7 @@ void batadv_interface_rx(struct net_deviif (!pskb_may_pull (skb,VLAN_ETH_HLEN )) goto dropped; + ethhdr =eth_hdr (skb); vhdr =skb_vlan_eth_hdr (skb);/* drop batman-in-batman packets to prevent loops */
Greg Kroah-Hartman
maintainerPATCH 1640/2077 batman-adv: access unicast_ttvn skb->data only after skb realloc
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 7141990add3f75436f2933cb310654cad3b1e3e9 upstream.
The pskb_may_pull() called by batadv_get_vid() could reallocate the buffer behind the skb. Variables which were pointing to the old buffer need to be reassigned to avoid an use-after-free.
This was done correctly for the ethernet header but missed for the unicast_packet pointer.
--- net/batman-adv/routing.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/batman-adv/routing.c +1 -1
@@ -855,8 +855,8 @@ static bool batadv_check_unicast_ttvn(stif (skb_cow (skb,sizeof (*unicast_packet)) <0 )return false; - unicast_packet = (struct batadv_unicast_packet *)skb->data; vid =batadv_get_vid (skb, hdr_len); + unicast_packet = (struct batadv_unicast_packet *)skb->data; ethhdr = (struct ethhdr *)(skb->data + hdr_len);/* do not reroute multicast frames in a unicast header */
Greg Kroah-Hartman
maintainerPATCH 1641/2077 batman-adv: dat: acquire ARP hw source only after skb realloc
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 48067b2ae4504500a7093d9e1e16b42e70330480 upstream.
The pskb_may_pull() called by batadv_get_vid() could reallocate the buffer behind the skb. Variables which were pointing to the old buffer need to be reassigned to avoid an use-after-free.
--- net/batman-adv/distributed-arp-table.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/batman-adv/distributed-arp-table.c +4 -1
@@ -1746,6 +1746,7 @@ void batadv_dat_snoop_incoming_dhcp_ack(struct ethhdr *ethhdr;__be32 ip_src, yiaddr;unsigned short vid; +int hdr_size_tmp;__be16 proto;u8 *hw_src;
@@ -1762,8 +1763,10 @@ void batadv_dat_snoop_incoming_dhcp_ack(if (!batadv_dat_check_dhcp_ack (skb, proto, &ip_src, chaddr, &yiaddr))return ; + hdr_size_tmp = hdr_size; + vid =batadv_dat_get_vid (skb, &hdr_size_tmp); + ethhdr = (struct ethhdr *)(skb->data + hdr_size); hw_src = ethhdr->h_source; - vid =batadv_dat_get_vid (skb, &hdr_size);batadv_dat_entry_add (bat_priv, yiaddr, chaddr, vid);batadv_dat_entry_add (bat_priv, ip_src, hw_src, vid);
Greg Kroah-Hartman
maintainerPATCH 1642/2077 batman-adv: bla: reacquire gw address after skb realloc
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit cdf3b5af2bc4431e58629e8ad2086b1e9185c761 upstream.
The pskb_may_pull() called by batadv_bla_is_backbone_gw() could reallocate the buffer behind the skb. Variables which were pointing to the old buffer need to be reassigned to avoid an use-after-free.
--- net/batman-adv/routing.c | 1 + 1 file changed, 1 insertion(+)
net/batman-adv/routing.c +1 -0
@@ -1029,6 +1029,7 @@ int batadv_recv_unicast_packet(struct sk hdr_size);batadv_orig_node_put (orig_node_gw);if (is_gw) { + orig_addr_gw =eth_hdr (skb)->h_source;batadv_dbg (BATADV_DBG_BLA , bat_priv,"%s(): Dropped unicast pkt received from another backbone gw %pM.\n" , __func__, orig_addr_gw);
Greg Kroah-Hartman
maintainerPATCH 1643/2077 batman-adv: dat: ensure accessible eth_hdr proto field
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 26560c4a03dc4d607331600c187f59ab2df5f341 upstream.
When batadv_get_vid() accesses the proto field of the ethernet header, it is not checking if the data itself is accessible. The caller is responsible for it. But in contrast to other call sites, batadv_dat_get_vid() and its caller didn't make sure this is true. This could have caused an out-of-bounds access.
--- net/batman-adv/distributed-arp-table.c | 23 +++++++++++++++++++++++ net/batman-adv/main.c | 3 +++ 2 files changed, 26 insertions(+)
net/batman-adv/distributed-arp-table.c +23 -0
@@ -1065,6 +1065,9 @@ out:* @skb: the buffer containing the packet to extract the VID from * @hdr_size: the size of the batman-adv header encapsulating the packet * +* The caller must ensure that at least @hdr_size + ETH_HLEN bytes are +* accessible after skb->data. +* * Return: If the packet embedded in the skb is vlan tagged this function * returns the VID with the BATADV_VLAN_HAS_TAG flag. Otherwise BATADV_NO_FLAGS * is returned.
@@ -1147,6 +1150,10 @@ bool batadv_dat_snoop_outgoing_arp_requeif (!atomic_read (&bat_priv->distributed_arp_table)) goto out; +/* first, find out the vid. */ +if (!pskb_may_pull (skb, hdr_size +ETH_HLEN )) + goto out; + vid =batadv_dat_get_vid (skb, &hdr_size); type =batadv_arp_get_type (bat_priv, skb, hdr_size);
@@ -1242,6 +1249,10 @@ bool batadv_dat_snoop_incoming_arp_requeif (!atomic_read (&bat_priv->distributed_arp_table)) goto out; +/* first, find out the vid. */ +if (!pskb_may_pull (skb, hdr_size +ETH_HLEN )) + goto out; + vid =batadv_dat_get_vid (skb, &hdr_size); type =batadv_arp_get_type (bat_priv, skb, hdr_size);
@@ -1304,6 +1315,10 @@ void batadv_dat_snoop_outgoing_arp_replyif (!atomic_read (&bat_priv->distributed_arp_table))return ; +/* first, find out the vid. */ +if (!pskb_may_pull (skb, hdr_size +ETH_HLEN )) +return ; + vid =batadv_dat_get_vid (skb, &hdr_size); type =batadv_arp_get_type (bat_priv, skb, hdr_size);
@@ -1352,6 +1367,10 @@ bool batadv_dat_snoop_incoming_arp_replyif (!atomic_read (&bat_priv->distributed_arp_table)) goto out; +/* first, find out the vid. */ +if (!pskb_may_pull (skb, hdr_size +ETH_HLEN )) + goto out; + vid =batadv_dat_get_vid (skb, &hdr_size); type =batadv_arp_get_type (bat_priv, skb, hdr_size);
@@ -1806,6 +1825,10 @@ bool batadv_dat_drop_broadcast_packet(stif (batadv_forw_packet_is_rebroadcast (forw_packet)) goto out; +/* first, find out the vid. */ +if (!pskb_may_pull (forw_packet->skb, hdr_size +ETH_HLEN )) + goto out; + vid =batadv_dat_get_vid (forw_packet->skb, &hdr_size); type =batadv_arp_get_type (bat_priv, forw_packet->skb, hdr_size);
net/batman-adv/main.c +3 -0
@@ -566,6 +566,9 @@ void batadv_recv_handler_unregister(u8 p* @skb: the buffer containing the packet * @header_len: length of the batman header preceding the ethernet header * +* The caller must ensure that at least @header_len + ETH_HLEN bytes are +* accessible after skb->data. +* * Return: VID with the BATADV_VLAN_HAS_TAG flag when the packet embedded in the * skb is vlan tagged. Otherwise BATADV_NO_FLAGS. */
Greg Kroah-Hartman
maintainerPATCH 1644/2077 batman-adv: ensure minimal ethernet header on TX
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 49df66b7993c80b80c7eb9a84ba5b3410c8296a0 upstream.
As documented in commit 8bd67ebb50c0 ("net: bridge: xmit: make sure we have at least eth header len bytes"), it is possible by for a local user with eBPF TC hook access to attach a tc filter which truncates the packet and redirects to an batadv interface. But the code assumes that at least ETH_HLEN bytes are available and thus might read outside of the available buffer.
The batadv_interface_tx() must therefore always check itself if enough data is available for the ethernet header and don't rely on min_header_len.
--- net/batman-adv/mesh-interface.c | 3 +++ 1 file changed, 3 insertions(+)
net/batman-adv/mesh-interface.c +3 -0
@@ -193,6 +193,9 @@ static netdev_tx_t batadv_interface_tx(sif (atomic_read (&bat_priv->mesh_state) !=BATADV_MESH_ACTIVE ) goto dropped; +if (!pskb_may_pull (skb,ETH_HLEN )) + goto dropped; +/* reset control block to avoid left overs from previous users */ memset (skb->cb,0 ,sizeof (struct batadv_skb_cb ));
Greg Kroah-Hartman
maintainerPATCH 1645/2077 batman-adv: dat: fix tie-break for candidate selection
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 98052bdaf6ac1639a63ffc10244eeeab1f62ed2b upstream.
The original version of the candidate selection for DAT attempted to compare both candidate and max_orig_node to identify which has the smaller MAC address. This comparison is required as tie-break when a hash collision happened.
But the used function returned 0 when the function was not equal and a non-zero value when it was equal. As result, the actually selected node was dependent on the order of entries in the orig_hash and not actually on the mac addresses. The last originator in the hash collision would always win.
To have a proper ordering, it must diff the actual MAC address bytes and reject the candidate when the diff is not smaller than 0.
--- net/batman-adv/distributed-arp-table.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/batman-adv/distributed-arp-table.c +1 -1
@@ -545,7 +545,7 @@ static bool batadv_is_orig_node_eligible* the one with the lowest address */ if (tmp_max == max && max_orig_node && -batadv_compare_eth (candidate->orig, max_orig_node->orig)) +memcmp (candidate->orig, max_orig_node->orig,ETH_ALEN ) >=0 ) goto out; ret = true;
Greg Kroah-Hartman
maintainerPATCH 1646/2077 batman-adv: tt: avoid request storms during pending request
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 27c7d40008231ae4140d35501b60087a9de2d2c3 upstream.
batadv_send_tt_request() allocates a tt_req_node when none exists for the destination originator node. This should prevent that a multiple TT requests are send at the same time to an originator.
But if allocation of the send buffer failed, this request must be cleaned up again. But indicator for such a failure is "ret == false". But the actual implementation is checking for "ret == true".
The check must be inverted to not loose the information about the TT request directly after it was attempted to be sent out. This should avoid potential request storms.
--- net/batman-adv/translation-table.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/batman-adv/translation-table.c +1 -1
@@ -2963,7 +2963,7 @@ static bool batadv_send_tt_request(struc out:batadv_hardif_put (primary_if); -if (ret && tt_req_node) { +if (!ret && tt_req_node) {spin_lock_bh (&bat_priv->tt.req_list_lock);if (!hlist_unhashed (&tt_req_node->list)) {hlist_del_init (&tt_req_node->list);
Greg Kroah-Hartman
maintainerPATCH 1647/2077 batman-adv: fix VLAN priority offset
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit fdb3be00ba4dafa313e699d6b5b90d13f22f3f25 upstream.
The batadv_skb_set_priority() receives an SKB with the inner ethernet header at position "offset". When it tries to extract the IPv4 and IPv6 header, it needs to skip the ethernet header to get access to the IP header.
But for VLAN header, it performs the access with the struct vlan_ethhdr. This struct contains both both the ethernet header and the VLAN header. It is therefore incorrect to skip over the whole vlan_ethhdr size to get access to the vlan_ethhdr.
--- net/batman-adv/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/batman-adv/main.c +1 -1
@@ -354,7 +354,7 @@ void batadv_skb_set_priority(struct sk_bswitch (ethhdr->h_proto) {case htons (ETH_P_8021Q ): - vhdr =skb_header_pointer (skb, offset +sizeof (*vhdr), + vhdr =skb_header_pointer (skb, offset,sizeof (*vhdr), &vhdr_tmp);if (!vhdr)return ;
Greg Kroah-Hartman
maintainerPATCH 1648/2077 batman-adv: frag: free unfragmentable packet
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 6b628425aed49a1c7a4ffc997583840fc582d32b upstream.
The caller of batadv_frag_send_packet() assume that the skb provided to the function are always consumed. But the pre-check for an empty payload or the zero fragment size returned an error without any further actions.
A failed pre-check must use the same error handling code as the rest of the function.
--- net/batman-adv/fragmentation.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/batman-adv/fragmentation.c +4 -2
@@ -516,8 +516,10 @@ int batadv_frag_send_packet(struct sk_bu mtu = min_t(unsigned int, mtu, BATADV_FRAG_MAX_FRAG_SIZE); max_fragment_size = mtu - header_size; -if (skb->len ==0 || max_fragment_size ==0 ) -return -EINVAL ; +if (skb->len ==0 || max_fragment_size ==0 ) { + ret = -EINVAL ; + goto free_skb; + } num_fragments = (skb->len -1 ) / max_fragment_size +1 ; max_fragment_size = (skb->len -1 ) / num_fragments +1 ;
Greg Kroah-Hartman
maintainerPATCH 1649/2077 batman-adv: clean untagged VLAN on netdev registration failure
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 8669a550c752d86baebc5fdc83b8ff35c4372c0e upstream.
When an mesh interface is registered, it creates an untagged struct batadv_meshif_vlan on top of it via the NETDEV_REGISTER notifier. But in this process, another receiver of this notification can veto the registration. The netdev registration will be aborted because of this veto.
The register_netdevice() call will try to clean up the net_device using unregister_netdevice_queue() - which only uses the .priv_destructor to free private resources. In this situation, .dellink will not be called.
The cleanup of the untagged batadv_meshif_vlan must thefore be done in the destructor to avoid a leak of this object.
--- net/batman-adv/main.c | 8 ++++++++ net/batman-adv/mesh-interface.c | 13 ++----------- net/batman-adv/mesh-interface.h | 2 ++ 3 files changed, 12 insertions(+), 11 deletions(-)
net/batman-adv/main.c +8 -0
@@ -245,6 +245,7 @@ err_orig:void batadv_mesh_free (struct net_device *mesh_iface) {struct batadv_priv *bat_priv =netdev_priv (mesh_iface); +struct batadv_meshif_vlan *vlan;atomic_set (&bat_priv->mesh_state,BATADV_MESH_DEACTIVATING );
@@ -259,6 +260,13 @@ void batadv_mesh_free(struct net_devicebatadv_mcast_free (bat_priv); +/* destroy the "untagged" VLAN */ + vlan =batadv_meshif_vlan_get (bat_priv,BATADV_NO_FLAGS ); +if (vlan) { +batadv_meshif_destroy_vlan (bat_priv, vlan); +batadv_meshif_vlan_put (vlan); + } +/* Free the TT and the originator tables only after having terminated * all the other depending components which may use these structures for * their purposes.
net/batman-adv/mesh-interface.c +2 -11
@@ -593,8 +593,8 @@ int batadv_meshif_create_vlan(struct bat* @bat_priv: the bat priv with all the mesh interface information * @vlan: the object to remove */ -static void batadv_meshif_destroy_vlan (struct batadv_priv *bat_priv, -struct batadv_meshif_vlan *vlan) +void batadv_meshif_destroy_vlan (struct batadv_priv *bat_priv, +struct batadv_meshif_vlan *vlan) {/* explicitly remove the associated TT local entry because it is marked * with the NOPURGE flag
@@ -1089,22 +1089,13 @@ static int batadv_meshif_newlink(structstatic void batadv_meshif_destroy_netlink (struct net_device *mesh_iface,struct list_head *head) { -struct batadv_priv *bat_priv =netdev_priv (mesh_iface);struct batadv_hard_iface *hard_iface; -struct batadv_meshif_vlan *vlan;while (!list_empty (&mesh_iface->adj_list.lower)) { hard_iface =netdev_adjacent_get_private (mesh_iface->adj_list.lower.next);batadv_hardif_disable_interface (hard_iface); } -/* destroy the "untagged" VLAN */ - vlan =batadv_meshif_vlan_get (bat_priv,BATADV_NO_FLAGS ); -if (vlan) { -batadv_meshif_destroy_vlan (bat_priv, vlan); -batadv_meshif_vlan_put (vlan); - } -unregister_netdevice_queue (mesh_iface, head); }
net/batman-adv/mesh-interface.h +2 -0
@@ -21,6 +21,8 @@ void batadv_interface_rx(struct net_devibool batadv_meshif_is_valid (const struct net_device *net_dev);extern struct rtnl_link_ops batadv_link_ops;int batadv_meshif_create_vlan (struct batadv_priv *bat_priv,unsigned short vid); +void batadv_meshif_destroy_vlan (struct batadv_priv *bat_priv, +struct batadv_meshif_vlan *vlan);void batadv_meshif_vlan_release (struct kref *ref);struct batadv_meshif_vlan *batadv_meshif_vlan_get (struct batadv_priv *bat_priv,unsigned short vid);
Greg Kroah-Hartman
maintainerPATCH 1650/2077 batman-adv: frag: fix primary_if leak on failed linearization
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 353d2c1d5492e53ae34f490a84494124dc3d3531 upstream.
If the skb has a frag_list, it must be linearized before it can be split using skb_split(). But when this step failed, it must not only free the skb but also take care of the reference to the already found primary_if.
--- net/batman-adv/fragmentation.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/batman-adv/fragmentation.c +1 -1
@@ -545,7 +545,7 @@ int batadv_frag_send_packet(struct sk_bu*/ if (skb_has_frag_list (skb) &&__skb_linearize (skb)) { ret = -ENOMEM ; - goto free_skb; + goto put_primary_if; }/* Create one header to be copied to all fragments */
Greg Kroah-Hartman
maintainerPATCH 1651/2077 batman-adv: mcast: avoid OOB read of num_dests header
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 38eaed28e250895d56f4b7989bd65479a511c5c3 upstream.
Before the access to struct batadv_tvlv_mcast_tracker's num_dests, it is attempted to check whether enough space is actually in the network header. But instead of using offsetofend() to check for the whole size (2) which must be accessible, offsetof() of is called. The latter is always returning
0. The comparison with the network header length will always return that enough data is available - even when only 1 or 0 bytes are accessible.
Instead of using offsetofend(), use the more common check for the whole header.
--- net/batman-adv/multicast_forw.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
net/batman-adv/multicast_forw.c +3 -4
@@ -927,11 +927,11 @@ static int batadv_mcast_forw_packet(stru {struct batadv_tvlv_mcast_tracker *mcast_tracker;struct batadv_neigh_node *neigh_node; -unsigned long offset, num_dests_off;struct sk_buff *nexthop_skb;unsigned char *skb_net_hdr;bool local_recv = false;unsigned int tvlv_len; +unsigned long offset;bool xmitted = false;u8 *dest, *next_dest;u16 num_dests;
@@ -940,9 +940,8 @@ static int batadv_mcast_forw_packet(stru/* (at least) TVLV part needs to be linearized */ SKB_LINEAR_ASSERT (skb); -/* check if num_dests is within skb length */ - num_dests_off = offsetof(struct batadv_tvlv_mcast_tracker , num_dests); -if (num_dests_off >skb_network_header_len (skb)) +/* check if batadv_tvlv_mcast_tracker header is within skb length */ +if (sizeof (*mcast_tracker) >skb_network_header_len (skb))return -EINVAL ; skb_net_hdr =skb_network_header (skb);
Greg Kroah-Hartman
maintainerPATCH 1652/2077 batman-adv: tt: prevent TVLV OOB check overflow
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 7a581d9aaba8c82bd6177fa36b2588eea77f6e2b upstream.
A TT unicast TVLV contains the number of VLANs stored in it. This number is an u16 and gets multiplied by the size of the struct batadv_tvlv_tt_vlan_data (8 bytes). The size can therefore overflow the u16 used to store the tt_vlan_len. All additional safety checks to prevent out-of-bounds access of the TVLV buffer are invalid due to this overflow.
Using size_t prevents this overflow and ensures that the safety checks compare against the actual buffer requirements.
--- net/batman-adv/translation-table.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/batman-adv/translation-table.c +2 -1
@@ -4025,7 +4025,8 @@ static int batadv_tt_tvlv_unicast_handle u16 tvlv_value_len) {struct batadv_tvlv_tt_data *tt_data; -u16 tt_vlan_len, tt_num_entries; +u16 tt_num_entries; +size_t tt_vlan_len;char tt_flag;bool ret;
Greg Kroah-Hartman
maintainerPATCH 1653/2077 cifs: invalidate cfid on unlink/rename/rmdir
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shyam Prasad N <[email protected]>
commit f71d68d2b473e47db260c27c98212829590d8bae upstream.
Today we do not invalidate the cached_dirent or the entire parent cfid when a dentry in a dir has been removed/moved.
This change invalidates the parent cfid so that we don't serve directory contents from the cache.
--- fs/smb/client/inode.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)
fs/smb/client/inode.c +29 -1
@@ -28,6 +28,23 @@#include "cached_dir.h" #include "reparse.h" +static void cifs_invalidate_cached_dir (struct cifs_tcon *tcon, +struct dentry *parent) +{ +struct cached_fid *parent_cfid =NULL ; + +if (!tcon || !parent) +return ; + +if (!open_cached_dir_by_dentry (tcon, parent, &parent_cfid)) { +mutex_lock (&parent_cfid->dirents.de_mutex); + parent_cfid->dirents.is_valid = false; + parent_cfid->dirents.is_failed = true; +mutex_unlock (&parent_cfid->dirents.de_mutex); +close_cached_dir (parent_cfid); + } +} +/* * Set parameters for the netfs library */
@@ -2067,6 +2084,9 @@ psx_del_no_retry:cifs_set_file_info (inode, attrs, xid, full_path, origattr); out_reval: +if (!rc && dentry->d_parent) +cifs_invalidate_cached_dir (tcon, dentry->d_parent); +if (inode) { cifs_inode =CIFS_I (inode); cifs_inode->time =0 ;/* will force revalidate to get info
@@ -2378,7 +2398,6 @@ int cifs_rmdir(struct inode *inode, stru } rc = server->ops->rmdir (xid, tcon, full_path, cifs_sb); -cifs_put_tlink (tlink); cifsInode =CIFS_I (d_inode (direntry));
@@ -2388,6 +2407,8 @@ int cifs_rmdir(struct inode *inode, strui_size_write (d_inode (direntry),0 );clear_nlink (d_inode (direntry));spin_unlock (&d_inode (direntry)->i_lock); +if (direntry->d_parent) +cifs_invalidate_cached_dir (tcon, direntry->d_parent); }/* force revalidate to go get info when needed */
@@ -2402,6 +2423,7 @@ int cifs_rmdir(struct inode *inode, struinode_set_ctime_current (d_inode (direntry));inode_set_mtime_to_ts (inode,inode_set_ctime_current (inode)); +cifs_put_tlink (tlink); rmdir_exit:free_dentry_path (page);
@@ -2668,6 +2690,12 @@ unlink_target: }/* force revalidate to go get info when needed */ +if (!rc) { +cifs_invalidate_cached_dir (tcon, source_dentry->d_parent); +if (target_dentry->d_parent != source_dentry->d_parent) +cifs_invalidate_cached_dir (tcon, target_dentry->d_parent); + } +CIFS_I (source_dir)->time =CIFS_I (target_dir)->time =0 ; cifs_rename_exit:
Greg Kroah-Hartman
maintainerPATCH 1654/2077 mfd: tps6586x: Fix OF node refcount
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bartosz Golaszewski <[email protected]>
commit 3001ed2b4e06da2276c42ace6551617065a5b1f9 upstream.
Platform devices created with platform_device_alloc() call platform_device_release() when the last reference to the device's kobject is dropped. This function calls of_node_put() unconditionally. This works fine for devices created with platform_device_register_full() but users of the split approach (platform_device_alloc() + platform_device_add()) must bump the reference of the of_node they assign manually. Add the missing call to of_node_get().
--- drivers/mfd/tps6586x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/tps6586x.c +1 -1
@@ -397,7 +397,7 @@ static int tps6586x_add_subdevs(struct t pdev->dev.parent = tps6586x->dev; pdev->dev.platform_data = subdev->platform_data; - pdev->dev.of_node = subdev->of_node; + pdev->dev.of_node =of_node_get (subdev->of_node); ret =platform_device_add (pdev);if (ret) {
Greg Kroah-Hartman
maintainerPATCH 1655/2077 backlight: ktd2801: Enable BL_CORE_SUSPENDRESUME
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Duje Mihanović <[email protected]>
commit f37f5a2ac9d3737617c08f0dc7270b42e9cad907 upstream.
Boards using this backlight chip do not power the backlight off on suspend. Enable BL_CORE_SUSPENDRESUME so the chip gets powered off by the backlight core on suspend.
Tested on samsung,coreprimevelte.
--- drivers/video/backlight/ktd2801-backlight.c | 1 + 1 file changed, 1 insertion(+)
drivers/video/backlight/ktd2801-backlight.c +1 -0
@@ -53,6 +53,7 @@ static int ktd2801_update_status(struct }static const struct backlight_ops ktd2801_backlight_ops = { + .options =BL_CORE_SUSPENDRESUME , .update_status = ktd2801_update_status, };
Greg Kroah-Hartman
maintainerPATCH 1656/2077 cxl: Fix CXL_HEADERLOG_SIZE to match RAS Capability size
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Terry Bowman <[email protected]>
commit c268f949e219f9e179558e836f457f6c5fbec416 upstream.
The CXL r4.0 8.2.4.17.7 RAS Capability Structure has total length 0x58 bytes (CXL_RAS_CAPABILITY_LENGTH); the Header Log occupies the trailing 64 bytes at offset 0x18. CXL_HEADERLOG_SIZE was defined as SZ_512, eight times the actual on-device size.
header_log_copy() reads CXL_HEADERLOG_SIZE_U32 (128) dwords from the RAS capability iomap, overrunning the 88-byte mapping by 448 bytes. The cxl_aer_uncorrectable_error trace event memcpy()s CXL_HEADERLOG_SIZE
(512) bytes from its source. For the CPER caller the source is struct cxl_ras_capability_regs::header_log[16] (64 bytes) embedded in a stack-local cxl_cper_prot_err_work_data, so the memcpy reads 448 bytes of kernel stack into the trace event ring buffer where userspace can read it via tracefs.
Set CXL_HEADERLOG_SIZE to 64 and derive CXL_HEADERLOG_SIZE_U32 from it, bringing all iomap readers into agreement on 16 dwords. Userspace tools such as rasdaemon have grown a dependency on the buggy 512-byte (128 u32) header_log layout in the cxl_aer_uncorrectable_error trace event. Add CXL_HEADERLOG_TRACE_SIZE_U32 = 128 and use it for the trace event __array and its memcpy to preserve that ABI. Both callers now pass a zero-filled u32[CXL_HEADERLOG_TRACE_SIZE_U32] staging buffer with only the first CXL_HEADERLOG_SIZE_U32 (16) entries populated from hardware; the remaining 112 u32s are zero-padded, keeping the 512-byte trace ring buffer layout intact.
[ dj: Replaced 64 with SZ_64 per RichardC ]
--- drivers/cxl/core/ras.c | 27 ++++++++++++++++++++------- drivers/cxl/core/trace.h | 24 ++++++++++++++++-------- drivers/cxl/cxl.h | 14 ++++++++++++-- 3 files changed, 48 insertions(+), 17 deletions(-)
drivers/cxl/core/ras.c +20 -7
@@ -8,6 +8,10 @@#include <cxlpci.h> #include "trace.h" +/* Check that UCE header definition is maintained to keep ABI intact */ +static_assert (CXL_HEADERLOG_TRACE_SIZE_U32 ==128 , +"rasdaemon ABI requires exactly 128 u32s" ); +static void cxl_cper_trace_corr_port_prot_err (struct pci_dev *pdev,struct cxl_ras_capability_regs ras_cap) {
@@ -19,6 +23,7 @@ static void cxl_cper_trace_corr_port_prostatic void cxl_cper_trace_uncorr_port_prot_err (struct pci_dev *pdev,struct cxl_ras_capability_regs ras_cap) { +u32 hl[CXL_HEADERLOG_TRACE_SIZE_U32 ] = {};u32 status = ras_cap.uncor_status & ~ras_cap.uncor_mask;u32 fe;
@@ -28,8 +33,8 @@ static void cxl_cper_trace_uncorr_port_pelse fe = status; -trace_cxl_port_aer_uncorrectable_error (&pdev->dev, status, fe, - ras_cap.header_log); +memcpy (hl, ras_cap.header_log,CXL_HEADERLOG_SIZE ); +trace_cxl_port_aer_uncorrectable_error (&pdev->dev, status, fe, hl); } static void cxl_cper_trace_corr_prot_err(struct cxl_memdev *cxlmd,
@@ -44,6 +49,7 @@ static void cxl_cper_trace_uncorr_prot_err(struct cxl_memdev *cxlmd, struct cxl_ras_capability_regs ras_cap) { + u32 hl[CXL_HEADERLOG_TRACE_SIZE_U32] = {};u32 status = ras_cap.uncor_status & ~ras_cap.uncor_mask;u32 fe;
@@ -53,8 +59,15 @@ cxl_cper_trace_uncorr_prot_err(struct cxelse fe = status; -trace_cxl_aer_uncorrectable_error (cxlmd, status, fe, - ras_cap.header_log); +/* +* ras_cap.header_log[] holds CXL_HEADERLOG_SIZE_U32 (16) hardware +* dwords. Copy them into the front of a zero-filled +* CXL_HEADERLOG_TRACE_SIZE_U32 (128) u32 staging buffer so the trace +* event memcpy sees a full 512-byte source and the userspace ABI +* (rasdaemon) is preserved. +*/ +memcpy (hl, ras_cap.header_log,CXL_HEADERLOG_SIZE ); +trace_cxl_aer_uncorrectable_error (cxlmd, status, fe, hl); }static int match_memdev_by_parent (struct device *dev,const void *uport)
@@ -204,12 +217,12 @@ static void header_log_copy(void __iomem {void __iomem *addr;u32 *log_addr; -int i, log_u32_size =CXL_HEADERLOG_SIZE /sizeof (u32); +int i; addr = ras_base +CXL_RAS_HEADER_LOG_OFFSET ; log_addr = log; -for (i =0 ; i < log_u32_size; i++) { +for (i =0 ; i <CXL_HEADERLOG_SIZE_U32 ; i++) { *log_addr =readl (addr); log_addr++; addr +=sizeof (u32);
@@ -222,7 +235,7 @@ static void header_log_copy(void __iomem*/ bool cxl_handle_ras (struct device *dev,void __iomem *ras_base) { -u32 hl[CXL_HEADERLOG_SIZE_U32 ]; +u32 hl[CXL_HEADERLOG_TRACE_SIZE_U32 ] = {};void __iomem *addr;u32 status;u32 fe;
drivers/cxl/core/trace.h +16 -8
@@ -56,7 +56,7 @@ TRACE_EVENT(cxl_port_aer_uncorrectable_e __string(host, dev_name(dev->parent)) __field(u32, status) __field(u32, first_error) -__array (u32, header_log,CXL_HEADERLOG_SIZE_U32 ) +__array (u32, header_log,CXL_HEADERLOG_TRACE_SIZE_U32 ) ),TP_fast_assign ( __assign_str(device);
@@ -64,10 +64,14 @@ TRACE_EVENT(cxl_port_aer_uncorrectable_e __entry->status = status; __entry->first_error = fe;/* -* Embed the 512B headerlog data for user app retrieval and -* parsing, but no need to print this in the trace buffer. +* Embed headerlog data for user app retrieval and parsing, +* but no need to print in the trace buffer. Only +* CXL_HEADERLOG_SIZE_U32 (16) dwords are hardware data; +* the remaining entries preserve the 512-byte ABI layout +* rasdaemon depends on and are zero-filled by the caller. */ -memcpy (__entry->header_log, hl,CXL_HEADERLOG_SIZE ); +memcpy (__entry->header_log, hl, +CXL_HEADERLOG_TRACE_SIZE_U32 *sizeof (u32)); ), TP_printk("device=%s host=%s status: '%s' first_error: '%s'", __get_str(device), __get_str(host),
@@ -85,7 +89,7 @@ TRACE_EVENT(cxl_aer_uncorrectable_error, __field(u64, serial) __field(u32, status) __field(u32, first_error) -__array (u32, header_log,CXL_HEADERLOG_SIZE_U32 ) +__array (u32, header_log,CXL_HEADERLOG_TRACE_SIZE_U32 ) ),TP_fast_assign ( __assign_str(memdev);
@@ -94,10 +98,14 @@ TRACE_EVENT(cxl_aer_uncorrectable_error, __entry->status = status; __entry->first_error = fe;/* -* Embed the 512B headerlog data for user app retrieval and -* parsing, but no need to print this in the trace buffer. +* Embed headerlog data for user app retrieval and parsing, +* but no need to print in the trace buffer. Only +* CXL_HEADERLOG_SIZE_U32 (16) dwords are hardware data; +* the remaining entries preserve the 512-byte ABI layout +* rasdaemon depends on and are zero-filled by the caller. */ -memcpy (__entry->header_log, hl,CXL_HEADERLOG_SIZE ); +memcpy (__entry->header_log, hl, +CXL_HEADERLOG_TRACE_SIZE_U32 *sizeof (u32)); ), TP_printk("memdev=%s host=%s serial=%lld: status: '%s' first_error: '%s'", __get_str(memdev), __get_str(host), __entry->serial,
drivers/cxl/cxl.h +12 -2
@@ -158,8 +158,18 @@ static inline int ways_to_eiw(unsigned i#define CXL_RAS_CAP_CONTROL_FE_MASK GENMASK(5, 0)#define CXL_RAS_HEADER_LOG_OFFSET 0x18#define CXL_RAS_CAPABILITY_LENGTH 0x58 -#define CXL_HEADERLOG_SIZE SZ_512 -#define CXL_HEADERLOG_SIZE_U32 SZ_512 / sizeof(u32) +#define CXL_HEADERLOG_SIZE SZ_64 +#define CXL_HEADERLOG_SIZE_U32 (CXL_HEADERLOG_SIZE / sizeof(u32)) + +/* +* The RAS UCE trace event header array was originally sized at SZ_512/sizeof(u32) +* = 128 u32s due to a bug. Userspace tools (rasdaemon) have grown a dependency +* on that 512-byte layout. Keep the trace array at 128 u32s to preserve the +* ABI; only CXL_HEADERLOG_SIZE_U32 (16) dwords are valid hardware data, the +* remainder are zero-filled. +*/ +#define CXL_HEADERLOG_TRACE_SIZE SZ_512 +#define CXL_HEADERLOG_TRACE_SIZE_U32 (CXL_HEADERLOG_TRACE_SIZE / sizeof(u32))/* CXL 2.0 8.2.8.1 Device Capabilities Array Register */ #define CXLDEV_CAP_ARRAY_OFFSET 0x0
Greg Kroah-Hartman
maintainerPATCH 1657/2077 jbd2: fix integer underflow in jbd2_journal_initialize_fast_commit()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Junrui Luo <[email protected]>
commit 289a2ca0c9b7eae74f93fc213b0b971669b8683d upstream.
jbd2_journal_initialize_fast_commit() validates journal capacity by checking (journal->j_last - num_fc_blks < JBD2_MIN_JOURNAL_BLOCKS). Both j_last and num_fc_blks are unsigned, so when num_fc_blks exceeds j_last the subtraction wraps to a large value, bypassing the bounds check.
The resulting underflow corrupts j_last, j_fc_first, and j_free, leading to journal abort.
Fix by checking num_fc_blks against j_last before the subtraction, returning -EFSCORRUPTED.
--- fs/jbd2/journal.c | 2 ++ 1 file changed, 2 insertions(+)
fs/jbd2/journal.c +2 -0
@@ -2263,6 +2263,8 @@ jbd2_journal_initialize_fast_commit(jourunsigned long long num_fc_blks; num_fc_blks =jbd2_journal_get_num_fc_blks (sb); +if (num_fc_blks > journal->j_last) +return -EFSCORRUPTED ;if (journal->j_last - num_fc_blks <JBD2_MIN_JOURNAL_BLOCKS )return -ENOSPC ;
Greg Kroah-Hartman
maintainerPATCH 1658/2077 nvdimm/btt: Free arenas on btt_init() error paths
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abdun Nihaal <[email protected]>
commit 1a6b6442a982d0ca5fb6a1a39b6f6dfd760eda57 upstream.
The arenas allocated by discover_arenas() or create_arenas() are not freed on some error paths in btt_init(). This leaks memory when BTT initialization fails.
Call free_arenas() from the affected error paths to release the allocations.
[ as: commit message and log edits ]
--- drivers/nvdimm/btt.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/nvdimm/btt.c +7 -4
@@ -1589,7 +1589,7 @@ static struct btt *btt_init(struct nd_btif (btt->init_state !=INIT_READY && nd_region->ro) {dev_warn (dev,"%s is read-only, unable to init btt metadata\n" ,dev_name (&nd_region->dev)); -return NULL ; + goto err; }else if (btt->init_state !=INIT_READY ) { btt->num_arenas = (rawsize /ARENA_MAX_SIZE ) + ((rawsize %ARENA_MAX_SIZE ) ?1 :0 );
@@ -1599,25 +1599,28 @@ static struct btt *btt_init(struct nd_bt ret =create_arenas (btt);if (ret) {dev_info (dev,"init: create_arenas: %d\n" , ret); -return NULL ; + goto err; } ret =btt_meta_init (btt);if (ret) {dev_err (dev,"init: error in meta_init: %d\n" , ret); -return NULL ; + goto err; } } ret =btt_blk_init (btt);if (ret) {dev_err (dev,"init: error in blk_init: %d\n" , ret); -return NULL ; + goto err; }btt_debugfs_init (btt);return btt; +err: +free_arenas (btt); +return NULL ; }/**
Greg Kroah-Hartman
maintainerPATCH 1659/2077 nvdimm/btt: Free arena sub-allocations on discover_arenas() error path
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abdun Nihaal <[email protected]>
commit 13fe4cd9ddd0aacb7777812328be525a11ea3fea upstream.
Memory allocated by btt_freelist_init(), btt_rtt_init(), and btt_maplocks_init() is not freed on some discover_arenas() error paths. This leaks memory when arena discovery fails.
Add the missing kfree() calls to release the allocations before returning an error.
[ as: commit message and log edits ]
--- drivers/nvdimm/btt.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/nvdimm/btt.c +3 -0
@@ -919,6 +919,9 @@ static int discover_arenas(struct btt *breturn ret; out: +kfree (arena->freelist); +kfree (arena->rtt); +kfree (arena->map_locks);kfree (arena);free_arenas (btt);return ret;
Greg Kroah-Hartman
maintainerPATCH 1660/2077 pinctrl: renesas: rzg2l: Use -ENOTSUPP instead of -EOPNOTSUPP
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Claudiu Beznea <[email protected]>
commit c1492da3939c89372929e062d731f328f7693f1e upstream.
The pinctrl and GPIO core code make exceptions for the -ENOTSUPP error code. One such example is gpio_set_config_with_argument_optional(), which returns success when gpio_set_config_with_argument() returns -ENOTSUPP, but reports failure for all other error codes.
Returning -EOPNOTSUPP from the pinctrl driver on the unsupported pinctrl operation may lead to boot failures when pinctrl drivers implements struct gpio_chip::set_config, the system uses GPIO hogs, and the struct gpio_chip::set_config implementation returns -EOPNOTSUPP for the unsupported operations.
Return -ENOTSUPP for the unsupported pinctrl operation.
--- drivers/pinctrl/renesas/pinctrl-rzg2l.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/pinctrl/renesas/pinctrl-rzg2l.c +4 -4
@@ -1103,7 +1103,7 @@ static int rzg2l_read_oen(struct rzg2l_pint bit;if (!pctrl->data->pin_to_oen_bit) -return -EOPNOTSUPP ; +return -ENOTSUPP ; bit = pctrl->data->pin_to_oen_bit (pctrl, _pin);if (bit <0 )
@@ -1145,7 +1145,7 @@ static int rzg2l_write_oen(struct rzg2l_u8 val;if (!pctrl->data->pin_to_oen_bit) -return -EOPNOTSUPP ; +return -ENOTSUPP ; bit = pctrl->data->pin_to_oen_bit (pctrl, _pin);if (bit <0 )
@@ -1576,7 +1576,7 @@ static int rzg2l_pinctrl_pinconf_set(strbreak ;default : -return -EOPNOTSUPP ; +return -ENOTSUPP ; } }
@@ -1658,7 +1658,7 @@ static int rzg2l_pinctrl_pinconf_group_g/* Check config matching between to pin */ if (i && prev_config != *config) -return -EOPNOTSUPP ; +return -ENOTSUPP ; prev_config = *config; }
Greg Kroah-Hartman
maintainerPATCH 1661/2077 sunrpc: pin svc_xprt across the asynchronous TLS handshake callback
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
commit 4f988f3a2808fb659f3880c282041ff067acad78 upstream.
svc_tcp_handshake() stores the raw svc_xprt pointer in tls_handshake_args.ta_data and submits the request through tls_server_hello_x509(). The handshake core takes only sock_hold(req->hr_sk); nothing references the embedding struct svc_sock that svc_tcp_handshake_done() reaches via container_of().
Two close races leave the in-flight callback writing through a freed svc_sock. svc_sock_free() calls tls_handshake_cancel() and discards its return value: a false return means handshake_complete() has already set HANDSHAKE_F_REQ_COMPLETED but hp_done() may not have finished, yet svc_sock_free() proceeds to kfree(svsk). The cancel-loser fall-through inside svc_tcp_handshake() itself produces the same window: when wait_for_completion_interruptible_timeout() returns <= 0 (timeout or signal) and tls_handshake_cancel() returns false, the function does not drain, returns, and svc_handle_xprt() calls svc_xprt_received(), which clears XPT_BUSY and can drop the last reference. A concurrent close then runs svc_sock_free() while svc_tcp_handshake_done() is still updating xpt_flags and walking svsk->sk_handshake_done.
The corruption surfaces as set_bit/clear_bit RMW into the freed xpt_flags slab slot and as complete_all() walking and writing the freed wait_queue_head_t list embedded in sk_handshake_done -- a slab-corruption primitive, not a benign read. The path is reachable on any TLS-enabled NFS server whenever a connection close overlaps the tlshd downcall delivery window; the interruptible wait means signal delivery suffices, not just SVC_HANDSHAKE_TO expiry.
Take svc_xprt_get(xprt) immediately before tls_server_hello_x509() so the in-flight callback owns its own reference. Release it on the two edges where the callback is guaranteed not to fire -- submission failure from tls_server_hello_x509() and a successful tls_handshake_cancel() -- and at the tail of svc_tcp_handshake_done() after complete_all().
--- net/sunrpc/svcsock.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/sunrpc/svcsock.c +6 -0
@@ -471,6 +471,7 @@ static void svc_tcp_handshake_done(void }clear_bit (XPT_HANDSHAKE , &xprt->xpt_flags);complete_all (&svsk->sk_handshake_done); +svc_xprt_put (xprt); }/**
@@ -494,9 +495,13 @@ static void svc_tcp_handshake(struct svcclear_bit (XPT_TLS_SESSION , &xprt->xpt_flags);init_completion (&svsk->sk_handshake_done); +/* Pin the transport across the asynchronous handshake callback. */ +svc_xprt_get (xprt); + ret =tls_server_hello_x509 (&args,GFP_KERNEL );if (ret) {trace_svc_tls_not_started (xprt); +svc_xprt_put (xprt); goto out_failed; }
@@ -505,6 +510,7 @@ static void svc_tcp_handshake(struct svcif (ret <=0 ) {if (tls_handshake_cancel (sk)) {trace_svc_tls_timed_out (xprt); +svc_xprt_put (xprt); goto out_close; } }
Greg Kroah-Hartman
maintainerPATCH 1662/2077 sunrpc: wait for in-flight TLS handshake callback when cancel loses race
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
commit d00e32f84ca1a77cb67a3fbf59f58dada95f5a21 upstream.
When wait_for_completion_interruptible_timeout() in svc_tcp_handshake() returns 0 (timeout) or -ERESTARTSYS (signal) and tls_handshake_cancel() then returns false, handshake_complete() has won the cancellation race: it has set HANDSHAKE_F_REQ_COMPLETED and is about to invoke svc_tcp_handshake_done(), but the callback's side effects on xpt_flags and on svsk->sk_handshake_done have not yet committed.
The current code reads xpt_flags immediately to decide whether the session succeeded. Two races result.
If the callback has executed set_bit(XPT_TLS_SESSION) but not yet clear_bit(XPT_HANDSHAKE), svc_tcp_handshake() sees a session, enqueues the transport, and returns. svc_xprt_received() then clears XPT_BUSY, a worker thread picks the transport up, the dispatcher in svc_handle_xprt() observes XPT_HANDSHAKE still set, and xpo_handshake is invoked a second time. That svc_tcp_handshake() calls init_completion(&svsk->sk_handshake_done) while the original callback concurrently calls complete_all() on it, corrupting the embedded swait_queue.
If the callback has set HANDSHAKE_F_REQ_COMPLETED but not yet entered svc_tcp_handshake_done(), svc_tcp_handshake() reads XPT_TLS_SESSION as clear and tears the connection down even though the handshake is about to succeed.
Wait for the callback to commit before inspecting xpt_flags. The completion is guaranteed to fire because handshake_complete() invokes svc_tcp_handshake_done() unconditionally once it has set HANDSHAKE_F_REQ_COMPLETED.
--- net/sunrpc/svcsock.c | 4 ++++ 1 file changed, 4 insertions(+)
net/sunrpc/svcsock.c +4 -0
@@ -513,6 +513,10 @@ static void svc_tcp_handshake(struct svcsvc_xprt_put (xprt); goto out_close; } +/* Cancellation lost to handshake_complete(): the +* callback is in flight and should finish quickly. +*/ +wait_for_completion (&svsk->sk_handshake_done); }if (!test_bit (XPT_TLS_SESSION , &xprt->xpt_flags)) {
Greg Kroah-Hartman
maintainerPATCH 1663/2077 sunrpc: harden rq_procinfo lifecycle to prevent double-free
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luxiao Xu <[email protected]>
commit 18d216788bef06332ff8901670ecf1ed8f6eb614 upstream.
The svc_release_rqst() function executes the callback inside rqstp->rq_procinfo->pc_release. However, if a worker thread begins processing a new request and encounters an early error path (e.g., unsupported protocol, short frame, or bad auth) before a valid rq_procinfo is installed, a stale release hook can be re-triggered against reused state from the previous RPC, resulting in a double-free or use-after-free vulnerability.
Harden the lifecycle of rq_procinfo by:
1. Ensuring svc_release_rqst() always clears rq_procinfo after the optional pc_release() call, regardless of whether the hook exists.
2. Explicitly clearing rq_procinfo at request entry in svc_process() before any early decode or drop paths.
3. Ensuring svc_process_bc() does the same at backchannel entry.
This guarantees that error flows will not encounter a non-NULL stale rq_procinfo pointer when there is nothing to release.
--- net/sunrpc/svc.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
net/sunrpc/svc.c +10 -0
@@ -1598,6 +1598,12 @@ static void svc_release_rqst(struct svc_if (procp && procp->pc_release) procp->pc_release (rqstp); + +/* +* A subsequent svc_release_rqst() on this rqstp must not +* re-invoke pc_release against released state. +*/ + rqstp->rq_procinfo =NULL ; }/**
@@ -1616,6 +1622,9 @@ void svc_process(struct svc_rqst *rqstp)svc_xprt_deferred_close (rqstp->rq_xprt);#endif +/* Discard a stale release hook from a previous RPC. */ + rqstp->rq_procinfo =NULL ; +/* * Setup response xdr_buf. * Initially it has just one page
@@ -1672,6 +1681,7 @@ void svc_process_bc(struct rpc_rqst *reqint proc_error;/* Build the svc_rqst used by the common processing routine */ + rqstp->rq_procinfo =NULL ; rqstp->rq_xid = req->rq_xid; rqstp->rq_prot = req->rq_xprt->prot; rqstp->rq_bc_net = req->rq_xprt->xprt_net;
Greg Kroah-Hartman
maintainerPATCH 1664/2077 lockd: Plug nlm_file leak when nlm_do_fopen() fails
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
commit f16a1513452edb532fec81e591c64c320866719c upstream.
A client can repeatedly drive nlm_do_fopen() failures by presenting file handles that the underlying export rejects. After kzalloc_obj() succeeds in nlm_lookup_file(), the freshly allocated nlm_file is not yet inserted into nlm_files[]. The nlm_do_fopen() failure path jumps to out_unlock, which releases nlm_file_mutex and returns without freeing the allocation, so each failure leaks one nlm_file.
Route the failure through out_free so kfree() runs before the function returns.
--- fs/lockd/svcsubs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/lockd/svcsubs.c +1 -1
@@ -165,7 +165,7 @@ nlm_lookup_file(struct svc_rqst *rqstp, nfserr =nlm_do_fopen (rqstp, file, mode);if (nfserr) - goto out_unlock; + goto out_free;hlist_add_head (&file->f_list, &nlm_files[hash]);
Greg Kroah-Hartman
maintainerPATCH 1665/2077 lockd: Plug nlm_file refcount leak on cached nlm_do_fopen() failure
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
commit 70a38f87bed7f0694fd07988b47b2db1e10d8df3 upstream.
The cached-file path in nlm_lookup_file() reaches the found: label unconditionally, even when nlm_do_fopen() fails. At that label *result and file->f_count are updated before the error is returned. The wrappers nlm3svc_lookup_file() and nlm4svc_lookup_file() then bail out of their switch without copying *result back to their caller, so the proc handler's local nlm_file pointer remains NULL and the cleanup path skips nlm_release_file(). The f_count increment is never released, and nlm_traverse_files() can no longer reap the file because its refcount never returns to zero between requests.
Short-circuit the cached path so neither *result nor f_count is touched when nlm_do_fopen() fails on a hashed nlm_file.
--- fs/lockd/svcsubs.c | 2 ++ 1 file changed, 2 insertions(+)
fs/lockd/svcsubs.c +2 -0
@@ -149,6 +149,8 @@ nlm_lookup_file(struct svc_rqst *rqstp,mutex_lock (&file->f_mutex); nfserr =nlm_do_fopen (rqstp, file, mode);mutex_unlock (&file->f_mutex); +if (nfserr) + goto out_unlock; goto found; }nlm_debug_print_fh ("creating file for" , &lock->fh);
Greg Kroah-Hartman
maintainerPATCH 1666/2077 SUNRPC: Bound-check xdr_buf_to_bvec() stores before writing
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
commit 42f5b80dda6b86e424054baf1475df686c403d5c upstream.
xdr_buf_to_bvec() writes a bio_vec into the caller's array before testing whether that slot is in range, and the head branch performs the store with no check at all. When the caller's budget is exactly used up, the next store lands one element past the end of the array. The overflow label returns count - 1, which masks the surplus store but cannot undo it.
rq_bvec, the array passed by nfsd_vfs_write(), is allocated to exactly rq_maxpages entries with no slack. The OOB store can land in adjacent slab memory; the bv_len and bv_offset fields written there are derived from client-supplied RPC payload sizes.
Move the in-range check ahead of the store in the head, page-loop, and tail branches. With the check at the top of each sequence, count is incremented only after a successful store, so the overflow label can return count directly.
--- net/sunrpc/xdr.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
net/sunrpc/xdr.c +9 -5
@@ -152,6 +152,8 @@ unsigned int xdr_buf_to_bvec(struct bio_unsigned int count =0 ;if (head->iov_len) { +if (unlikely (count >= bvec_size)) + goto bvec_overflow;bvec_set_virt (bvec++, head->iov_base, head->iov_len); ++count; }
@@ -165,25 +167,27 @@ unsigned int xdr_buf_to_bvec(struct bio_while (remaining >0 ) { len = min_t(unsigned int, remaining,PAGE_SIZE - offset); +if (unlikely (count >= bvec_size)) + goto bvec_overflow;bvec_set_page (bvec++, *pages++, len, offset); remaining -= len; offset =0 ; -if (unlikely (++count > bvec_size)) - goto bvec_overflow; + ++count; } }if (tail->iov_len) { -bvec_set_virt (bvec, tail->iov_base, tail->iov_len); -if (unlikely (++count > bvec_size)) +if (unlikely (count >= bvec_size)) goto bvec_overflow; +bvec_set_virt (bvec, tail->iov_base, tail->iov_len); + ++count; }return count; bvec_overflow:pr_warn_once ("%s: bio_vec array overflow\n" , __func__); -return count -1 ; +return count; }EXPORT_SYMBOL_GPL (xdr_buf_to_bvec);
Greg Kroah-Hartman
maintainerPATCH 1667/2077 remoteproc: qcom: Fix leak when custom dump_segments addition fails
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wasim Nazir <[email protected]>
commit ecf9fc18e62c58eae1ceb65dab2bccb8a724de2d upstream.
Free allocated minidump_region 'name' in qcom_add_minidump_segments() when failing before adding the region to 'dump_segments'. Otherwise, the 'name' is not tracked and is never freed by qcom_minidump_cleanup().
Return error when adding to 'dump_segments' fails.
--- drivers/remoteproc/qcom_common.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/remoteproc/qcom_common.c +10 -4
@@ -109,6 +109,7 @@ static int qcom_add_minidump_segments(ststruct minidump_region __iomem *ptr;struct minidump_region region;int seg_cnt, i; +int ret =0 ;dma_addr_t da;size_t size;char *name;
@@ -129,17 +130,22 @@ static int qcom_add_minidump_segments(stif (le32_to_cpu (region.valid) ==MINIDUMP_REGION_VALID ) { name =kstrndup (region.name,MAX_REGION_NAME_LENGTH -1 ,GFP_KERNEL );if (!name) { -iounmap (ptr); -return -ENOMEM ; + ret = -ENOMEM ; +break ; } da =le64_to_cpu (region.address); size =le64_to_cpu (region.size); -rproc_coredump_add_custom_segment (rproc, da, size, rproc_dumpfn_t, name); + ret =rproc_coredump_add_custom_segment (rproc, da, size, rproc_dumpfn_t, + name); +if (ret) { +kfree (name); +break ; + } } }iounmap (ptr); -return 0 ; +return ret; } void qcom_minidump(struct rproc *rproc, unsigned int minidump_id,
Greg Kroah-Hartman
maintainerPATCH 1668/2077 remoteproc: xlnx: Check remote core state
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tanmay Shah <[email protected]>
commit a48df51d23138388900995add2854cda4aa68e55 upstream.
The remote state is set to RPROC_DETACHED if the resource table is found in the memory. However, this can be wrong if the remote is not started, but firmware is still loaded in the memory. Use PM_GET_NODE_STATUS call to the firmware to request the state of the RPU node. If the RPU is actually out of reset and running, only then move the remote state to RPROC_DETACHED, otherwise keep the remote state to RPROC_OFFLINE.
--- drivers/firmware/xilinx/zynqmp.c | 28 +++++++++++++++++++ drivers/remoteproc/xlnx_r5_remoteproc.c | 46 +++++++++++++++++++++++++------- include/linux/firmware/xlnx-zynqmp.h | 21 ++++++++++++++ 3 files changed, 85 insertions(+), 10 deletions(-)
drivers/firmware/xilinx/zynqmp.c +28 -0
@@ -1451,6 +1451,34 @@ int zynqmp_pm_get_node_status(const u32EXPORT_SYMBOL_GPL (zynqmp_pm_get_node_status);/** +* zynqmp_pm_get_rpu_node_status - PM call to request a RPU node's current power state +* @node: ID of the RPU component or sub-system in question +* @status: Current operating state of the requested RPU node. +* @requirements: Current requirements asserted on the RPU node. +* @usage: Usage information, used for RPU slave nodes only: +* PM_USAGE_NO_MASTER - No master is currently using +* the node +* PM_USAGE_CURRENT_MASTER - Only requesting master is +* currently using the node +* PM_USAGE_OTHER_MASTER - Only other masters are +* currently using the node +* PM_USAGE_BOTH_MASTERS - Both the current and at least +* one other master is currently +* using the node +* +* Return: Returns status, either success or error+reason +*/ +int zynqmp_pm_get_rpu_node_status (const u32 node,u32 *const status, +u32 *const requirements,u32 *const usage) +{ +if (zynqmp_pm_feature (PM_GET_NODE_STATUS ) <PM_API_VERSION_2 ) +return -EOPNOTSUPP ; + +return zynqmp_pm_get_node_status (node, status, requirements, usage); +} +EXPORT_SYMBOL_GPL (zynqmp_pm_get_rpu_node_status); + +/** * zynqmp_pm_force_pwrdwn - PM call to request for another PU or subsystem to * be powered down forcefully * @node: Node ID of the targeted PU or subsystem
drivers/remoteproc/xlnx_r5_remoteproc.c +36 -10
64 lines not on this page · raw message
include/linux/firmware/xlnx-zynqmp.h +21 -0
@@ -543,6 +543,18 @@ enum pm_gem_config_type { };/** +* enum pm_node_status - Device node status provided by xilpm fw +* @PM_NODE_UNUSED: Device is not used +* @PM_NODE_RUNNING: Device is power-on and out of reset +* @PM_NODE_HALT: Device is power-on but in the reset state +*/ +enum pm_node_status { +PM_NODE_UNUSED =0 , +PM_NODE_RUNNING =1 , +PM_NODE_HALT =12 , +}; + +/** * struct zynqmp_pm_query_data - PM query data * @qid: query ID * @arg1: Argument 1 of query data
@@ -630,6 +642,8 @@ int zynqmp_pm_set_rpu_mode(u32 node_id,int zynqmp_pm_set_tcm_config (u32 node_id,enum rpu_tcm_comb tcm_mode);int zynqmp_pm_get_node_status (const u32 node,u32 *const status,u32 *const requirements,u32 *const usage); +int zynqmp_pm_get_rpu_node_status (const u32 node,u32 *const status, +u32 *const requirements,u32 *const usage);int zynqmp_pm_set_sd_config (u32 node,enum pm_sd_config_type config,u32 value);int zynqmp_pm_set_gem_config (u32 node,enum pm_gem_config_type config,u32 value);
@@ -938,6 +952,13 @@ static inline int zynqmp_pm_get_node_sta {return -ENODEV ; } + +static inline int zynqmp_pm_get_rpu_node_status (const u32 node,u32 *const status, +u32 *const requirements, +u32 *const usage) +{ +return -ENODEV ; +} static inline int zynqmp_pm_set_sd_config(u32 node, enum pm_sd_config_type config,
Greg Kroah-Hartman
maintainerPATCH 1669/2077 mm/sparse-vmemmap: fix vmemmap accounting underflow
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muchun Song <[email protected]>
commit c373f7f98e6ad591c85d40548cf8b6443be69311 upstream.
Patch series "mm: Fix vmemmap optimization accounting and initialization", v8.
The series fixes several bugs in vmemmap optimization, mainly around incorrect page accounting and memmap initialization in DAX and memory hotplug paths. It also fixes pageblock migratetype initialization and struct page initialization for ZONE_DEVICE compound pages.
Patches 1-4 fix vmemmap accounting issues. Patch 1 fixes an accounting underflow in the section activation failure path by moving vmemmap page accounting into the lower-level allocation and freeing helpers. Patch 2 fixes incorrect altmap passing in the memory hotplug error path. Patch 3 passes pgmap through memory deactivation paths so the teardown side can determine whether vmemmap optimization was in effect. Patch 4 uses that information to account the optimized DAX vmemmap size correctly.
Patches 5-6 fix initialization issues in mm/mm_init. One makes sure all pageblocks in ZONE_DEVICE compound pages get their migratetype initialized. The other fixes a case where DAX memory hotplug reuses an unoptimized early-section memmap while compound_nr_pages() still assumes vmemmap optimization, leaving tail struct pages uninitialized.
This patch (of 6):
In section_activate(), if populate_section_memmap() fails, the error handling path calls section_deactivate() to roll back the state. This causes a vmemmap accounting imbalance.
Since commit c3576889d87b ("mm: fix accounting of memmap pages"), memmap pages are accounted for only after populate_section_memmap() succeeds. However, the failure path unconditionally calls section_deactivate(), which decreases the vmemmap count. Consequently, a failure in populate_section_memmap() leads to an accounting underflow, incorrectly reducing the system's tracked vmemmap usage.
Fix this more thoroughly by moving all accounting calls into the lower level functions that actually perform the vmemmap allocation and freeing:
- populate_section_memmap() accounts for newly allocated vmemmap pages -depopulate_section_memmap() unaccounts when vmemmap is freed
This ensures proper accounting in all code paths, including error handling and early section cases.
--- mm/sparse-vmemmap.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
mm/sparse-vmemmap.c +12 -8
@@ -656,7 +656,12 @@ static struct page * __meminit populate_ unsigned long nr_pages, int nid, struct vmem_altmap *altmap, struct dev_pagemap *pgmap) { - return __populate_section_memmap(pfn, nr_pages, nid, altmap, pgmap); + struct page *page = __populate_section_memmap(pfn, nr_pages, nid, altmap, + pgmap); + + memmap_pages_add(DIV_ROUND_UP(nr_pages * sizeof(struct page), PAGE_SIZE)); + +return page; } static void depopulate_section_memmap(unsigned long pfn, unsigned long nr_pages,
@@ -665,13 +670,17 @@ static void depopulate_section_memmap(ununsigned long start = (unsigned long )pfn_to_page (pfn);unsigned long end = start + nr_pages *sizeof (struct page ); +memmap_pages_add (-1L * (DIV_ROUND_UP (nr_pages *sizeof (struct page ),PAGE_SIZE )));vmemmap_free (start, end, altmap); } +static void free_map_bootmem (struct page *memmap) {unsigned long start = (unsigned long )memmap;unsigned long end = (unsigned long )(memmap +PAGES_PER_SECTION ); +memmap_boot_pages_add (-1L * (DIV_ROUND_UP (PAGES_PER_SECTION *sizeof (struct page ), +PAGE_SIZE )));vmemmap_free (start, end,NULL ); }
@@ -774,14 +783,10 @@ static void section_deactivate(unsigned* The memmap of early sections is always fully populated. See * section_activate() and pfn_valid() . */ -if (!section_is_early) { -memmap_pages_add (-1L * (DIV_ROUND_UP (nr_pages *sizeof (struct page ),PAGE_SIZE ))); +if (!section_is_early)depopulate_section_memmap (pfn, nr_pages, altmap); - }else if (memmap) { -memmap_boot_pages_add (-1L * (DIV_ROUND_UP (nr_pages *sizeof (struct page ), -PAGE_SIZE ))); +else if (memmap)free_map_bootmem (memmap); - }if (empty) ms->section_mem_map = (unsigned long )NULL ;
@@ -826,7 +831,6 @@ static struct page * __meminit section_asection_deactivate (pfn, nr_pages, altmap);return ERR_PTR (-ENOMEM ); } - memmap_pages_add(DIV_ROUND_UP(nr_pages * sizeof(struct page), PAGE_SIZE));return memmap; }
Greg Kroah-Hartman
maintainerPATCH 1670/2077 MIPS: ip22-gio: fix gio device memory leak
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 7de9a1b45f5a95b58145653c525c8fb80292d9ab upstream.
The gio device release callback was never wired up so gio devices are not freed when the last reference is dropped.
--- arch/mips/sgi-ip22/ip22-gio.c | 2 ++ 1 file changed, 2 insertions(+)
arch/mips/sgi-ip22/ip22-gio.c +2 -0
@@ -101,6 +101,8 @@ int gio_device_register(struct gio_devic { giodev->dev.bus = &gio_bus_type; giodev->dev.parent = &gio_bus; + giodev->dev.release = gio_release_dev; +return device_register (&giodev->dev); }EXPORT_SYMBOL_GPL (gio_device_register);
Greg Kroah-Hartman
maintainerPATCH 1671/2077 MIPS: ip22-gio: fix kfree() of static object
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit c62cdd3e919bdf84c37ec46810f87cdb1736e822 upstream.
The gio bus root device is a statically allocated object which must not be freed by kfree() on failure to register the device or bus.
--- arch/mips/sgi-ip22/ip22-gio.c | 1 - 1 file changed, 1 deletion(-)
arch/mips/sgi-ip22/ip22-gio.c +0 -1
@@ -30,7 +30,6 @@ static struct {static void gio_bus_release (struct device *dev) { -kfree (dev); }static struct device gio_bus = {
Greg Kroah-Hartman
maintainerPATCH 1672/2077 MIPS: ip22-gio: fix device reference leak in probe
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit b82930a4c5dbc5c4df39c0f93d968c239f2c6885 upstream.
The gio probe function needlessly takes a device reference which is never released and therefore prevents unbound gio devices from being freed.
--- arch/mips/sgi-ip22/ip22-gio.c | 4 ---- 1 file changed, 4 deletions(-)
arch/mips/sgi-ip22/ip22-gio.c +0 -4
@@ -133,13 +133,9 @@ static int gio_device_probe(struct devicif (!drv->probe)return error; -gio_dev_get (gio_dev); - match =gio_match_device (drv->id_table, gio_dev);if (match) error = drv->probe (gio_dev, match); -if (error) -gio_dev_put (gio_dev);return error; }
Greg Kroah-Hartman
maintainerPATCH 1673/2077 MIPS: DEC: Ensure 32-bit stack location for o32 prom_printf()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maciej W. Rozycki <[email protected]>
commit 5ff79e8bdc75db51e30298a75939e2308e7658e0 upstream.
In 64-bit configurations calling any firmware entry points from a kernel thread other than the initial one will result in a situation where the stack has been placed in the XKPHYS 64-bit memory segment.
Consequently the stack pointer is no longer a 32-bit value and when the 32-bit firmware code called uses 32-bit ALU operations to manipulate the stack pointer, the calculated result is incorrect (in fact in the 64-bit MIPS ISA almost all 32-bit ALU operations will produce an unpredictable result when executed on 64-bit data) and control goes astray.
This may happen when no final console driver has been enabled in the configuration and consequently the initial console continues being used late into bootstrap, or with an upcoming change that will switch the zs driver to use a platform device, which in turn will make the console handover happen only after other kernel threads have already been started, and the kernel will hang at:
pid_max: default: 32768 minimum: 301
or somewhat later, but always before:
cblist_init_generic: Setting adjustable number of callback queues.
has been printed.
It seems that only the prom_printf() entry point is affected. Of all the other entry points wired only rex_slot_address() and rex_gettcinfo() are called from a kernel thread other than the initial one, specifically kernel_init(), and they are leaf functions that do no business with the stack, having worked with no issue ever since 64-bit support was added for the platform back in 2002.
To address this issue then, arrange for the stack to be switched in the o32 wrapper as required for prom_printf() only, by supplying call_o32() with a pointer to a chunk of initdata space, which is placed in the CKSEG0 32-bit compatibility segment, observing that prom_printf() is only called from console output handler and therefore with the console lock held, implying no need for this code to be reentrant.
Other firmware entry points may be called with interrupts enabled and no lock held, and may therefore require that call_o32() be reentrant. They trigger no issue at this point and "if it ain't broke, don't fix it," so just leave them alone.
--- arch/mips/dec/prom/init.c | 6 +++++- arch/mips/include/asm/dec/prom.h | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-)
arch/mips/dec/prom/init.c +5 -1
@@ -3,7 +3,7 @@* init.c: PROM library initialisation code. * * Copyright (C) 1998 Harald Koerfgen -* Copyright (C) 2002, 2004 Maciej W. Rozycki +* Copyright (C) 2002, 2004, 2026 Maciej W. Rozycki */ #include <linux/init.h> #include <linux/kernel.h>
@@ -20,6 +20,10 @@#include <asm/dec/prom.h> +#ifdef CONFIG_64BIT +unsigned long o32_stk[O32_STK_SIZE ]__initdata = {0 }; +#endif +int (*__rex_bootinit)(void );int (*__rex_bootread)(void );int (*__rex_getbitmap)(memmap *);
arch/mips/include/asm/dec/prom.h +13 -2
@@ -4,7 +4,7 @@* * DECstation PROM interface. * -* Copyright (C) 2002 Maciej W. Rozycki +* Copyright (C) 2002, 2026 Maciej W. Rozycki * * Based on arch/mips/dec/prom/prom.h by the Anonymous. */
@@ -97,6 +97,17 @@ extern int (*__pmax_close)(int);#ifdef CONFIG_64BIT +#define O32_STK_SIZE 512 +extern unsigned long o32_stk[]; + +/* Switch the stack if outside the 32-bit address space. */ +static inline unsigned long *o32_get_stk (void ) +{ +long fp = (long )__builtin_frame_address (0 ); + +return fp != (int )fp ? o32_stk +O32_STK_SIZE :NULL ; +} +/* * On MIPS64 we have to call PROM functions via a helper * dispatcher to accommodate ABI incompatibilities.
@@ -128,7 +139,7 @@ int __DEC_PROM_O32(_prom_printf, (int (*#define prom_getchar () _prom_getchar(__prom_getchar, NULL)#define prom_getenv (x) _prom_getenv(__prom_getenv, NULL, x) -#define prom_printf(x...) _prom_printf(__prom_printf, NULL, x) +#define prom_printf(x...) _prom_printf(__prom_printf, o32_get_stk(), x)#else /* !CONFIG_64BIT */
Greg Kroah-Hartman
maintainerPATCH 1674/2077 mm/mm_init: fix pageblock migratetype for ZONE_DEVICE compound pages
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muchun Song <[email protected]>
commit 94405c6136839f7c462249c8b4b957bcb9527a9d upstream.
The memmap_init_zone_device() function only initializes the migratetype of the first pageblock of a compound page. If the compound page size exceeds pageblock_nr_pages (e.g., 1GB hugepages with 2MB pageblocks), subsequent pageblocks in the compound page remain uninitialized.
Move the migratetype initialization out of __init_zone_device_page() and into a separate pageblock_migratetype_init_range() function. This iterates over the entire PFN range of the memory, ensuring that all pageblocks are correctly initialized.
Also remove the stale confusing comment about MEMINIT_HOTPLUG above the migratetype setting since it is an obsolete relic from commit 966cf44f637e ("mm: defer ZONE_DEVICE page initialization to the point where we init pgmap") and no longer makes sense here.
--- mm/mm_init.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-)
mm/mm_init.c +19 -15
@@ -674,6 +674,20 @@ static inline void fixup_hashdist(void)static inline void fixup_hashdist (void ) {}#endif /* CONFIG_NUMA */ +#ifdef CONFIG_ZONE_DEVICE +static __meminit void pageblock_migratetype_init_range (unsigned long pfn, +unsigned long nr_pages,int migratetype) +{ +const unsigned long end = pfn + nr_pages; + +for (pfn =pageblock_align (pfn); pfn < end; pfn += pageblock_nr_pages) { +init_pageblock_migratetype (pfn_to_page (pfn), migratetype, false); +if (IS_ALIGNED (pfn,PAGES_PER_SECTION )) +cond_resched (); + } +} +#endif +/* * Initialize a reserved page unconditionally, finding its zone first. */
@@ -1012,21 +1026,6 @@ static void __ref __init_zone_device_pag page->zone_device_data =NULL ;/* -* Mark the block movable so that blocks are reserved for -* movable at startup. This will force kernel allocations -* to reserve their blocks rather than leaking throughout -* the address space during boot when many long-lived -* kernel allocations are made. -* -* Please note that MEMINIT_HOTPLUG path doesn't clear memmap -* because this is done early in section_activate() -*/ -if (pageblock_aligned (pfn)) { -init_pageblock_migratetype (page,MIGRATE_MOVABLE , false); -cond_resched (); - } - -/* * ZONE_DEVICE pages other than MEMORY_TYPE_GENERIC are released * directly to the driver page allocator which will set the page count * to 1 when allocating the page.
@@ -1122,6 +1121,9 @@ void __ref memmap_init_zone_device(struc__init_zone_device_page (page, pfn, zone_idx, nid, pgmap); +if (IS_ALIGNED (pfn,PAGES_PER_SECTION )) +cond_resched (); +if (pfns_per_compound ==1 )continue ;
@@ -1129,6 +1131,8 @@ void __ref memmap_init_zone_device(struc compound_nr_pages(altmap, pgmap)); } +pageblock_migratetype_init_range (start_pfn, nr_pages,MIGRATE_MOVABLE ); +pr_debug ("%s initialised %lu pages in %ums\n" , __func__, nr_pages,jiffies_to_msecs (jiffies - start)); }
Greg Kroah-Hartman
maintainerPATCH 1675/2077 power: supply: cpcap-battery: Fix missing nvmem_device_put() causing reference leak
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ma Ke <[email protected]>
commit a2c14ff63e0e02e3c832385e523e9cc81301171c upstream.
In cpcap_battery_detect_battery_type(), the reference to an nvmem device obtained via nvmem_device_find() is not released with nvmem_device_put() on the success or read-failure paths, causing a permanent reference leak. The driver’s retry logic on subsequent battery property reads can compound this leak, preventing the nvmem device from ever being freed.
Found by code review.
--- drivers/power/supply/cpcap-battery.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/power/supply/cpcap-battery.c +7 -4
@@ -439,10 +439,13 @@ static void cpcap_battery_detect_batteryif (IS_ERR_OR_NULL (nvmem)) { ddata->check_nvmem = true;dev_info_once (ddata->dev,"Can not find battery nvmem device. Assuming generic lipo battery\n" ); - }else if (nvmem_device_read (nvmem,2 ,1 , &battery_id) <0 ) { - battery_id =0 ; - ddata->check_nvmem = true; -dev_warn (ddata->dev,"Can not read battery nvmem device. Assuming generic lipo battery\n" ); + }else { +if (nvmem_device_read (nvmem,2 ,1 , &battery_id) <0 ) { + battery_id =0 ; + ddata->check_nvmem = true; +dev_warn (ddata->dev,"Can not read battery nvmem device. Assuming generic lipo battery\n" ); + } +nvmem_device_put (nvmem); }switch (battery_id) {
Greg Kroah-Hartman
maintainerPATCH 1676/2077 power: supply: max17042: fix OF node reference imbalance
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 68d234144b7dffd1f50b07ba74d0d6e833ef43a4 upstream.
The driver reuses the OF node of the parent multi-function device but fails to take another reference to balance the one dropped by the platform bus code when unbinding the MFD and deregistering the child devices.
Fix this by using the intended helper for reusing OF nodes.
--- drivers/power/supply/max17042_battery.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/power/supply/max17042_battery.c +2 -1
@@ -1254,7 +1254,8 @@ static int max17042_platform_probe(strucif (!i2c)return -EINVAL ; - dev->of_node = dev->parent->of_node; +device_set_of_node_from_dev (dev, dev->parent); + id =platform_get_device_id (pdev); irq =platform_get_irq (pdev,0 );
Greg Kroah-Hartman
maintainerPATCH 1677/2077 mm/hugetlb: fix hugetlb cgroup rsvd charge/uncharge mismatch
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Deepanshu Kartikey <[email protected]>
commit 15807d0ddde37407af72859426b654f3d1972b00 upstream.
In alloc_hugetlb_folio(), a single h_cg pointer is used for both the rsvd and non-rsvd hugetlb cgroup charges. When map_chg is set, hugetlb_cgroup_charge_cgroup_rsvd() stores the charged cgroup in h_cg, but the immediately following hugetlb_cgroup_charge_cgroup() overwrites h_cg with the non-rsvd cgroup pointer.
As a result, hugetlb_cgroup_commit_charge_rsvd() stores the wrong (non-rsvd) cgroup pointer into the folio's rsvd slot.
When the folio is later freed, free_huge_folio() unconditionally calls both hugetlb_cgroup_uncharge_folio() and hugetlb_cgroup_uncharge_folio_rsvd(). The rsvd uncharge reads back the wrong cgroup from the folio and decrements a counter that was never charged for that cgroup, causing a page_counter underflow:
page_counter underflow: -512 nr_pages=512
WARNING: mm/page_counter.c:61 at page_counter_cancel
Fix this by introducing a separate h_cg_rsvd pointer exclusively for the rsvd charge path, keeping the rsvd and non-rsvd charges fully independent through their charge, commit, and error uncharge paths.
--- mm/hugetlb.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
mm/hugetlb.c +4 -3
@@ -2862,6 +2862,7 @@ struct folio *alloc_hugetlb_folio(structmap_chg_state map_chg;int ret, idx;struct hugetlb_cgroup *h_cg =NULL ; +struct hugetlb_cgroup *h_cg_rsvd =NULL ;gfp_t gfp =htlb_alloc_mask (h) | __GFP_RETRY_MAYFAIL; idx =hstate_index (h);
@@ -2912,7 +2913,7 @@ struct folio *alloc_hugetlb_folio(struct*/ if (map_chg) { ret =hugetlb_cgroup_charge_cgroup_rsvd ( - idx,pages_per_huge_page (h), &h_cg); + idx,pages_per_huge_page (h), &h_cg_rsvd);if (ret) goto out_subpool_put; }
@@ -2954,7 +2955,7 @@ struct folio *alloc_hugetlb_folio(struct*/ if (map_chg) {hugetlb_cgroup_commit_charge_rsvd (idx,pages_per_huge_page (h), - h_cg, folio); + h_cg_rsvd, folio); }spin_unlock_irq (&hugetlb_lock);
@@ -3006,7 +3007,7 @@ out_uncharge_cgroup: out_uncharge_cgroup_reservation:if (map_chg)hugetlb_cgroup_uncharge_cgroup_rsvd (idx,pages_per_huge_page (h), - h_cg); + h_cg_rsvd); out_subpool_put:/* * put page to subpool iff the quota of subpool's rsv_hpages is used
Greg Kroah-Hartman
maintainerPATCH 1678/2077 mm/memory_hotplug: fix incorrect altmap passing in error path
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muchun Song <[email protected]>
commit 2fac4afa0e2e68841334c78c1821e49f74fbc66a upstream.
In create_altmaps_and_memory_blocks(), when arch_add_memory() succeeds with memmap_on_memory enabled, the vmemmap pages are allocated from params.altmap. If create_memory_block_devices() subsequently fails, the error path calls arch_remove_memory() with a NULL altmap instead of params.altmap.
This is a bug that could lead to memory corruption. Since altmap is NULL, vmemmap_free() falls back to freeing the vmemmap pages into the system buddy allocator via free_pages() instead of the altmap. arch_remove_memory() then immediately destroys the physical linear mapping for this memory. This injects unowned pages into the buddy allocator, causing machine checks or memory corruption if the system later attempts to allocate and use those freed pages.
Fix this by passing params.altmap to arch_remove_memory() in the error path.
--- mm/memory_hotplug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory_hotplug.c +1 -1
@@ -1470,7 +1470,7 @@ static int create_altmaps_and_memory_blo ret =create_memory_block_devices (cur_start, memblock_size, nid, params.altmap, group);if (ret) { -arch_remove_memory (cur_start, memblock_size,NULL ); +arch_remove_memory (cur_start, memblock_size, params.altmap);kfree (params.altmap); goto out; }
Greg Kroah-Hartman
maintainerPATCH 1679/2077 mm/damon/core: make charge_addr_from aware of end-address exclusivity
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: SeongJae Park <[email protected]>
commit 5a2d162e22bf33eb89d53e802d0fc1ec422e19b6 upstream.
DAMON region end address is exclusive one, but charge_addr_from is assigned assuming the end address is inclusive. As a result, DAMOS action to next up to min_region_sz memory can be skipped. This is quite negligible user impact. But, the bug is a bug that can be very simply fixed. Fix the wrong assignment to respect the exclusiveness of the address.
The issue was discovered [1] by Sashiko.
--- mm/damon/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/damon/core.c +1 -1
@@ -2106,7 +2106,7 @@ static void damos_apply_scheme(struct daif (damos_quota_is_set (quota) && quota->charged_sz >= quota->esz) { quota->charge_target_from = t; - quota->charge_addr_from = r->ar.end +1 ; + quota->charge_addr_from = r->ar.end; } }if (s->action !=DAMOS_STAT )
Greg Kroah-Hartman
maintainerPATCH 1680/2077 ntfs: grow index root value before reparent header update
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: DaeMyung Kang <[email protected]>
commit 0bb508fb3b97e4802ec727fd2af4d608f65dd190 upstream.
ntfs_ir_reparent() moves the resident index root entries into an index block and leaves a small root stub containing the child VCN. That root stub can be larger than the existing resident value. For example, an empty root with value_length 48 has an index area of 32 bytes, while the large-index root stub needs index_length and allocated_size of 40 bytes.
The current code publishes the larger index.index_length and index.allocated_size before resizing the resident value. If the resize returns -ENOSPC, the recovery path can call ntfs_inode_add_attrlist(), which looks attributes up again while the root header says allocated_size 40 but the resident value still only provides 32 bytes of index area. Lookup-time $INDEX_ROOT validation then correctly rejects that transient layout as corrupt.
This reproduces as a generic/013 failure under qemu. In the failing run, the transient root had value_len=48, index_size=32, index_length=40, and allocated_size=40, and ntfsprogs-plus ntfsck reported "Corrupt index root in MFT record 1177".
When the root stub grows, resize the resident value before publishing the larger root header. If the resize fails, the old root remains valid for recovery lookups. Keep the existing header-before-resize ordering for shrink or same-size cases so the resident value never temporarily exposes an allocated_size beyond its bounds.
--- fs/ntfs/index.c | 78 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 30 deletions(-)
fs/ntfs/index.c +48 -30
@@ -1176,6 +1176,8 @@ static int ntfs_ir_reparent(struct ntfs_struct index_entry *ie;struct index_block *ib =NULL ;s64 new_ib_vcn; +u32 index_length; +u32 old_value_length;int ix_root_size;int ret =0 ;
@@ -1223,6 +1225,21 @@ retry: goto clear_bmp; } + old_value_length =le32_to_cpu (ctx->attr->data.resident.value_length); + index_length =le32_to_cpu (ir->index.entries_offset) + +sizeof (struct index_entry_header ) +sizeof (s64); + ix_root_size = offsetof(struct index_root , index) + index_length; +/* Grow the resident value before publishing the larger root header. */ +if (ix_root_size > old_value_length) { + ret =ntfs_resident_attr_value_resize (ctx->mrec, ctx->attr, ix_root_size); +if (ret) + goto resize_failed; + + icx->idx_ni->data_size = ix_root_size; + icx->idx_ni->initialized_size = ix_root_size; + icx->idx_ni->allocated_size = (ix_root_size +7 ) & ~7 ; + } +ntfs_ir_nill (ir); ie =ntfs_ie_get_first (&ir->index);
@@ -1231,48 +1248,49 @@ retry: ir->index.flags =LARGE_INDEX ;NInoSetIndexAllocPresent (icx->idx_ni); - ir->index.index_length =cpu_to_le32 (le32_to_cpu (ir->index.entries_offset) + -le16_to_cpu (ie->length)); + ir->index.index_length =cpu_to_le32 (index_length); ir->index.allocated_size = ir->index.index_length; - ix_root_size =sizeof (struct index_root ) -sizeof (struct index_header ) + -le32_to_cpu (ir->index.allocated_size); - ret =ntfs_resident_attr_value_resize (ctx->mrec, ctx->attr, ix_root_size); -if (ret) { -/* -* When there is no space to build a non-resident -* index, we may have to move the root to an extent -*/ -if ((ret == -ENOSPC ) && (ctx->al_entry || !ntfs_inode_add_attrlist (icx->idx_ni))) { +if (ix_root_size <= old_value_length) { + ret =ntfs_resident_attr_value_resize (ctx->mrec, ctx->attr, ix_root_size); +if (ret) + goto resize_failed; + + icx->idx_ni->data_size = ix_root_size; + icx->idx_ni->initialized_size = ix_root_size; + icx->idx_ni->allocated_size = (ix_root_size +7 ) & ~7 ; + } +ntfs_ie_set_vcn (ie, new_ib_vcn); + goto err_out; + +resize_failed: +/* +* When there is no space to build a non-resident +* index, we may have to move the root to an extent +*/ +if ((ret == -ENOSPC ) && (ctx->al_entry || !ntfs_inode_add_attrlist (icx->idx_ni))) { +ntfs_attr_put_search_ctx (ctx); + ctx =NULL ; + ir =ntfs_ir_lookup (icx->idx_ni, icx->name, icx->name_len, &ctx); +if (ir && !ntfs_attr_record_move_away (ctx, ix_root_size - +le32_to_cpu (ctx->attr->data.resident.value_length))) { +if (ntfs_attrlist_update (ctx->base_ntfs_ino ? + ctx->base_ntfs_ino : ctx->ntfs_ino)) + goto clear_bmp;ntfs_attr_put_search_ctx (ctx); ctx =NULL ; - ir =ntfs_ir_lookup (icx->idx_ni, icx->name, icx->name_len, &ctx); -if (ir && !ntfs_attr_record_move_away (ctx, ix_root_size - -le32_to_cpu (ctx->attr->data.resident.value_length))) { -if (ntfs_attrlist_update (ctx->base_ntfs_ino ? - ctx->base_ntfs_ino : ctx->ntfs_ino)) - goto clear_bmp; -ntfs_attr_put_search_ctx (ctx); - ctx =NULL ; - goto retry; - } + goto retry; } - goto clear_bmp; - }else { - icx->idx_ni->data_size = icx->idx_ni->initialized_size = ix_root_size; - icx->idx_ni->allocated_size = (ix_root_size +7 ) & ~7 ; } -ntfs_ie_set_vcn (ie, new_ib_vcn); - +clear_bmp: +ntfs_ibm_clear (icx, new_ib_vcn); + goto err_out; err_out:kvfree (ib);if (ctx)ntfs_attr_put_search_ctx (ctx); out:return ret; -clear_bmp: -ntfs_ibm_clear (icx, new_ib_vcn); - goto err_out; }/*
Greg Kroah-Hartman
maintainerPATCH 1681/2077 ntfs: fix incorrect size of symbolic link
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hyunchul Lee <[email protected]>
commit 05a5ff86a7f12c861e3516d3dc4d092ce620742d upstream.
This patch fixes the issue where a symbolic link size is displayed as 0.
--- fs/ntfs/inode.c | 3 +++ 1 file changed, 3 insertions(+)
fs/ntfs/inode.c +3 -0
@@ -1201,6 +1201,9 @@ no_data_attr_special_case:else vi->i_blocks = ni->allocated_size >>9 ; +if (S_ISLNK (vi->i_mode) && ni->target) + vi->i_size =strlen (ni->target); +ntfs_debug ("Done." );return 0 ; unm_err_out:
Greg Kroah-Hartman
maintainerPATCH 1682/2077 ntfs: fix off-by-one in mapping pairs decoding bounds checks
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ron de Bruijn <[email protected]>
commit 18760a74ef7c28df93726445b5595162e62ed341 upstream.
In ntfs_mapping_pairs_decompress(), attr_end points one byte past the end of the attribute record:
attr_end = (u8 *)attr + le32_to_cpu(attr->length);
The two bounds checks validating that mapping pair data bytes fit within the attribute use strict greater-than (>), which allows a one-byte out-of-bounds read when the data extends exactly to attr_end:
b = *buf & 0xf;
if (b) {
if (unlikely(buf + b > attr_end)) // off-by-one
goto io_error;
for (deltaxcn = (s8)buf[b--]; b; b--)
deltaxcn = (deltaxcn << 8) + buf[b];
}When buf + b == attr_end, the check evaluates to false and buf[b] reads one byte past the valid attribute boundary. The same pattern appears in the LCN delta bytes check.
Fix both checks to use >= so that buf[b] at exactly attr_end is correctly rejected as out of bounds.
--- fs/ntfs/runlist.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/ntfs/runlist.c +3 -3
@@ -763,7 +763,7 @@ struct runlist_element *ntfs_mapping_pai buf = (u8 *)attr +le16_to_cpu (attr->data.non_resident.mapping_pairs_offset); attr_end = (u8 *)attr +le32_to_cpu (attr->length); -if (unlikely (buf < (u8 *)attr || buf > attr_end)) { +if (unlikely (buf < (u8 *)attr || buf >= attr_end)) {ntfs_error (vol->sb,"Corrupt attribute." );return ERR_PTR (-EIO ); }
@@ -811,7 +811,7 @@ struct runlist_element *ntfs_mapping_pai*/ b = *buf &0xf ;if (b) { -if (unlikely (buf + b > attr_end)) +if (unlikely (buf + b >= attr_end)) goto io_error;for (deltaxcn = (s8 )buf[b--]; b; b--) deltaxcn = (deltaxcn <<8 ) + buf[b];
@@ -855,7 +855,7 @@ struct runlist_element *ntfs_mapping_paiu8 b2 = *buf &0xf ; b = b2 + ((*buf >>4 ) &0xf ); -if (buf + b > attr_end) +if (buf + b >= attr_end) goto io_error;for (deltaxcn = (s8 )buf[b--]; b > b2; b--) deltaxcn = (deltaxcn <<8 ) + buf[b];
Greg Kroah-Hartman
maintainerPATCH 1683/2077 ntfs: Add WQ_PERCPU to alloc_workqueue users
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marco Crivellari <[email protected]>
commit 38e8db370843b518ff9bee4af46c6b800684cc78 upstream.
This continues the effort to refactor workqueue APIs, which began with the introduction of new workqueues and a new alloc_workqueue flag in:
commit 128ea9f6ccfb ("workqueue: Add system_percpu_wq and system_dfl_wq") commit 930c2ea566af ("workqueue: Add new WQ_PERCPU flag")
The refactoring is going to alter the default behavior of alloc_workqueue() to be unbound by default.
With the introduction of the WQ_PERCPU flag (equivalent to !WQ_UNBOUND), any alloc_workqueue() caller that doesn’t explicitly specify WQ_UNBOUND must now use WQ_PERCPU. For more details see the Link tag below.
In order to keep alloc_workqueue() behavior identical, explicitly request WQ_PERCPU.
--- fs/ntfs/super.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ntfs/super.c +1 -1
@@ -2656,7 +2656,7 @@ MODULE_ALIAS_FS("ntfs");static int ntfs_workqueue_init (void ) { - ntfs_wq =alloc_workqueue ("ntfs-bg-io" ,0 ,0 ); + ntfs_wq =alloc_workqueue ("ntfs-bg-io" ,WQ_PERCPU ,0 );if (!ntfs_wq)return -ENOMEM ;return 0 ;
Greg Kroah-Hartman
maintainerPATCH 1684/2077 ntfs: validate attribute values on lookup
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: DaeMyung Kang <[email protected]>
commit d5803e3345dae9c6470bb61869885236276b9a35 upstream.
ntfs_attr_find() and ntfs_external_attr_find() check that generic resident attribute values fit in their attribute records and that fixed-size resident values are large enough. For variable-length resident formats, however, the fixed part is not enough: embedded length fields can still point callers past the resident value.
A crafted image can set a small resident $FILE_NAME value_length while leaving file_name_length large. Callers then trust file_name_length and read past the resident value when converting or comparing the name. This was reproduced with a crafted image under KASAN as a slab-out-of-bounds read from the kmalloc-1k MFT record copy. The stack included ntfs_lookup(), ntfs_iget(), ntfs_read_locked_inode(), ntfs_attr_name_get(), ntfs_ucstonls(), and utf16s_to_utf8s().
Add a shared attribute value validator and use it before a lookup path can return an attribute, including the AT_UNUSED enumeration case where callers inspect returned attributes directly. The helper validates resident value bounds, minimum resident value sizes, variable-length $FILE_NAME fields, and non-resident mapping-pairs metadata that was previously checked separately in both lookup paths.
This also preserves the intended resident @val matching semantics in the external attribute lookup path. The old duplicated validation block overwrote the actual resident value length with the type-specific minimum length before comparing @val, so variable-length resident values could fail to match even when the bytes were identical. Keep the comparison on the actual value length, and make ntfs_attrlist_entry_add() compare resident attributes with lowest_vcn zero instead of reading the non-resident union member after a successful resident match.
Reject non-resident $FILE_NAME records too: the format requires $FILE_NAME to be resident and callers treat returned records as resident.
--- fs/ntfs/attrib.c | 160 ++++++++++++++++++++++++++++++++--------------------- fs/ntfs/attrlist.c | 11 ++- 2 files changed, 107 insertions(+), 64 deletions(-)
fs/ntfs/attrib.c +99 -61
@@ -595,6 +595,97 @@ static u32 ntfs_resident_attr_min_value_ } } +static bool ntfs_file_name_attr_value_is_valid (const u8 *value,const u32 value_length) +{ +const struct file_name_attr *fn; +u32 file_name_size; + + fn = (const struct file_name_attr *)value; + file_name_size = fn->file_name_length *sizeof (__le16); + +return file_name_size <= + value_length - offsetof(struct file_name_attr , file_name); +} + +struct ntfs_resident_attr_value { +const u8 *data; +u32 len; +}; + +static bool ntfs_resident_attr_value_get (const struct attr_record *a, +struct ntfs_resident_attr_value *value) +{ +u32 attr_len; +u16 value_offset; + + attr_len =le32_to_cpu (a->length); + if (attr_len < offsetof(struct attr_record, data.resident.reserved) + + sizeof(a->data.resident.reserved)) +return false; + + value->len =le32_to_cpu (a->data.resident.value_length); + value_offset =le16_to_cpu (a->data.resident.value_offset); + +if (value->len > attr_len || value_offset > attr_len - value->len) +return false; + + value->data = (const u8 *)a + value_offset; +return true; +} + +static bool ntfs_non_resident_attr_value_is_valid (const struct attr_record *a) +{ +u32 attr_len; +u32 min_len; +u16 mp_offset; + + attr_len =le32_to_cpu (a->length); + min_len = offsetof(struct attr_record, data.non_resident.initialized_size) + +sizeof (a->data.non_resident.initialized_size); +if (attr_len < min_len) +return false; + + mp_offset =le16_to_cpu (a->data.non_resident.mapping_pairs_offset); +return mp_offset >= min_len && mp_offset <= attr_len; +} + +static bool ntfs_attr_value_is_valid (struct ntfs_volume *vol, +const struct attr_record *a, +const u64 mft_no) +{ +struct ntfs_resident_attr_value value; +u32 min_len; + +if (a->non_resident) { +if (a->type ==AT_FILE_NAME ) + goto corrupt; +if (!ntfs_non_resident_attr_value_is_valid (a)) + goto corrupt; +return true; + } + +if (!ntfs_resident_attr_value_get (a, &value)) + goto corrupt; + + min_len =ntfs_resident_attr_min_value_length (a->type); +if (min_len && value.len < min_len) + goto corrupt; + +switch (a->type) { +case AT_FILE_NAME : +if (!ntfs_file_name_attr_value_is_valid (value.data, value.len)) + goto corrupt; +break ; + } +return true; + +corrupt: +ntfs_error (vol->sb, +"Corrupt %#x attribute in MFT record %llu\n" , +le32_to_cpu (a->type), mft_no); +return false; +} +/* * ntfs_attr_find - find (next) attribute in mft record * @type: attribute type to find
@@ -705,8 +796,11 @@ static int ntfs_attr_find(const __le32 t } } -if (type ==AT_UNUSED ) +if (type ==AT_UNUSED ) { +if (!ntfs_attr_value_is_valid (vol, a, ctx->ntfs_ino->mft_no)) +break ;return 0 ; + }if (a->type != type)continue ;/*
@@ -747,37 +841,8 @@ static int ntfs_attr_find(const __le32 t } } -/* Validate attribute's value offset/length */ -if (!a->non_resident) { -u32 min_len; -u32 value_length =le32_to_cpu (a->data.resident.value_length); -u16 value_offset =le16_to_cpu (a->data.resident.value_offset); - -if (value_length >le32_to_cpu (a->length) || - value_offset >le32_to_cpu (a->length) - value_length) -break ; - - min_len =ntfs_resident_attr_min_value_length (a->type); -if (min_len && value_length < min_len) { -ntfs_error (vol->sb, -"Too small %#x resident attribute value in MFT record %lld\n" , -le32_to_cpu (a->type), (long long )ctx->ntfs_ino->mft_no); -break ; - } - }else { -u32 min_len; -u16 mp_offset; - - min_len = offsetof(struct attr_record, data.non_resident.initialized_size) + -sizeof (a->data.non_resident.initialized_size); -if (le32_to_cpu (a->length) < min_len) -break ; - - mp_offset =le16_to_cpu (a->data.non_resident.mapping_pairs_offset); -if (mp_offset < min_len || - mp_offset >le32_to_cpu (a->length)) -break ; - } +if (!ntfs_attr_value_is_valid (vol, a, ctx->ntfs_ino->mft_no)) +break ;/* * The names match or @name not present and attribute is
@@ -1299,22 +1364,8 @@ do_next_attr_loop: ctx->attr = a; -if (a->non_resident) { -u32 min_len; -u16 mp_offset; - - min_len = offsetof(struct attr_record , - data.non_resident.initialized_size) + -sizeof (a->data.non_resident.initialized_size); - -if (le32_to_cpu (a->length) < min_len) -break ; - - mp_offset = -le16_to_cpu (a->data.non_resident.mapping_pairs_offset); -if (mp_offset < min_len || mp_offset > attr_len) -break ; - } +if (!ntfs_attr_value_is_valid (vol, a, ctx->ntfs_ino->mft_no)) +break ;/* * If no @val specified or @val specified and it matches, we
@@ -1326,19 +1377,6 @@ do_next_attr_loop:u32 value_length =le32_to_cpu (a->data.resident.value_length);u16 value_offset =le16_to_cpu (a->data.resident.value_offset); - if (attr_len < offsetof(struct attr_record, data.resident.reserved) + - sizeof(a->data.resident.reserved)) - break; -if (value_length > attr_len || value_offset > attr_len - value_length) -break ; - - value_length =ntfs_resident_attr_min_value_length (a->type); -if (value_length &&le32_to_cpu (a->data.resident.value_length) < - value_length) { -pr_err ("Too small resident attribute value in MFT record %lld, type %#x\n" , - (long long )ctx->ntfs_ino->mft_no, a->type); -break ; - }if (value_length == val_len && !memcmp ((u8 *)a + value_offset, val, val_len)) { attr_found:
fs/ntfs/attrlist.c +8 -3
@@ -118,6 +118,7 @@ int ntfs_attrlist_entry_add(struct ntfs_int entry_len, entry_offset, err;struct mft_record *ni_mrec;u8 *old_al; +__le64 lowest_vcn;if (!ni || !attr) {ntfs_debug ("Invalid arguments.\n" );
@@ -158,17 +159,21 @@ int ntfs_attrlist_entry_add(struct ntfs_ntfs_error (ni->vol->sb,"Failed to get search context" ); goto err_out; } +if (attr->non_resident) + lowest_vcn = attr->data.non_resident.lowest_vcn; +else + lowest_vcn =0 ; err =ntfs_attr_lookup (attr->type, (attr->name_length) ? (__le16 *) ((u8 *)attr +le16_to_cpu (attr->name_offset)) :AT_UNNAMED , attr->name_length,CASE_SENSITIVE , - (attr->non_resident) ?le64_to_cpu (attr->data.non_resident.lowest_vcn) : -0 , (attr->non_resident) ?NULL : ((u8 *)attr + +le64_to_cpu (lowest_vcn), + (attr->non_resident) ?NULL : ((u8 *)attr +le16_to_cpu (attr->data.resident.value_offset)), (attr->non_resident) ?0 :le32_to_cpu (attr->data.resident.value_length), ctx);if (!err) {/* Found some extent, check it to be before new extent. */ -if (ctx->al_entry->lowest_vcn == attr->data.non_resident.lowest_vcn) { +if (ctx->al_entry->lowest_vcn == lowest_vcn) { err = -EEXIST ;ntfs_debug ("Such attribute already present in the attribute list.\n" );ntfs_attr_put_search_ctx (ctx);
Greg Kroah-Hartman
maintainerPATCH 1685/2077 ntfs: add bounds check before accessing EA entries
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hyunchul Lee <[email protected]>
commit 937282f7d15b593d0be765fa2ced164130ec87f7 upstream.
in ntfs_ea_lookup and ntfs_listxattr, this verifies that there is enough space in the EA entry before accessing the next_entry_offset field of the EA entry.
--- fs/ntfs/ea.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
fs/ntfs/ea.c +8 -8
@@ -53,11 +53,11 @@ static int ntfs_ea_lookup(char *ea_buf,loff_t offset, p_ea_size;unsigned int next; -if (ea_buf_size <sizeof (struct ea_attr )) - goto out; - offset =0 ; do { + if (ea_buf_size - offset < sizeof(struct ea_attr)) + break; + p_ea = (const struct ea_attr *)&ea_buf[offset]; next = le32_to_cpu(p_ea->next_entry_offset); p_ea_size = next ? next : (ea_buf_size - offset);
@@ -479,13 +479,13 @@ ssize_t ntfs_listxattr(struct dentry *deif (ea_info_qsize > ea_buf_size || ea_info_qsize ==0 ) goto out; -if (ea_info_qsize <sizeof (struct ea_attr )) { - err = -EIO ; - goto out; - } - offset =0 ; do { + if (ea_info_qsize - offset < sizeof(struct ea_attr)) { + err = -EIO; + goto out; + } + p_ea = (const struct ea_attr *)&ea_buf[offset]; next = le32_to_cpu(p_ea->next_entry_offset); ea_size = next ? next : (ea_info_qsize - offset);
Greg Kroah-Hartman
maintainerPATCH 1686/2077 ntfs: not change 0-byte $DATA attribute to non-resident
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hyunchul Lee <[email protected]>
commit 0aad21570197973af4a1b25b3fb8ed3aeb9e7670 upstream.
When ntfs_resident_attr_resize() cannot grow a resident attribute in place, it retries after converting other resident attributes to non-resident to free space in the MFT recrord.
Do not select zero-length resident $DATA attributes for this conversion. fsck treats 0-byte non-resident $DATA attribute as corruptions.
--- fs/ntfs/attrib.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
fs/ntfs/attrib.c +5 -2
@@ -4621,10 +4621,12 @@ attr_resize_again:while (!(err =ntfs_attr_lookup (AT_UNUSED ,NULL ,0 ,0 ,0 ,NULL ,0 , ctx))) {struct inode *tvi;struct attr_record *a; +u32 value_len; a = ctx->attr;if (a->non_resident || a->type ==AT_ATTRIBUTE_LIST )continue ; + value_len =le32_to_cpu (a->data.resident.value_length);if (ntfs_attr_can_be_non_resident (vol, a->type))continue ;
@@ -4636,6 +4638,8 @@ attr_resize_again:if (le32_to_cpu (a->length) <= (sizeof (struct attr_record ) -sizeof (s64)) + ((a->name_length *sizeof (__le16) +7 ) & ~7 ) +8 )continue ; +if (a->type ==AT_DATA && !value_len) +continue ;if (a->type ==AT_DATA ) tvi =ntfs_iget (sb, base_ni->mft_no);
@@ -4648,8 +4652,7 @@ attr_resize_again:continue ; } -if (ntfs_attr_make_non_resident (NTFS_I (tvi), -le32_to_cpu (ctx->attr->data.resident.value_length))) { +if (ntfs_attr_make_non_resident (NTFS_I (tvi), value_len)) {iput (tvi);continue ; }
Greg Kroah-Hartman
maintainerPATCH 1687/2077 ntfs: validate index block header more strictly
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hyunchul Lee <[email protected]>
commit 14bc34fe948523dc2b0174691f9af9e74eb4f3fd upstream.
Modify ntfs_index_block_inconsisent() to perform stricter validation of INDEX_HEADER geometry in INDX blocks, and update ntfs_lookup_inode_by_name() to use that function to validate INDX blocks.
--- fs/ntfs/dir.c | 38 +++----------------- fs/ntfs/index.c | 103 +++++++++++++++++++++++++++++++++++++++----------------- fs/ntfs/index.h | 3 + 3 files changed, 82 insertions(+), 62 deletions(-)
fs/ntfs/dir.c +7 -31
@@ -342,43 +342,19 @@ fast_descend_into_child_node: dir_ni->mft_no); goto unm_err_out; } -/* Catch multi sector transfer fixup errors. */ -if (unlikely (!ntfs_is_indx_record (ia->magic))) { -ntfs_error (sb, -"Directory index record with vcn 0x%llx is corrupt. Corrupt inode 0x%llx. Run chkdsk." , - vcn, dir_ni->mft_no); - goto unm_err_out; - } -if (le64_to_cpu (ia->index_block_vcn) != vcn) { -ntfs_error (sb, -"Actual VCN (0x%llx) of index buffer is different from expected VCN (0x%llx). Directory inode 0x%llx is corrupt or driver bug." , -le64_to_cpu (ia->index_block_vcn), - vcn, dir_ni->mft_no); - goto unm_err_out; - } -if (le32_to_cpu (ia->index.allocated_size) +0x18 != - dir_ni->itype.index.block_size) { -ntfs_error (sb, -"Index buffer (VCN 0x%llx) of directory inode 0x%llx has a size (%u) differing from the directory specified size (%u). Directory inode is corrupt or driver bug." , - vcn, dir_ni->mft_no, -le32_to_cpu (ia->index.allocated_size) +0x18 , - dir_ni->itype.index.block_size); - goto unm_err_out; - } index_end = (u8 *)ia + dir_ni->itype.index.block_size;if (index_end > kaddr +PAGE_SIZE ) {ntfs_error (sb, -"Index buffer (VCN 0x%llx) of directory inode 0x%llx crosses page boundary. Impossible! Cannot access! This is probably a bug in the driver." , - vcn, dir_ni->mft_no); +"Index buffer (VCN 0x%llx) of directory inode 0x%llx crosses page boundary. Impossible! Cannot access! This is probably a bug in the driver." , + vcn, dir_ni->mft_no); goto unm_err_out; } - index_end = (u8 *)&ia->index +le32_to_cpu (ia->index.index_length); -if (index_end > (u8 *)ia + dir_ni->itype.index.block_size) { -ntfs_error (sb, -"Size of index buffer (VCN 0x%llx) of directory inode 0x%llx exceeds maximum size." , - vcn, dir_ni->mft_no); + err =ntfs_index_block_inconsistent (vol, ia, + dir_ni->itype.index.block_size, + vcn, dir_ni->mft_no); +if (err) goto unm_err_out; - } + index_end = (u8 *)&ia->index +le32_to_cpu (ia->index.index_length);/* The first index entry. */ ie = (struct index_entry *)((u8 *)&ia->index +le32_to_cpu (ia->index.entries_offset));
fs/ntfs/index.c +72 -31
149 lines not on this page · raw message
fs/ntfs/index.h +3 -0
@@ -89,6 +89,9 @@ struct ntfs_index_context {bool sync_write; }; +int ntfs_index_block_inconsistent (struct ntfs_volume *vol, +const struct index_block *ib, +u32 block_size,s64 vcn,u64 inum);int ntfs_index_entry_inconsistent (struct ntfs_index_context *icx,struct ntfs_volume *vol,const struct index_entry *ie,__le32 collation_rule,u64 inum); struct ntfs_index_context *ntfs_index_ctx_get(struct ntfs_inode *ni, __le16 *name,
Greg Kroah-Hartman
maintainerPATCH 1688/2077 ntfs: free volume-wide resources on fill_super failure
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: DaeMyung Kang <[email protected]>
commit a9523a7d3b24b3a6b25ec1eb668ee6618cacf05e upstream.
ntfs_fill_super()'s err_out_now path frees only the volume struct via kfree(vol), leaving several vol-owned allocations behind on every mount failure:
- vol->nls_map, loaded by ntfs_init_fs_context() via load_nls_default() (or replaced by an explicit nls= option in ntfs_parse_param()), is never unload_nls()'d.
- vol->volume_label, allocated by load_system_files() through ntfs_ucstonls() once the $Volume name attribute has been parsed, is not released by load_system_files()'s own error labels nor by the fill_super() inline cleanup that only runs on d_make_root() failure. Any later failure inside load_system_files() leaks it.
- vol->lcn_empty_bits_per_page was kvfree()'d in unl_upcase_iput_tmp_ino_err_out_now without clearing the pointer, so it could not be folded into a single common cleanup.
Because the failure paths never call ntfs_volume_free() and never reach the d_make_root() inline cleanup block (it sits above the label and is jumped over by the load_system_files() / kvmalloc failure gotos), these resources accumulate per failed mount attempt with no chance of recovery short of unloading the module. This is a silent leak: the inodes loaded prior to failure remain hashed but generic_shutdown_super() skips evict_inodes() when sb->s_root is unset, so no CHECK_DATA_CORRUPTION warning is emitted either.
Move the per-volume frees down to err_out_now and drop the lcn_empty_bits_per_page kvfree() from the upper label so the cleanup is performed exactly once on every failure path. Using unconditional kvfree() / kfree() / unload_nls() is safe because they all accept NULL and the upper labels that previously freed nls_map (the d_make_root() inline cleanup) already clear the pointer.
--- fs/ntfs/super.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/ntfs/super.c +3 -2
@@ -2536,8 +2536,6 @@ static int ntfs_fill_super(struct super_ }/* Error exit code path. */ unl_upcase_iput_tmp_ino_err_out_now: -if (vol->lcn_empty_bits_per_page) -kvfree (vol->lcn_empty_bits_per_page);/* * Decrease the number of upcase users and destroy the global default * upcase table if necessary.
@@ -2557,6 +2555,9 @@ iput_tmp_ino_err_out_now:/* Errors at this stage are irrelevant. */ err_out_now: sb->s_fs_info =NULL ; +kvfree (vol->lcn_empty_bits_per_page); +kfree (vol->volume_label); +unload_nls (vol->nls_map);kfree (vol);ntfs_debug ("Failed, returning -EINVAL." );lockdep_on ();
Greg Kroah-Hartman
maintainerPATCH 1689/2077 ntfs: update index root allocated size before shrink
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: DaeMyung Kang <[email protected]>
commit e782ca90ceb798bb1811b214bf814216f11aae6a upstream.
ntfs_ir_truncate() currently shrinks the resident $INDEX_ROOT value first and only updates index.allocated_size after re-looking up the attribute. During that relookup, the resident value_length can already be smaller while index.allocated_size still contains the old larger size.
That leaves a transiently inconsistent $INDEX_ROOT layout and prevents lookup-time $INDEX_ROOT validation from being enabled: validation can correctly reject allocated_size extending past the newly shrunk resident value.
When shrinking, lower index.allocated_size before shrinking value_length. If the truncate fails, restore the old allocated_size. Keep the existing grow ordering because the old allocated_size remains within the enlarged resident value until it is updated after the relookup. The shrink path is safe because the new value_length still covers struct index_root, so the index.allocated_size field remains present while it is updated first.
--- fs/ntfs/index.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
fs/ntfs/index.c +15 -3
@@ -1342,9 +1342,16 @@ out:static int ntfs_ir_truncate (struct ntfs_index_context *icx,int data_size) {int ret; +u32 old_allocated_size; +bool shrink;ntfs_debug ("Entering\n" ); + old_allocated_size =le32_to_cpu (icx->ir->index.allocated_size); + shrink = data_size < old_allocated_size; +if (shrink) + icx->ir->index.allocated_size =cpu_to_le32 (data_size); +/* * INDEX_ROOT must be resident and its entries can be moved to * struct index_block, so ENOSPC isn't a real error.
@@ -1356,9 +1363,14 @@ static int ntfs_ir_truncate(struct ntfs_if (!icx->ir)return -ENOENT ; - icx->ir->index.allocated_size =cpu_to_le32 (data_size); - }else if (ret != -ENOSPC ) -ntfs_error (icx->idx_ni->vol->sb,"Failed to truncate INDEX_ROOT" ); +if (!shrink) + icx->ir->index.allocated_size =cpu_to_le32 (data_size); + }else { +if (shrink) + icx->ir->index.allocated_size =cpu_to_le32 (old_allocated_size); +if (ret != -ENOSPC ) +ntfs_error (icx->idx_ni->vol->sb,"Failed to truncate INDEX_ROOT" ); + }return ret; }
Greg Kroah-Hartman
maintainerPATCH 1690/2077 ntfs: centalize $INDEX_ROOT header validation
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hyunchul Lee <[email protected]>
commit 8b97b302f553a480fb76d2afd53cd6c0635a9dcd upstream.
Add a dedicated helper to perform stricter validation of $INDEX_ROOT and use it for both directory inodes and named index inodes. This keeps the root size and header geometry checks consistent across both read paths.
--- fs/ntfs/index.c | 18 ++++++++++++++++++ fs/ntfs/index.h | 3 +++ fs/ntfs/inode.c | 11 ++--------- 3 files changed, 23 insertions(+), 9 deletions(-)
fs/ntfs/index.c +18 -0
@@ -544,6 +544,24 @@ int ntfs_index_block_inconsistent(structreturn 0 ; } +int ntfs_index_root_inconsistent (struct ntfs_volume *vol, +const struct attr_record *a, +const struct index_root *ir,u64 inum) +{ +u32 value_length =le32_to_cpu (a->data.resident.value_length); + +if (value_length < offsetof(struct index_root , index)) { +ntfs_error (vol->sb,"$INDEX_ROOT in inode %llu is too small." , + (unsigned long long )inum); +return -EIO ; + } + +return ntfs_index_header_inconsistent (vol, &ir->index, + value_length - + offsetof(struct index_root , index), + inum); +} +static struct index_root *ntfs_ir_lookup (struct ntfs_inode *ni,__le16 *name,u32 name_len,struct ntfs_attr_search_ctx **ctx) {
fs/ntfs/index.h +3 -0
@@ -89,6 +89,9 @@ struct ntfs_index_context {bool sync_write; }; +int ntfs_index_root_inconsistent (struct ntfs_volume *vol, +const struct attr_record *a, +const struct index_root *ir,u64 inum);int ntfs_index_block_inconsistent (struct ntfs_volume *vol,const struct index_block *ib,u32 block_size,s64 vcn,u64 inum);
fs/ntfs/inode.c +2 -9
@@ -896,7 +896,6 @@ skip_attr_list_load:*/ if (S_ISDIR (vi->i_mode)) {struct index_root *ir; -u8 *ir_end, *index_end; view_index_meta:/* It is a directory, find index root attribute. */
@@ -946,10 +945,7 @@ view_index_meta: } ir = (struct index_root *)((u8 *)a +le16_to_cpu (a->data.resident.value_offset)); - ir_end = (u8 *)ir +le32_to_cpu (a->data.resident.value_length); - index_end = (u8 *)&ir->index + -le32_to_cpu (ir->index.index_length); -if (index_end > ir_end) { +if (ntfs_index_root_inconsistent (ni->vol, a, ir, ni->mft_no)) {ntfs_error (vi->i_sb,"Directory index is corrupt." ); goto unm_err_out; }
@@ -1492,7 +1488,6 @@ static int ntfs_read_locked_index_inode(struct attr_record *a;struct ntfs_attr_search_ctx *ctx;struct index_root *ir; -u8 *ir_end, *index_end;int err =0 ;ntfs_debug ("Entering for i_ino 0x%llx." , ni->mft_no);
@@ -1543,9 +1538,7 @@ static int ntfs_read_locked_index_inode( } ir = (struct index_root *)((u8 *)a +le16_to_cpu (a->data.resident.value_offset)); - ir_end = (u8 *)ir +le32_to_cpu (a->data.resident.value_length); - index_end = (u8 *)&ir->index +le32_to_cpu (ir->index.index_length); -if (index_end > ir_end) { +if (ntfs_index_root_inconsistent (vol, a, ir, ni->mft_no)) {ntfs_error (vi->i_sb,"Index is corrupt." ); goto unm_err_out; }
Greg Kroah-Hartman
maintainerPATCH 1691/2077 ntfs: skip extent mft records in writeback to prevent deadlock
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hyunchul Lee <[email protected]>
commit 76bc14c7097ff678b2b5dbfd4fa33b46897d87ce upstream.
This patch fixes the ABBA deadlock between extent_lock and extent mrec_lock triggered by xfstests generic/113, that occurs since the commit 6994acf33bae ("ntfs: use base mft_no when looking up base inode for
extent record").
Path A (inode writeback):
VFS writeback
-> ntfs_write_inode()
-> __ntfs_write_inode()
-> mutex_lock(&ni->extent_lock)
-> mutex_lock(&tni->mrec_lock)Path B (MFT folio writeback):
VFS writeback of $MFT dirty folios
-> ntfs_mft_writepages()
-> ntfs_write_mft_block()
-> ntfs_may_write_mft_record()
-> holds one extent mrec_lock from a previous iteration
-> tries to acquire another base inode extent_lockBy removing all extent_lock and extent mrec_lock acquisition from the MFT folio writeback path, the ABBA lock ordering is eliminated:
Path A: __ntfs_write_inode(): extent_lock -> mrec_lock Path B (removed): ntfs_write_mft_block(): mrec_lock -> extent_lock
Path B is always redundant for extent records because:
1. mark_mft_record_dirty(ext_ni) does NOT dirty the MFT folio. It only sets NInoDirty(ext_ni) and marks the base VFS inode dirty via __mark_inode_dirty(I_DIRTY_DATASYNC), which triggers Path A. Therefore, normal extent modifications never create a situation where the MFT folio is dirty and Path B is not scheduled.
2. The MFT folio only gets dirtied via ntfs_mft_mark_dirty() inside ntfs_mft_record_alloc(). But all identified callers in attrib.c (ntfs_attr_add, ntfs_attr_record_move_away, ntfs_attr_make_non_resident, ntfs_attr_record_resize) follow through with mark_mft_record_dirty(), which triggers Path A to write the complete record.
3. ntfs_evict_big_inode() calls ntfs_commit_inode() before freeing extent inodes, ensuring all dirty extents are flushed via Path A before the base inode leaves the icache.
--- fs/ntfs/mft.c | 129 +--------------------------------------------------------- 1 file changed, 4 insertions(+), 125 deletions(-)
fs/ntfs/mft.c +4 -125
@@ -743,23 +743,6 @@ static int ntfs_test_inode_wb(struct ino* * If the mft record is not a FILE record or it is a base mft record, we can * safely write it and return 'true'. -* -* We now know the mft record is an extent mft record. We check if the inode -* corresponding to its base mft record is in icache. If it is not, we cannot -* safely determine the state of the extent inode, so we return 'false'. -* -* We now have the base inode for the extent mft record. We check if it has an -* ntfs inode for the extent mft record attached. If not, it is safe to write -* the extent mft record and we return 'true'. -* -* If the extent inode is attached, we check if it is dirty. If so, we return -* 'false' (letting the standard write_inode path handle it). -* -* If it is not dirty, we attempt to lock the extent mft record. If the lock -* was already taken, it is not safe to write and we return 'false'. -* -* If we manage to obtain the lock we have exclusive access to the extent mft -* record. We set @locked_ni to the now locked ntfs inode and return 'true'. */ static bool ntfs_may_write_mft_record(struct ntfs_volume *vol, const u64 mft_no, const struct mft_record *m, struct ntfs_inode **locked_ni,
@@ -768,8 +751,7 @@ static bool ntfs_may_write_mft_record(ststruct super_block *sb = vol->sb;struct inode *mft_vi = vol->mft_ino;struct inode *vi; -struct ntfs_inode *ni, *eni, **extent_nis; -int i; +struct ntfs_inode *ni;struct ntfs_attr na = {0 };ntfs_debug ("Entering for inode 0x%llx." , mft_no);
@@ -849,100 +831,10 @@ static bool ntfs_may_write_mft_record(st mft_no);return true; } -/* -* This is an extent mft record. Check if the inode corresponding to -* its base mft record is in icache and obtain a reference to it if it -* is. -*/ - na.mft_no =MREF_LE (m->base_mft_record); - na.state =0 ; -ntfs_debug ("Mft record 0x%llx is an extent record. Looking for base inode 0x%llx in icache." , - mft_no, na.mft_no); -if (!na.mft_no) { -/* Balance the below iput(). */ - vi =igrab (mft_vi); -WARN_ON (vi != mft_vi); - }else { - vi =find_inode_nowait (sb, na.mft_no, ntfs_test_inode_wb, &na); -if (na.state == NI_BeingDeleted || na.state == NI_BeingCreated) -return false; - } -if (!vi) -return false; -ntfs_debug ("Base inode 0x%llx is in icache." , na.mft_no); -/* -* The base inode is in icache. Check if it has the extent inode -* corresponding to this extent mft record attached. -*/ - ni =NTFS_I (vi); -mutex_lock (&ni->extent_lock); -if (ni->nr_extents <=0 ) { -/* -* The base inode has no attached extent inodes, write this -* extent mft record. -*/ -mutex_unlock (&ni->extent_lock); - *ref_vi = vi; -ntfs_debug ("Base inode 0x%llx has no attached extent inodes, write the extent record." , - na.mft_no); -return true; - } -/* Iterate over the attached extent inodes. */ - extent_nis = ni->ext.extent_ntfs_inos; -for (eni =NULL , i =0 ; i < ni->nr_extents; ++i) { -if (mft_no == extent_nis[i]->mft_no) { -/* -* Found the extent inode corresponding to this extent -* mft record. -*/ - eni = extent_nis[i]; -break ; - } - } -/* -* If the extent inode was not attached to the base inode, write this -* extent mft record. -*/ -if (!eni) { -mutex_unlock (&ni->extent_lock); - *ref_vi = vi; -ntfs_debug ("Extent inode 0x%llx is not attached to its base inode 0x%llx, write the extent record." , - mft_no, na.mft_no); -return true; - } -ntfs_debug ("Extent inode 0x%llx is attached to its base inode 0x%llx." , - mft_no, na.mft_no); -/* Take a reference to the extent ntfs inode. */ -atomic_inc (&eni->count); -mutex_unlock (&ni->extent_lock); - -/* if extent inode is dirty, write_inode will write it */ -if (NInoDirty (eni)) { -atomic_dec (&eni->count); - *ref_vi = vi; -return false; - } - -/* -* Found the extent inode coresponding to this extent mft record. -* Try to take the mft record lock. -*/ -if (unlikely (!mutex_trylock (&eni->mrec_lock))) { -atomic_dec (&eni->count); - *ref_vi = vi; -ntfs_debug ("Extent mft record 0x%llx is already locked, do not write it." , - mft_no); -return false; - } -ntfs_debug ("Managed to lock extent mft record 0x%llx, write it." , - mft_no); -/* -* The write has to occur while we hold the mft record lock so return -* the locked extent ntfs inode. -*/ - *locked_ni = eni; -return true; +ntfs_debug ("Mft record 0x%llx is an extent record, skip it." , + mft_no); +return false; }static const char *es =" Leaving inconsistent metadata. Unmount and run chkdsk." ;
@@ -2792,19 +2684,6 @@ static int ntfs_write_mft_block(struct fs64 rl_len =0 ;/* -* Skip $MFT extent mft records and let them being written -* by writeback to avioid deadlocks. the $MFT runlist -* lock must be taken before $MFT extent mrec_lock is taken. -*/ -if (tni && tni->nr_extents <0 && - tni->ext.base_ntfs_ino ==NTFS_I (vol->mft_ino)) { -mutex_unlock (&tni->mrec_lock); -atomic_dec (&tni->count); -iput (vol->mft_ino); -continue ; - } - -/* * The record should be written. If a locked ntfs * inode was returned, add it to the array of locked * ntfs inodes.
Greg Kroah-Hartman
maintainerPATCH 1692/2077 ntfs: reinit search context before volume information lookup
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: DaeMyung Kang <[email protected]>
commit 45dd046ced0f5982a6d64ca449de3a61f5f15669 upstream.
On mount the volume inode is searched for $VOLUME_NAME and then, reusing the same search context, for $VOLUME_INFORMATION. The $VOLUME_NAME lookup is optional and its result is otherwise ignored.
Once lookup-time validation can reject a corrupt $VOLUME_NAME with -EIO, the search context is left in an undefined state: ntfs_attr_find() documents that on an actual error @ctx->attr is undefined. Continuing the $VOLUME_INFORMATION search from that context is not contractually valid.
Reinitialize the search context before the $VOLUME_INFORMATION lookup so it always starts from a well-defined state regardless of the $VOLUME_NAME lookup outcome.
--- fs/ntfs/super.c | 1 + 1 file changed, 1 insertion(+)
fs/ntfs/super.c +1 -0
@@ -1537,6 +1537,7 @@ iput_volume_failed: vol->volume_label =NULL ; } +ntfs_attr_reinit_search_ctx (ctx);if (ntfs_attr_lookup (AT_VOLUME_INFORMATION ,NULL ,0 ,0 ,0 ,NULL ,0 , ctx) || ctx->attr->non_resident || ctx->attr->flags) {ntfs_attr_put_search_ctx (ctx);
Greg Kroah-Hartman
maintainerPATCH 1693/2077 ntfs: only alias volume $UpCase to default on exact match
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: DaeMyung Kang <[email protected]>
commit 8f4b6e8bda121ae3d4d8e332b789664604d3e9d2 upstream.
load_and_init_upcase() currently aliases vol->upcase to the global default upcase whenever the shared prefix matches, and then truncates vol->upcase_len to that shorter prefix. The result is correct only by
accident: upcase[] accesses in name collation are gated by upcase_len, so the prefix-equality alias produces the same fold output as keeping the volume's own shorter table.
Still, prefix equality is not equality: the volume table is logically distinct from the default and should not be replaced by it unless they are byte-for-byte identical. Use memcmp() to compare the complete table in one expression and drop the now-redundant upcase_len rewrite.
No user-visible change is expected for compliant volumes whose $UpCase has exactly default_upcase_len entries; shorter volume tables are no longer aliased to the default.
--- fs/ntfs/super.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
fs/ntfs/super.c +3 -9
@@ -1329,7 +1329,6 @@ static bool load_and_init_upcase(structu8 *addr;pgoff_t index, max_index;unsigned int size; -int i, max;ntfs_debug ("Entering." );/* Read upcase table and setup vol->upcase and vol->upcase_len. */
@@ -1380,16 +1379,11 @@ read_partial_upcase_page:mutex_unlock (&ntfs_lock);return true; } - max = default_upcase_len; -if (max > vol->upcase_len) - max = vol->upcase_len; -for (i =0 ; i < max; i++) -if (vol->upcase[i] != default_upcase[i]) -break ; -if (i == max) { +if (default_upcase_len == vol->upcase_len && + !memcmp (vol->upcase, default_upcase, + default_upcase_len *sizeof (*default_upcase))) {kvfree (vol->upcase); vol->upcase = default_upcase; - vol->upcase_len = max; ntfs_nr_upcase_users++;mutex_unlock (&ntfs_lock);ntfs_debug ("Volume specified $UpCase matches default. Using default." );
Greg Kroah-Hartman
maintainerPATCH 1694/2077 ntfs: avoid heap allocation for free-cluster readahead state
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: DaeMyung Kang <[email protected]>
commit c05132077df57a384919f61d7f8a8e76d748a6d4 upstream.
get_nr_free_clusters() allocates a temporary file_ra_state before it publishes the precomputed free cluster count, sets NVolFreeClusterKnown(), and wakes vol->free_waitq. If that allocation fails, the worker returns without setting the flag or waking waiters, so callers waiting for the free count can block indefinitely.
The readahead state is only used synchronously while scanning the bitmap. Keep it on the stack and pass it by address to the readahead helper. This eliminates the early allocation failure path instead of adding a special case that publishes a conservative count and wakes the waitqueue. Zero-initialize the on-stack state because file_ra_state_init() only sets ra_pages and prev_pos.
Apply the same treatment to __get_nr_free_mft_records(), which scans the MFT bitmap with the same short-lived readahead state.
--- fs/ntfs/super.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-)
fs/ntfs/super.c +6 -16
@@ -1955,7 +1955,7 @@ s64 get_nr_free_clusters(struct ntfs_volstruct address_space *mapping = vol->lcnbmp_ino->i_mapping;struct folio *folio;pgoff_t index, max_index; -struct file_ra_state *ra; +struct file_ra_state ra = {0 };ntfs_debug ("Entering." );/* Serialize accesses to the cluster bitmap. */
@@ -1963,11 +1963,7 @@ s64 get_nr_free_clusters(struct ntfs_volif (NVolFreeClusterKnown (vol))return atomic64_read (&vol->free_clusters); - ra =kzalloc (sizeof (*ra),GFP_NOFS ); -if (!ra) -return 0 ; - -file_ra_state_init (ra, mapping); +file_ra_state_init (&ra, mapping);/* * Convert the number of bits into bytes rounded up, then convert into
@@ -1986,7 +1982,7 @@ s64 get_nr_free_clusters(struct ntfs_vol* Get folio from page cache, getting it from backing store * if necessary, and increment the use count. */ - folio =ntfs_get_locked_folio (mapping, index, max_index, ra); + folio =ntfs_get_locked_folio (mapping, index, max_index, &ra);/* Ignore pages which errored synchronously. */ if (IS_ERR (folio)) {
@@ -2025,7 +2021,6 @@ s64 get_nr_free_clusters(struct ntfs_volelse atomic64_set (&vol->free_clusters, nr_free); -kfree (ra);NVolSetFreeClusterKnown (vol);wake_up_all (&vol->free_waitq);ntfs_debug ("Exiting." );
@@ -2080,15 +2075,11 @@ static unsigned long __get_nr_free_mft_rstruct address_space *mapping = vol->mftbmp_ino->i_mapping;struct folio *folio;pgoff_t index; -struct file_ra_state *ra; +struct file_ra_state ra = {0 };ntfs_debug ("Entering." ); - ra =kzalloc (sizeof (*ra),GFP_NOFS ); -if (!ra) -return 0 ; - -file_ra_state_init (ra, mapping); +file_ra_state_init (&ra, mapping);/* Use multiples of 4 bytes, thus max_size is PAGE_SIZE / 4. */ ntfs_debug("Reading $MFT/$BITMAP, max_index = 0x%lx, max_size = 0x%lx.",
@@ -2100,7 +2091,7 @@ static unsigned long __get_nr_free_mft_r* Get folio from page cache, getting it from backing store * if necessary, and increment the use count. */ - folio =ntfs_get_locked_folio (mapping, index, max_index, ra); + folio =ntfs_get_locked_folio (mapping, index, max_index, &ra);/* Ignore pages which errored synchronously. */ if (IS_ERR (folio)) {
@@ -2132,7 +2123,6 @@ static unsigned long __get_nr_free_mft_relse atomic64_set (&vol->free_mft_records, nr_free); -kfree (ra);ntfs_debug ("Exiting." );return nr_free; }
Greg Kroah-Hartman
maintainerPATCH 1695/2077 ntfs: validate index entries on reading
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hyunchul Lee <[email protected]>
commit 2221b691d7b2e17f08153f95848dacaa5d87e21d upstream.
Validate index entries immediately after reading an index root or index block from disk. This eliminates repeated checks in lookup and readdir, and reduce the risk of missing checks in those paths.
--- fs/ntfs/dir.c | 28 +----------------- fs/ntfs/index.c | 86 ++++++++++++++++++++++++++++++-------------------------- fs/ntfs/index.h | 8 +++-- fs/ntfs/inode.c | 8 +++-- 4 files changed, 61 insertions(+), 69 deletions(-)
fs/ntfs/dir.c +3 -25
@@ -135,10 +135,6 @@ u64 ntfs_lookup_inode_by_name(struct ntf/* Key length should not be zero if it is not last entry. */ if (!ie->key_length) goto dir_err_out; -/* Check the consistency of an index entry */ -if (ntfs_index_entry_inconsistent (NULL , vol, ie,COLLATION_FILE_NAME , - dir_ni->mft_no)) - goto dir_err_out;/* * We perform a case sensitive comparison and if that matches * we are done and return the mft reference of the inode (i.e.
@@ -351,7 +347,8 @@ fast_descend_into_child_node: } err =ntfs_index_block_inconsistent (vol, ia, dir_ni->itype.index.block_size, - vcn, dir_ni->mft_no); + vcn,COLLATION_FILE_NAME , + dir_ni->mft_no);if (err) goto unm_err_out; index_end = (u8 *)&ia->index +le32_to_cpu (ia->index.index_length);
@@ -364,15 +361,6 @@ fast_descend_into_child_node:* reach the last entry. */ for (;; ie = (struct index_entry *)((u8 *)ie +le16_to_cpu (ie->length))) { -/* Bounds checks. */ -if ((u8 *)ie < (u8 *)ia || - (u8 *)ie +sizeof (struct index_entry_header ) > index_end || - (u8 *)ie +sizeof (struct index_entry_header ) +le16_to_cpu (ie->key_length) > - index_end || (u8 *)ie +le16_to_cpu (ie->length) > index_end) { -ntfs_error (sb,"Index entry out of bounds in directory inode 0x%llx." , - dir_ni->mft_no); - goto unm_err_out; - }/* * The last entry cannot contain a name. It can however contain * a pointer to a child node in the B+tree so we just break out.
@@ -382,10 +370,6 @@ fast_descend_into_child_node:/* Key length should not be zero if it is not last entry. */ if (!ie->key_length) goto unm_err_out; -/* Check the consistency of an index entry */ -if (ntfs_index_entry_inconsistent (NULL , vol, ie,COLLATION_FILE_NAME , - dir_ni->mft_no)) - goto unm_err_out;/* * We perform a case sensitive comparison and if that matches * we are done and return the mft reference of the inode (i.e.
@@ -868,6 +852,7 @@ static int ntfs_readdir(struct file *fil ictx->vcn_size_bits = vol->cluster_size_bits; else ictx->vcn_size_bits = NTFS_BLOCK_SIZE_BITS; + ictx->cr = ir->collation_rule;/* The first index entry. */ next = (struct index_entry *)((u8 *)&ir->index +
@@ -905,13 +890,6 @@ static int ntfs_readdir(struct file *filif (!next)break ; nextdir: -/* Check the consistency of an index entry */ -if (ntfs_index_entry_inconsistent (ictx, vol, next,COLLATION_FILE_NAME , - ndir->mft_no)) { - err = -EIO ; - goto out; - } -if (ie_pos < actor->pos) { ie_pos +=le16_to_cpu (next->length);continue ;
fs/ntfs/index.c +47 -39
118 lines not on this page · raw message
fs/ntfs/index.h +5 -3
@@ -94,9 +94,11 @@ int ntfs_index_root_inconsistent(struct const struct index_root *ir, u64 inum);int ntfs_index_block_inconsistent (struct ntfs_volume *vol,const struct index_block *ib, -u32 block_size,s64 vcn,u64 inum); -int ntfs_index_entry_inconsistent (struct ntfs_index_context *icx,struct ntfs_volume *vol, -const struct index_entry *ie,__le32 collation_rule,u64 inum); +u32 block_size,s64 vcn, +__le32 cr,u64 inum); +int ntfs_index_entries_inconsistent (const struct ntfs_volume *vol, +const struct index_header *ih, +__le32 collation_rule,u64 inum);struct ntfs_index_context *ntfs_index_ctx_get (struct ntfs_inode *ni,__le16 *name,u32 name_len);void ntfs_index_ctx_put (struct ntfs_index_context *ictx);
fs/ntfs/inode.c +6 -2
@@ -945,7 +945,9 @@ view_index_meta: } ir = (struct index_root *)((u8 *)a +le16_to_cpu (a->data.resident.value_offset)); -if (ntfs_index_root_inconsistent (ni->vol, a, ir, ni->mft_no)) { +if (ntfs_index_root_inconsistent (ni->vol, a, ir, ni->mft_no) || +ntfs_index_entries_inconsistent (ni->vol, &ir->index, + ir->collation_rule, ni->mft_no)) {ntfs_error (vi->i_sb,"Directory index is corrupt." ); goto unm_err_out; }
@@ -1538,7 +1540,9 @@ static int ntfs_read_locked_index_inode( } ir = (struct index_root *)((u8 *)a +le16_to_cpu (a->data.resident.value_offset)); -if (ntfs_index_root_inconsistent (vol, a, ir, ni->mft_no)) { +if (ntfs_index_root_inconsistent (vol, a, ir, ni->mft_no) || +ntfs_index_entries_inconsistent (vol, &ir->index, + ir->collation_rule, ni->mft_no)) {ntfs_error (vi->i_sb,"Index is corrupt." ); goto unm_err_out; }
Greg Kroah-Hartman
maintainerPATCH 1696/2077 ntfs: detect mapping-pairs LCN accumulator overflow
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Samuel Moelius <[email protected]>
commit ec4f061f2219e0f0c6465d56d0380bf749235a53 upstream.
The NTFS mapping-pairs parser accumulates relative LCN deltas in a signed integer. A corrupted attribute can drive that addition past the representable range.
One corrupt runlist shape sets the accumulated LCN to S64_MAX and then adds a delta of 1 in the next mapping-pairs entry.
Signed overflow is undefined and can turn an invalid runlist into a different set of physical clusters.
Check the LCN addition for overflow before storing the next run.
--- fs/ntfs/runlist.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/ntfs/runlist.c +5 -1
@@ -860,7 +860,11 @@ struct runlist_element *ntfs_mapping_pairs_decompress(const struct ntfs_volume *for (deltaxcn = (s8 )buf[b--]; b > b2; b--) deltaxcn = (deltaxcn <<8 ) + buf[b];/* Change the current lcn to its new value. */ - lcn += deltaxcn; +if (unlikely (check_add_overflow (lcn, deltaxcn, &lcn))) { +ntfs_error (vol->sb, +"LCN overflow in mapping pairs array." ); + goto err_out; + }#ifdef DEBUG /* * On NTFS 1.2-, apparently can have lcn == -1 to
Signature · 1 line
2.55.0
Greg Kroah-Hartman
maintainerPATCH 1697/2077 ntfs: do not replace volume name after lookup errors
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: DaeMyung Kang <[email protected]>
commit 40d88020d0797f96a93edd2e8edc413c2e2d8f84 upstream.
ntfs_write_volume_label() removes an existing $VOLUME_NAME attribute and then adds the replacement. The old code only distinguished lookup success from all other results, so any lookup error was treated like an absent label and the add path still ran.
That is unsafe once lookup-time validation rejects corrupt $VOLUME_NAME records with -EIO: the corrupt record would remain in place and a second $VOLUME_NAME record could be appended next to it.
Only add the replacement after the old label was removed successfully or after lookup returned -ENOENT. Propagate all other lookup errors, and also stop if removing the old attribute fails.
--- fs/ntfs/super.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
fs/ntfs/super.c +8 -3
@@ -452,10 +452,15 @@ int ntfs_write_volume_label(struct ntfs_ goto out; } -if (!ntfs_attr_lookup (AT_VOLUME_NAME ,NULL ,0 ,0 ,0 ,NULL ,0 , - ctx)) -ntfs_attr_record_rm (ctx); + ret =ntfs_attr_lookup (AT_VOLUME_NAME ,NULL ,0 ,0 ,0 ,NULL ,0 , + ctx); +if (!ret) + ret =ntfs_attr_record_rm (ctx); +else if (ret == -ENOENT ) + ret =0 ;ntfs_attr_put_search_ctx (ctx); +if (ret) + goto out; ret =ntfs_resident_attr_record_add (vol_ni,AT_VOLUME_NAME ,AT_UNNAMED ,0 , (u8 *)uname, uname_len *sizeof (__le16),0 );
Greg Kroah-Hartman
maintainerPATCH 1698/2077 ntfs: validate resident volume name values on lookup
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: DaeMyung Kang <[email protected]>
commit b3f6cd1d54aa279cc4f47aa27939ebe517a2c390 upstream.
The shared lookup-time attribute validator now has a safe caller path for $VOLUME_NAME corruption: ntfs_write_volume_label() no longer treats lookup errors as an absent label, and the mount path reinitializes its search context before continuing to $VOLUME_INFORMATION.
Add $VOLUME_NAME-specific resident value validation. A volume name is stored as a UTF-16LE string, so reject odd byte lengths, and reject values longer than the NTFS volume label limit. Empty labels remain valid.
Also reject non-resident $VOLUME_NAME records. $VOLUME_NAME is required to be resident, like $FILE_NAME; a crafted non-resident record would otherwise pass lookup and ntfs_write_volume_label() would remove it as if it were a normal resident attribute.
--- fs/ntfs/attrib.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
fs/ntfs/attrib.c +13 -1
@@ -607,6 +607,14 @@ static bool ntfs_file_name_attr_value_is value_length - offsetof(struct file_name_attr , file_name); } +static bool ntfs_volume_name_attr_value_is_valid (const u32 value_length) +{ +if (value_length &1 ) +return false; + +return value_length <=NTFS_MAX_LABEL_LEN *sizeof (__le16); +} +struct ntfs_resident_attr_value {const u8 *data;u32 len;
@@ -657,7 +665,7 @@ static bool ntfs_attr_value_is_valid(stru32 min_len;if (a->non_resident) { -if (a->type ==AT_FILE_NAME ) +if (a->type ==AT_FILE_NAME || a->type ==AT_VOLUME_NAME ) goto corrupt;if (!ntfs_non_resident_attr_value_is_valid (a)) goto corrupt;
@@ -676,6 +684,10 @@ static bool ntfs_attr_value_is_valid(strif (!ntfs_file_name_attr_value_is_valid (value.data, value.len)) goto corrupt;break ; +case AT_VOLUME_NAME : +if (!ntfs_volume_name_attr_value_is_valid (value.len)) + goto corrupt; +break ; }return true;
Greg Kroah-Hartman
maintainerPATCH 1699/2077 ntfs: validate resident index root values on lookup
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: DaeMyung Kang <[email protected]>
commit fcf5bf0e8570798970e3ae8c95d04765ba2c5b97 upstream.
Resident $INDEX_ROOT values carry index header fields that callers consume after lookup. Some callers already validate parts of the layout before walking entries, but those checks are scattered and do not cover all root header invariants, such as entries_offset alignment and lower bound, index_length, and allocated_size consistency.
The resident root resize paths now keep these header fields consistent while the value size changes: ntfs_ir_truncate() lowers index.allocated_size before shrinking the resident value, and ntfs_ir_reparent() grows the resident value before publishing a larger root header. Lookup-time validation can therefore cover these invariants without tripping over the driver's own resize paths.
Add $INDEX_ROOT to the minimum resident value size table and validate the resident index header fields before returning the attribute from lookup. Require 8-byte aligned index header fields, a sane entries_offset, an index_length within allocated_size, allocated_size within the resident value, and enough entry space for at least an index entry header.
The shared validator already rejects non-resident records for resident-only attribute types, including $INDEX_ROOT.
--- fs/ntfs/attrib.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
fs/ntfs/attrib.c +31 -0
@@ -588,6 +588,8 @@ static u32 ntfs_resident_attr_min_value_sizeof (__le16) *1 ;case AT_VOLUME_INFORMATION :return sizeof (struct volume_information ); +case AT_INDEX_ROOT : +return sizeof (struct index_root );case AT_EA_INFORMATION :return sizeof (struct ea_information );default :
@@ -615,6 +617,31 @@ static bool ntfs_volume_name_attr_value_return value_length <=NTFS_MAX_LABEL_LEN *sizeof (__le16); } +static bool ntfs_index_root_attr_value_is_valid (const u8 *value,const u32 value_length) +{ +const struct index_root *ir; +u32 index_size; +u32 entries_offset; +u32 index_length; +u32 allocated_size; + + ir = (const struct index_root *)value; + index_size = value_length - offsetof(struct index_root , index); + entries_offset =le32_to_cpu (ir->index.entries_offset); + index_length =le32_to_cpu (ir->index.index_length); + allocated_size =le32_to_cpu (ir->index.allocated_size); + +if ((entries_offset | index_length | allocated_size) &7 || + entries_offset <sizeof (struct index_header ) || + entries_offset > index_length || + index_length > allocated_size || + allocated_size > index_size || + index_length - entries_offset <sizeof (struct index_entry_header )) +return false; + +return true; +} +struct ntfs_resident_attr_value {const u8 *data;u32 len;
@@ -688,6 +715,10 @@ static bool ntfs_attr_value_is_valid(strif (!ntfs_volume_name_attr_value_is_valid (value.len)) goto corrupt;break ; +case AT_INDEX_ROOT : +if (!ntfs_index_root_attr_value_is_valid (value.data, value.len)) + goto corrupt; +break ; }return true;
Greg Kroah-Hartman
maintainerPATCH 1700/2077 ntfs: reject non-resident records for resident-only attributes
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: DaeMyung Kang <[email protected]>
commit 097cdfd0a55df5af82c9753833f39a8bfadbcfcb upstream.
The shared lookup-time attribute validator rejects non-resident $FILE_NAME and $VOLUME_NAME records because their formats require resident values and callers handle returned records as resident attributes. Other resident-only attribute types still pass through the generic non-resident mapping-pairs checks.
That leaves real resident/non-resident union confusion paths. Inode load looks up $STANDARD_INFORMATION and then reads data.resident.value_offset without checking a->non_resident. ntfs_inode_sync_standard_information() does the same when updating the standard information value. ntfs_write_volume_flags() also looks up $VOLUME_INFORMATION and reads data.resident.value_offset directly. $INDEX_ROOT callers in dir.c and index.c depend on the same lookup contract before consuming the resident index root value.
Reject non-resident records for all resident-only attribute types in the shared validator. Keep the existing $FILE_NAME and $VOLUME_NAME behavior, but factor it through a helper and extend it to $STANDARD_INFORMATION, $OBJECT_ID, $VOLUME_INFORMATION, $INDEX_ROOT, and $EA_INFORMATION. For $OBJECT_ID and $EA_INFORMATION this is contract hardening for resident-only formats; this patch only rejects the non-resident form and does not add new resident value validation for those types.
--- fs/ntfs/attrib.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
fs/ntfs/attrib.c +17 -1
@@ -597,6 +597,22 @@ static u32 ntfs_resident_attr_min_value_ } } +static bool ntfs_attr_type_is_resident_only (const __le32 type) +{ +switch (type) { +case AT_STANDARD_INFORMATION : +case AT_FILE_NAME : +case AT_OBJECT_ID : +case AT_VOLUME_NAME : +case AT_VOLUME_INFORMATION : +case AT_INDEX_ROOT : +case AT_EA_INFORMATION : +return true; +default : +return false; + } +} +static bool ntfs_file_name_attr_value_is_valid (const u8 *value,const u32 value_length) {const struct file_name_attr *fn;
@@ -692,7 +708,7 @@ static bool ntfs_attr_value_is_valid(stru32 min_len;if (a->non_resident) { -if (a->type ==AT_FILE_NAME || a->type ==AT_VOLUME_NAME ) +if (ntfs_attr_type_is_resident_only (a->type)) goto corrupt;if (!ntfs_non_resident_attr_value_is_valid (a)) goto corrupt;
Greg Kroah-Hartman
maintainerPATCH 1701/2077 fs/ntfs3: fix syncing wrong inode on DIRSYNC cross-directory rename
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhan Xusheng <[email protected]>
commit 932fa0c1496286e39e14e27194c1ee7c2181629f upstream.
In ntfs3_rename(), when IS_DIRSYNC(new_dir) is true, the code syncs the renamed file inode instead of the target directory new_dir:
if (IS_DIRSYNC(new_dir))
ntfs_sync_inode(inode); /* should be new_dir */
DIRSYNC requires that directory metadata changes are written to disk synchronously. Since new_dir was modified (a new directory entry was added), it is new_dir that must be synced to satisfy the guarantee, not the renamed file itself.
This bug has existed since the initial ntfs3 implementation and was carried through the refactoring in commit 78ab59fee07f ("fs/ntfs3: Rework file operations").
Fix by syncing new_dir instead of inode.
--- fs/ntfs3/namei.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ntfs3/namei.c +1 -1
@@ -340,7 +340,7 @@ static int ntfs_rename(struct mnt_idmapntfs_sync_inode (dir);if (IS_DIRSYNC (new_dir)) -ntfs_sync_inode (inode); +ntfs_sync_inode (new_dir); }if (dir_ni != new_dir_ni)
Greg Kroah-Hartman
maintainerPATCH 1702/2077 fs/ntfs3: bound DeleteIndexEntryAllocation memmove length
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Konstantin Komarov <[email protected]>
commit fc4626bb3656362de8b0ecd56605d47a19ec3518 upstream.
In do_action()'s DeleteIndexEntryAllocation case, e->size comes from an on-disk INDEX_BUFFER entry. When e->size makes e + e->size point past hdr + hdr->used,PtrOffset(e1, Add2Ptr(hdr, used)) returns a negative ptrdiff_t that is silently cast to a quasi-infinite size_t when passed to memmove(). The memmove then walks past the destination buffer.
The sibling DeleteIndexEntryRoot case at fslog.c:3540-3543 already carries the corresponding guard:
if (PtrOffset(e1, Add2Ptr(hdr, used)) < esize ||
Add2Ptr(e, esize) > Add2Ptr(lrh, rec_len) ||
used + esize > le32_to_cpu(hdr->total)) {
goto dirty_vol;
}Apply the same shape to the allocation-path case. Also reject esize == 0: memmove(e, e, ...) is a no-op and leaves hdr->used unchanged, hiding a malformed entry from the existing check_index_header() walk.
Reproduced under UML+KASAN on mainline 8d90b09e6741 by mounting a crafted NTFS image: the unguarded memmove takes a length of 0xffffffffffffff00 and the kernel oopses in memmove+0x81/0x1a0 on the do_action+0x36a2 frame.
--- fs/ntfs3/fslog.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
fs/ntfs3/fslog.c +15 -1
@@ -3573,9 +3573,23 @@ move_data: } e1 =Add2Ptr (e, esize); - nsize = esize; used =le32_to_cpu (hdr->used); +/* +* Reject crafted entries whose e->size makes e + esize +* point past the INDEX_HDR's used boundary. Without this, +* PtrOffset(e1, hdr + used) underflows to a quasi-infinite +* size_t when fed to the memmove() below. +* +* Also reject esize == 0: memmove(e, e, ...) is a no-op and +* leaves hdr->used unchanged, masking the crafted entry. +*/ +if (!esize ||Add2Ptr (e, esize) >Add2Ptr (hdr, used) || +PtrOffset (e1,Add2Ptr (hdr, used)) < esize) + goto dirty_vol; + + nsize = esize; +memmove (e, e1,PtrOffset (e1,Add2Ptr (hdr, used))); hdr->used =cpu_to_le32 (used - nsize);
Greg Kroah-Hartman
maintainerPATCH 1703/2077 fs/ntfs3: bound copy_lcns dp->page_lcns[] index in analysis pass
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 5e7b598660cfa8e5af172cf4c65cffc126333307 upstream.
In log_replay()'s analysis pass, after find_dp() returns a valid DIR_PAGE_ENTRY for the (target_attr, target_vcn) tuple, the copy_lcns block walks lrh->lcns_follow further entries:
t16 = le16_to_cpu(lrh->lcns_follow);
for (i = 0; i < t16; i++) {
size_t j = (size_t)(le64_to_cpu(lrh->target_vcn) -
le64_to_cpu(dp->vcn));
dp->page_lcns[j + i] = lrh->page_lcns[i];
}find_dp() only validates that target_vcn falls within [dp->vcn, dp->vcn + dp->lcns_follow), i.e., that the FIRST cluster is covered. The walk through the further entries is not bounded against dp->lcns_follow. For a malformed LRH where target_vcn = dp->vcn + dp->lcns_follow - 1 and lrh->lcns_follow > 1, the i > 0 writes overflow the dp's allocated page_lcns[] array.
Add the missing j + lrh->lcns_follow <= dp->lcns_follow guard.
Reproduced under UML+KASAN on mainline 8d90b09e6741 as a slab-out-of-bounds write of size 8 from log_replay+0x68d4 on the mount path.
This is distinct from Pavitra Jha's 2026-05-02 patch ("fs/ntfs3: validate lcns_follow in log_replay conversion", <[email protected]>) which addresses the separate version-0 dirty-page-table conversion path's memmove(&dp->vcn, ...) call. The two fixes are complementary; both should land.
[[email protected]: clang-formatted the changes, fixed conflicts]
--- fs/ntfs3/fslog.c | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-)
fs/ntfs3/fslog.c +29 -17
@@ -3369,8 +3369,8 @@ move_data:if (run_get_highest_vcn (le64_to_cpu (attr->nres.svcn),attr_run (attr), -le32_to_cpu (attr->size) - -le16_to_cpu (attr->nres.run_off), +le32_to_cpu (attr->size) - +le16_to_cpu (attr->nres.run_off), &t64)) { goto dirty_vol; }
@@ -4579,22 +4579,34 @@ copy_lcns:* whole routine a loop, case Lcns do not fit below. */ t16 =le16_to_cpu (lrh->lcns_follow); - t32 =le32_to_cpu (dp->lcns_follow); -if (le64_to_cpu (lrh->target_vcn) <le64_to_cpu (dp->vcn)) { - err = -EINVAL ; - goto out; - } - -for (i =0 ; i < t16; i++) { -size_t j = (size_t )(le64_to_cpu (lrh->target_vcn) - -le64_to_cpu (dp->vcn)); -if (j >= t32 || i >= t32 - j) { - err = -EINVAL ; - goto out; - } - dp->page_lcns[j + i] = lrh->page_lcns[i]; - } + t32 =le32_to_cpu (dp->lcns_follow); +if (le64_to_cpu (lrh->target_vcn) <le64_to_cpu (dp->vcn)) { + err = -EINVAL ; + goto out; + } + +/* +* find_dp() only validates that target_vcn is the first +* cluster covered by dp. The walk through lrh->lcns_follow +* further entries must stay within the allocated +* dp->page_lcns[] array, which is sized by dp->lcns_follow. +*/ +if (le64_to_cpu (lrh->target_vcn) -le64_to_cpu (dp->vcn) + t16 > +le32_to_cpu (dp->lcns_follow)) { + err = -EINVAL ; + log->set_dirty = true; + goto out; + } +for (i =0 ; i < t16; i++) { +size_t j = (size_t )(le64_to_cpu (lrh->target_vcn) - +le64_to_cpu (dp->vcn)); +if (j >= t32 || i >= t32 - j) { + err = -EINVAL ; + goto out; + } + dp->page_lcns[j + i] = lrh->page_lcns[i]; + } goto next_log_record_analyze;case DeleteDirtyClusters: {
Greg Kroah-Hartman
maintainerPATCH 1704/2077 fs/ntfs3: bound attr_off in UpdateResidentValue against data_off
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Konstantin Komarov <[email protected]>
commit d1570c48f49a693974d000251030370ee2e83539 upstream.
In do_action()'s UpdateResidentValue case (fslog.c:3307), lrh->attr_off and lrh->redo_len come from the on-disk LRH. When they satisfy aoff + dlen < attr->res.data_off, the assignment
attr->res.data_size = cpu_to_le32(aoff + dlen - data_off);
underflows to ~4 GiB (e.g. 0xFFFFFFF9 when aoff=0x10, dlen=1, data_off=0x18). Subsequent code that reads attr->res.data_size to walk the resident attribute payload would then read up to 4 GiB past the 1024-byte MFT record allocation.
The existing mi_enum_attr() defense in fs/ntfs3/record.c:287 catches the corrupted data_size on the next attribute walk and fails the mount, but only on the path that walks all attributes. A read site that picks an attribute by name and reads its data_size without re-validating is not covered. Validate aoff against data_off and asize at the source.
Reproduced under UML+KASAN on mainline 8d90b09e6741 via pr_warn-only probe: with aoff=0x10 and data_off=0x18, the post-assignment data_size is 0xfffffff9 (mount then fails at -22 from mi_enum_attr).
--- fs/ntfs3/fslog.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
fs/ntfs3/fslog.c +11 -0
@@ -3325,6 +3325,17 @@ skip_load_parent: nsize =ALIGN (nsize,8 ); data_off =le16_to_cpu (attr->res.data_off); +/* +* aoff comes from the on-disk lrh->attr_off. Forbid +* writes that begin below the resident attribute's +* data_off (which would overwrite the resident header), +* and forbid aoff + dlen < data_off, which would make +* the data_size assignment below underflow to ~4 GiB. +*/ +if (aoff < data_off || aoff + dlen < data_off || + aoff + dlen > asize) + goto dirty_vol; +if (nsize < asize) {memmove (Add2Ptr (attr, aoff), data, dlen); data =NULL ;// To skip below memmove().
Greg Kroah-Hartman
maintainerPATCH 1705/2077 fs/ntfs3: validate lcns_follow in log_replay conversion
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Konstantin Komarov <[email protected]>
commit 6a4c53a2e26a865565bd6a460961e8d6fcb32329 upstream.
log_replay() converts DIR_PAGE_ENTRY_32 records into DIR_PAGE_ENTRY records when replaying version 0 restart tables.
During this conversion, the memmove() length is derived directly from the on-disk lcns_follow field:
memmove(&dp->vcn, &dp0->vcn_low, 2 * sizeof(u64) + le32_to_cpu(dp->lcns_follow) * sizeof(u64));
check_rstbl() validates restart table structure, but does not constrain per-entry lcns_follow values relative to the entry size. A malformed filesystem image can provide an oversized lcns_follow value, causing the conversion memmove() to access memory beyond the bounds of the allocated restart table buffer.
The same field is later used to bound iteration over page_lcns[], so validating lcns_follow during conversion also prevents downstream out-of-bounds access from the same malformed metadata.
Compute the maximum valid lcns_follow from the already-validated restart table entry size and reject entries that exceed this bound. Reuse the existing t16/t32 scratch variables already declared in log_replay() to avoid introducing new declarations.
--- fs/ntfs3/fslog.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
fs/ntfs3/fslog.c +16 -3
@@ -4262,13 +4262,26 @@ check_dirty_page_table:if (rst->major_ver) goto end_conv_1;/* reduce tab pressure. */ + t16 =le16_to_cpu (dptbl->size); +if (t16 <sizeof (struct DIR_PAGE_ENTRY )) { + log->set_dirty = true; + goto out; + } + + t32 = (t16 -sizeof (struct DIR_PAGE_ENTRY )) /sizeof (u64); + dp =NULL ;while ((dp =enum_rstbl (dptbl, dp))) {struct DIR_PAGE_ENTRY_32 *dp0 = (struct DIR_PAGE_ENTRY_32 *)dp; -// NOTE: Danger. Check for of boundary. +u32 lcns =le32_to_cpu (dp->lcns_follow); + +if (lcns > t32) { + log->set_dirty = true; + goto out; + } +memmove (&dp->vcn, &dp0->vcn_low, -2 *sizeof (u64) + -le32_to_cpu (dp->lcns_follow) *sizeof (u64)); +2 *sizeof (u64) + lcns *sizeof (u64)); } end_conv_1:
Greg Kroah-Hartman
maintainerPATCH 1706/2077 fs/ntfs3: add depth limit to indx_find_buffer to prevent stack overflow
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 1ebd684b8f627f75bc3e03f8b2ad8400fd1f02cd upstream.
indx_find_buffer() recursively descends the B+ tree index with no depth limit. A crafted NTFS image with circular index node references causes unbounded recursion, overflowing the kernel stack and panicking the system.
This is reachable by mounting a malicious NTFS filesystem (e.g. from a USB drive via desktop automount) and deleting a file whose index entry triggers the rebalancing fallback path in indx_delete_entry().
Add a depth parameter and bail out with -EINVAL when it reaches the fnd->nodes array bound, matching the constraint already enforced by fnd_push() in indx_find().
The related function indx_find() was previously patched for a similar infinite-loop issue (commit 1732053c8a6b), but indx_find_buffer() was missed.
--- fs/ntfs3/index.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
fs/ntfs3/index.c +12 -3
@@ -2022,13 +2022,21 @@ out1:static struct indx_node *indx_find_buffer (struct ntfs_index *indx,struct ntfs_inode *ni,const struct INDEX_ROOT *root, -__le64 vbn,struct indx_node *n) +__le64 vbn,struct indx_node *n, +int depth) {int err;const struct NTFS_DE *e;struct indx_node *r;const struct INDEX_HDR *hdr = n ? &n->index->ihdr : &root->ihdr; +/* +* Limit recursion depth to prevent stack overflow from crafted +* images. Use the same bound as the fnd->nodes array (20). +*/ +if (depth >ARRAY_SIZE (((struct ntfs_fnd *)NULL )->nodes)) +return ERR_PTR (-EINVAL ); +/* Step 1: Scan one level. */ for (e =hdr_first_de (hdr);; e =hdr_next_de (hdr, e)) {if (!e)
@@ -2049,7 +2057,8 @@ static struct indx_node *indx_find_buffeif (err)return ERR_PTR (err); - r =indx_find_buffer (indx, ni, root, vbn, n); + r =indx_find_buffer (indx, ni, root, vbn, n, + depth +1 );if (r)return r; }
@@ -2462,7 +2471,7 @@ int indx_delete_entry(struct ntfs_indexfnd_clear (fnd); - in =indx_find_buffer (indx, ni, root, sub_vbn,NULL ); + in =indx_find_buffer (indx, ni, root, sub_vbn,NULL ,0 );if (IS_ERR (in)) { err =PTR_ERR (in); goto out;
Greg Kroah-Hartman
maintainerPATCH 1707/2077 fs/ntfs3: bound NTFS_DE view.data_off in UpdateRecordData{Root,Allocation}
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 3e127829e57f5190f612412ece4541cb96d5ec7a upstream.
In do_action()'s UpdateRecordDataRoot (fslog.c:3489) and UpdateRecordDataAllocation (fslog.c:3697) cases, the memmove destination is Add2Ptr(e, le16_to_cpu(e->view.data_off)), where e->view.data_off comes from an on-disk NTFS_DE inside an INDEX_ROOT or INDEX_BUFFER. Neither case validates view.data_off + dlen against e->size; the existing check_if_index_root / check_if_alloc_index helpers walk the entry chain and validate the entry's offset, but not its internal view fields.
The neighbouring read sites (e.g., fs/ntfs3/index.c when iterating view entries) check view.data_off + view.data_size <= e->size. Apply the same bound at the two memmove sites.
Reproduced under UML+KASAN on mainline 8d90b09e6741 via pr_warn-only probe instrumentation: with view.data_off forced to 0xFFFC, the memmove writes 32 bytes past the end of the NTFS_DE.
This is similar in shape to Pavitra Jha's 2026-05-02 patch "fs/ntfs3: prevent oob in case UpdateRecordDataRoot" (<[email protected]>) which proposes calling ntfs3_bad_de_range(); that helper does not exist in mainline. This patch uses inline checks.
--- fs/ntfs3/fslog.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
fs/ntfs3/fslog.c +18 -0
@@ -3511,6 +3511,18 @@ move_data: e =Add2Ptr (attr,le16_to_cpu (lrh->attr_off)); +/* +* e->view.data_off and dlen come from the on-disk +* INDEX_ROOT entry / LRH. The neighbouring read sites +* (e.g. fs/ntfs3/index.c) check that +* view.data_off + view.data_size <= e->size; mirror that +* bound here so the memmove cannot reach past the entry. +*/ +if (le16_to_cpu (e->view.data_off) >le16_to_cpu (e->size) || +le16_to_cpu (e->view.data_off) + dlen > +le16_to_cpu (e->size)) + goto dirty_vol; +memmove (Add2Ptr (e,le16_to_cpu (e->view.data_off)), data, dlen); mi->dirty = true;
@@ -3717,6 +3729,12 @@ move_data: goto dirty_vol; } +/* See UpdateRecordDataRoot for the rationale. */ +if (le16_to_cpu (e->view.data_off) >le16_to_cpu (e->size) || +le16_to_cpu (e->view.data_off) + dlen > +le16_to_cpu (e->size)) + goto dirty_vol; +memmove (Add2Ptr (e,le16_to_cpu (e->view.data_off)), data, dlen); a_dirty = true;
Greg Kroah-Hartman
maintainerPATCH 1708/2077 ntfs3: cap RESTART_TABLE free-chain walker at rt->used
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 9611f644302c07d21bc8af97e3e06a3d30064253 upstream.
A crafted NTFS3 disk image triggers an in-kernel infinite loop at mount time, hanging the mounting thread and firing the soft-lockup watchdog within ~22s on multi-CPU hosts (panic with kernel.softlockup_panic=1). The bug is reachable from desktop USB auto-mount on distributions where udisks2 routes the NTFS signature to the in-tree ntfs3 driver (Arch family and an increasing fraction of Fedora / openSUSE / RHEL deployments); CAP_SYS_ADMIN-class manual mount elsewhere.
check_rstbl()'s second walker iterates the free-entry singly-linked list headed by rt->first_free with no upper bound on iteration count:
for (off = ff; off;) {
if (off == RESTART_ENTRY_ALLOCATED)
return false;
off = le32_to_cpu(*(__le32 *)Add2Ptr(rt, off));
if (off > ts - sizeof(__le32))
return false;
}The existing guards cover three exits: end-of-list (off == 0), the in-use marker (off == RESTART_ENTRY_ALLOCATED), and out-of-bounds (off > ts - sizeof(__le32)). None of the three prevents an in-bounds cycle.
A crafted on-disk RESTART_TABLE whose free chain contains a self-loop or A->B->A cycle whose offsets satisfy:
- in range [sizeof(struct RESTART_TABLE), ts - sizeof(__le32)]
- (off - sizeof(struct RESTART_TABLE)) % rsize == 0
passes all existing guards and spins the mount-time thread forever. Reproduced in UML by hand-forging a 2 MB NTFS3 image whose journal RESTART_TABLE first_free = 0x18 and whose entry at offset 0x18 stores 0x18 as its next pointer; mount of the forged image with the in-tree ntfs3 driver never returns.
Bound the walker by rt->used. Each entry on a legitimate free chain is unique, and the total slot count is ne = le16_to_cpu (rt->used). A traversal that visits more than ne slots is by construction malformed; reject it as a corrupt RESTART_TABLE.
After this patch, mount of the forged image returns with -EINVAL and a log_replay failure message, and mkntfs-produced legitimate images mount cleanly (verified in the same UML harness).
--- fs/ntfs3/fslog.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
fs/ntfs3/fslog.c +12 -1
@@ -764,8 +764,19 @@ static bool check_rstbl(const struct RES/* * Walk through the list headed by the first entry to make * sure none of the entries are currently being used. +* +* Bound traversal by ne (rt->used) to defeat a crafted on-disk +* cycle in the free chain. Each entry in a legitimate free +* list is unique, so a chain that visits more than ne slots +* is malformed. Without this guard, an attacker-controlled +* RESTART_TABLE with a self-loop or A->B->A cycle whose +* offsets satisfy the existing alignment + in-bounds guards +* spins forever at mount time. */ -for (off = ff; off;) { +for (off = ff, i =0 ; off; i++) { +if (i > ne) +return false; +if (off ==RESTART_ENTRY_ALLOCATED )return false;
Greg Kroah-Hartman
maintainerPATCH 1709/2077 ntfs3: bound to_move in indx_insert_into_root before hdr_insert_head
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 9b6926ac9c970ae0b2c2fe6289b16e9aa10b6a67 upstream.
indx_insert_into_root() promotes a full resident $INDEX_ROOT into $INDEX_ALLOCATION and copies all non-last resident root entries into a newly allocated INDEX_BUFFER via hdr_insert_head(). The source byte count 'to_move' is summed from the on-disk resident entry sizes and is independent of the destination buffer size, which comes from root->index_block_size (via indx->index_bits).
A crafted NTFS image that keeps a valid, full resident root but shrinks root->index_block_size down to 512 after the root has been populated makes hdr_insert_head() memcpy attacker-controlled resident entry bytes past the end of the kmalloc(1u << indx->index_bits) allocation returned by indx_new(). For a 512-byte destination and a resident root whose non-last entries total 560 bytes, the memcpy overruns by 120 bytes and a following memmove extends the highest written offset to 136 bytes past the allocation. The overflow bytes are a direct copy of on-disk entries (via kmemdup), so they are fully attacker-controlled.
The write is reachable from unprivileged open(O_CREAT) on a mounted crafted NTFS image: a single sufficiently long create in a directory whose resident root is already full forces root promotion and triggers the copy.
This is a controlled out-of-bounds write of 120-136 bytes past a kmalloc(index_block_size) allocation, with attacker-controlled content. It is a bounded adjacent-heap corruption primitive; it is not an arbitrary-address write. Successful exploitation into a named victim object depends on the surrounding slab layout.
Reject the copy at the sink. The destination's INDEX_HDR already reports hdr_total (the payload capacity of the new buffer) and hdr_used (the bytes already consumed by the terminal END entry installed by indx_new()); require that to_move fits in the remaining payload before calling hdr_insert_head(). On mismatch, fail with -EINVAL and mark the filesystem as having a detected on-disk inconsistency, which is the same behaviour as the surrounding validation in this function.
--- fs/ntfs3/index.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
fs/ntfs3/index.c +16 -0
@@ -1742,6 +1742,22 @@ static int indx_insert_into_root(struct hdr_used =le32_to_cpu (hdr->used); hdr_total =le32_to_cpu (hdr->total); +/* +* The destination INDEX_BUFFER has 'hdr_total' bytes of payload +* available after the header, of which 'hdr_used' are already +* consumed by the single terminal END entry installed by +* indx_new(). A crafted image can present a resident root whose +* non-last entries (summing to 'to_move') exceed what fits in +* this buffer; copying them unchecked would overrun the +* kmalloc(1u << indx->index_bits) allocation backing the new +* buffer. Reject the copy in that case. +*/ +if (to_move > hdr_total - hdr_used) { + err = -EINVAL ; +ntfs_set_state (sbi,NTFS_DIRTY_ERROR ); + goto out_put_n; + } +/* Copy root entries into new buffer. */ hdr_insert_head (hdr, re, to_move);
Greg Kroah-Hartman
maintainerPATCH 1710/2077 ntfs3: validate split-point offset in indx_insert_into_buffer
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit f1df9d771df47aa40de6d70949c28720ae1e430d upstream.
indx_insert_into_buffer() computes
used = used1 - to_copy - sp_size;
memmove(de_t, Add2Ptr(sp, sp_size), used - le32_to_cpu(hdr1->de_off));where sp and sp_size come from hdr_find_split(). hdr_find_split() walks entries by le16_to_cpu(e->size) without validating that each step stays within hdr->used or that the size field is at least sizeof(struct NTFS_DE). index_hdr_check(), the on-load gatekeeper, only validates header-level fields (used, total, de_off) and does not walk per-entry sizes.
A crafted NTFS image whose leaf INDEX_HDR reports used == total but contains one interior NTFS_DE with size = 0xFFF0 therefore passes validation, descends to indx_insert_into_buffer() through the ntfs_create() -> indx_insert_entry() path, and makes hdr_find_split() return an sp whose sp_size (0xFFF0) greatly exceeds the remaining bytes in the buffer. The u32 subtraction underflows and the memmove count becomes a near-4-GiB value, producing an out-of-bounds kernel write that corrupts adjacent allocations and panics the kernel.
Reproduced on 7.0.0-rc7 with UML + KASAN via a crafted image and a single 'touch' inside the mounted directory; crash site resolves to fs/ntfs3/index.c at the memmove. Trigger requires only local mount of an attacker-supplied filesystem image (USB, loopback, or removable media auto-mount).
Reject the split whenever the chosen sp plus its declared size already extends past hdr1->used. This is the minimal fix; it preserves the existing hdr_find_split() contract and relies on the same out: cleanup path as the pre-existing error returns.
A prior OOB read in the very same indx_insert_into_buffer() memmove was fixed in commit b8c44949044e ("fs/ntfs3: Fix OOB read in indx_insert_into_buffer") by tightening hdr_find_e(), but that fix does not cover the split-point size field path addressed here: sp is returned by hdr_find_split(), not hdr_find_e(), and the underflow is driven by sp->size rather than hdr->used exceeding hdr->total.
--- fs/ntfs3/index.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
fs/ntfs3/index.c +14 -0
@@ -1862,6 +1862,20 @@ indx_insert_into_buffer(struct ntfs_indememcpy (up_e, sp, sp_size); used1 =le32_to_cpu (hdr1->used); + +/* +* hdr_find_split does not validate per-entry sizes, so a crafted +* NTFS_DE whose le16 size field is out of range can place sp such +* that (PtrOffset(hdr1, sp) + sp_size) exceeds used1. Without this +* guard the u32 'used = used1 - to_copy - sp_size' underflows and +* the subsequent memmove count becomes a near-4-GiB value, +* triggering an out-of-bounds kernel write. +*/ +if (PtrOffset (hdr1, sp) + sp_size > used1) { + err = -EINVAL ; + goto out; + } + hdr1_saved =kmemdup (hdr1, used1,GFP_NOFS );if (!hdr1_saved) { err = -ENOMEM ;
Greg Kroah-Hartman
maintainerPATCH 1711/2077 ntfs3: fix out-of-bounds read in decompress_lznt
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tristan Madani <[email protected]>
commit 7160a57192fb16d7a6fa9b7f5c7ac341d2444a89 upstream.
decompress_lznt() does not validate array index bounds before accessing the decompression table. A corrupted NTFS3 image with invalid compressed data can trigger an out-of-bounds read.
Add index bounds checking to prevent the OOB access.
--- fs/ntfs3/lznt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ntfs3/lznt.c +1 -1
@@ -240,7 +240,7 @@ static inline ssize_t decompress_chunk(uif (up - unc >LZNT_CHUNK_SIZE )return -EINVAL ;/* Correct index */ -while (unc + s_max_off[index] < up) +while (index <ARRAY_SIZE (s_max_off) -1 && unc + s_max_off[index] < up) index +=1 ;/* Check the current flag for zero. */
Greg Kroah-Hartman
maintainerPATCH 1712/2077 ntfs: fix mrec_lock ABBA deadlock in rename
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peiyang He <[email protected]>
commit eb94f5a41a193a425e09a63cb75dffd151d8f42e upstream.
ntfs_file_fsync(), ntfs_dir_fsync() and __ntfs_write_inode() lock an inode's mrec_lock before taking the mrec_lock of its parent directory.
ntfs_rename() takes old_ni->mrec_lock and old_dir_ni->mrec_lock before taking new_ni->mrec_lock for an existing target, or new_dir_ni->mrec_lock for a cross-directory rename.
This can deadlock when ntfs_file_fsync() or __ntfs_write_inode() holds the target inode, or when ntfs_dir_fsync() holds a child target directory, while rename() holds the parent directory and waits for the target.
Fix this by locking the existing target inode before taking any parent directory mrec_lock. For cross-directory renames where the target parent is a descendant of the source parent, lock the target parent before the source parent so the directory order matches the child-to-parent order used by ntfs_file_fsync(), ntfs_dir_fsync(), and __ntfs_write_inode().
--- fs/ntfs/namei.c | 62 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 31 deletions(-)
fs/ntfs/namei.c +31 -31
@@ -1264,6 +1264,7 @@ static int ntfs_rename(struct mnt_idmapstruct ntfs_volume *vol =NTFS_SB (sb);struct ntfs_inode *old_ni, *new_ni =NULL ;struct ntfs_inode *old_dir_ni =NTFS_I (old_dir), *new_dir_ni =NTFS_I (new_dir); +bool new_dir_first = false;if (NVolShutdown (old_dir_ni->vol))return -EIO ;
@@ -1299,36 +1300,39 @@ static int ntfs_rename(struct mnt_idmap old_inode = old_dentry->d_inode; new_inode = new_dentry->d_inode; old_ni =NTFS_I (old_inode); +if (new_inode) + new_ni =NTFS_I (new_inode); +if (old_dir != new_dir) + new_dir_first =is_subdir (new_dentry->d_parent, + old_dentry->d_parent);if (!(vol->vol_flags &VOLUME_IS_DIRTY ))ntfs_set_volume_flags (vol,VOLUME_IS_DIRTY );mutex_lock_nested (&old_ni->mrec_lock,NTFS_INODE_MUTEX_NORMAL ); -mutex_lock_nested (&old_dir_ni->mrec_lock,NTFS_INODE_MUTEX_PARENT ); +if (new_ni) +mutex_lock_nested (&new_ni->mrec_lock,NTFS_INODE_MUTEX_NORMAL_2 ); + +if (old_dir == new_dir) { +mutex_lock_nested (&old_dir_ni->mrec_lock,NTFS_INODE_MUTEX_PARENT ); + }else if (new_dir_first) { +mutex_lock_nested (&new_dir_ni->mrec_lock,NTFS_INODE_MUTEX_PARENT ); +mutex_lock_nested (&old_dir_ni->mrec_lock,NTFS_INODE_MUTEX_PARENT_2 ); + }else { +mutex_lock_nested (&old_dir_ni->mrec_lock,NTFS_INODE_MUTEX_PARENT ); +mutex_lock_nested (&new_dir_ni->mrec_lock,NTFS_INODE_MUTEX_PARENT_2 ); + } -if (NInoBeingDeleted (old_ni) ||NInoBeingDeleted (old_dir_ni)) { +if (NInoBeingDeleted (old_ni) ||NInoBeingDeleted (old_dir_ni) || + (new_ni &&NInoBeingDeleted (new_ni)) || + (old_dir != new_dir &&NInoBeingDeleted (new_dir_ni))) { err = -ENOENT ; - goto unlock_old; + goto err_out; } is_dir =S_ISDIR (old_inode->i_mode);if (new_inode) { - new_ni =NTFS_I (new_inode); -mutex_lock_nested (&new_ni->mrec_lock,NTFS_INODE_MUTEX_NORMAL_2 ); -if (old_dir != new_dir) { -mutex_lock_nested (&new_dir_ni->mrec_lock,NTFS_INODE_MUTEX_PARENT_2 ); -if (NInoBeingDeleted (new_dir_ni)) { - err = -ENOENT ; - goto err_out; - } - } - -if (NInoBeingDeleted (new_ni)) { - err = -ENOENT ; - goto err_out; - } -if (is_dir) {struct mft_record *ni_mrec;
@@ -1346,14 +1350,6 @@ static int ntfs_rename(struct mnt_idmap err =ntfs_delete (new_ni, new_dir_ni, uname_new, new_name_len, false);if (err) goto err_out; - }else { -if (old_dir != new_dir) { -mutex_lock_nested (&new_dir_ni->mrec_lock,NTFS_INODE_MUTEX_PARENT_2 ); -if (NInoBeingDeleted (new_dir_ni)) { - err = -ENOENT ; - goto err_out; - } - } } err =__ntfs_link (old_ni, new_dir_ni, uname_new, new_name_len);
@@ -1384,13 +1380,17 @@ static int ntfs_rename(struct mnt_idmapinode_inc_iversion (new_dir); err_out: -if (old_dir != new_dir) +if (old_dir == new_dir) { +mutex_unlock (&old_dir_ni->mrec_lock); + }else if (new_dir_first) { +mutex_unlock (&old_dir_ni->mrec_lock);mutex_unlock (&new_dir_ni->mrec_lock); -if (new_inode) + }else { +mutex_unlock (&new_dir_ni->mrec_lock); +mutex_unlock (&old_dir_ni->mrec_lock); + } +if (new_ni)mutex_unlock (&new_ni->mrec_lock); - -unlock_old: -mutex_unlock (&old_dir_ni->mrec_lock);mutex_unlock (&old_ni->mrec_lock);if (uname_new)kmem_cache_free (ntfs_name_cache, uname_new);
Greg Kroah-Hartman
maintainerPATCH 1713/2077 ntfs: fail attrlist updates when the superblock is inactive
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peiyang He <[email protected]>
commit 0ebe8f625ab0520217a425d7cd366e4670484941 upstream.
generic_shutdown_super() clears SB_ACTIVE before evicting cached inodes. If eviction selects the fake inode for a base inode's unnamed $ATTRIBUTE_LIST attribute, ntfs_evict_big_inode() drops the fake inode's reference on the base inode while the fake inode is still hashed and marked I_FREEING.
That iput can synchronously write back the base inode. The writeback path may update mapping pairs and call ntfs_attrlist_update(), which unconditionally calls ntfs_attr_iget() for the same $ATTRIBUTE_LIST fake inode. VFS then finds the I_FREEING inode and waits for eviction to finish, but the current task is still inside that eviction path, causing a self-deadlock in find_inode().
Fix this by mirroring the teardown guard used by __ntfs_write_inode():
once SB_ACTIVE has been cleared, do not try to iget the attribute-list fake inode. Return -EIO so teardown aborts the update instead of waiting on the inode it is evicting.
--- fs/ntfs/attrlist.c | 9 +++++++++ 1 file changed, 9 insertions(+)
fs/ntfs/attrlist.c +9 -0
@@ -57,6 +57,15 @@ int ntfs_attrlist_update(struct ntfs_inostruct ntfs_inode *attr_ni;int err; +/* +* generic_shutdown_super() clears SB_ACTIVE before evicting cached +* inodes. Do not look up the attribute-list inode after SB_ACTIVE has +* been cleared; it may already be I_FREEING, and waiting on it can +* self-deadlock. +*/ +if (!(VFS_I (base_ni)->i_sb->s_flags &SB_ACTIVE )) +return -EIO ; + attr_vi =ntfs_attr_iget (VFS_I (base_ni),AT_ATTRIBUTE_LIST ,AT_UNNAMED ,0 );if (IS_ERR (attr_vi)) { err =PTR_ERR (attr_vi);
Greg Kroah-Hartman
maintainerPATCH 1714/2077 ntfs: sanitize MFT references returned from ntfs_lookup_inode_by_name()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
commit d97a36bae86a9a4021562ded2987f904e6bcb1d7 upstream.
ntfs_lookup_inode_by_name() returns MFT references read from directory index entries on disk. These values are untrusted, but the function can currently return an error-marked MFT reference to its callers without validating it.
Callers later decode lookup failures with MREF_ERR(). A crafted NTFS image can set the MREF error bit while leaving the low bits as an arbitrary value, causing callers to consume a bogus pseudo-errno instead of treating the lookup result as corrupted on-disk metadata.
Fix this at the source by normalizing every error-marked MFT reference returned from ntfs_lookup_inode_by_name() to ERR_MREF(-EIO). Apply this to all four directory lookup return paths so every caller gets a validated result without needing additional checks or an API change.
This keeps the sanitization in the common lookup helper, which is cleaner than duplicating validation in each caller.
--- fs/ntfs/dir.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
fs/ntfs/dir.c +11 -4
@@ -23,6 +23,13 @@__le16 I30 [5 ] = {cpu_to_le16 ('$' ),cpu_to_le16 ('I' ),cpu_to_le16 ('3' ),cpu_to_le16 ('0' ),0 }; +static inline u64 ntfs_check_mref (u64 mref) +{ +if (IS_ERR_MREF (mref)) +return ERR_MREF (-EIO ); +return mref; +} +/* * ntfs_lookup_inode_by_name - find an inode in a directory given its name * @dir_ni: ntfs inode of the directory in which to search for the name
@@ -178,7 +185,7 @@ u64 ntfs_lookup_inode_by_name(struct ntfs_inode *dir_ni, const __le16 *uname, mref =le64_to_cpu (ie->data.dir.indexed_file);ntfs_attr_put_search_ctx (ctx);unmap_mft_record (dir_ni); -return mref; +return ntfs_check_mref (mref); }/* * For a case insensitive mount, we also perform a case
@@ -273,7 +280,7 @@ u64 ntfs_lookup_inode_by_name(struct ntfs_inode *dir_ni, const __le16 *uname,if (name) {ntfs_attr_put_search_ctx (ctx);unmap_mft_record (dir_ni); -return name->mref; +return ntfs_check_mref (name->mref); }ntfs_debug ("Entry not found." ); err = -ENOENT ;
@@ -413,7 +420,7 @@ u64 ntfs_lookup_inode_by_name(struct ntfs_inode *dir_ni, const __le16 *uname, mref =le64_to_cpu (ie->data.dir.indexed_file);kfree (kaddr);iput (ia_vi); -return mref; +return ntfs_check_mref (mref); }/* * For a case insensitive mount, we also perform a case
@@ -538,7 +545,7 @@ u64 ntfs_lookup_inode_by_name(struct ntfs_inode *dir_ni, const __le16 *uname,if (name) {kfree (kaddr);iput (ia_vi); -return name->mref; +return ntfs_check_mref (name->mref); }ntfs_debug ("Entry not found." ); err = -ENOENT ;
Signature · 1 line
2.55.0
Greg Kroah-Hartman
maintainerPATCH 1715/2077 ntfs: avoid self-deadlock during inode eviction
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hyunchul Lee <[email protected]>
commit 77dc384207d5fa63ba97c3bf3285fe1215a1cbf6 upstream.
An attribute-list update performed while allocating clusters can drop the last reference to the temporary attribute inode. Evicting that inode drops its reference to the base inode and can invoke ntfs_drop_big_inode() for the base inode from within the base inode's own writeback path.
If the base inode is unlinked, ntfs_drop_big_inode() calls truncate_setsize(), which waits for the inode's folio writeback to complete. The same writeback worker is responsible for completing that writeback, so it waits for itself indefinitely.
Prevent this self-deadlock by grabbing a reference to the base inode at the beginning of ntfs_writepages() and releasing it at the end of the function. This defers eviction until all bios have been submitted, allowing the wait for folio writeback to complete safely.
--- fs/ntfs/aops.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
fs/ntfs/aops.c +16 -1
@@ -251,6 +251,8 @@ static int ntfs_writepages(struct address_space *mapping, .wbc = wbc, .ops = &ntfs_writeback_ops, }; +bool need_iput = false; +int ret;if (NVolShutdown (ni->vol))return -EIO ;
@@ -267,7 +269,20 @@ static int ntfs_writepages(struct address_space *mapping,return -EOPNOTSUPP ; } -return iomap_writepages (&wpc); +/* +* Prevent eviction in writeback to avoid deadlock in +* ntfs_drop_big_inode(). +*/ +if ((ni->type ==AT_DATA || ni->type ==AT_INDEX_ALLOCATION ) && +igrab (inode)) + need_iput = true; + + ret =iomap_writepages (&wpc); + +if (need_iput) +iput (inode); + +return ret; } static int ntfs_swap_activate(struct swap_info_struct *sis,
Signature · 1 line
2.55.0
Greg Kroah-Hartman
maintainerPATCH 1716/2077 ntfs: make system files immutable to prevent corruption
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
commit f72df3a4c33b64de3418ec74d1ad4f028e09d161 upstream.
When a system file such as $Bitmap is exposed via show_sys_files and written from userspace, the volume is corrupted and, because the cluster allocator scans $Bitmap through the same inode's page cache, a write to $Bitmap also deadlocks writeback against the folio it already holds locked.
These files are maintained by the driver itself and have no valid reason to be written through the file interface. Mark base metadata files (mft_no < FILE_first_user) as immutable during inode read so the VFS rejects write, mmap, truncate and unlink with -EPERM. Directories are skipped so the root and $Extend remain usable. Internal metadata updates do not go through the VFS write path and are unaffected.
--- fs/ntfs/inode.c | 9 +++++++++ 1 file changed, 9 insertions(+)
fs/ntfs/inode.c +9 -0
@@ -1184,6 +1184,15 @@ no_data_attr_special_case: vi->i_flags |=S_IMMUTABLE ;/* +* System files such as $Bitmap and $MFT are maintained by the driver +* itself, and writing them from userspace corrupts the volume. +* Always make them immutable regardless of the sys_immutable option. +* Directories are skipped so the root and $Extend stay usable. +*/ +if (ni->mft_no < FILE_first_user &&S_ISREG (vi->i_mode)) + vi->i_flags |=S_IMMUTABLE ; + +/* * The number of 512-byte blocks used on disk (for stat). This is in so * far inaccurate as it doesn't account for any named streams or other * special non-resident attributes, but that is how Windows works, too,
Greg Kroah-Hartman
maintainerPATCH 1717/2077 ntfs: fix WARN_ON for resident attribute in ntfs_map_runlist_nolock()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
commit b8d6c528e9d57d263fee1a648409f84a68b2561d upstream.
When ntfs_map_runlist_nolock() needs to look up the attribute extent containing a target VCN (ctx_needs_reset == true), it calls ntfs_attr_lookup() and then expects the result to be a non-resident attribute, since only non-resident attributes have a mapping pairs array to decompress.
A crafted NTFS image can place a resident attribute where a non-resident one is expected, causing ntfs_attr_lookup() to succeed but return a resident attribute record. Previously this was caught only by a WARN_ON(), which does not stop execution. The code then falls through to read a->data.non_resident.highest_vcn from what is actually a resident attribute, accessing the wrong union member and corrupting the VCN range check.
The caller path triggering this warning during mount is:
ntfs_map_runlist_nolock
ntfs_empty_logfile
load_system_files
ntfs_fill_super
In this path ctx is NULL, so ntfs_map_runlist_nolock() allocates a temporary search context internally and sets ctx_needs_reset = true. The existing resident-attribute guard in the ctx != NULL branch already returns -EIO silently for the same condition; make the ctx_needs_reset path consistent by replacing the WARN_ON() with the same -EIO error return.
This causes the crafted image to be rejected with a mount error instead of triggering a kernel warning.
--- fs/ntfs/attrib.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/ntfs/attrib.c +4 -1
@@ -174,7 +174,10 @@ int ntfs_map_runlist_nolock(struct ntfs_ err = -EIO ; goto err_out; } -WARN_ON (!ctx->attr->non_resident); +if (unlikely (!ctx->attr->non_resident)) { + err = -EIO ; + goto err_out; + } } a = ctx->attr;/*
Greg Kroah-Hartman
maintainerPATCH 1718/2077 ntfs: fix hole runlist memory leak in insert range error path
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peiyang He <[email protected]>
commit 06769b8f23b4b645b270c438649fff79768fb6fe upstream.
ntfs_non_resident_attr_insert_range() allocates hole_rl before mapping the whole runlist. If ntfs_attr_map_whole_runlist() fails, the error path drops ni->runlist.lock and returns without freeing hole_rl. This leaks memory of sizeof(*hole_rl) * 2 bytes.
Fix this memory leak by freeing hole_rl before returning from that error path, matching the later error paths in the same function.
--- fs/ntfs/attrib.c | 1 + 1 file changed, 1 insertion(+)
fs/ntfs/attrib.c +1 -0
@@ -5327,6 +5327,7 @@ int ntfs_non_resident_attr_insert_range( ret =ntfs_attr_map_whole_runlist (ni);if (ret) {up_write (&ni->runlist.lock); +kfree (hole_rl);return ret; }
Greg Kroah-Hartman
maintainerPATCH 1719/2077 landlock: Fix LANDLOCK_SCOPE_SIGNAL bypass on the SIGIO path
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
commit 4b80320ca7ed03d6e683f95b6066565dc97b9f92 upstream.
LANDLOCK_SCOPE_SIGNAL must prevent a sandboxed process from signaling processes outside its Landlock domain. It can be bypassed through the asynchronous SIGIO delivery path.
A sandboxed process that owns any file or socket can arm it with fcntl(fd, F_SETOWN, -pgid), fcntl(fd, F_SETSIG, SIGKILL) and O_ASYNC, so that an I/O event makes the kernel deliver the chosen signal to the whole process group. As the head of its process group's task list (the default position right after fork()) that group can also hold the non-sandboxed process that launched it, e.g. a supervisor or a security monitor. The sandbox can thus kill or signal the processes LANDLOCK_SCOPE_SIGNAL is meant to protect from it.
The scope is enforced in hook_file_send_sigiotask() against the Landlock domain recorded at F_SETOWN time, not the live domain of the sender. control_current_fowner() decides whether to record that domain and skips recording it when the fowner target is in the caller's thread group, which is safe only for a single-task target (PIDTYPE_PID, PIDTYPE_TGID). For a process group (PIDTYPE_PGID) pid_task() returns only one member; recording is skipped whenever that member shares the caller's thread group, and hook_file_send_sigiotask() then lets the signal fan out to the whole group unchecked.
Record the domain for every non single-process target so the scope is enforced against each group member at delivery time.
That recording is necessary but not sufficient on its own: the kernel signals a process group through its members' thread-group leaders, and the leader of the registrant's own process can carry a different Landlock domain than the sibling thread that armed the owner. domain_is_scoped() would then deny that leader, even though commit 18eb75f3af40 ("landlock: Always allow signals between threads of the same process") requires same-process delivery to be allowed. hook_task_kill() avoids this by evaluating same_thread_group() live, per recipient; the SIGIO path instead delegates the whole decision to a single registration-time check, which a process-group fan-out cannot honor.
So also record the registrant's thread group next to its domain and exempt it at delivery: hook_file_send_sigiotask() allows the signal whenever the recipient belongs to the registrant's own process, restoring the same-process guarantee while keeping out-of-domain group members blocked. The direct kill() path (hook_task_kill) already evaluates the live domain and is unaffected.
[mic: Check pid_type earlier and improve comment, fix commit message, fix comment formatting]
--- security/landlock/fs.c | 14 ++++++++++++++ security/landlock/fs.h | 10 ++++++++++ security/landlock/task.c | 11 +++++++++++ 3 files changed, 35 insertions(+)
security/landlock/fs.c +14 -0
@@ -1901,6 +1901,14 @@ static bool control_current_fowner(struclockdep_assert_held (&fown->lock);/* +* A process-group or session owner (PIDTYPE_PGID/PIDTYPE_SID) fans the +* signal out to every member at delivery time, so record the domain and +* let hook_file_send_sigiotask() check the live scope per recipient. +*/ +if (fown->pid_type !=PIDTYPE_PID && fown->pid_type !=PIDTYPE_TGID ) +return true; + +/* * Some callers (e.g. fcntl_dirnotify) may not be in an RCU read-side * critical section. */
@@ -1916,6 +1924,7 @@ static void hook_file_set_fowner(struct {struct landlock_ruleset *prev_dom;struct landlock_cred_security fown_subject = {}; +struct pid *prev_tg, *fown_tg =NULL ;size_t fown_layer =0 ;if (control_current_fowner (file_f_owner (file))) {
@@ -1928,21 +1937,26 @@ static void hook_file_set_fowner(structif (new_subject) {landlock_get_ruleset (new_subject->domain); fown_subject = *new_subject; + fown_tg =get_pid (task_tgid (current)); } } prev_dom =landlock_file (file)->fown_subject.domain; + prev_tg =landlock_file (file)->fown_tg;landlock_file (file)->fown_subject = fown_subject; +landlock_file (file)->fown_tg = fown_tg;#ifdef CONFIG_AUDIT landlock_file (file)->fown_layer = fown_layer;#endif /* CONFIG_AUDIT*/ /* May be called in an RCU read-side critical section. */ landlock_put_ruleset_deferred (prev_dom); +put_pid (prev_tg); }static void hook_file_free_security (struct file *file) { +put_pid (landlock_file (file)->fown_tg);landlock_put_ruleset_deferred (landlock_file (file)->fown_subject.domain); }
security/landlock/fs.h +10 -0
@@ -78,6 +78,16 @@ struct landlock_file_security {* euid. */ struct landlock_cred_security fown_subject; +/** +* @fown_tg: Thread group of the task that set the file owner, pinned +* while @fown_subject holds a domain. It lets +* hook_file_send_sigiotask() always allow a SIGIO delivered to the +* owner's own process -- e.g. the thread-group leader reached through a +* process-group owner -- matching the same-process exemption of +* hook_task_kill(). NULL when no domain is recorded. Protected by +* file->f_owner->lock, like @fown_subject. +*/ +struct pid *fown_tg; };#ifdef CONFIG_AUDIT
security/landlock/task.c +11 -0
@@ -411,6 +411,17 @@ static int hook_file_send_sigiotask(struif (!subject->domain)return 0 ; +/* +* Always allow delivery to the file owner's own process, including a +* thread-group leader reached through a process-group owner. This +* mirrors hook_task_kill()'s same-process exemption and preserves the +* guarantee of commit 18eb75f3af40 ("landlock: Always allow signals +* between threads of the same process"), which the registration-time +* check cannot honor for a process-group target. +*/ +if (task_tgid (tsk) ==landlock_file (fown->file)->fown_tg) +return 0 ; +scoped_guard (rcu) { is_scoped = domain_is_scoped(subject->domain,
Greg Kroah-Hartman
maintainerPATCH 1720/2077 power: supply: charger-manager: fix refcount leak in is_full_charged()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: WenTao Liang <[email protected]>
commit 4373cfa38ead58f980362c841b0d0bdf8c4d956c upstream.
In is_full_charged(), power_supply_get_by_name() is called to obtain a reference to the fuel_gauge power supply. If the voltage check (uV >= desc->fullbatt_uV) succeeds, the function returns true directly without releasing the reference, leaking the refcount.
Fix this by setting a flag and jumping to the out label where power_supply_put() properly drops the reference.
--- drivers/power/supply/charger-manager.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/power/supply/charger-manager.c +4 -2
@@ -303,8 +303,10 @@ static bool is_full_charged(struct chargif (cm->battery_status ==POWER_SUPPLY_STATUS_FULL && desc->fullbatt_vchkdrop_uV) uV += desc->fullbatt_vchkdrop_uV; -if (uV >= desc->fullbatt_uV) -return true; +if (uV >= desc->fullbatt_uV) { + is_full = true; + goto out; + } } }
Greg Kroah-Hartman
maintainerPATCH 1721/2077 selftests/landlock: Test SCOPE_SIGNAL on the SIGIO/fowner pgid path
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
commit 76579d09beedaffe7fe76e9c05644f73983e1ceb upstream.
Add regression tests for the LANDLOCK_SCOPE_SIGNAL handling of the asynchronous SIGIO delivery path (fcntl(F_SETOWN)) with a process-group owner.
sigio_to_pgid_members covers the bypass: a sandboxed process at the head of its process group's PGID hlist (the default after fork()) arms F_SETOWN(-pgrp) + O_ASYNC and triggers the fan-out; the in-domain owner must be signaled (proving the trigger fired) while the non-sandboxed member of the group, outside the domain, must not.
sigio_to_pgid_self covers the same-process guarantee: the owner is registered from a sandboxed non-leader thread, whose domain differs from the thread-group leader the kernel signals for a process-group owner. That leader belongs to the owner's own process and must still be signaled.
Without the fix the first test sees the out-of-domain member signaled and the second sees the owner's own leader denied.
--- tools/testing/selftests/landlock/scoped_signal_test.c | 182 ++++++++++++++++++ 1 file changed, 182 insertions(+)
tools/testing/selftests/landlock/scoped_signal_test.c +182 -0
@@ -559,4 +559,186 @@ TEST_F(fown, sigurg_socket) _metadata->exit_code =KSFT_FAIL ; } +/* +* Checks that LANDLOCK_SCOPE_SIGNAL is enforced on the asynchronous SIGIO +* delivery path (fcntl(F_SETOWN)) when the file owner is a process group. +* +* A sandboxed process sitting at the head of its process group's PID hlist (the +* default position right after fork()) used to escape the fcntl(F_SETOWN, +* -pgrp) domain recording: pid_task(pgrp, PIDTYPE_PGID) resolved to the process +* itself, so the same-thread-group exemption skipped recording its Landlock +* domain. At SIGIO time that domain was then unset and the signal fanned out +* to every group member, including non-sandboxed processes outside the domain. +*/ +TEST (sigio_to_pgid_members) +{ +int trigger[2 ], sync_child[2 ]; +char buf; +pid_t child; +int status, i; + +drop_caps (_metadata); + +/* +* Isolates the test in its own process group so the SIGIO fan-out stays +* bounded to this parent and the child forked below. +*/ +ASSERT_EQ (0 ,setpgid (0 ,0 )); + +/* The non-sandboxed parent is the protected (out-of-domain) target. */ +ASSERT_EQ (0 ,setup_signal_handler (SIGURG )); + signal_received =0 ; + +ASSERT_EQ (0 ,pipe2 (trigger,O_CLOEXEC )); +ASSERT_EQ (0 ,pipe2 (sync_child,O_CLOEXEC )); + + child =fork (); +ASSERT_LE (0 , child); +if (child ==0 ) { +/* +* The child inherits the parent's new process group and, just +* attached with hlist_add_head_rcu(), is now the head of the +* pgid hlist: this is the case that used to skip the recording. +*/ +EXPECT_EQ (0 ,close (sync_child[0 ])); + +/* In-domain positive control: the child must be signaled. */ +ASSERT_EQ (0 ,setup_signal_handler (SIGURG )); + signal_received =0 ; + +create_scoped_domain (_metadata,LANDLOCK_SCOPE_SIGNAL ); + +/* Owns the SIGIO source for the whole process group. */ +ASSERT_EQ (0 ,fcntl (trigger[0 ],F_SETSIG ,SIGURG )); +ASSERT_EQ (0 ,fcntl (trigger[0 ],F_SETOWN , -getpgrp ())); +ASSERT_EQ (0 ,fcntl (trigger[0 ],F_SETFL ,O_ASYNC )); + +/* Fans SIGURG out to every member of the process group. */ +ASSERT_EQ (1 ,write (trigger[1 ],"." ,1 )); + +/* +* The sandboxed child is in its own domain and must always be +* signaled: this proves the SIGIO actually fired. +*/ +for (i =0 ; i <1000 && !signal_received; i++) +usleep (1000 ); +EXPECT_EQ (1 , signal_received); + +ASSERT_EQ (1 ,write (sync_child[1 ],"." ,1 )); +EXPECT_EQ (0 ,close (sync_child[1 ])); + +_exit (_metadata->exit_code); +return ; + } +EXPECT_EQ (0 ,close (sync_child[1 ])); +EXPECT_EQ (0 ,close (trigger[0 ])); +EXPECT_EQ (0 ,close (trigger[1 ])); + +/* Waits for the child to generate the SIGIO. */ +ASSERT_EQ (1 ,read (sync_child[0 ], &buf,1 )); +EXPECT_EQ (0 ,close (sync_child[0 ])); + +/* Lets a delivered-but-pending signal run our handler, if any. */ +for (i =0 ; i <100 && !signal_received; i++) +usleep (1000 ); + +/* +* SCOPE_SIGNAL must block the fan-out to this non-sandboxed parent, +* which is outside the child's Landlock domain. Before the fix the +* parent was signaled here. +*/ +EXPECT_EQ (0 , signal_received); + +ASSERT_EQ (child,waitpid (child, &status,0 )); +if (WIFSIGNALED (status) || !WIFEXITED (status) || +WEXITSTATUS (status) !=EXIT_SUCCESS ) + _metadata->exit_code =KSFT_FAIL ; +} + +static void *thread_setown_scoped (void *arg) +{ +const int fd = *(int *)arg; +int ruleset_fd; +const struct landlock_ruleset_attr ruleset_attr = { + .scoped =LANDLOCK_SCOPE_SIGNAL , + }; + +/* Sandboxes only this non-leader thread (no thread syncing). */ + ruleset_fd = +landlock_create_ruleset (&ruleset_attr,sizeof (ruleset_attr),0 ); +if (ruleset_fd <0 ) +return (void *)THREAD_ERROR ; +if (prctl (PR_SET_NO_NEW_PRIVS ,1 ,0 ,0 ,0 ) || +landlock_restrict_self (ruleset_fd,0 )) { +close (ruleset_fd); +return (void *)THREAD_ERROR ; + } +close (ruleset_fd); + +/* Makes this process group own the SIGIO source. */ +if (fcntl (fd,F_SETSIG ,SIGURG ) ||fcntl (fd,F_SETOWN , -getpgrp ()) || +fcntl (fd,F_SETFL ,O_ASYNC )) +return (void *)THREAD_ERROR ; + +return (void *)THREAD_SUCCESS ; +} + +/* +* Checks that the SIGIO fan-out is still delivered to the file owner's own +* process when fcntl(F_SETOWN, -pgrp) was issued from a sandboxed non-leader +* thread. +* +* The Landlock domain is recorded for a process-group owner (so out-of-domain +* members stay blocked, see sigio_to_pgid_members), but the kernel signals a +* process group through its members' thread-group leaders. Here the leader is +* not sandboxed and thus has a different domain than the registering thread, so +* the registration-time check cannot tell that it belongs to the owner's own +* process. hook_file_send_sigiotask() must recognize it through the recorded +* thread group and allow the delivery, matching the same-process guarantee of +* commit 18eb75f3af40. Without that exemption the leader is wrongly denied and +* never signaled. +*/ +TEST (sigio_to_pgid_self) +{ +int trigger[2 ]; +pthread_t thread; +enum thread_return ret =THREAD_INVALID ; +int i; + +drop_caps (_metadata); + +/* Bounds the SIGIO fan-out to this process. */ +ASSERT_EQ (0 ,setpgid (0 ,0 )); + +/* The non-sandboxed thread-group leader is the SIGIO target. */ +ASSERT_EQ (0 ,setup_signal_handler (SIGURG )); + signal_received =0 ; + +ASSERT_EQ (0 ,pipe2 (trigger,O_CLOEXEC )); + +/* +* Registers the process-group fowner from a sibling thread that +* sandboxes only itself, so its domain differs from the leader's. +*/ +ASSERT_EQ (0 ,pthread_create (&thread,NULL , thread_setown_scoped, + &trigger[0 ])); +ASSERT_EQ (0 ,pthread_join (thread, (void **)&ret)); +ASSERT_EQ (THREAD_SUCCESS , ret); + +/* Fans SIGURG out to the process group. */ +ASSERT_EQ (1 ,write (trigger[1 ],"." ,1 )); + +for (i =0 ; i <1000 && !signal_received; i++) +usleep (1000 ); + +/* +* Same-process delivery must always be allowed, even though the owner +* was registered from a sandboxed sibling thread. +*/ +EXPECT_EQ (1 , signal_received); + +EXPECT_EQ (0 ,close (trigger[0 ])); +EXPECT_EQ (0 ,close (trigger[1 ])); +} +TEST_HARNESS_MAIN
Greg Kroah-Hartman
maintainerPATCH 1722/2077 mips: sched: Fix CPUMASK_OFFSTACK memory corruption
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aaron Tomlin <[email protected]>
commit 98e37db4a34d3af3fb2f4648295c25b5e40b20e3 upstream.
This patch addresses a critical memory management flaw. When CONFIG_CPUMASK_OFFSTACK is enabled, cpumask_var_t is a pointer. Consequently, sizeof(new_mask) evaluates to the pointer size, causing copy_from_user() to clobber the mask pointer. Furthermore, the old logic performed copy_from_user() before allocating the mask.
Fix this by allocating new_mask first. To handle variable-sized user masks correctly, use cpumask_size() to truncate overly large user masks or pad undersized masks with zeros before copying the data directly into the allocated buffer.
--- arch/mips/kernel/mips-mt-fpaff.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
arch/mips/kernel/mips-mt-fpaff.c +15 -13
@@ -71,11 +71,16 @@ asmlinkage long mipsmt_sys_sched_setaffistruct task_struct *p;int retval; -if (len <sizeof (new_mask)) -return -EINVAL ; - -if (copy_from_user (&new_mask, user_mask_ptr,sizeof (new_mask))) -return -EFAULT ; +if (!alloc_cpumask_var (&new_mask,GFP_KERNEL )) +return -ENOMEM ; +if (len <cpumask_size ()) +cpumask_clear (new_mask); +else if (len >cpumask_size ()) + len =cpumask_size (); +if (copy_from_user (new_mask, user_mask_ptr, len)) { + retval = -EFAULT ; + goto out_free_new_mask; + }cpus_read_lock ();rcu_read_lock ();
@@ -84,7 +89,8 @@ asmlinkage long mipsmt_sys_sched_setaffiif (!p) {rcu_read_unlock ();cpus_read_unlock (); -return -ESRCH ; + retval = -ESRCH ; + goto out_free_new_mask; }/* Prevent p going away */
@@ -95,13 +101,9 @@ asmlinkage long mipsmt_sys_sched_setaffi retval = -ENOMEM ; goto out_put_task; } -if (!alloc_cpumask_var (&new_mask,GFP_KERNEL )) { - retval = -ENOMEM ; - goto out_free_cpus_allowed; - }if (!alloc_cpumask_var (&effective_mask,GFP_KERNEL )) { retval = -ENOMEM ; - goto out_free_new_mask; + goto out_free_cpus_allowed; }if (!check_same_owner (p) && !capable (CAP_SYS_NICE )) { retval = -EPERM ;
@@ -142,13 +144,13 @@ asmlinkage long mipsmt_sys_sched_setaffi } out_unlock:free_cpumask_var (effective_mask); -out_free_new_mask: -free_cpumask_var (new_mask); out_free_cpus_allowed:free_cpumask_var (cpus_allowed); out_put_task:put_task_struct (p);cpus_read_unlock (); +out_free_new_mask: +free_cpumask_var (new_mask);return retval; }
Greg Kroah-Hartman
maintainerPATCH 1723/2077 mm/huge_memory: preserve pmd_swp_uffd_wp on device-private PMD downgrade
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kiryl Shutsemau (Meta) <[email protected]>
commit f7e2c21bd1f57cd5350eecdfdb5d6025ca6afbab upstream.
change_non_present_huge_pmd() rewrites a writable device-private PMD swap entry into a readable one without carrying pmd_swp_uffd_wp() across. The PTE-level change_softleaf_pte() does this correctly; mirror that here, matching what copy_huge_pmd() does for the fork path. Without the carry, a plain mprotect() over a UFFD_WP-marked device-private THP strips the bit and the trap is bypassed on swap-in.
--- mm/huge_memory.c | 2 ++ 1 file changed, 2 insertions(+)
mm/huge_memory.c +2 -0
@@ -2638,6 +2638,8 @@ static void change_non_present_huge_pmd( }else if (softleaf_is_device_private_write (entry)) { entry =make_readable_device_private_entry (swp_offset (entry)); newpmd =swp_entry_to_pmd (entry); +if (pmd_swp_uffd_wp (*pmd)) + newpmd =pmd_swp_mkuffd_wp (newpmd); }else { newpmd = *pmd; }
Greg Kroah-Hartman
maintainerPATCH 1724/2077 riscv: cacheinfo: Fix node reference leak in populate_cache_leaves
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zishun Yi <[email protected]>
commit bf4a195f063b0a0805c1417f6aad1dd32ea48f0f upstream.
Currently, the while loop drops the reference to prev in each iteration. If the loop terminates early due to a break, the final of_node_put(np) correctly drops the reference to the current node.
However, if the loop terminates naturally because np == NULL, calling of_node_put(np) is a no-op. This leaves the last valid node stored in prev without its reference dropped, resulting in a node reference leak.
Fix this by changing the final of_node_put(np) to of_node_put(prev).
--- arch/riscv/kernel/cacheinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/cacheinfo.c +1 -1
@@ -133,7 +133,7 @@ int populate_cache_leaves(unsigned int cci_leaf_init (this_leaf++,CACHE_TYPE_DATA , level); levels = level; } -of_node_put (np); +of_node_put (prev);return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 1725/2077 mm/damon/core: always put unsuccessfully committed target pids
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: SeongJae Park <[email protected]>
commit 6a66c557a2ab2609575bafd15e093669c05f9711 upstream.
damon_commit_target() puts and gets the destination and the source target pids. It puts the destination target pid because it will be overwritten by the source target pid. It gets the source pid because the caller is supposed to eventually put the pids. In more detail, the caller will call damon_destroy_ctx() after damon_commit_ctx() to destroy the entire source context. And in this case, [f]vaddr operation set's cleanup_target() callback will put the pids.
The commit operation is made at the context level. The operation can fail in multiple places including in the middle and after the targets commit operations. For any such failures, immediately the error is returned to the damon_commit_ctx() caller. If some or all of the source target pids were committed to the destination during the unsuccessful context commit attempt, those pids should be put twice.
The source context will do the put operations using the above explained routine. However, let's suppose the destination context was not originally using [f]vaddr operation set and the commit failed before the ops of the source context is committed. The destination does not have the cleanup_target() ops callback, so it cannot put the pids via the damon_destroy_ctx().
As a result, the pids are leaked. The issue in the real world would be not very common. The commit feature is for changing parameters of running DAMON context while inheriting internal status like the monitoring results. The monitoring results of a physical address range ain't have things that are beneficial to be inherited to a virtual address ranges monitoring. So the problem-causing DAMON control would be not very common in the real world. That said, it is a supported feature. And damon_commit_target() failure due to memory allocation is relatively realistic [1] if there are a huge number of target regions.
Fix by putting the pids in the commit operation in case of the failures.
The issue was discovered [2] by Sashiko.
--- mm/damon/core.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 8 deletions(-)
mm/damon/core.c +47 -8
@@ -1257,10 +1257,36 @@ static int damon_commit_target(return 0 ; } +/* +* damon_revert_target_commits() - revert unsuccessful target commits. +* @dst: Commit destination context +* @failed: Commit failed destination target +* @src: Commit source context +* +* Revert target states that changed by damon_commit_target(), and cannot be +* cleaned up by the destination context's ops.cleanup_target(). +*/ +static void damon_revert_target_commits (struct damon_ctx *dst, +struct damon_target *failed,struct damon_ctx *src) +{ +struct damon_target *target; + +if (!damon_target_has_pid (src)) +return ; +if (dst->ops.cleanup_target) +return ; +damon_for_each_target (target, dst) { +if (target == failed) +return ; +put_pid (target->pid); + } +} +static int damon_commit_targets (struct damon_ctx *dst,struct damon_ctx *src) {struct damon_target *dst_target, *next, *src_target, *new_target; +struct damon_target *failed;int i =0 , j =0 , err;damon_for_each_target_safe (dst_target, next, dst) {
@@ -1274,8 +1300,10 @@ static int damon_commit_targets( dst_target,damon_target_has_pid (dst), src_target,damon_target_has_pid (src), src->min_region_sz); -if (err) -return err; +if (err) { + failed = dst_target; + goto out; + } }else {struct damos *s;
@@ -1289,25 +1317,34 @@ static int damon_commit_targets( } } + failed =NULL ;damon_for_each_target_safe (src_target, next, src) {if (j++ < i)continue ;/* target to remove has no matching dst */ -if (src_target->obsolete) -return -EINVAL ; +if (src_target->obsolete) { + err = -EINVAL ; + goto out; + } new_target =damon_new_target (); -if (!new_target) -return -ENOMEM ; +if (!new_target) { + err = -ENOMEM ; + goto out; + } err =damon_commit_target (new_target, false, src_target,damon_target_has_pid (src), src->min_region_sz);if (err) {damon_destroy_target (new_target,NULL ); -return err; + goto out; }damon_add_target (dst, new_target); }return 0 ; + +out: +damon_revert_target_commits (dst, failed, src); +return err; }/**
@@ -1346,8 +1383,10 @@ int damon_commit_ctx(struct damon_ctx *d*/ if (!damon_attrs_equals (&dst->attrs, &src->attrs)) { err =damon_set_attrs (dst, &src->attrs); -if (err) +if (err) { +damon_revert_target_commits (dst,NULL , src);return err; + } } dst->ops = src->ops; dst->addr_unit = src->addr_unit;
Greg Kroah-Hartman
maintainerPATCH 1726/2077 mm/damon/sysfs-schemes: fix dir put orders in access_pattern_add_dirs()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: SeongJae Park <[email protected]>
commit d58fdbe37a829fd2e5803dd4e5a72992dd8c5368 upstream.
Patch series "mm/damon/sysfs-schemes: fix wrong directories put orders in error paths".
Error paths of damon_sysfs_access_pattern_add_dirs() and damon_sysfs_scheme_add_dirs() functions put references to directories in wrong orders. As a result, uninitialized memory dereference and/or memory leak can happen. Fix those.
This patch (of 2):
In access_pattern_add_dirs(), error handling path puts references starting from setup failed directories. If the failure happpened from the initial allication in the setup functions, uninitialized memory dereference happen. The allocation failures will not commonly happen, but the consequence is quite bad. Fix the wrong reference put orders.
The issue was discovered [1] by Sashiko.
--- mm/damon/sysfs-schemes.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
mm/damon/sysfs-schemes.c +3 -6
@@ -1767,22 +1767,19 @@ static int damon_sysfs_access_pattern_ad err =damon_sysfs_access_pattern_add_range_dir (access_pattern, &access_pattern->sz,"sz" );if (err) - goto put_sz_out; +return err; err =damon_sysfs_access_pattern_add_range_dir (access_pattern, &access_pattern->nr_accesses,"nr_accesses" );if (err) - goto put_nr_accesses_sz_out; + goto put_sz_out; err =damon_sysfs_access_pattern_add_range_dir (access_pattern, &access_pattern->age,"age" );if (err) - goto put_age_nr_accesses_sz_out; + goto put_nr_accesses_sz_out;return 0 ; -put_age_nr_accesses_sz_out: -kobject_put (&access_pattern->age->kobj); - access_pattern->age =NULL ; put_nr_accesses_sz_out:kobject_put (&access_pattern->nr_accesses->kobj); access_pattern->nr_accesses =NULL ;
Greg Kroah-Hartman
maintainerPATCH 1727/2077 mm/damon/sysfs-schemes: put stats for scheme_add_dirs() internal error
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: SeongJae Park <[email protected]>
commit 05ea83ee88ca70f8932906d9f2617ff996f45b50 upstream.
damon_sysfs_scheme_add_dirs() setup the tried_regions directory after the stats directory setup is completed. When the tried_regions directory setup is failed, the setup function ensures the reference for the tried regions directory is released. Hence the error path should put references on setup succeeded directory objects, starting from the stats directory. However, the error path is putting the tried_regions directory instead of the stats directory.
As a direct result, the stats directory object is leaked. Worse yet, if the tried_regions directory setup failed from the initial allocation, the scheme->tried_regions field remains uninitialized. The following kobject_put(&scheme->tried_regions->kobj) call in the error path will dereference the uninitialized memory. The setup failures should not be common. But once it happens, the consequence is quite bad.
Fix this issue by correctly putting the stats directory instead of the tried_regions directory.
The issue was discovered [1] by Sashiko.
--- mm/damon/sysfs-schemes.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
mm/damon/sysfs-schemes.c +4 -4
@@ -2283,12 +2283,12 @@ static int damon_sysfs_scheme_add_dirs(s goto put_filters_watermarks_quotas_access_pattern_out; err =damon_sysfs_scheme_set_tried_regions (scheme);if (err) - goto put_tried_regions_out; + goto put_stats_out;return 0 ; -put_tried_regions_out: -kobject_put (&scheme->tried_regions->kobj); - scheme->tried_regions =NULL ; +put_stats_out: +kobject_put (&scheme->stats->kobj); + scheme->stats =NULL ; put_filters_watermarks_quotas_access_pattern_out:kobject_put (&scheme->ops_filters->kobj); scheme->ops_filters =NULL ;
Greg Kroah-Hartman
maintainerPATCH 1728/2077 fs/proc/task_mmu: fix make_uffd_wp_huge_pte() prot-update race
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kiryl Shutsemau (Meta) <[email protected]>
commit 04718f7c9290f95385f0dd328758753dc1c36dec upstream.
Patch series "userfaultfd/pagemap: pre-existing fixes".
These are pre-existing bug fixes that were carried at the front of the userfaultfd RWP working-set-tracking series up to v5 [1]. Per review feedback that fixes should not sit in the middle of a feature series, they are split out and sent on their own; the RWP series is reposted rebased on top of this.
All six were flagged by the Sashiko AI review of the RWP series and carry
independent of RWP, apply to mm-new directly, and carry Cc: stable@.
1: fs/proc/task_mmu: a missing huge_ptep_modify_prot_start() in
make_uffd_wp_huge_pte() can lose hardware Dirty/Accessed updates when PAGEMAP_SCAN write-protects a hugetlb PTE.
2: fs/proc/task_mmu: pagemap_scan_hugetlb_entry() compares the range
against HPAGE_SIZE rather than the hstate page size, so it never write-protects gigantic hugetlb pages.
3: fs/proc/task_mmu: PAGEMAP_SCAN with PM_SCAN_WP_MATCHING over an
unpopulated hugetlb range self-deadlocks -- pagemap_scan_pte_hole() calls uffd_wp_range() while walk_hugetlb_range() holds the hugetlb vma lock for read, and hugetlb_change_protection() then takes it for write. Install the marker inline instead.
4: mm/huge_memory: change_non_present_huge_pmd() drops pmd_swp_uffd_wp
on a device-private PMD permission downgrade, silently losing the uffd-wp marker.
5: userfaultfd: must_wait() applies pte_write() to a locklessly read
PTE without checking pte_present(), so swap/migration entries decode random offset bits and a thread can stay parked on a stale fault.
6: userfaultfd: __VMA_UFFD_FLAGS feeds VMA_UFFD_MINOR_BIT (41) to
mk_vma_flags() unconditionally, an out-of-bounds write into the single-word vma_flags_t on 32-bit. Build the mask from config-gated per-mode masks so an unavailable bit is never materialised.
This patch (of 6):
make_uffd_wp_huge_pte() arms the UFFD_WP bit on a present HugeTLB PTE by calling huge_ptep_modify_prot_commit() with a ptent snapshot that was fetched without the corresponding huge_ptep_modify_prot_start(). The start helper is what atomically clears the entry so the kernel-owned snapshot stays consistent until the commit; without it, the hardware may set Dirty or Accessed in the live PTE between the original read and the commit, and huge_ptep_modify_prot_commit() (whose generic implementation just calls set_huge_pte_at()) then writes the stale snapshot back over the live hardware bits, losing the update.
The non-hugetlb sibling make_uffd_wp_pte() does this correctly via ptep_modify_prot_start() / ptep_modify_prot_commit(). Mirror that pattern for the present-PTE branch. The migration case stays as-is -- migration entries are non-present, so there's no hardware update to race against.
--- fs/proc/task_mmu.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
fs/proc/task_mmu.c +8 -4
@@ -2523,12 +2523,16 @@ static void make_uffd_wp_huge_pte(structif (softleaf_is_hwpoison (entry) ||softleaf_is_marker (entry))return ; -if (softleaf_is_migration (entry)) +if (softleaf_is_migration (entry)) {set_huge_pte_at (vma->vm_mm, addr, ptep,pte_swp_mkuffd_wp (ptent), psize); -else -huge_ptep_modify_prot_commit (vma, addr, ptep, ptent, - huge_pte_mkuffd_wp(ptent)); + }else { +pte_t old_pte, new_pte; + + old_pte =huge_ptep_modify_prot_start (vma, addr, ptep); + new_pte =huge_pte_mkuffd_wp (old_pte); +huge_ptep_modify_prot_commit (vma, addr, ptep, old_pte, new_pte); + } }#endif /* CONFIG_HUGETLB_PAGE */
Greg Kroah-Hartman
maintainerPATCH 1729/2077 fs/proc/task_mmu: fix hugetlb self-deadlock in pagemap_scan_pte_hole()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kiryl Shutsemau (Meta) <[email protected]>
commit e92d92bbafb264dc0518d52b846a3c07ed8d523f upstream.
A PAGEMAP_SCAN ioctl requesting PM_SCAN_WP_MATCHING on a hugetlb VMA hangs the calling thread, unkillably, as soon as the scan reaches an unpopulated part of the range:
do_pagemap_scan()
walk_page_range()
walk_hugetlb_range()
hugetlb_vma_lock_read() # take the vma lock for read ...
pagemap_scan_pte_hole() # ... ->pte_hole() for a hole
uffd_wp_range()
change_protection()
hugetlb_change_protection()
hugetlb_vma_lock_write() # ... and block taking it for write
walk_hugetlb_range() holds the hugetlb vma lock for read across the whole walk. A present entry goes to ->hugetlb_entry(); an unpopulated one goes to ->pte_hole(), i.e. pagemap_scan_pte_hole(). To write-protect the hole that handler calls uffd_wp_range(), which on a hugetlb VMA reaches hugetlb_change_protection() and takes the same vma lock for write. The thread then blocks in down_write() waiting for the read lock it is itself holding.
The populated path avoids this: pagemap_scan_hugetlb_entry() write-protects the entry inline under the page-table lock and never enters hugetlb_change_protection().
Do the same for holes. Fault in the page table and install the uffd-wp marker directly with make_uffd_wp_huge_pte() under the page-table lock, rather than routing through uffd_wp_range(). That is the same sequence hugetlb_change_protection() runs for an unpopulated entry, minus the vma write lock -- which is safe to skip because PMD sharing is disabled on uffd-wp VMAs (hugetlb_unshare_all_pmds() runs at registration), leaving nothing for that lock to serialise against.
--- fs/proc/task_mmu.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-)
fs/proc/task_mmu.c +58 -1
@@ -2890,8 +2890,62 @@ out_unlock: return ret; } + +/* +* Write-protect the unpopulated hugetlb entries covering [addr, end) by +* installing uffd-wp markers inline, exactly as pagemap_scan_hugetlb_entry() +* does for populated entries. +* +* walk_hugetlb_range() currently calls ->pte_hole() once per huge page, so the +* loop normally runs a single iteration; it is written to cover the full range +* in case the walker ever coalesces adjacent holes. +* +* The obvious route -- uffd_wp_range() -> hugetlb_change_protection() -- +* cannot be used here: it takes hugetlb_vma_lock_write(), but the page-table +* walker (walk_hugetlb_range()) already holds hugetlb_vma_lock_read() on the +* same VMA, so the scanning thread would deadlock against itself. PMD sharing +* is disabled on uffd-wp VMAs (hugetlb_unshare_all_pmds() at registration), so +* the vma lock guards nothing that matters for these entries anyway. +*/ +static int pagemap_scan_hugetlb_hole_wp (struct vm_area_struct *vma, +unsigned long addr,unsigned long end) +{ +struct hstate *h =hstate_vma (vma); +unsigned long psize =huge_page_size (h); +struct mm_struct *mm = vma->vm_mm; +spinlock_t *ptl; +pte_t *ptep; +pte_t pte; + +for (addr =ALIGN_DOWN (addr, psize); addr < end; addr += psize) { + ptep =huge_pte_alloc (mm, vma, addr, psize); +if (!ptep) +return -ENOMEM ; + +i_mmap_lock_write (vma->vm_file->f_mapping); + ptl =huge_pte_lock (h, mm, ptep); + pte =huge_ptep_get (mm, addr, ptep); +make_uffd_wp_huge_pte (vma, addr, ptep, pte); +/* +* A none entry has no cached translation, so installing the +* marker needs no TLB flush. Flush only if a fault populated +* the entry between huge_pte_alloc() and the page table lock. +*/ +if (!huge_pte_none (pte)) +flush_hugetlb_tlb_range (vma, addr, addr + psize); +spin_unlock (ptl); +i_mmap_unlock_write (vma->vm_file->f_mapping); + } + +return 0 ; +}#else #define pagemap_scan_hugetlb_entry NULL +static int pagemap_scan_hugetlb_hole_wp (struct vm_area_struct *vma, +unsigned long addr,unsigned long end) +{ +return 0 ; +}#endif static int pagemap_scan_pte_hole(unsigned long addr, unsigned long end,
@@ -2911,7 +2965,10 @@ static int pagemap_scan_pte_hole(unsigneif (~p->arg.flags &PM_SCAN_WP_MATCHING )return ret; - err =uffd_wp_range (vma, addr, end - addr, true); +if (is_vm_hugetlb_page (vma)) + err =pagemap_scan_hugetlb_hole_wp (vma, addr, end); +else + err =uffd_wp_range (vma, addr, end - addr, true);if (err <0 ) ret = err;
Greg Kroah-Hartman
maintainerPATCH 1730/2077 fs/proc/task_mmu: use huge_page_size() in pagemap_scan_hugetlb_entry()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kiryl Shutsemau (Meta) <[email protected]>
commit 1b074e3270e1c061c829150c742eb83bad4dddd1 upstream.
The partial-page check compares against HPAGE_SIZE (PMD_SIZE), which is wrong for gigantic hugetlb hstates (e.g. 1G). The walker hands the callback a huge_page_size()-sized range, never start + HPAGE_SIZE, so the comparison always declares it partial and aborts the WP. Compare against the actual hstate's page size.
--- fs/proc/task_mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/proc/task_mmu.c +1 -1
@@ -2873,7 +2873,7 @@ static int pagemap_scan_hugetlb_entry(ptif (~categories &PAGE_IS_WRITTEN ) goto out_unlock; -if (end != start +HPAGE_SIZE ) { +if (end != start +huge_page_size (hstate_vma (vma))) {/* Partial HugeTLB page WP isn't possible. */ pagemap_scan_backout_range (p, start, end); p->arg.walk_end = start;
Greg Kroah-Hartman
maintainerPATCH 1731/2077 fs/proc/task_mmu: do not warn on seeing non-migration pmd entry
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dev Jain <[email protected]>
commit cd1fc0e3c1f67c0c31dfc215e5d9b771133dedc0 upstream.
Patch series "mm/hmm: A fix and a selftest", v3.
Patch 1 fixes a stale warning present from the time when only migration softleaf entries were supported at the PMD level.
Patch 2 adds some code into hmm-tests.c which exercises the pagemap path for PMD device-private entries.
This patch (of 2):
pagemap_pmd_range_thp() warns if a non-present PMD is not a migration entry. This became false once device-private entries at the PMD level were added.
Therefore, remove the stale migration-only assertion.
--- fs/proc/task_mmu.c | 1 - 1 file changed, 1 deletion(-)
fs/proc/task_mmu.c +0 -1
@@ -2042,7 +2042,6 @@ static int pagemap_pmd_range_thp(pmd_t * flags |=PM_SOFT_DIRTY ;if (pmd_swp_uffd_wp (pmd)) flags |=PM_UFFD_WP ; -VM_WARN_ON_ONCE (!pmd_is_migration_entry (pmd)); page =softleaf_to_page (entry); }
Greg Kroah-Hartman
maintainerPATCH 1732/2077 proc: only bump parent nlink when registering directories
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Krzysztof Wilczyński <[email protected]>
commit 16b02eb4b9b272c221255c20d34ccd5db53a3ed3 upstream.
proc_register() increments the parent directory's link count for every entry it registers, while remove_proc_entry() and remove_proc_subtree() decrement it only when the removed entry is a directory. Regular files thus inflate the parent's count while they exist, and leak one link permanently on every create and remove cycle.
For example, /proc/bus/pci/00 with twenty-two device files and no subdirectories reports nlink 24 instead of 2, and SR-IOV VF enable and disable cycles, each creating and removing the VF config space entries under /proc/bus/pci/<bus>, inflate the link count of that directory without bound.
Before commit e06689bf5701 ("proc: change ->nlink under proc_subdir_lock"), the increment lived in proc_mkdir_data() and proc_create_mount_point(), and was therefore applied only to directories. Moving it into proc_register() to bring it under proc_subdir_lock dropped the S_ISDIR check.
Thus, move the nlink accounting into pde_subdir_insert() and pde_erase(), only updating it for directories in both, so the link count is always changed together with the directory entry itself.
--- fs/proc/generic.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
fs/proc/generic.c +4 -5
@@ -112,6 +112,8 @@ static bool pde_subdir_insert(struct pro/* Add new node and rebalance tree. */ rb_link_node (&de->subdir_node, parent, new);rb_insert_color (&de->subdir_node, root); +if (S_ISDIR (de->mode)) + dir->nlink++;return true; }
@@ -404,7 +406,6 @@ struct proc_dir_entry *proc_register(strwrite_unlock (&proc_subdir_lock); goto out_free_inum; } - dir->nlink++;write_unlock (&proc_subdir_lock);return dp;
@@ -702,6 +703,8 @@ static void pde_erase(struct proc_dir_en {rb_erase (&pde->subdir_node, &parent->subdir);RB_CLEAR_NODE (&pde->subdir_node); +if (S_ISDIR (pde->mode)) + parent->nlink--; }/*
@@ -727,8 +730,6 @@ void remove_proc_entry(const char *name, de =NULL ; }else {pde_erase (de, parent); -if (S_ISDIR (de->mode)) - parent->nlink--; } }write_unlock (&proc_subdir_lock);
@@ -787,8 +788,6 @@ int remove_proc_subtree(const char *namecontinue ; } next = de->parent; -if (S_ISDIR (de->mode)) - next->nlink--;write_unlock (&proc_subdir_lock);proc_entry_rundown (de);
Greg Kroah-Hartman
maintainerPATCH 1733/2077 fs/proc: fix KPF_KSM reported for all anonymous pages
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jinjiang Tu <[email protected]>
commit 81401cebfc1598306b0a981b5f9ee5b58c1aac52 upstream.
Reading /proc/kpageflags for any anonymous page returns KPF_KSM set, even when KSM is not in use. As a result, tools misclassify all anonymous pages as KSM merged.
In stable_page_flags(), if the page is anonymous, then use (mapping & FOLIO_MAPPING_KSM) check to identify if the anonymous page is KSM page. However, FOLIO_MAPPING_KSM is FOLIO_MAPPING_ANON | FOLIO_MAPPING_ANON_KSM, (mapping & FOLIO_MAPPING_KSM) check returns true for all anonymous pages.
To fix it, use FOLIO_MAPPING_ANON_KSM instead.
--- fs/proc/page.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/proc/page.c +1 -1
@@ -173,7 +173,7 @@ u64 stable_page_flags(const struct page u |=1 <<KPF_MMAP ;if (is_anon) { u |=1 <<KPF_ANON ; -if (mapping &FOLIO_MAPPING_KSM ) +if ((mapping &FOLIO_MAPPING_FLAGS ) ==FOLIO_MAPPING_KSM ) u |=1 <<KPF_KSM ; }
Greg Kroah-Hartman
maintainerPATCH 1734/2077 powerpc/dt_cpu_ftrs: Set CPU_FTR_P11_PVR for Power11 and later processors
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amit Machhiwal <[email protected]>
commit e4de1b9cb3b5c981e4fe9bca253a7fb9161f5acd upstream.
When using device tree CPU features (dt-cpu-ftrs), the kernel bypasses the traditional cputable-based CPU identification and instead derives CPU features from the device tree's "ibm,powerpc-cpu-features" node provided by firmware.
However, CPU_FTR_P11_PVR is a kernel-internal feature flag used to identify Power11 and later processors, and is not represented in the device tree's ISA feature set. While ISA v3.1 support (indicated by CPU_FTR_ARCH_31) is present on both Power10 and Power11, the CPU_FTR_P11_PVR flag is specifically needed by code that must distinguish between Power10 and Power11 processors.
Without this flag set, code that checks for Power11 using cpu_has_feature(CPU_FTR_P11_PVR) will incorrectly return false on Power11+ systems using dt-cpu-ftrs, leading to incorrect behavior.
This issue manifests specifically in powernv environments (bare-metal or QEMU TCG with powernv machine type), where skiboot/OPAL firmware provides the "ibm,powerpc-cpu-features" node, causing the kernel to use dt-cpu-ftrs. The issue does not affect pseries guests, where SLOF firmware does not provide this node, causing the kernel to fall back to the traditional cputable path (identify_cpu) which correctly sets CPU_FTR_P11_PVR during PVR-based CPU identification.
In powernv TCG guests, the missing flag causes KVM code to trigger warnings when attempting to create KVM guests, as cpu_features shows 0x000c00eb8f4fb187 (missing bit 53) instead of the correct 0x002c00eb8f4fb187 (with bit 53 set).
Fix this by setting CPU_FTR_P11_PVR for all processors with PVR >= PVR_POWER11 when ISA v3.1 support is detected in cpufeatures_setup_start(). This approach ensures forward compatibility with future processor generations.
--- arch/powerpc/kernel/dt_cpu_ftrs.c | 9 +++++++++ 1 file changed, 9 insertions(+)
arch/powerpc/kernel/dt_cpu_ftrs.c +9 -0
@@ -704,6 +704,15 @@ static void __init cpufeatures_setup_staif (isa >=ISA_V3_1 ) { cur_cpu_spec->cpu_features |=CPU_FTR_ARCH_31 ; cur_cpu_spec->cpu_user_features2 |=PPC_FEATURE2_ARCH_3_1 ; + +/* +* CPU_FTR_P11_PVR is a kernel-internal flag to identify +* Power11 and later processors. While ISA v3.1 is supported +* by Power10+, this flag specifically indicates Power11+ +* for code that needs to distinguish between P10 and P11. +*/ +if (PVR_VER (mfspr (SPRN_PVR )) >=PVR_POWER11 ) + cur_cpu_spec->cpu_features |=CPU_FTR_P11_PVR ; } }
Greg Kroah-Hartman
maintainerPATCH 1735/2077 mm/mm_init: fix uninitialized struct pages for ZONE_DEVICE
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muchun Song <[email protected]>
commit cd681403a87085562499d60325b7b45d3be11217 upstream.
If DAX memory is hotplugged into an unoccupied subsection of an early section, section_activate() reuses the unoptimized boot memmap. However, compound_nr_pages() still assumes that vmemmap optimization is in effect and initializes only the reduced number of struct pages. As a result, the remaining tail struct pages are left uninitialized, which can later lead to unexpected behavior or crashes.
Fix this by treating early sections as unoptimized when calculating how many struct pages to initialize.
--- mm/mm_init.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
mm/mm_init.c +10 -3
@@ -1055,10 +1055,17 @@ static void __ref __init_zone_device_pag* of how the sparse_vmemmap internals handle compound pages in the lack * of an altmap. See vmemmap_populate_compound_pages(). */ -static inline unsigned long compound_nr_pages (struct vmem_altmap *altmap, +static inline unsigned long compound_nr_pages (unsigned long pfn, +struct vmem_altmap *altmap,struct dev_pagemap *pgmap) { -if (!vmemmap_can_optimize (altmap, pgmap)) +/* +* If DAX memory is hot-plugged into an unoccupied subsection +* of an early section, the unoptimized boot memmap is reused. +* See section_activate(). +*/ +if (early_section (__pfn_to_section (pfn)) || + !vmemmap_can_optimize (altmap, pgmap))return pgmap_vmemmap_nr (pgmap);return VMEMMAP_RESERVE_NR * (PAGE_SIZE /sizeof (struct page ));
@@ -1128,7 +1135,7 @@ void __ref memmap_init_zone_device(struccontinue ;memmap_init_compound (page, pfn, zone_idx, nid, pgmap, -compound_nr_pages (altmap, pgmap)); +compound_nr_pages (pfn, altmap, pgmap)); }pageblock_migratetype_init_range (start_pfn, nr_pages,MIGRATE_MOVABLE );
Greg Kroah-Hartman
maintainerPATCH 1736/2077 kcov: use WRITE_ONCE() for selftest mode stores
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
commit 9a79524d1420e6b79a6868208c264f4518d1318e upstream.
The KCOV selftest enables coverage by setting current->kcov_mode to KCOV_MODE_TRACE_PC without installing a coverage area. If an interrupt records coverage in that window, the access should fault and expose the bug.
When building for QEMU raspi0 (Raspberry Pi Zero, ARMv6, CONFIG_CPU_V6K=y, CONFIG_CURRENT_POINTER_IN_TPIDRURO=y) with GCC 13.3.0, the store that enables the mode is removed. The generated kcov_init() code only stores zero after the wait loop:
mrc 15, 0, r3, cr13, cr0, {3}
str r4, [r3, #2028]
where r4 is zero. There is no store of KCOV_MODE_TRACE_PC before the loop, so the selftest reports success without exercising coverage.
Use WRITE_ONCE() for the temporary mode stores. With the same compiler and config, kcov_init() contains the intended mode store:
mov r3, #2
mrc 15, 0, r2, cr13, cr0, {3}
str r3, [r2, #2028]
Now that the KCOV selftest is actually executed, it may expose KCOV instrumentation issues depending on the kernel config. That is expected for a selftest that was intended to catch coverage from interrupt paths.
--- kernel/kcov.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/kcov.c +2 -2
@@ -1109,10 +1109,10 @@ static void __init selftest(void)* potentially traced functions in this region. */ start = jiffies; - current->kcov_mode =KCOV_MODE_TRACE_PC ; +WRITE_ONCE (current->kcov_mode,KCOV_MODE_TRACE_PC );while ((jiffies - start) *MSEC_PER_SEC /HZ <300 ) ; - current->kcov_mode =0 ; +WRITE_ONCE (current->kcov_mode,0 ); pr_err("done running self test\n"); }#endif
Greg Kroah-Hartman
maintainerPATCH 1737/2077 mtd: slram: remove failed entries from the device list
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruoyu Wang <[email protected]>
commit 36f1648644d769c496a8e47e53603e863e358d73 upstream.
register_device() links a new slram_mtdlist entry before allocating all of the state needed by the entry. If a later allocation, memremap(), or mtd_device_register() fails, the partially initialized entry remains on the global list. A later cleanup can then dereference or free invalid state from that failed entry.
Unwind the partially initialized entry and clear the list tail on each failure path after the entry has been linked.
--- drivers/mtd/devices/slram.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
drivers/mtd/devices/slram.c +16 -6
@@ -129,6 +129,7 @@ static int slram_write(struct mtd_info *static int register_device (char *name,unsigned long start,unsigned long length) {slram_mtd_list_t **curmtd; +int ret = -ENOMEM ; curmtd = &slram_mtdlist;while (*curmtd) {
@@ -155,14 +156,15 @@ static int register_device(char *name, uif (!(*curmtd)->mtdinfo) {E ("slram: Cannot allocate new MTD device.\n" ); -return (-ENOMEM ); + goto err_free_list; }if (!(((slram_priv_t *)(*curmtd)->mtdinfo->priv)->start =memremap (start, length,MEMREMAP_WB |MEMREMAP_WT |MEMREMAP_WC ))) {E ("slram: memremap failed\n" ); -return -EIO ; + ret = -EIO ; + goto err_free_priv; } ((slram_priv_t *)(*curmtd)->mtdinfo->priv)->end = ((slram_priv_t *)(*curmtd)->mtdinfo->priv)->start + length;
@@ -183,10 +185,8 @@ static int register_device(char *name, uif (mtd_device_register ((*curmtd)->mtdinfo,NULL ,0 )) {E ("slram: Failed to register new device\n" ); -memunmap (((slram_priv_t *)(*curmtd)->mtdinfo->priv)->start); -kfree ((*curmtd)->mtdinfo->priv); -kfree ((*curmtd)->mtdinfo); -return (-EAGAIN ); + ret = -EAGAIN ; + goto err_unmap; }T ("slram: Registered device %s from %luKiB to %luKiB\n" , name, (start /1024 ), ((start + length) /1024 ));
@@ -194,6 +194,16 @@ static int register_device(char *name, u ((slram_priv_t *)(*curmtd)->mtdinfo->priv)->start, ((slram_priv_t *)(*curmtd)->mtdinfo->priv)->end);return (0 ); + +err_unmap: +memunmap (((slram_priv_t *)(*curmtd)->mtdinfo->priv)->start); +err_free_priv: +kfree ((*curmtd)->mtdinfo->priv); +err_free_list: +kfree ((*curmtd)->mtdinfo); +kfree (*curmtd); + *curmtd =NULL ; +return ret; }static void unregister_devices (void )
Greg Kroah-Hartman
maintainerPATCH 1738/2077 9p: skip nlink update in cacheless mode to fix WARN_ON
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Breno Leitao <[email protected]>
commit 574aa0b4799470ac814479f1138d19efe6262255 upstream.
v9fs_dec_count() unconditionally calls drop_nlink() on regular files, even when the inode's nlink is already zero. In cacheless mode the client refetches inode metadata from the server (the source of truth) on every operation, so by the time v9fs_remove() returns, the locally cached nlink may already reflect the post-unlink value:
1. Client initiates unlink, server processes it and sets nlink to 0
2. Client refetches inode metadata (nlink=0) before unlink returns
3. Client's v9fs_remove() completes successfully
4. Client calls v9fs_dec_count() which calls drop_nlink() on nlink=0
This race is easily triggered under heavy unlink workloads, such as stress-ng's unlink stressor, producing the following warning:
WARNING: fs/inode.c:417 at drop_nlink+0x4c/0xc8 Call trace: drop_nlink+0x4c/0xc8 v9fs_remove+0x1e0/0x250 [9p] v9fs_vfs_unlink+0x20/0x38 [9p] vfs_unlink+0x13c/0x258 ...
In cacheless mode the server is authoritative and the inode is on its way out, so locally adjusting nlink buys nothing. Skip v9fs_dec_count() entirely when neither CACHE_META nor CACHE_LOOSE is set, which both avoids the warning and removes a class of nlink races (two concurrent unlinkers observing nlink > 0 and both calling drop_nlink()) that an nlink == 0 guard alone would only narrow rather than close.
Message-ID: <[email protected]>
--- fs/9p/vfs_inode.c | 9 +++++++++ 1 file changed, 9 insertions(+)
fs/9p/vfs_inode.c +9 -0
@@ -488,10 +488,19 @@ static int v9fs_at_to_dotl_flags(int fla* - ext4 (with dir_nlink feature enabled) sets nlink to 1 if a dir has more * than EXT4_LINK_MAX (65000) links. * +* In cacheless mode the server is the source of truth for nlink and the +* inode is going away immediately, so locally adjusting i_nlink buys +* nothing and races with concurrent metadata fetches that may already +* have observed the post-unlink value (nlink == 0). +* * @inode: inode whose nlink is being dropped */ static void v9fs_dec_count (struct inode *inode) { +struct v9fs_session_info *v9ses =v9fs_inode2v9ses (inode); + +if (!(v9ses->cache & (CACHE_META |CACHE_LOOSE ))) +return ;if (!S_ISDIR (inode->i_mode) || inode->i_nlink >2 )drop_nlink (inode); }
Greg Kroah-Hartman
maintainerPATCH 1739/2077 power: supply: bq257xx: Fix VSYSMIN clamping logic
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexey Charkov <[email protected]>
commit b6c6b9260a92dacef6edef8e93bc2767b86b1dfe upstream.
The minimal system voltage (VSYSMIN) is meant to protect the battery from dangerous over-discharge. When the device tree provides a value for the minimum design voltage of the battery, the user should not be allowed to set a lower VSYSMIN, as that would defeat the purpose of this protection.
Flip the clamping logic when setting VSYSMIN to ensure that battery design voltage is respected.
--- drivers/power/supply/bq257xx_charger.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/power/supply/bq257xx_charger.c +3 -4
@@ -128,9 +128,8 @@ static int bq25703_get_min_vsys(struct b* @vsys: voltage value to set in uV. * * This function takes a requested minimum system voltage value, clamps -* it between the minimum supported value by the charger and a user -* defined minimum system value, and then writes the value to the -* appropriate register. +* it between the user defined minimum system value and the maximum supported +* value by the charger, and then writes the value to the appropriate register. * * Return: Returns 0 on success or error if an error occurs. */
@@ -139,7 +138,7 @@ static int bq25703_set_min_vsys(struct bunsigned int reg;int vsys_min = pdata->vsys_min; - vsys =clamp (vsys,BQ25703_MINVSYS_MIN_UV , vsys_min); + vsys =clamp (vsys, vsys_min,BQ25703_MINVSYS_MAX_UV ); reg = ((vsys -BQ25703_MINVSYS_MIN_UV ) /BQ25703_MINVSYS_STEP_UV ); reg =FIELD_PREP (BQ25703_MINVSYS_MASK , reg);
Greg Kroah-Hartman
maintainerPATCH 1740/2077 scsi: smartpqi: Use shost_to_hba() in pqi_scan_finished()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Martin Wilck <[email protected]>
commit 57db1307afb1f83d45f5ff53b93f8d040100d13e upstream.
shost_to_hba() is used everywhere except to obtain pqi_ctrl_info from shosti, except in pqi_scan_finished(), where shost_priv() is used. This causes one pointer dereference to be missed, as shost->hostdata is a pointer in smartpqi. Fix it.
--- drivers/scsi/smartpqi/smartpqi_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/smartpqi/smartpqi_init.c +1 -1
@@ -2642,7 +2642,7 @@ static int pqi_scan_finished(struct Scsi {struct pqi_ctrl_info *ctrl_info; - ctrl_info =shost_priv (shost); + ctrl_info =shost_to_hba (shost);return !mutex_is_locked (&ctrl_info->scan_mutex); }
Greg Kroah-Hartman
maintainerPATCH 1741/2077 kho: make sure scratch size is always aligned by CMA_MIN_ALIGNMENT_BYTES
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pratyush Yadav (Google) <[email protected]>
commit 0e39380a7316122e1b00012b3f3cd3e318b3e7d3 upstream.
When using scratch_scale, the scratch sizes are rounded up to CMA_MIN_ALIGNMENT_BYTES since they will be released as MIGRATE_CMA. This is not done when using fixed scratch sizes via command line. This can result in user specifying a size which is not aligned, and thus kernel releasing a pageblock that is only partially scratch.
Do the rounding up for both cases in scratch_size_update().
--- kernel/liveupdate/kexec_handover.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-)
kernel/liveupdate/kexec_handover.c +21 -11
@@ -593,20 +593,30 @@ early_param("kho_scratch", kho_parse_scrstatic void __init scratch_size_update (void ) { -phys_addr_t size; +/* +* If fixed sizes are not provided via command line, calculate them +* now. +*/ +if (scratch_scale) { +phys_addr_t size; -if (!scratch_scale) -return ; + size =memblock_reserved_kern_size (ARCH_LOW_ADDRESS_LIMIT , +NUMA_NO_NODE ); + size = size * scratch_scale /100 ; + scratch_size_lowmem = size; - size =memblock_reserved_kern_size (ARCH_LOW_ADDRESS_LIMIT , -NUMA_NO_NODE ); - size = size * scratch_scale /100 ; - scratch_size_lowmem =round_up (size,CMA_MIN_ALIGNMENT_BYTES ); + size =memblock_reserved_kern_size (MEMBLOCK_ALLOC_ANYWHERE , +NUMA_NO_NODE ); + size = size * scratch_scale /100 - scratch_size_lowmem; + scratch_size_global = size; + } - size =memblock_reserved_kern_size (MEMBLOCK_ALLOC_ANYWHERE , -NUMA_NO_NODE ); - size = size * scratch_scale /100 - scratch_size_lowmem; - scratch_size_global =round_up (size,CMA_MIN_ALIGNMENT_BYTES ); +/* +* Scratch areas are released as MIGRATE_CMA. Round them up to the right +* size. +*/ + scratch_size_lowmem =round_up (scratch_size_lowmem,CMA_MIN_ALIGNMENT_BYTES ); + scratch_size_global =round_up (scratch_size_global,CMA_MIN_ALIGNMENT_BYTES ); }static phys_addr_t __init scratch_size_node (int nid)
Greg Kroah-Hartman
maintainerPATCH 1742/2077 scsi: sas: Skip opt_sectors when DMA reports no real optimization hint
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ionut Nechita <[email protected]>
commit be8fcd4a8217a916344c88a4b1b84f5736dda17e upstream.
sas_host_setup() unconditionally sets shost->opt_sectors from dma_opt_mapping_size().
When the IOMMU is disabled or in passthrough mode and no DMA ops provide an opt_mapping_size callback, dma_opt_mapping_size() returns min(dma_max_mapping_size(), SIZE_MAX) which equals dma_max_mapping_size() — a hard upper bound, not an optimization hint.
On a Dell PowerEdge R750 with mpt3sas (Broadcom SAS3816, FW 33.15.00.00) and intel_iommu=off the following values are observed:
dma_opt_mapping_size() = dma_max_mapping_size() (no real hint)
shost->max_sectors = 32767
opt_sectors = min(32767, huge >> 9) = 32767
optimal_io_size = 32767 << 9 = 16776704
→ round_down(16776704, 4096) = 16773120The SAS disk (SAMSUNG MZILT800HBHQ0D3) does not report an Optimal Transfer Length in VPD page B0, so sdkp->opt_xfer_blocks remains 0.
sd_revalidate_disk() then uses min_not_zero(0, opt_sectors) = opt_sectors, propagating the bogus value into the block device's optimal_io_size (visible as OPT-IO = 16773120 in lsblk --topology).
mkfs.xfs picks up optimal_io_size and minimum_io_size and computes:
swidth = 16773120 / 4096 = 4095
sunit = 8192 / 4096 = 2
Since 4095 % 2 != 0, XFS rejects the geometry:
SB stripe unit sanity check failed
This makes it impossible to create XFS filesystems (e.g. for /var/lib/docker) during system bootstrap.
Fix this by introducing a sas_dma_setup_opt_sectors() helper that sets opt_sectors only when dma_opt_mapping_size() is strictly less than dma_max_mapping_size(), indicating a genuine DMA optimization constraint.
The helper computes min(opt_sectors, max_sectors) first, then rounds down to a power of two so that filesystem geometry calculations always produce clean results.
When the two DMA values are equal, no backend provided a real hint, so opt_sectors stays at 0 ("no preference").
[mkp: implemented hch's suggestion]
--- drivers/scsi/scsi_transport_sas.c | 41 +++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-)
drivers/scsi/scsi_transport_sas.c +36 -5
@@ -27,6 +27,7 @@#include <linux/module.h> #include <linux/jiffies.h> #include <linux/err.h> +#include <linux/log2.h> #include <linux/slab.h> #include <linux/string.h> #include <linux/blkdev.h>
@@ -220,12 +221,45 @@ static int sas_bsg_initialize(struct Scs* SAS host attributes */ +/* +* Set shost->opt_sectors from the DMA optimal mapping size, but only +* when dma_opt_mapping_size() is strictly less than dma_max_mapping_size(), +* indicating a genuine optimization hint from an IOMMU or DMA backend. +* When the two are equal (e.g. IOMMU disabled / passthrough), no real +* hint exists, so leave opt_sectors at 0 to avoid bogus optimal_io_size +* values that break filesystem geometry (e.g. mkfs.xfs stripe alignment). +*/ +static void sas_dma_setup_opt_sectors (struct Scsi_Host *shost) +{ +struct device *dma_dev = shost->dma_dev; +size_t opt =dma_opt_mapping_size (dma_dev); +size_t max =dma_max_mapping_size (dma_dev); +unsigned int opt_sectors; + +/* opt >= max means no real hint was provided by the DMA layer */ +if (opt >= max) +return ; + +/* Clamp to max_sectors to avoid overflow in sector arithmetic */ + opt_sectors = min_t(unsigned int, opt >> SECTOR_SHIFT, + shost->max_sectors); + +/* Guard against zero before rounddown_pow_of_two() */ +if (!opt_sectors) +return ; + +/* +* Round down to power-of-two so filesystem geometry calculations +* (e.g. XFS stripe width/unit) always produce clean divisors. +*/ + shost->opt_sectors =rounddown_pow_of_two (opt_sectors); +} +static int sas_host_setup (struct transport_container *tc,struct device *dev,struct device *cdev) {struct Scsi_Host *shost =dev_to_shost (dev);struct sas_host_attrs *sas_host =to_sas_host_attrs (shost); -struct device *dma_dev = shost->dma_dev;INIT_LIST_HEAD (&sas_host->rphy_list);mutex_init (&sas_host->lock);
@@ -237,10 +271,7 @@ static int sas_host_setup(struct transpodev_printk (KERN_ERR , dev,"fail to a bsg device %d\n" , shost->host_no); -if (dma_dev->dma_mask) { - shost->opt_sectors = min_t(unsigned int, shost->max_sectors, -dma_opt_mapping_size (dma_dev) >>SECTOR_SHIFT ); - } +sas_dma_setup_opt_sectors (shost);return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 1743/2077 openrisc: Add full instruction cache invalidate functions
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stafford Horne <[email protected]>
commit 1be031de802ba486a7605b52eda825f128b026e2 upstream.
Add functions to invalidate all cache lines which we will use for static_key patching.
On OpenRISC there is no instruction to invalidate an entire cache so we loop and invalidate cache lines one by one. This is not extremely expensive on OpenRISC as we usually have only a few hundred cache lines.
I considered using the invalidate cache page or range functions. However, tracking which ranges need invalidation would have been more expensive than flushing all pages.
--- arch/openrisc/include/asm/cacheflush.h | 4 ++++ arch/openrisc/kernel/smp.c | 21 +++++++++++++++++++++ arch/openrisc/mm/cache.c | 16 ++++++++++++++++ 3 files changed, 41 insertions(+)
arch/openrisc/include/asm/cacheflush.h +4 -0
@@ -26,6 +26,7 @@ extern void local_icache_page_inv(structextern void local_dcache_range_flush (unsigned long start,unsigned long end);extern void local_dcache_range_inv (unsigned long start,unsigned long end);extern void local_icache_range_inv (unsigned long start,unsigned long end); +extern void local_icache_all_inv (void );/* * Data cache flushing always happen on the local cpu. Instruction cache
@@ -35,10 +36,13 @@ extern void local_icache_range_inv(unsig#ifndef CONFIG_SMP #define dcache_page_flush (page) local_dcache_page_flush(page)#define icache_page_inv (page) local_icache_page_inv(page) +#define icache_all_inv () local_icache_all_inv()#else /* CONFIG_SMP */ #define dcache_page_flush (page) local_dcache_page_flush(page)#define icache_page_inv (page) smp_icache_page_inv(page) +#define icache_all_inv () smp_icache_all_inv()extern void smp_icache_page_inv (struct page *page); +extern void smp_icache_all_inv (void );#endif /* CONFIG_SMP */ /*
arch/openrisc/kernel/smp.c +21 -0
@@ -346,3 +346,24 @@ void smp_icache_page_inv(struct page *paon_each_cpu (ipi_icache_page_inv, page,1 ); }EXPORT_SYMBOL (smp_icache_page_inv); + +static void ipi_icache_all_inv (void *arg) +{ +local_icache_all_inv (); +} + +void smp_icache_all_inv (void ) +{ +if (num_online_cpus () <2 ) { +local_icache_all_inv (); +return ; + } + +/* +* Ensure stores complete before we request remote icaches +* to invalidate. +*/ +mb (); + +on_each_cpu (ipi_icache_all_inv,NULL ,1 ); +}
arch/openrisc/mm/cache.c +16 -0
@@ -63,6 +63,22 @@ void local_icache_page_inv(struct page * }EXPORT_SYMBOL (local_icache_page_inv); +void local_icache_all_inv (void ) +{ +if (cpu_cache_is_present (SPR_UPR_ICP )) { +unsigned long iccfgr =mfspr (SPR_ICCFGR ); +unsigned long sets =1 << ((iccfgr &SPR_ICCFGR_NCS ) >>3 ); +unsigned long block_size =16 << ((iccfgr &SPR_ICCFGR_CBS ) >>7 ); +unsigned long paddr =0 ; +unsigned long end = sets * block_size; + +while (paddr < end) { +mtspr (SPR_ICBIR , paddr); + paddr += block_size; + } + } +} +void local_dcache_range_flush (unsigned long start,unsigned long end) {cache_loop (start, end,SPR_DCBFR ,SPR_UPR_DCP );
Greg Kroah-Hartman
maintainerPATCH 1744/2077 mtd: maps: vmu-flash: fix fault in unaligned fixup
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Fuchs <[email protected]>
commit 79d1661502c6e4b6f626185cef72cf2fa78116e1 upstream.
Use kzalloc_obj() / kzalloc_objs() to allocate the memcard structs, instead of kmalloc_obj() / kmalloc_objs() to prevent access to uninitialized data.
Fixes runtime error: Fault in unaligned fixup: 0000 [#1] at mtd_get_fact_prot_info.
--- drivers/mtd/maps/vmu-flash.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/mtd/maps/vmu-flash.c +3 -3
@@ -609,7 +609,7 @@ static int vmu_connect(struct maple_devi basic_flash_data =be32_to_cpu (mdev->devinfo.function_data[c -1 ]); - card = kmalloc_obj(struct memcard); + card = kzalloc_obj(struct memcard);if (!card) { error = -ENOMEM ; goto fail_nomem;
@@ -627,13 +627,13 @@ static int vmu_connect(struct maple_devi* Not sure there are actually any multi-partition devices in the * real world, but the hardware supports them, so, so will we */ - card->parts = kmalloc_objs(struct vmupart, card->partitions); + card->parts = kzalloc_objs(struct vmupart, card->partitions);if (!card->parts) { error = -ENOMEM ; goto fail_partitions; } - card->mtd = kmalloc_objs(struct mtd_info, card->partitions); + card->mtd = kzalloc_objs(struct mtd_info, card->partitions);if (!card->mtd) { error = -ENOMEM ; goto fail_mtd_info;
Greg Kroah-Hartman
maintainerPATCH 1745/2077 ocfs2: use kzalloc for quota recovery bitmap allocation
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tristan Madani <[email protected]>
commit 93c8c6ea90be9e9df8fe14048ad4e3caad0770a6 upstream.
ocfs2 quota recovery allocates a bitmap buffer with kmalloc and does not fully initialize it. This can lead to use of uninitialized bits during quota recovery from a corrupted filesystem image.
Use kzalloc instead to ensure the bitmap is zero-initialized.
--- fs/ocfs2/quota_local.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ocfs2/quota_local.c +1 -1
@@ -302,7 +302,7 @@ static int ocfs2_add_recovery_chunk(struif (!rc)return -ENOMEM ; rc->rc_chunk = chunk; - rc->rc_bitmap =kmalloc (sb->s_blocksize,GFP_NOFS ); + rc->rc_bitmap =kzalloc (sb->s_blocksize,GFP_NOFS );if (!rc->rc_bitmap) {kfree (rc);return -ENOMEM ;
Greg Kroah-Hartman
maintainerPATCH 1746/2077 mtd: rawnand: pl353: fix probe resource allocation
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bastien Curutchet <[email protected]>
commit 19ed11aee966d91beebdef9d32ce926474872f79 upstream.
During probe(), the devm_ioremap() is called with the parent device instead of the current one. So when the module is unloaded, the register area isn't released.
Target the pl35x device in the devm_ioremap() instead of its parent.
--- drivers/mtd/nand/raw/pl35x-nand-controller.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/pl35x-nand-controller.c +1 -1
@@ -1155,7 +1155,7 @@ static int pl35x_nand_probe(struct platf nfc->controller.ops = &pl35x_nandc_ops;INIT_LIST_HEAD (&nfc->chips); - nfc->conf_regs =devm_ioremap_resource (&smc_amba->dev, &smc_amba->res); + nfc->conf_regs =devm_ioremap_resource (nfc->dev, &smc_amba->res);if (IS_ERR (nfc->conf_regs))return PTR_ERR (nfc->conf_regs);
Greg Kroah-Hartman
maintainerPATCH 1747/2077 net/9p: fix infinite loop in p9_client_rpc on fatal signal
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vasiliy Kovalev <[email protected]>
commit 6b4f48728faa8bb514368f7eacda05565dea8696 upstream.
When p9_client_rpc() is called with type P9_TFLUSH and the transport has no peer (e.g. fd transport backed by pipes with no 9p server), a fatal signal causes an infinite loop:
again:
err = io_wait_event_killable(req->wq, ...)
/* SIGKILL wakes the task, returns -ERESTARTSYS */
if (err == -ERESTARTSYS && c->status == Connected &&
type == P9_TFLUSH) {
sigpending = 1;
clear_thread_flag(TIF_SIGPENDING);
goto again;
}clear_thread_flag() clears TIF_SIGPENDING before jumping back to io_wait_event_killable(). signal_pending_state() checks TIF_SIGPENDING, finds it zero, and the task goes to sleep again. The task can only wake on the next signal delivery that calls signal_wake_up() and sets TIF_SIGPENDING again. When that happens the loop repeats, clears TIF_SIGPENDING, and sleeps again indefinitely.
This is triggered in practice by coredump_wait(): when a thread in a multi-threaded process causes a coredump (e.g. via SIGSYS from Syscall User Dispatch), coredump_wait() sends SIGKILL to all other threads and waits for them to call mm_release(). If one of those threads is blocked in p9_client_rpc() over an fd transport with no peer, it enters the P9_TFLUSH loop and never calls mm_release(), so coredump_wait() stalls forever:
INFO: task syz.0.18:676 blocked for more than 143 seconds.
Not tainted 6.12.77+ #1
task:syz.0.18 state:D stack:27600 pid:676 tgid:673 ppid:630 flags:0x00000004
Call Trace:
<TASK>
context_switch kernel/sched/core.c:5344 [inline]
__schedule+0xcb4/0x5d50 kernel/sched/core.c:6724
__schedule_loop kernel/sched/core.c:6801 [inline]
schedule+0xe5/0x350 kernel/sched/core.c:6816
schedule_timeout+0x253/0x290 kernel/time/timer.c:2593
do_wait_for_common kernel/sched/completion.c:95 [inline]
__wait_for_common+0x409/0x600 kernel/sched/completion.c:116
wait_for_common kernel/sched/completion.c:127 [inline]
wait_for_completion_state+0x1d/0x40 kernel/sched/completion.c:264
coredump_wait fs/coredump.c:448 [inline]
do_coredump+0x854/0x4350 fs/coredump.c:629
get_signal+0x1425/0x2730 kernel/signal.c:2903
arch_do_signal_or_restart+0x81/0x880 arch/x86/kernel/signal.c:337
exit_to_user_mode_loop kernel/entry/common.c:111 [inline]
exit_to_user_mode_prepare include/linux/entry-common.h:328 [inline]
__syscall_exit_to_user_mode_work kernel/entry/common.c:207 [inline]
syscall_exit_to_user_mode+0xf9/0x160 kernel/entry/common.c:218
do_syscall_64+0x102/0x220 arch/x86/entry/common.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
</TASK>Fix: check fatal_signal_pending() before clearing TIF_SIGPENDING in the P9_TFLUSH retry loop. At that point TIF_SIGPENDING is still set, so fatal_signal_pending() works correctly. If a fatal signal is pending, jump to recalc_sigpending to restore TIF_SIGPENDING and return -ERESTARTSYS to the caller.
The same defect is present in stable kernels back to 5.4. On those kernels the infinite loop is broken earlier by a second SIGKILL from the parent process (e.g. kill_and_wait() retrying after a timeout), resulting in a zombie process and a shutdown delay rather than a permanent D-state hang, but the underlying flaw is the same.
Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
Message-ID: <[email protected]>
--- net/9p/client.c | 2 ++ 1 file changed, 2 insertions(+)
net/9p/client.c +2 -0
@@ -600,6 +600,8 @@ again:if (err == -ERESTARTSYS && c->status == Connected && type ==P9_TFLUSH ) { +if (fatal_signal_pending (current)) + goto recalc_sigpending; sigpending =1 ;clear_thread_flag (TIF_SIGPENDING ); goto again;
Greg Kroah-Hartman
maintainerPATCH 1748/2077 mtd: rawnand: fix condition in nand_select_target()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arseniy Krasnov <[email protected]>
commit 8507c2cc9e4fa402401819f44d1e8a5ef4d11d8b upstream.
'cs' here must be in range [0:nanddev_ntargets[.
--- drivers/mtd/nand/raw/nand_base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/nand_base.c +1 -1
@@ -175,7 +175,7 @@ void nand_select_target(struct nand_chip* cs should always lie between 0 and nanddev_ntargets(), when that's * not the case it's a bug and the caller should be fixed. */ -if (WARN_ON (cs >nanddev_ntargets (&chip->base))) +if (WARN_ON (cs >=nanddev_ntargets (&chip->base)))return ; chip->cur_cs = cs;
Greg Kroah-Hartman
maintainerPATCH 1749/2077 ocfs2: avoid moving extents to occupied clusters
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kyle Zeng <[email protected]>
commit 22920541c35a9f23f219038ba5874c843a7c4419 upstream.
For non-auto OCFS2_IOC_MOVE_EXT operations, userspace supplies a physical me_goal. ocfs2_move_extent() initializes new_phys_cpos from that goal and expects ocfs2_probe_alloc_group() to replace it with a free run in the target block group.
The probe currently leaves *phys_cpos unchanged if the scan reaches the end of the group without finding a free run. An occupied goal at the last bit can therefore survive the probe and be passed to __ocfs2_move_extent(), which copies file data into a cluster still owned by another inode before the bitmap is updated.
When the probe does find a free run, it also subtracts move_len from the ending bit. The start of an N-bit run ending at i is i - N + 1, so the current calculation can report the bit immediately before the free run.
Clear *phys_cpos before scanning and use the correct free-run start. Callers already treat a zero result as -ENOSPC, so failed probes no longer continue with an occupied caller-controlled goal.
--- fs/ocfs2/move_extents.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/ocfs2/move_extents.c +3 -1
@@ -534,6 +534,8 @@ static void ocfs2_probe_alloc_group(struu32 base_cpos =ocfs2_blocks_to_clusters (inode->i_sb,le64_to_cpu (gd->bg_blkno)); + *phys_cpos =0 ; +for (i = base_bit; i <le16_to_cpu (gd->bg_bits); i++) { used =ocfs2_test_bit (i, (unsigned long *)gd->bg_bitmap);
@@ -555,7 +557,7 @@ static void ocfs2_probe_alloc_group(stru last_free_bits++;if (last_free_bits == move_len) { - i -= move_len; + i = i - move_len +1 ; *goal_bit = i; *phys_cpos = base_cpos + i;break ;
Greg Kroah-Hartman
maintainerPATCH 1750/2077 ocfs2: fix NULL h_transaction deref in ocfs2_assure_trans_credits
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Bridges <[email protected]>
commit f9ab30c96b0f00c20c6dac93681bdae3a033d229 upstream.
[BUG]
A direct write over unwritten extents can panic the kernel in ocfs2_assure_trans_credits() when the journal aborts during DIO completion. The crash is a general protection fault from a NULL pointer dereference.
[CAUSE]ocfs2_dio_end_io_write() loops over a direct write's unwritten extents, marking each written under a single journal handle. If the journal aborts (for example after an I/O error) while the extent tree is being updated, the handle is left aborted with its transaction pointer cleared. The extent merge treats that failure as not critical and reports success, so the loop keeps using the handle. ocfs2_assure_trans_credits() reads the handle's remaining credits without first checking whether the handle is aborted, and that read dereferences the cleared transaction pointer.
[FIX]
A journal abort is recorded in the handle itself, so callers are expected to test the handle rather than rely on a returned error. Make ocfs2_assure_trans_credits() do that, as the other ocfs2 journal helpers already do, and return -EROFS when the handle is aborted.
--- fs/ocfs2/journal.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/ocfs2/journal.c +5 -1
@@ -473,8 +473,12 @@ bail:*/ int ocfs2_assure_trans_credits (handle_t *handle,int nblocks) { -int old_nblks =jbd2_handle_buffer_credits (handle); +int old_nblks; +if (is_handle_aborted (handle)) +return -EROFS ; + + old_nblks =jbd2_handle_buffer_credits (handle);trace_ocfs2_assure_trans_credits (old_nblks);if (old_nblks >= nblocks)return 0 ;
Greg Kroah-Hartman
maintainerPATCH 1751/2077 ocfs2: fix UBSAN array-index-out-of-bounds in ocfs2_sum_rightmost_rec
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Bridges <[email protected]>
commit 452a8467be8143747292218212671deeb186d2ae upstream.
[BUG]
On-disk corruption setting l_next_free_rec to 0 in an inode's embedded extent list triggers a UBSAN panic on the next write to that file.
[CAUSE]ocfs2_sum_rightmost_rec() computes
i = le16_to_cpu(el->l_next_free_rec) - 1
and accesses el->l_recs[i] without validating i. When l_next_free_rec is 0, i becomes -1; when l_next_free_rec exceeds l_count, i falls past the end of the array. Either case violates the __counted_by_le(l_count) annotation on l_recs[] and triggers UBSAN.
[FIX]
Validate the inode's embedded extent list when the inode is read, in ocfs2_validate_inode_block(): l_count must be non-zero and no larger than the inode block can hold, and l_next_free_rec must not exceed l_count. A corrupt list is rejected at read time, before the b-tree code can index l_recs[] out of bounds.
--- fs/ocfs2/inode.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
fs/ocfs2/inode.c +32 -0
@@ -1582,6 +1582,38 @@ int ocfs2_validate_inode_block(struct su goto bail; } +if (ocfs2_dinode_has_extents (di)) { +struct ocfs2_extent_list *el = &di->id2.i_list; +u16 count =le16_to_cpu (el->l_count); +u16 next_free =le16_to_cpu (el->l_next_free_rec); + +if (count ==0 ) { + rc =ocfs2_error (sb, +"Invalid dinode %llu: extent list l_count is zero\n" , + (unsigned long long )bh->b_blocknr); + goto bail; + } +/* +* The exact capacity depends on i_xattr_inline_size, another +* unvalidated on-disk field. Inline xattrs only shrink the +* list, so the no-xattr maximum is a safe upper bound that a +* valid l_count never exceeds. +*/ +if (count >ocfs2_extent_recs_per_inode (sb)) { + rc =ocfs2_error (sb, +"Invalid dinode %llu: extent list l_count %u exceeds max %u\n" , + (unsigned long long )bh->b_blocknr, count, +ocfs2_extent_recs_per_inode (sb)); + goto bail; + } +if (next_free > count) { + rc =ocfs2_error (sb, +"Invalid dinode %llu: extent list l_next_free_rec %u exceeds l_count %u\n" , + (unsigned long long )bh->b_blocknr, next_free, count); + goto bail; + } + } + rc =0 ; bail:
Greg Kroah-Hartman
maintainerPATCH 1752/2077 ocfs2: add journal NULL check in ocfs2_checkpoint_inode()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
commit a291c77c034b7a81849ce9b71cc9ecda9e587d89 upstream.
During unmount, ocfs2_journal_shutdown() frees the journal and sets osb->journal to NULL. Later, when VFS evicts remaining cached inodes, ocfs2_evict_inode() -> ocfs2_clear_inode() -> ocfs2_checkpoint_inode() -> ocfs2_ci_fully_checkpointed() dereferences osb->journal, causing a NULL pointer dereference.
Fix this by adding a NULL check for osb->journal in ocfs2_checkpoint_inode(). If the journal is NULL, it has already been fully flushed and destroyed during shutdown, so there is nothing to checkpoint.
--- fs/ocfs2/journal.h | 3 +++ 1 file changed, 3 insertions(+)
fs/ocfs2/journal.h +3 -0
@@ -196,6 +196,9 @@ static inline void ocfs2_checkpoint_inodif (ocfs2_mount_local (osb))return ; +if (!osb->journal) +return ; +if (!ocfs2_ci_fully_checkpointed (INODE_CACHE (inode))) {/* WARNING: This only kicks off a single * checkpoint. If someone races you and adds more
Greg Kroah-Hartman
maintainerPATCH 1753/2077 ocfs2: reject dinodes with non-canonical i_mode type
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 5366a017099c6a3c443be908a05f26fd72af12a1 upstream.
Patch series "ocfs2: harden inode validators against forged metadata", v2.
This series adds three structural checks to OCFS2 dinode validation so malformed on-disk fields are rejected before ocfs2_populate_inode() copies them into the in-core inode.
The checks cover:
- i_mode values whose type bits do not name a canonical POSIX file
type;
- non-device dinodes whose id1.dev1.i_rdev field is non-zero; and
- non-inline dinodes that claim non-zero i_size while i_clusters is zero, covering directories unconditionally and regular files on non-sparse volumes.
The normal read path reports these through ocfs2_error(), matching the existing suballoc-slot, inline-data, chain-list, and refcount checks. The online filecheck path uses the same structural predicates but keeps its own reporting contract, returning OCFS2_FILECHECK_ERR_INVALIDINO instead of calling ocfs2_error().
This patch (of 3):
ocfs2_validate_inode_block() currently accepts any non-zero i_mode value. ocfs2_populate_inode() then copies that mode verbatim into inode->i_mode and dispatches on i_mode & S_IFMT to the file/dir/symlink/special_file iops; an unrecognised type falls through to ocfs2_special_file_iops and init_special_inode().
Reject dinodes whose type bits do not name one of the seven canonical POSIX file types. Use fs_umode_to_ftype(), the same generic file-type conversion helper OCFS2 already uses for directory entries, so the accepted inode type set matches the kernel file-type vocabulary instead of open-coding a local switch.
Apply the same structural check to the online filecheck read path. filecheck keeps its own error namespace, so it reports malformed i_mode through the filecheck logger and OCFS2_FILECHECK_ERR_INVALIDINO instead of calling ocfs2_error(), but it must not allow a malformed dinode to proceed into ocfs2_populate_inode().
--- fs/ocfs2/inode.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-)
fs/ocfs2/inode.c +34 -2
@@ -13,6 +13,7 @@#include <linux/pagemap.h> #include <linux/quotaops.h> #include <linux/iversion.h> +#include <linux/fs_dirent.h> #include <asm/byteorder.h>
@@ -64,7 +65,12 @@ static int ocfs2_filecheck_read_inode_blstatic int ocfs2_filecheck_validate_inode_block (struct super_block *sb,struct buffer_head *bh);static int ocfs2_filecheck_repair_inode_block (struct super_block *sb, -struct buffer_head *bh); +struct buffer_head *bh); + +static bool ocfs2_valid_inode_mode (umode_t mode) +{ +return fs_umode_to_ftype (mode) !=FT_UNKNOWN ; +}void ocfs2_set_inode_flags (struct inode *inode) {
@@ -1494,6 +1500,24 @@ int ocfs2_validate_inode_block(struct su goto bail; } +/* +* Reject dinodes whose i_mode does not name one of the seven +* canonical POSIX file types. ocfs2_populate_inode() copies +* i_mode verbatim into inode->i_mode and then dispatches via +* switch (mode & S_IFMT) to file/dir/symlink/special_file iops; +* an unrecognised type falls into ocfs2_special_file_iops with +* init_special_inode(), which interprets i_rdev. Constrain the +* type here so the dispatch only ever sees a value mkfs.ocfs2 / +* VFS can produce. +*/ +if (!ocfs2_valid_inode_mode (le16_to_cpu (di->i_mode))) { + rc =ocfs2_error (sb, +"Invalid dinode #%llu: mode 0%o has unknown file type\n" , + (unsigned long long )bh->b_blocknr, +le16_to_cpu (di->i_mode)); + goto bail; + } +if (le16_to_cpu (di->i_dyn_features) &OCFS2_INLINE_DATA_FL ) {struct ocfs2_inline_data *data = &di->id2.i_data;
@@ -1679,6 +1703,15 @@ static int ocfs2_filecheck_validate_inod (unsigned long long )bh->b_blocknr, le32_to_cpu(di->i_fs_generation)); rc = -OCFS2_FILECHECK_ERR_GENERATION ; + goto bail; + } + +if (!ocfs2_valid_inode_mode (le16_to_cpu (di->i_mode))) { +mlog (ML_ERROR , +"Filecheck: invalid dinode #%llu: mode 0%o has unknown file type\n" , + (unsigned long long )bh->b_blocknr, +le16_to_cpu (di->i_mode)); + rc = -OCFS2_FILECHECK_ERR_INVALIDINO ; } bail:
@@ -1867,4 +1900,3 @@ const struct ocfs2_caching_operations oc .co_io_lock = ocfs2_inode_cache_io_lock, .co_io_unlock = ocfs2_inode_cache_io_unlock, }; -
Greg Kroah-Hartman
maintainerPATCH 1754/2077 ocfs2: reject dinodes whose i_rdev disagrees with the file type
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 51407c2d249987a466416890a5c931a2354a46aa upstream.
id1.dev1.i_rdev is the device-number arm of the ocfs2_dinode id1 union. It is only meaningful for character and block device inodes. For any other user-visible file type the on-disk value must be zero.
ocfs2_populate_inode() currently copies id1.dev1.i_rdev into inode->i_rdev before the S_IFMT switch decides whether the inode is a special file. A non-device inode with a non-zero i_rdev can therefore publish stale or attacker-controlled device state into the in-core inode.
System inodes legitimately use other arms of the same union, so keep the cross-check restricted to non-system inodes. Factor that predicate into a helper and use it in both the normal validator and online filecheck path; filecheck reports the malformed dinode through OCFS2_FILECHECK_ERR_INVALIDINO instead of ocfs2_error().
--- fs/ocfs2/inode.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+)
fs/ocfs2/inode.c +55 -0
@@ -72,6 +72,16 @@ static bool ocfs2_valid_inode_mode(umodereturn fs_umode_to_ftype (mode) !=FT_UNKNOWN ; } +static bool ocfs2_dinode_has_unexpected_rdev (struct ocfs2_dinode *di) +{ +umode_t mode =le16_to_cpu (di->i_mode); + +if (le32_to_cpu (di->i_flags) &OCFS2_SYSTEM_FL ) +return false; + +return !S_ISCHR (mode) && !S_ISBLK (mode) && di->id1.dev1.i_rdev !=0 ; +} +void ocfs2_set_inode_flags (struct inode *inode) {unsigned int flags =OCFS2_I (inode)->ip_attr;
@@ -1518,6 +1528,41 @@ int ocfs2_validate_inode_block(struct su goto bail; } +/* +* id1.dev1.i_rdev is the device-number arm of the id1 union and +* is only meaningful for character and block device inodes. For +* any other regular user-visible file type the on-disk value +* must be zero. ocfs2_populate_inode() currently runs +* +* inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev)); +* +* unconditionally, before the S_IFMT switch decides whether the +* inode is a special file. As a result, an i_rdev value present +* on a non-device inode is silently published into the in-core +* inode; a subsequent forced re-read or in-core mode mutation +* (cluster peer with raw write access to the shared LUN, +* on-disk corruption, or a separately forged dinode) can then +* expose the attacker-controlled device number to +* init_special_inode() without ever showing an unusual i_mode +* at validation time. +* +* System inodes (OCFS2_SYSTEM_FL) legitimately use the bitmap1 +* and journal1 arms of the same union (allocator i_used / +* i_total counters and the journal ij_flags / +* ij_recovery_generation pair); those bytes are not an i_rdev +* and must not be checked here. Restrict the cross-check to +* non-system inodes, which is the full attacker-controllable +* surface. +*/ +if (ocfs2_dinode_has_unexpected_rdev (di)) { + rc =ocfs2_error (sb, +"Invalid dinode #%llu: non-device mode 0%o with i_rdev %llu\n" , + (unsigned long long )bh->b_blocknr, +le16_to_cpu (di->i_mode), + (unsigned long long )le64_to_cpu (di->id1.dev1.i_rdev)); + goto bail; + } +if (le16_to_cpu (di->i_dyn_features) &OCFS2_INLINE_DATA_FL ) {struct ocfs2_inline_data *data = &di->id2.i_data;
@@ -1712,6 +1757,16 @@ static int ocfs2_filecheck_validate_inod (unsigned long long )bh->b_blocknr, le16_to_cpu(di->i_mode)); rc = -OCFS2_FILECHECK_ERR_INVALIDINO ; + goto bail; + } + +if (ocfs2_dinode_has_unexpected_rdev (di)) { +mlog (ML_ERROR , +"Filecheck: invalid dinode #%llu: non-device mode 0%o with i_rdev %llu\n" , + (unsigned long long )bh->b_blocknr, +le16_to_cpu (di->i_mode), + (unsigned long long )le64_to_cpu (di->id1.dev1.i_rdev)); + rc = -OCFS2_FILECHECK_ERR_INVALIDINO ; } bail:
Greg Kroah-Hartman
maintainerPATCH 1755/2077 ocfs2: reject non-inline dinodes with i_size and zero i_clusters
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 7ebc672fab7a76e1e47e0f2fc1ee48118d27fde4 upstream.
On a volume mounted without OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC, a non-inline regular file with non-zero i_size and zero i_clusters is structurally malformed: the extent map declares no allocated clusters yet the size header claims content exists. Keep rejecting that shape, but express it through a shared predicate so the same invariant is available to normal inode reads and online filecheck.
The same zero-cluster shape is also malformed for non-inline directories. ocfs2 directory growth allocates backing storage before advancing i_size, and ocfs2_dir_foreach_blk_el() later walks until ctx->pos reaches i_size_read(inode). A forged directory dinode with a huge i_size and no clusters would repeatedly fail on holes while advancing through the claimed size.
Sparse regular files remain exempt: on sparse-alloc volumes, truncate can legitimately grow i_size without allocating clusters. System inodes and inline-data dinodes also retain their separate storage rules.
Mirror the check in ocfs2_filecheck_validate_inode_block() as well. filecheck reports through its own error namespace, so malformed size/cluster state is logged as a filecheck invalid-inode result rather than via ocfs2_error(), but it must not proceed into ocfs2_populate_inode().
--- fs/ocfs2/inode.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+)
fs/ocfs2/inode.c +60 -0
@@ -82,6 +82,24 @@ static bool ocfs2_dinode_has_unexpected_return !S_ISCHR (mode) && !S_ISBLK (mode) && di->id1.dev1.i_rdev !=0 ; } +static bool ocfs2_dinode_has_size_without_clusters (struct super_block *sb, +struct ocfs2_dinode *di) +{ +umode_t mode =le16_to_cpu (di->i_mode); + +if (le32_to_cpu (di->i_flags) &OCFS2_SYSTEM_FL ) +return false; +if (le16_to_cpu (di->i_dyn_features) &OCFS2_INLINE_DATA_FL ) +return false; +if (!le64_to_cpu (di->i_size) ||le32_to_cpu (di->i_clusters)) +return false; + +if (S_ISDIR (mode)) +return true; + +return !ocfs2_sparse_alloc (OCFS2_SB (sb)) &&S_ISREG (mode); +} +void ocfs2_set_inode_flags (struct inode *inode) {unsigned int flags =OCFS2_I (inode)->ip_attr;
@@ -1563,6 +1581,33 @@ int ocfs2_validate_inode_block(struct su goto bail; } +/* +* Non-inline directories must not have i_size without allocated +* clusters: directory growth adds storage before advancing i_size, +* and readdir walks i_size block-by-block. A forged directory +* with zero clusters and a huge i_size would repeatedly fault on +* holes while advancing through the claimed size. +* +* Non-inline regular files have the same invariant on non-sparse +* volumes. Sparse regular files are different: truncate can +* legitimately grow i_size without allocating clusters, so keep +* the sparse-alloc carveout for S_IFREG only. System inodes and +* inline-data dinodes have their own storage rules. +*/ +if (ocfs2_dinode_has_size_without_clusters (sb, di)) { +if (S_ISDIR (le16_to_cpu (di->i_mode))) + rc =ocfs2_error (sb, +"Invalid dinode #%llu: directory i_size %llu with i_clusters 0 and no inline-data flag\n" , + (unsigned long long )bh->b_blocknr, + (unsigned long long )le64_to_cpu (di->i_size)); +else + rc =ocfs2_error (sb, +"Invalid dinode #%llu: regular file i_size %llu with i_clusters 0 and no inline-data flag on non-sparse volume\n" , + (unsigned long long )bh->b_blocknr, + (unsigned long long )le64_to_cpu (di->i_size)); + goto bail; + } +if (le16_to_cpu (di->i_dyn_features) &OCFS2_INLINE_DATA_FL ) {struct ocfs2_inline_data *data = &di->id2.i_data;
@@ -1767,6 +1812,21 @@ static int ocfs2_filecheck_validate_inodle16_to_cpu (di->i_mode), (unsigned long long)le64_to_cpu(di->id1.dev1.i_rdev)); rc = -OCFS2_FILECHECK_ERR_INVALIDINO ; + goto bail; + } + +if (ocfs2_dinode_has_size_without_clusters (sb, di)) { +if (S_ISDIR (le16_to_cpu (di->i_mode))) +mlog (ML_ERROR , +"Filecheck: invalid dinode #%llu: directory i_size %llu with i_clusters 0 and no inline-data flag\n" , + (unsigned long long )bh->b_blocknr, + (unsigned long long )le64_to_cpu (di->i_size)); +else +mlog (ML_ERROR , +"Filecheck: invalid dinode #%llu: regular file i_size %llu with i_clusters 0 and no inline-data flag on non-sparse volume\n" , + (unsigned long long )bh->b_blocknr, + (unsigned long long )le64_to_cpu (di->i_size)); + rc = -OCFS2_FILECHECK_ERR_INVALIDINO ; } bail:
Greg Kroah-Hartman
maintainerPATCH 1756/2077 fpga: dfl: add bounds check in dfh_get_param_size()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Alba Vives <[email protected]>
commit 9e8bc49f91f3f81d957c4f1c1f09fe94e2f88f6a upstream.
dfh_get_param_size() can return a parameter size larger than the feature region because the loop bounds check is evaluated before incrementing size. If the EOP (End of Parameters) bit is set in the same iteration, the inflated size is returned without re-validation against max.
This can cause create_feature_instance() to call memcpy_fromio() with a size exceeding the ioremap'd region when a malicious FPGA device provides crafted DFHv1 parameter headers.
Add a bounds check after the size increment to ensure the accumulated size never exceeds the feature boundary.
--- drivers/fpga/dfl.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/fpga/dfl.c +2 -0
@@ -1132,6 +1132,8 @@ static int dfh_get_param_size(void __iomreturn -EINVAL ; size += next *sizeof (u64); +if (size > max) +return -EINVAL ;if (FIELD_GET (DFHv1_PARAM_HDR_NEXT_EOP, v))return size;
Greg Kroah-Hartman
maintainerPATCH 1757/2077 bus: mhi: host: pci_generic: Fix the physical function check
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manivannan Sadhasivam <[email protected]>
commit 32845111e8ea6ef5e837b6d25080e69e99bd4561 upstream.
Commit b4d01c5b9a9d ("bus: mhi: host: pci_generic: Read SUBSYSTEM_VENDOR_ID for VF's to check status") added the check for physical function by checking for 'pdev->is_physfn. But 'pdev->is_physfn' is only set for the physical function of a SR-IOV capable device. But for the non-SR-IOV device this variable will be 0. So this check ended up breaking the health check functionality for all non-SR-IOV devices.
Fix it by checking for '!pdev->is_virtfn' to make sure that the check is only skipped for virtual functions.
--- drivers/bus/mhi/host/pci_generic.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/bus/mhi/host/pci_generic.c +10 -10
@@ -1247,7 +1247,7 @@ static void mhi_pci_recovery_work(structdev_warn (&pdev->dev,"device recovery started\n" ); -if (pdev->is_physfn) +if (!pdev->is_virtfn)timer_delete (&mhi_pdev->health_check_timer);pm_runtime_forbid (&pdev->dev);
@@ -1277,7 +1277,7 @@ static void mhi_pci_recovery_work(structset_bit (MHI_PCI_DEV_STARTED , &mhi_pdev->status); -if (pdev->is_physfn) +if (!pdev->is_virtfn)mod_timer (&mhi_pdev->health_check_timer, jiffies +HEALTH_CHECK_PERIOD );return ;
@@ -1368,7 +1368,7 @@ static int mhi_pci_probe(struct pci_dev mhi_cntrl_config = info->config;/* Initialize health check monitor only for Physical functions */ -if (pdev->is_physfn) +if (!pdev->is_virtfn)timer_setup (&mhi_pdev->health_check_timer, health_check,0 ); mhi_cntrl = &mhi_pdev->mhi_cntrl;
@@ -1390,7 +1390,7 @@ static int mhi_pci_probe(struct pci_dev mhi_cntrl->mru = info->mru_default; mhi_cntrl->name = info->name; -if (pdev->is_physfn) +if (!pdev->is_virtfn) mhi_pdev->reset_on_remove = info->reset_on_remove;if (info->edl_trigger)
@@ -1439,7 +1439,7 @@ static int mhi_pci_probe(struct pci_devset_bit (MHI_PCI_DEV_STARTED , &mhi_pdev->status);/* start health check */ -if (pdev->is_physfn) +if (!pdev->is_virtfn)mod_timer (&mhi_pdev->health_check_timer, jiffies +HEALTH_CHECK_PERIOD );/* Allow runtime suspend only if both PME from D3Hot and M3 are supported */
@@ -1468,7 +1468,7 @@ static void mhi_pci_remove(struct pci_depm_runtime_forbid (&pdev->dev);pci_disable_sriov (pdev); -if (pdev->is_physfn) +if (!pdev->is_virtfn)timer_delete_sync (&mhi_pdev->health_check_timer);cancel_work_sync (&mhi_pdev->recovery_work);
@@ -1500,7 +1500,7 @@ static void mhi_pci_reset_prepare(structdev_info (&pdev->dev,"reset\n" ); -if (pdev->is_physfn) +if (!pdev->is_virtfn)timer_delete (&mhi_pdev->health_check_timer);/* Clean up MHI state */
@@ -1546,7 +1546,7 @@ static void mhi_pci_reset_done(struct pc }set_bit (MHI_PCI_DEV_STARTED , &mhi_pdev->status); -if (pdev->is_physfn) +if (!pdev->is_virtfn)mod_timer (&mhi_pdev->health_check_timer, jiffies +HEALTH_CHECK_PERIOD ); }
@@ -1612,7 +1612,7 @@ static int __maybe_unused mhi_pci_runtiif (test_and_set_bit (MHI_PCI_DEV_SUSPENDED , &mhi_pdev->status))return 0 ; -if (pdev->is_physfn) +if (!pdev->is_virtfn)timer_delete (&mhi_pdev->health_check_timer);cancel_work_sync (&mhi_pdev->recovery_work);
@@ -1665,7 +1665,7 @@ static int __maybe_unused mhi_pci_runtim }/* Resume health check */ -if (pdev->is_physfn) +if (!pdev->is_virtfn)mod_timer (&mhi_pdev->health_check_timer, jiffies +HEALTH_CHECK_PERIOD );/* It can be a remote wakeup (no mhi runtime_get), update access time */
Greg Kroah-Hartman
maintainerPATCH 1758/2077 bus: mhi: ep: Protect mhi_ep_handle_syserr() in the error path
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manivannan Sadhasivam <[email protected]>
commit 519ddf194b158b91439319f6b977b8a465fda0fb upstream.
All the callers of mhi_ep_handle_syserr() except mhi_ep_process_cmd_ring() are holding the 'state_lock' to avoid the race in setting the MHI state. So do the same in mhi_ep_process_cmd_ring() for sanity.
--- drivers/bus/mhi/ep/main.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/bus/mhi/ep/main.c +2 -0
@@ -232,7 +232,9 @@ static int mhi_ep_process_cmd_ring(struc ret =mhi_ep_create_device (mhi_cntrl, ch_id);if (ret) {dev_err (dev,"Error creating device for channel (%u)\n" , ch_id); +mutex_lock (&mhi_cntrl->state_lock);mhi_ep_handle_syserr (mhi_cntrl); +mutex_unlock (&mhi_cntrl->state_lock);return ret; } }
Greg Kroah-Hartman
maintainerPATCH 1759/2077 net: thunderbolt: Fix frags[] overflow by bounding frame_count
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maoyi Xie <[email protected]>
commit 55d9895f89970501fe126d1026b586b04a224c27 upstream.
tbnet_poll() assembles a multi-frame ThunderboltIP packet into one skb. The first frame goes into the skb linear area and every further frame is added as a page fragment.
skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page, hdr_size, frame_size, TBNET_RX_PAGE_SIZE - hdr_size);
A packet of frame_count frames therefore ends up with frame_count - 1 fragments. tbnet_check_frame() only bounds the peer supplied frame_count to TBNET_RING_SIZE / 4 (64), which is far above MAX_SKB_FRAGS (17 by default). A peer that sends a packet of 19 or more small frames pushes nr_frags past MAX_SKB_FRAGS, so skb_add_rx_frag() writes past skb_shinfo()->frags[] and corrupts memory after the shared info.
Tighten the start of packet bound to MAX_SKB_FRAGS + 1 so a packet can never produce more fragments than frags[] can hold. This matches the recent skb frags overflow fixes in other receive paths, for example f0813bcd2d9d ("net:
wwan: t7xx: fix potential skb->frags overflow in RX path") and 600dc40554dc ("net: usb: cdc-phonet: fix skb frags[] overflow in rx_complete()").
--- drivers/net/thunderbolt/main.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/thunderbolt/main.c +6 -2
@@ -787,8 +787,12 @@ static bool tbnet_check_frame(struct tbnreturn true; } -/* Start of packet, validate the frame header */ -if (frame_count ==0 || frame_count >TBNET_RING_SIZE /4 ) { +/* Start of packet, validate the frame header. tbnet_poll() puts the +* first frame in the skb linear area and every further frame in a page +* fragment, so a packet may not span more than MAX_SKB_FRAGS + 1 frames +* without overflowing skb_shinfo()->frags[]. +*/ +if (frame_count ==0 || frame_count >MAX_SKB_FRAGS +1 ) { net->stats.rx_length_errors++;return false; }
Greg Kroah-Hartman
maintainerPATCH 1760/2077 fpga: microchip-spi: fix zero header_size OOB read in mpf_ops_parse_header()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Alba Vives <[email protected]>
commit 43a1974da6bc7ce8f4d1dc1d03d56997428c29c3 upstream.
mpf_ops_parse_header() reads header_size from the bitstream at MPF_HEADER_SIZE_OFFSET (24). When header_size is zero, the expression *(buf + header_size - 1) reads one byte before the buffer start.
Since initial_header_size is set to 71 in mpf_ops, the fpga-mgr core guarantees the buffer is large enough to reach MPF_HEADER_SIZE_OFFSET. The only real gap is the zero header_size case, which cannot be resolved by providing a larger buffer, so return -EINVAL.
--- drivers/fpga/microchip-spi.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/fpga/microchip-spi.c +3 -0
@@ -116,6 +116,9 @@ static int mpf_ops_parse_header(struct f } header_size = *(buf +MPF_HEADER_SIZE_OFFSET ); +if (!header_size) +return -EINVAL ; +if (header_size > count) { info->header_size = header_size;return -EAGAIN ;
Greg Kroah-Hartman
maintainerPATCH 1761/2077 s390/pkey: Check length in PKEY_VERIFYPROTK ioctl
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Holger Dengler <[email protected]>
commit b3d4ab2d7df9426f7f1d3671d7e2108f2ca6e970 upstream.
Explicitly check the buffer length request structure provided by user-space and fail, if it exceeds the buffer size.
--- drivers/s390/crypto/pkey_api.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/s390/crypto/pkey_api.c +7 -0
@@ -334,6 +334,13 @@ static int pkey_ioctl_verifyprotk(structif (copy_from_user (&kvp, uvp,sizeof (kvp)))return -EFAULT ; +if (kvp.protkey.len >sizeof (kvp.protkey.protkey)) { +PKEY_DBF_ERR ("%s protkey length %u exceeds protkey buffer size\n" , + __func__, kvp.protkey.len); +memzero_explicit (&kvp,sizeof (kvp)); +return -EINVAL ; + } + keytype =pkey_aes_bitsize_to_keytype (8 * kvp.protkey.len);if (!keytype) { PKEY_DBF_ERR("%s unknown/unsupported protkey length %u\n",
Greg Kroah-Hartman
maintainerPATCH 1762/2077 s390/pkey: Check length in pkey_pckmo handler implementation
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Holger Dengler <[email protected]>
commit 1ac287e2af9a9112fe271427ef45eceb26bce8b4 upstream.
Explicitly check the length of the target buffer in the pkey_pckmo implementation of the key_to_protkey() handler function. The handler function fails, if the generated output data exceeds the length of the provided target buffer.
--- drivers/s390/crypto/pkey_pckmo.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/s390/crypto/pkey_pckmo.c +4 -0
@@ -257,6 +257,10 @@ static int pckmo_key2protkey(const u8 *k goto out;break ; } +if (t->len > *protkeylen) { + rc = -EINVAL ; + goto out; + }memcpy (protkey, t->protkey, t->len); *protkeylen = t->len; *protkeytype = t->keytype;
Greg Kroah-Hartman
maintainerPATCH 1763/2077 mtd: spi-nor: swp: Improve locking user experience
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Miquel Raynal <[email protected]>
commit e1d456b26bf23e30db305a6184e8abd9ab68bbf2 upstream.
In the case of the first block being locked (or the few first blocks), if the user want to fully unlock the device it has two possibilities:
- either it asks to unlock the entire device, and this works;
- or it asks to unlock just the block(s) that are currently locked, which fails.
It fails because the conditions "can_be_top" and "can_be_bottom" are true. Indeed, in this case, we unlock everything, so the TB bit does not matter. However in the current implementation, use_top would be true (as this is the favourite option) and lock_len, which in practice should be reduced down to 0, is set to "nor->params->size - (ofs + len)" which is a positive number. This is wrong.
An easy way is to simply add an extra condition. In the unlock() path, if we can achieve the same result from both sides, it means we unlock everything and lock_len must simply be 0. A comment is added to clarify that logic.
--- drivers/mtd/spi-nor/swp.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/mtd/spi-nor/swp.c +9 -2
@@ -282,8 +282,15 @@ static int spi_nor_sr_unlock(struct spi_/* Prefer top, if both are valid */ use_top = can_be_top; -/* lock_len: length of region that should remain locked */ -if (use_top) +/* +* lock_len: length of region that should remain locked. +* +* When can_be_top and can_be_bottom booleans are true, both adjacent +* regions are unlocked, thus the entire flash can be unlocked. +*/ +if (can_be_top && can_be_bottom) + lock_len =0 ; +else if (use_top) lock_len = nor->params->size - (ofs + len);else lock_len = ofs;
Greg Kroah-Hartman
maintainerPATCH 1764/2077 mtd: spi-nor: spansion: use die erase for multi-die devices only
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takahiro Kuwano <[email protected]>
commit 306e443156b82a2a14a3f33da908c303be45529c upstream.
Die erase opcode is supported in multi-die devices only. For single die devices, default chip erase opcode must be used.
In s25hx_t_late_init(), die erase opcode is set only when the device is multi-die.
--- drivers/mtd/spi-nor/spansion.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mtd/spi-nor/spansion.c +3 -1
@@ -674,7 +674,9 @@ static int s25hx_t_late_init(struct spi_ params->ready = cypress_nor_sr_ready_and_clear;cypress_nor_ecc_init (nor); - params->die_erase_opcode =SPINOR_OP_CYPRESS_DIE_ERASE ; +if (params->n_dice >1 ) + params->die_erase_opcode =SPINOR_OP_CYPRESS_DIE_ERASE ; +return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 1765/2077 mtd: rawnand: Pause continuous reads at block boundaries
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Miquel Raynal <[email protected]>
commit 8e4531667d718e2e9b193928cf9b2497fa0d01ef upstream.
Some chips do not support sequential cached reads past block boundaries, like Winbond. In practice when using UBI, this should very rarely happen, but let's make sure it never happens.
--- drivers/mtd/nand/raw/nand_base.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/mtd/nand/raw/nand_base.c +12 -12
@@ -1216,32 +1216,32 @@ static int nand_lp_exec_read_page_op(strreturn nand_exec_op (chip, &op); } -static unsigned int rawnand_last_page_of_lun (unsigned int pages_per_lun,unsigned int lun) +static unsigned int rawnand_last_page_of_block (unsigned int ppb,unsigned int block) { -/* lun is expected to be very small */ -return (lun * pages_per_lun) + pages_per_lun -1 ; +/* block is expected to be very small */ +return (block * ppb) + ppb -1 ; }static void rawnand_cap_cont_reads (struct nand_chip *chip) {struct nand_memory_organization *memorg; -unsigned int ppl, first_lun, last_lun; +unsigned int ppb, first_block, last_block; memorg =nanddev_get_memorg (&chip->base); - ppl = memorg->pages_per_eraseblock * memorg->eraseblocks_per_lun; - first_lun = chip->cont_read.first_page / ppl; - last_lun = chip->cont_read.last_page / ppl; - -/* Prevent sequential cache reads across LUN boundaries */ -if (first_lun != last_lun) - chip->cont_read.pause_page =rawnand_last_page_of_lun (ppl, first_lun); + ppb = memorg->pages_per_eraseblock; + first_block = chip->cont_read.first_page / ppb; + last_block = chip->cont_read.last_page / ppb; + +/* Prevent sequential cache reads across block boundaries */ +if (first_block != last_block) + chip->cont_read.pause_page =rawnand_last_page_of_block (ppb, first_block);else chip->cont_read.pause_page = chip->cont_read.last_page;if (chip->cont_read.first_page == chip->cont_read.pause_page) { chip->cont_read.first_page++; chip->cont_read.pause_page =min (chip->cont_read.last_page, -rawnand_last_page_of_lun (ppl, first_lun +1 )); +rawnand_last_page_of_block (ppb, first_block +1 )); }if (chip->cont_read.first_page >= chip->cont_read.last_page)
Greg Kroah-Hartman
maintainerPATCH 1766/2077 openrisc: Fix jump_label smp syncing
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stafford Horne <[email protected]>
commit aca063c9024522e4e5b9a9d1927433f6a01785a3 upstream.
The original commit 8c30b0018f9d ("openrisc: Add jump label support") copies from arm64 and does not properly consider how icache invalidation on remote cores works in OpenRISC. On OpenRISC remote icaches need to be invalidated otherwise static key's may remain state after updating.
Fix SMP cache syncing by:
1. Properly invalidate remote core icaches on SMP systems by using icache_all_inv. The old code uses kick_all_cpus_sync() which runs a no-op IPI function call on remote CPU's which does execute a lot of code and flushes many cache lines in the process, but does not flush all and it's not correct on OpenRISC.
2. For architectures that do not have WRITETHROUGH caches be sure to flush the dcache after patching.
To test this I first reproduced the issue using a custom test module [0]. The test confirmed that some icache lines maintained stale static_key code sequences after calling static_branch_enable(). After this patch there are no longer jump_label coherency issues.
[0] https://github.com/stffrdhrn/or1k-utils/tree/master/tests/smp_static_key_test
--- arch/openrisc/kernel/jump_label.c | 2 +- arch/openrisc/kernel/patching.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-)
arch/openrisc/kernel/jump_label.c +1 -1
@@ -47,5 +47,5 @@ bool arch_jump_label_transform_queue(strvoid arch_jump_label_transform_apply (void ) { -kick_all_cpus_sync (); +icache_all_inv (); }
arch/openrisc/kernel/patching.c +3 -0
@@ -49,6 +49,9 @@ static int __patch_insn_write(void *addr waddr =patch_map (addr,FIX_TEXT_POKE0 ); ret =copy_to_kernel_nofault (waddr, &insn,OPENRISC_INSN_SIZE ); +if (!IS_ENABLED (CONFIG_DCACHE_WRITETHROUGH )) +local_dcache_range_flush ((unsigned long )waddr, + (unsigned long )waddr +OPENRISC_INSN_SIZE );local_icache_range_inv ((unsigned long )waddr, (unsigned long )waddr +OPENRISC_INSN_SIZE );
Greg Kroah-Hartman
maintainerPATCH 1767/2077 mtd: maps: vmu-flash: fix NULL pointer dereference in initialization
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Fuchs <[email protected]>
commit 357e3b8e3a8769ba36eb8ec5e053e4825f1a9329 upstream.
The mtd_info contains a struct device, which must be linked to its parent. Without this, the initialization of the MTD fails with a NULL pointer dereference.
--- drivers/mtd/maps/vmu-flash.c | 1 + 1 file changed, 1 insertion(+)
drivers/mtd/maps/vmu-flash.c +1 -0
@@ -547,6 +547,7 @@ static void vmu_queryblocks(struct maple mpart->partition = card->partition; mtd_cur->priv = mpart; mtd_cur->owner =THIS_MODULE ; + mtd_cur->dev.parent = &mdev->dev; pcache = kzalloc_obj(struct vmu_cache);if (!pcache)
Greg Kroah-Hartman
maintainerPATCH 1768/2077 taskstats: retain dead thread stats in TGID queries
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yiyang Chen <[email protected]>
commit b3e4fbb04220efc3bc022bcf31b5689d39c6b111 upstream.
Patch series "taskstats: fix TGID dead-thread stat retention", v3.
This series fixes a taskstats TGID aggregation bug where fields added in the TGID query path were not preserved after thread exit, and adds a kselftest covering the regression.
The first patch keeps the cached TGID aggregate used for dead threads in step with the fields already accumulated for live threads, and also fixes the final TGID exit notification emitted when group_dead is true.
The second patch adds a kselftest that verifies TGID CPU stats do not regress after a worker thread exits and has been reaped.
This patch (of 2):
fill_stats_for_tgid() builds TGID stats from two sources: the cached aggregate in signal->stats and a scan of the live threads in the group.
However, fill_tgid_exit() only accumulates delay accounting into signal->stats. This means that once a thread exits, TGID queries lose the fields that fill_stats_for_tgid() adds for live threads.
This gap was introduced incrementally by two earlier changes that extended fill_stats_for_tgid() but did not make the corresponding update to fill_tgid_exit():
- commit 8c733420bdd5 ("taskstats: add e/u/stime for TGID command") added ac_etime, ac_utime, and ac_stime to the TGID query path.
- commit b663a79c1915 ("taskstats: add context-switch counters") added nvcsw and nivcsw to the TGID query path.
As a result, those fields were accounted for live threads in TGID queries, but were dropped from the cached TGID aggregate after thread exit. The final TGID exit notification emitted when group_dead is true also copies that cached aggregate, so it loses the same fields.
Factor the per-task TGID accumulation into tgid_stats_add_task() and use it in both fill_stats_for_tgid() and fill_tgid_exit(). This keeps the cached aggregate used for dead threads aligned with the live-thread accumulation used by TGID queries.
--- kernel/taskstats.c | 62 ++++++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 29 deletions(-)
kernel/taskstats.c +33 -29
@@ -210,13 +210,39 @@ static int fill_stats_for_pid(pid_t pid,return 0 ; } +static void tgid_stats_add_task (struct taskstats *stats, +struct task_struct *tsk,u64 now_ns) +{ +u64 delta, utime, stime; + +/* +* Each accounting subsystem calls its functions here to +* accumulate its per-task stats for tsk, into the per-tgid structure +* +* per-task-foo(stats, tsk); +*/ +delayacct_add_tsk (stats, tsk); + +/* calculate task elapsed time in nsec */ + delta = now_ns - tsk->start_time; +/* Convert to micro seconds */ +do_div (delta,NSEC_PER_USEC ); + stats->ac_etime += delta; + +task_cputime (tsk, &utime, &stime); + stats->ac_utime +=div_u64 (utime,NSEC_PER_USEC ); + stats->ac_stime +=div_u64 (stime,NSEC_PER_USEC ); + + stats->nvcsw += tsk->nvcsw; + stats->nivcsw += tsk->nivcsw; +} +static int fill_stats_for_tgid (pid_t tgid,struct taskstats *stats) {struct task_struct *tsk, *first;unsigned long flags;int rc = -ESRCH ; -u64 delta, utime, stime; -u64 start_time; +u64 now_ns;/* * Add additional stats from live tasks except zombie thread group
@@ -233,30 +259,12 @@ static int fill_stats_for_tgid(pid_t tgielse memset (stats,0 ,sizeof (*stats)); - start_time =ktime_get_ns (); + now_ns =ktime_get_ns ();for_each_thread (first, tsk) {if (tsk->exit_state)continue ; -/* -* Accounting subsystem can call its functions here to -* fill in relevant parts of struct taskstsats as follows -* -* per-task-foo(stats, tsk); -*/ -delayacct_add_tsk (stats, tsk); - -/* calculate task elapsed time in nsec */ - delta = start_time - tsk->start_time; -/* Convert to micro seconds */ -do_div (delta,NSEC_PER_USEC ); - stats->ac_etime += delta; - -task_cputime (tsk, &utime, &stime); - stats->ac_utime +=div_u64 (utime,NSEC_PER_USEC ); - stats->ac_stime +=div_u64 (stime,NSEC_PER_USEC ); - stats->nvcsw += tsk->nvcsw; - stats->nivcsw += tsk->nivcsw; +tgid_stats_add_task (stats, tsk, now_ns); }unlock_task_sighand (first, &flags);
@@ -275,18 +283,14 @@ out:static void fill_tgid_exit (struct task_struct *tsk) {unsigned long flags; +u64 now_ns;spin_lock_irqsave (&tsk->sighand->siglock, flags);if (!tsk->signal->stats) goto ret; -/* -* Each accounting subsystem calls its functions here to -* accumalate its per-task stats for tsk, into the per-tgid structure -* -* per-task-foo(tsk->signal->stats, tsk); -*/ -delayacct_add_tsk (tsk->signal->stats, tsk); + now_ns =ktime_get_ns (); +tgid_stats_add_task (tsk->signal->stats, tsk, now_ns); ret:spin_unlock_irqrestore (&tsk->sighand->siglock, flags);return ;
Greg Kroah-Hartman
maintainerPATCH 1769/2077 irqchip/crossbar: Use correct index in crossbar_domain_free()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bhargav Joshi <[email protected]>
commit 043db005a8d6932dc7d217c86307e9af0bc10ddc upstream.
crossbar_domain_free() resets the domain data and then uses the nulled out irq_data->hwirq member as index to reset the irq_map[] entry and to write the relevant crossbar register with a safe entry. That means it never frees the correct index and keeps the crossbar register connection to the source interrupt active.
If it would not reset the domain data, then this would be even worse as irq_data->hwirq holds the source interrupt number, but both the map and register index need the corresponding GIC SPI number and not the source interrupt number. This might even result in an out of bounds access as the source interrupt number can be higher than the maximal index space.
Fix this by using the GIC SPI index from the parent domain's irq_data.
--- drivers/irqchip/irq-crossbar.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/irqchip/irq-crossbar.c +7 -2
@@ -158,9 +158,14 @@ static void crossbar_domain_free(structfor (i =0 ; i < nr_irqs; i++) {struct irq_data *d =irq_domain_get_irq_data (domain, virq + i); +/* +* irq_map[] is indexed by GIC SPI number. The parent domain's +* hwirq contains the GIC interrupt number (GIC SPI + +* GIC_IRQ_START). +*/ + cb->irq_map[d->parent_data->hwirq -GIC_IRQ_START ] =IRQ_FREE ; + cb->write (d->parent_data->hwirq -GIC_IRQ_START , cb->safe_map);irq_domain_reset_irq_data (d); - cb->irq_map[d->hwirq] =IRQ_FREE ; - cb->write (d->hwirq, cb->safe_map); }raw_spin_unlock (&cb->lock);irq_domain_free_irqs_parent (domain, virq, nr_irqs);
Greg Kroah-Hartman
maintainerPATCH 1770/2077 tpm: restore timeout for key creation commands
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Baoli Zhang <[email protected]>
commit de59d78e64039baa5fed455ddb905ba8263e7ede upstream.
Commit 207696b17f38 ("tpm: use a map for tpm2_calc_ordinal_duration()") inadvertently reduced the timeout for TPM2 key creation commands (CREATE_PRIMARY, CREATE, CREATE_LOADED) from 300 seconds to 30 seconds.
This causes intermittent timeout failures, with several failures observed across hundreds of test runs on some Intel platforms using Infineon SLB9670 and SLB9672 TPM modules. Restore the timeout to 300 seconds to avoid spurious failures.
--- drivers/char/tpm/tpm2-cmd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/char/tpm/tpm2-cmd.c +3 -3
@@ -71,9 +71,9 @@ static const struct { {TPM2_CC_HIERARCHY_CHANGE_AUTH, 2000}, {TPM2_CC_GET_CAPABILITY, 750}, {TPM2_CC_NV_READ, 2000}, - {TPM2_CC_CREATE_PRIMARY, 30000}, - {TPM2_CC_CREATE, 30000}, - {TPM2_CC_CREATE_LOADED, 30000}, + {TPM2_CC_CREATE_PRIMARY, 300000}, + {TPM2_CC_CREATE, 300000}, + {TPM2_CC_CREATE_LOADED, 300000}, };/**
Greg Kroah-Hartman
maintainerPATCH 1771/2077 tpm: tpm_tis_spi: Use wait_woken() in wait_for_tmp_stat()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jarkko Sakkinen <[email protected]>
commit c0c9cfb3b75def8bf200a2d4db09015806acfeaf upstream.
wait_event_interruptible_timeout() evaluates its condition after setting the current task state to TASK_INTERRUPTIBLE.
With CONFIG_DEBUG_ATOMIC_SLEEP this triggers a warning when the IRQ wait path is used:
tpm_tis_status()
tpm_tis_spi_read_bytes()
tpm_tis_spi_transfer_full()
spi_bus_lock()
mutex_lock()Address this with the following measures:
1. Call wait_tpm_stat_cond() only while tasking is running.
2. Use wait_woken() to wait for changes.
--- drivers/char/tpm/tpm_tis_core.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-)
drivers/char/tpm/tpm_tis_core.c +21 -14
@@ -66,8 +66,8 @@ static int wait_for_tpm_stat(struct tpm_ bool check_cancel) {struct tpm_tis_data *priv =dev_get_drvdata (&chip->dev); +DEFINE_WAIT_FUNC (wait, woken_wake_function);unsigned long stop; -long rc;u8 status;bool canceled = false;u8 sts_mask;
@@ -87,23 +87,30 @@ static int wait_for_tpm_stat(struct tpm_/* process status changes with irq support */ if (sts_mask) { ret = -ETIME ; +add_wait_queue (queue, &wait); again: +if (wait_for_tpm_stat_cond (chip, sts_mask, check_cancel, + &canceled)) { + ret = canceled ? -ECANCELED :0 ; + goto out; + } + timeout = stop - jiffies;if ((long )timeout <=0 ) -return -ETIME ; - rc =wait_event_interruptible_timeout (*queue, -wait_for_tpm_stat_cond (chip, sts_mask, check_cancel, - &canceled), - timeout); -if (rc >0 ) { -if (canceled) -return -ECANCELED ; - ret =0 ; - } -if (rc == -ERESTARTSYS &&freezing (current)) { -clear_thread_flag (TIF_SIGPENDING ); - goto again; + goto out; + +if (signal_pending (current)) { +if (freezing (current)) { +clear_thread_flag (TIF_SIGPENDING ); + goto again; + } + goto out; } + +wait_woken (&wait,TASK_INTERRUPTIBLE , timeout); + goto again; +out: +remove_wait_queue (queue, &wait); }if (ret)
Greg Kroah-Hartman
maintainerPATCH 1772/2077 tpm: tpm2-sessions: wait for async KPP completion in tpm_buf_append_salt
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 73851a7c43dfa52d2ed9415889b33daf85da0ed9 upstream.
tpm_buf_append_salt() in drivers/char/tpm/tpm2-sessions.c calls crypto_kpp_generate_public_key() and crypto_kpp_compute_shared_secret() without installing a completion callback, discards both return values, and immediately frees the kpp_request via kpp_request_free(). When the resolved ecdh-nist-p256 KPP backend is asynchronous (atmel-ecc, HPRE, keembay-ocs), either operation returns -EINPROGRESS and the deferred completion worker dereferences the freed request.
The path fires automatically from the hwrng_fillfn kernel thread via tpm_get_random -> tpm2_get_random -> tpm2_start_auth_session -> tpm_buf_append_salt on every entropy poll, without any userland action.
Install crypto_req_done as the completion callback, wrap both KPP operations in crypto_wait_req(), and propagate errors to the caller. The wait is a no-op for synchronous backends.
--- drivers/char/tpm/tpm2-sessions.c | 45 +++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 11 deletions(-)
drivers/char/tpm/tpm2-sessions.c +34 -11
@@ -489,15 +489,17 @@ static void tpm2_KDFe(u8 z[EC_PT_SZ], cosha256_final (&sctx, out); } -static void tpm_buf_append_salt (struct tpm_buf *buf,struct tpm_chip *chip, -struct tpm2_auth *auth) +static int tpm_buf_append_salt (struct tpm_buf *buf,struct tpm_chip *chip, +struct tpm2_auth *auth) {struct crypto_kpp *kpp;struct kpp_request *req; +DECLARE_CRYPTO_WAIT (wait);struct scatterlist s[2 ], d[1 ];struct ecdh p = {0 };u8 encoded_key[EC_PT_SZ ], *x, *y;unsigned int buf_len; +int rc;/* secret is two sized points */ tpm_buf_append_u16 (buf, (EC_PT_SZ +2 )*2 );
@@ -520,14 +522,15 @@ static void tpm_buf_append_salt(struct t kpp =crypto_alloc_kpp ("ecdh-nist-p256" ,CRYPTO_ALG_INTERNAL ,0 );if (IS_ERR (kpp)) {dev_err (&chip->dev,"crypto ecdh allocation failed\n" ); -return ; +return PTR_ERR (kpp); } buf_len =crypto_ecdh_key_len (&p);if (sizeof (encoded_key) < buf_len) {dev_err (&chip->dev,"salt buffer too small needs %d\n" , buf_len); - goto out; + rc = -EINVAL ; + goto err_free_kpp; }crypto_ecdh_encode_key (encoded_key, buf_len, &p);/* this generates a random private key */
@@ -535,11 +538,17 @@ static void tpm_buf_append_salt(struct t/* salt is now the public point of this private key */ req =kpp_request_alloc (kpp,GFP_KERNEL ); -if (!req) - goto out; +if (!req) { + rc = -ENOMEM ; + goto err_free_kpp; + } +kpp_request_set_callback (req,CRYPTO_TFM_REQ_MAY_BACKLOG , + crypto_req_done, &wait);kpp_request_set_input (req,NULL ,0 );kpp_request_set_output (req, s,EC_PT_SZ *2 ); -crypto_kpp_generate_public_key (req); + rc =crypto_wait_req (crypto_kpp_generate_public_key (req), &wait); +if (rc) + goto err_free_req;/* * we're not done: now we have to compute the shared secret * which is our private key multiplied by the tpm_key public
@@ -551,8 +560,9 @@ static void tpm_buf_append_salt(struct tkpp_request_set_input (req, s,EC_PT_SZ *2 );sg_init_one (d, auth->salt,EC_PT_SZ );kpp_request_set_output (req, d,EC_PT_SZ ); -crypto_kpp_compute_shared_secret (req); -kpp_request_free (req); + rc =crypto_wait_req (crypto_kpp_compute_shared_secret (req), &wait); +if (rc) + goto err_free_req;/* * pass the shared secret through KDFe for salt. Note salt
@@ -562,8 +572,16 @@ static void tpm_buf_append_salt(struct t*/ tpm2_KDFe (auth->salt,"SECRET" , x, chip->null_ec_key_x, auth->salt); - out: +kpp_request_free (req);crypto_free_kpp (kpp); +return 0 ; + +err_free_req: +kpp_request_free (req); + +err_free_kpp: +crypto_free_kpp (kpp); +return rc; }/**
@@ -1018,7 +1036,12 @@ int tpm2_start_auth_session(struct tpm_ctpm_buf_append (&buf, auth->our_nonce,sizeof (auth->our_nonce));/* append encrypted salt and squirrel away unencrypted in auth */ -tpm_buf_append_salt (&buf, chip, auth); + rc =tpm_buf_append_salt (&buf, chip, auth); +if (rc) { +tpm2_flush_context (chip, null_key); +tpm_buf_destroy (&buf); + goto out; + }/* session type (HMAC, audit or policy) */ tpm_buf_append_u8 (&buf,TPM2_SE_HMAC );
Greg Kroah-Hartman
maintainerPATCH 1773/2077 sunrpc: fix uninitialized xprt_create_args structure
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hongling Zeng <[email protected]>
commit 17d90b68c3a3d7d7e95b49e1fe9381a723f637a8 upstream.
The xprt_create_args structure is allocated on the stack without initialization in rpc_sysfs_xprt_switch_add_xprt_store(). While some fields are manually populated, critical fields like srcaddr, bc_xps, and flags contain uninitialized stack garbage.
This can lead to:
1. Kernel panic when xs_setup_xprt() dereferences garbage srcaddr
2. Information leak if srcaddr points to sensitive stack data
3. Unpredictable behavior if flags has random bits set
The fix is to zero-initialize the structure to ensure all unused fields are NULL/0, preventing the transport setup code from acting on garbage data.
--- net/sunrpc/sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sunrpc/sysfs.c +1 -1
@@ -327,7 +327,7 @@ static ssize_t rpc_sysfs_xprt_switch_add {struct rpc_xprt_switch *xprt_switch =rpc_sysfs_xprt_switch_kobj_get_xprt (kobj); -struct xprt_create xprt_create_args; +struct xprt_create xprt_create_args = {};struct rpc_xprt *xprt, *new;if (!xprt_switch)
Greg Kroah-Hartman
maintainerPATCH 1774/2077 dmaengine: tegra: Fix burst size calculation
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kartik Rajput <[email protected]>
commit 4651df83b6c796daead3447e8fd874322918ee4f upstream.
Currently, the Tegra GPC DMA hardware requires the transfer length to be a multiple of the max burst size configured for the channel. When a client requests a transfer where the length is not evenly divisible by the configured max burst size, the DMA hangs with partial burst at the end.
Fix this by reducing the burst size to the largest power-of-2 value that evenly divides the transfer length. For example, a 40-byte transfer with a 16-byte max burst will now use an 8-byte burst (40 / 8 = 5 complete bursts) instead of causing a hang.
This issue was observed with the PL011 UART driver where TX DMA transfers of arbitrary lengths were stuck.
--- drivers/dma/tegra186-gpc-dma.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/dma/tegra186-gpc-dma.c +7 -0
@@ -825,6 +825,13 @@ static unsigned int get_burst_size(struc* len to calculate the optimum burst size */ burst_byte = burst_size ? burst_size * slave_bw : len; + +/* +* Find the largest burst size that evenly divides the transfer length. +* The hardware requires the transfer length to be a multiple of the +* burst size - partial bursts are not supported. +*/ + burst_byte =min (burst_byte,1U <<__ffs (len)); burst_mmio_width = burst_byte /4 ;if (burst_mmio_width <TEGRA_GPCDMA_MMIOSEQ_BURST_MIN )