7.1.5-rc1 review
Subsystems (15)
Greg Kroah-Hartman
maintainerPATCH 1083/2077 regcache: Do not overwrite error code when finalizing cache after error
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Francesco Lavra <[email protected]>
[ Upstream commit 9108f7fa493b4c88cbc09503e0c164244456bad5 ]
During regcache initialization, if an error occurs in the cache_ops->populate callback, and if cache operations include an exit callback, the error code from populate() is overwritten with the return value from exit(). This hides the error condition from the caller of regcache_init(), and can cause NULL pointer dereferences when the regcache is later accessed.
--- drivers/base/regmap/regcache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/regmap/regcache.c +1 -1
@@ -245,7 +245,7 @@ int regcache_init(struct regmap *map, const struct regmap_config *config)if (map->cache_ops->exit) {dev_dbg (map->dev,"Destroying %s cache\n" , map->cache_ops->name); map->lock (map->lock_arg); - ret = map->cache_ops->exit (map); + map->cache_ops->exit (map); map->unlock (map->lock_arg); } err_free_reg_defaults:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1084/2077 drm/i915: clear CRTC color blob pointers after dropping refs
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit 31f077088e0faae6be8377741f356dea1b94ba46 ]
intel_crtc_put_color_blobs() drops the CRTC color blob references, but leaves the corresponding pointers unchanged.
This can matter in intel_crtc_prepare_cleared_state(), which frees the old CRTC hw state before calling intel_dp_tunnel_atomic_clear_stream_bw(). The latter can fail while looking up the DP tunnel group state, for example with -EDEADLK.
If that happens, the function returns without completing the cleared state preparation. The failed atomic state will then be cleared by the atomic core and intel_crtc_free_hw_state() can be called again for the same state, dropping the same blob references again.
Clear the blob pointers after dropping the references so repeated cleanup of the same CRTC hw state is safe.
--- drivers/gpu/drm/i915/display/intel_atomic.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/gpu/drm/i915/display/intel_atomic.c +6 -0
@@ -289,6 +289,12 @@ static void intel_crtc_put_color_blobs(struct intel_crtc_state *crtc_state)drm_property_blob_put (crtc_state->pre_csc_lut);drm_property_blob_put (crtc_state->post_csc_lut); + + crtc_state->hw.degamma_lut =NULL ; + crtc_state->hw.gamma_lut =NULL ; + crtc_state->hw.ctm =NULL ; + crtc_state->pre_csc_lut =NULL ; + crtc_state->post_csc_lut =NULL ; }void intel_crtc_free_hw_state (struct intel_crtc_state *crtc_state)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1085/2077 drm/xe: Fix wa_oob codegen recipe for external module builds
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Hellström <[email protected]>
[ Upstream commit 92dc59ab2a09097cdf249e0288ff9b69261761c6 ]
When building with 'make M=drivers/gpu/drm/xe modules', kbuild invokes scripts/Makefile.build with obj=., causing $(obj) to expand to '.'. Make normalizes './xe_gen_wa_oob' to 'xe_gen_wa_oob' when constructing the $^ automatic variable (target name normalization), so the recipe command becomes just 'xe_gen_wa_oob ...' without any path prefix, and the shell cannot find the tool.
Fix by replacing $^ with explicit $(obj)/xe_gen_wa_oob and $(src)/<rules-file> references in both wa_oob recipe commands. In recipe strings, make does not apply target name normalization, so $(obj)/xe_gen_wa_oob correctly expands to './xe_gen_wa_oob' and the shell can execute it. This matches the pattern already used by other DRM drivers (e.g. radeon's mkregtable).
--- drivers/gpu/drm/xe/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/xe/Makefile +2 -2
@@ -16,14 +16,14 @@ subdir-ccflags-y += -I$(obj) -I$(src) hostprogs := xe_gen_wa_oob generated_oob := $(obj)/generated/xe_wa_oob.c $(obj)/generated/xe_wa_oob.h quiet_cmd_wa_oob = GEN $(notdir $(generated_oob)) - cmd_wa_oob = mkdir -p $(@D); $^ $(generated_oob) + cmd_wa_oob = mkdir -p $(@D); $(obj)/xe_gen_wa_oob $(src)/xe_wa_oob.rules $(generated_oob) $(obj)/generated/%_wa_oob.c $(obj)/generated/%_wa_oob.h: $(obj)/xe_gen_wa_oob \ $(src)/xe_wa_oob.rules $(call cmd,wa_oob) generated_device_oob := $(obj)/generated/xe_device_wa_oob.c $(obj)/generated/xe_device_wa_oob.h quiet_cmd_device_wa_oob = GEN $(notdir $(generated_device_oob)) - cmd_device_wa_oob = mkdir -p $(@D); $^ $(generated_device_oob) + cmd_device_wa_oob = mkdir -p $(@D); $(obj)/xe_gen_wa_oob $(src)/xe_device_wa_oob.rules $(generated_device_oob) $(obj)/generated/%_device_wa_oob.c $(obj)/generated/%_device_wa_oob.h: $(obj)/xe_gen_wa_oob \ $(src)/xe_device_wa_oob.rules $(call cmd,device_wa_oob)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1086/2077 spi: dw: fix wrong BAUDR setting after resume
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jisheng Zhang <[email protected]>
[ Upstream commit 66b6605bcea7af7aca3d1d858b9c5f14903f9f9a ]
After resuming from suspend to ram, spi transfer stops working. Further debugging shows that the BAUDR register isn't correctly set, this is due to dws->current_freq doesn't match the HW BAUDR setting, specifically, the dws->current_freq equals to speed_hz, but BAUDR is 0. so the dw_spi_set_clk() in below code won't be called:
if (dws->current_freq != speed_hz) {
dw_spi_set_clk(dws, clk_div);
dws->current_freq = speed_hz;
}The mismatch comes from dw_spi_shutdown_chip() when suspending. Fix this mismatch by setting dws->current_freq to 0 as well when clearing BAUDR reg in dw_spi_shutdown_chip().
--- drivers/spi/spi-dw.h | 1 + 1 file changed, 1 insertion(+)
drivers/spi/spi-dw.h +1 -0
@@ -282,6 +282,7 @@ static inline void dw_spi_shutdown_chip(struct dw_spi *dws) {dw_spi_enable_chip (dws,0 );dw_spi_set_clk (dws,0 ); + dws->current_freq =0 ; }extern void dw_spi_set_cs (struct spi_device *spi,bool enable);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1087/2077 i3c: master: Update dev_nack_retry_count under maintenance lock
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
[ Upstream commit ab5f9c5cb527c03790a92142ad368881a9100aaf ]
Protect master->dev_nack_retry_count against concurrent sysfs updates by updating it while holding the bus maintenance lock.
Consequently, combine adjacent return statements into one.
For consistency, read dev_nack_retry_count while holding the bus normaluse lock.
--- drivers/i3c/master.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/i3c/master.c +11 -7
@@ -742,7 +742,14 @@ static DEVICE_ATTR_RW(hotjoin);static ssize_t dev_nack_retry_count_show (struct device *dev,struct device_attribute *attr,char *buf) { -return sysfs_emit (buf,"%u\n" ,dev_to_i3cmaster (dev)->dev_nack_retry_count); +struct i3c_bus *i3cbus =dev_to_i3cbus (dev); +ssize_t ret; + +i3c_bus_normaluse_lock (i3cbus); + ret =sysfs_emit (buf,"%u\n" ,dev_to_i3cmaster (dev)->dev_nack_retry_count); +i3c_bus_normaluse_unlock (i3cbus); + +return ret; } static ssize_t dev_nack_retry_count_store(struct device *dev,
@@ -760,14 +767,11 @@ static ssize_t dev_nack_retry_count_store(struct device *dev,i3c_bus_maintenance_lock (i3cbus); ret = master->ops->set_dev_nack_retry (master, val); +if (!ret) + master->dev_nack_retry_count = val;i3c_bus_maintenance_unlock (i3cbus); -if (ret) -return ret; - - master->dev_nack_retry_count = val; - -return count; +return ret ?: count; }static DEVICE_ATTR_RW (dev_nack_retry_count);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1088/2077 i3c: master: Add missing runtime PM get in dev_nack_retry_count_store()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
[ Upstream commit 79ce29e100ab3de0cad66eb48d32a7de4043e2ae ]
Ensure the device is runtime resumed while updating the retry configuration to avoid accessing the controller while suspended.
Call i3c_master_rpm_get() before accessing the controller in dev_nack_retry_count_store() and release it with i3c_master_rpm_put() afterwards.
--- drivers/i3c/master.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/i3c/master.c +6 -0
@@ -765,12 +765,18 @@ static ssize_t dev_nack_retry_count_store(struct device *dev,if (ret)return ret; + ret =i3c_master_rpm_get (master); +if (ret) +return ret; +i3c_bus_maintenance_lock (i3cbus); ret = master->ops->set_dev_nack_retry (master, val);if (!ret) master->dev_nack_retry_count = val;i3c_bus_maintenance_unlock (i3cbus); +i3c_master_rpm_put (master); +return ret ?: count; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1089/2077 erofs: call erofs_exit_ishare() before rcu_barrier()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gao Xiang <[email protected]>
[ Upstream commit 289cf458a69ccda4a4aee2b0274d233d415814ca ]
Ensure all inode free callbacks have completed before destroying the inode slab cache.
--- fs/erofs/super.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/erofs/super.c +2 -2
@@ -1048,11 +1048,11 @@ static int __init erofs_module_init(void) static void __exit erofs_module_exit(void) {unregister_filesystem (&erofs_fs_type); +erofs_exit_ishare (); -/* Ensure all RCU free inodes / pclusters are safe to be destroyed. */ +/* ensure all delayed rcu free inodes & pclusters are flushed */ rcu_barrier (); -erofs_exit_ishare ();erofs_exit_sysfs ();z_erofs_exit_subsystem ();erofs_exit_shrinker ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1090/2077 ALSA: usb-audio: qcom: Free sideband sg_table objects
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xu Rao <[email protected]>
[ Upstream commit 7d69804a35103a50852eae41bfe6a2e0061c68fd ]
The Qualcomm USB audio offload driver obtains an endpoint transfer-ring table by calling xhci_sideband_get_endpoint_buffer(). This getter passes the endpoint ring to xhci_ring_to_sgtable(), which allocates the outer struct sg_table with kzalloc_obj(*sgt). The event-ring path is
equivalent: xhci_sideband_get_event_buffer() also returns the result of xhci_ring_to_sgtable().
Inside xhci_ring_to_sgtable(), sg_alloc_table_from_pages() separately allocates the scatterlist storage referenced by sgt->sgl. The returned object therefore has two allocation layers: the outer struct sg_table and its internal scatterlist storage.
The Qualcomm caller only invokes sg_free_table(sgt). sg_free_table() releases the scatterlist storage owned by the table, but it does not free the separately allocated outer struct sg_table. The local sgt pointer is then discarded, so every successful endpoint or event-ring query leaks the outer object.
Call kfree(sgt) after sg_free_table(sgt) in both setup paths, after the required page and DMA addresses have been copied out.
--- sound/usb/qcom/qc_audio_offload.c | 2 ++ 1 file changed, 2 insertions(+)
sound/usb/qcom/qc_audio_offload.c +2 -0
@@ -1165,6 +1165,7 @@ uaudio_endpoint_setup(struct snd_usb_substream *subs, tr_pa =page_to_phys (pg); mem_info->dma =sg_dma_address (sgt->sgl);sg_free_table (sgt); +kfree (sgt);/* data transfer ring */ iova = uaudio_iommu_map_pa(MEM_XFER_RING, dma_coherent, tr_pa,
@@ -1234,6 +1235,7 @@ static int uaudio_event_ring_setup(struct snd_usb_substream *subs, er_pa =page_to_phys (pg); mem_info->dma =sg_dma_address (sgt->sgl);sg_free_table (sgt); +kfree (sgt); iova =uaudio_iommu_map_pa (MEM_EVENT_RING , dma_coherent, er_pa,PAGE_SIZE );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1091/2077 xfrm: Fix xfrm state cache insertion race
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Herbert Xu <[email protected]>
[ Upstream commit ddd3d0132920319ac426e12456013eadbae67e15 ]
The xfrm input state cache insertion code checks the validity of the state before acquiring the global xfrm_state_lock. Thus it's possible for someone else to kill the state after it passed the validity check, and then the insertion will add the dead state to the cache.
Fix this by moving the validity check inside the lock.
This entire function is called on the input path, where BH must be off (e.g., the caller of this function xfrm_input acquires its spinlocks without disabling BH).
So there is no need to disable BH here or take the RCU read lock. Remove both and replace them with an assertion that trips if BH is accidentally enabled on some future calling path.
--- net/xfrm/xfrm_state.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
net/xfrm/xfrm_state.c +14 -7
@@ -1207,9 +1207,11 @@ struct xfrm_state *xfrm_input_state_lookup(struct net *net, u32 mark,struct hlist_head *state_cache_input;struct xfrm_state *x =NULL ; +/* BH is always disabled on the input path. */ +lockdep_assert_in_softirq (); + state_cache_input =raw_cpu_ptr (net->xfrm.state_cache_input); -rcu_read_lock ();hlist_for_each_entry_rcu (x, state_cache_input, state_cache_input) { if (x->props.family != family || x->id.spi != spi ||
@@ -1227,20 +1229,25 @@ struct xfrm_state *xfrm_input_state_lookup(struct net *net, u32 mark,xfrm_hash_ptrs_get (net, &state_ptrs); x =__xfrm_state_lookup (&state_ptrs, mark, daddr, spi, proto, family); - -if (x && x->km.state ==XFRM_STATE_VALID ) { -spin_lock_bh (&net->xfrm.xfrm_state_lock); -if (hlist_unhashed (&x->state_cache_input)) { +if (x) { +spin_lock (&net->xfrm.xfrm_state_lock); +if (x->km.state !=XFRM_STATE_VALID ) { +/* +* The state is about to be destroyed. +* +* Don't add it to the cache but still +* return it to the caller. +*/ + }else if (hlist_unhashed (&x->state_cache_input)) {hlist_add_head_rcu (&x->state_cache_input, state_cache_input); }else {hlist_del_rcu (&x->state_cache_input);hlist_add_head_rcu (&x->state_cache_input, state_cache_input); } -spin_unlock_bh (&net->xfrm.xfrm_state_lock); +spin_unlock (&net->xfrm.xfrm_state_lock); } out: -rcu_read_unlock ();return x; }EXPORT_SYMBOL (xfrm_input_state_lookup);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1092/2077 xfrm: annotate data-races around xfrm_policy_count[] and xfrm_policy_default[]
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 68de007d5ac9df0e3f4f187a179c5c842bb5a2be ]
KCSAN reported a data race involving net->xfrm.policy_count access.
Add missing READ_ONCE()/WRITE_ONCE() annotations on xfrm_policy_count and xfrm_policy_default.
--- include/net/xfrm.h | 8 ++++---- net/xfrm/xfrm_policy.c | 24 ++++++++++++------------ net/xfrm/xfrm_user.c | 18 +++++++++--------- 3 files changed, 25 insertions(+), 25 deletions(-)
include/net/xfrm.h +4 -4
@@ -1250,8 +1250,8 @@ int __xfrm_policy_check(struct sock *, int dir, struct sk_buff *skb,static inline bool __xfrm_check_nopolicy (struct net *net,struct sk_buff *skb,int dir) { -if (!net->xfrm.policy_count[dir] && !secpath_exists (skb)) -return net->xfrm.policy_default[dir] ==XFRM_USERPOLICY_ACCEPT ; +if (!READ_ONCE (net->xfrm.policy_count[dir]) && !secpath_exists (skb)) +return READ_ONCE (net->xfrm.policy_default[dir]) ==XFRM_USERPOLICY_ACCEPT ;return false; }
@@ -1351,8 +1351,8 @@ static inline int xfrm_route_forward(struct sk_buff *skb, unsigned short family) {struct net *net =dev_net (skb->dev); -if (!net->xfrm.policy_count[XFRM_POLICY_OUT ] && - net->xfrm.policy_default[XFRM_POLICY_OUT ] ==XFRM_USERPOLICY_ACCEPT ) +if (!READ_ONCE (net->xfrm.policy_count[XFRM_POLICY_OUT ]) && +READ_ONCE (net->xfrm.policy_default[XFRM_POLICY_OUT ]) ==XFRM_USERPOLICY_ACCEPT )return true; return (skb_dst(skb)->flags & DST_NOXFRM) ||
net/xfrm/xfrm_policy.c +12 -12
@@ -685,7 +685,7 @@ static void xfrm_byidx_resize(struct net *net)static inline int xfrm_bydst_should_resize (struct net *net,int dir,int *total) { -unsigned int cnt = net->xfrm.policy_count[dir]; +unsigned int cnt =READ_ONCE (net->xfrm.policy_count[dir]);unsigned int hmask = net->xfrm.policy_bydst[dir].hmask;if (total)
@@ -711,12 +711,12 @@ static inline int xfrm_byidx_should_resize(struct net *net, int total)void xfrm_spd_getinfo (struct net *net,struct xfrmk_spdinfo *si) { - si->incnt = net->xfrm.policy_count[XFRM_POLICY_IN ]; - si->outcnt = net->xfrm.policy_count[XFRM_POLICY_OUT ]; - si->fwdcnt = net->xfrm.policy_count[XFRM_POLICY_FWD ]; - si->inscnt = net->xfrm.policy_count[XFRM_POLICY_IN +XFRM_POLICY_MAX ]; - si->outscnt = net->xfrm.policy_count[XFRM_POLICY_OUT +XFRM_POLICY_MAX ]; - si->fwdscnt = net->xfrm.policy_count[XFRM_POLICY_FWD +XFRM_POLICY_MAX ]; + si->incnt =READ_ONCE (net->xfrm.policy_count[XFRM_POLICY_IN ]); + si->outcnt =READ_ONCE (net->xfrm.policy_count[XFRM_POLICY_OUT ]); + si->fwdcnt =READ_ONCE (net->xfrm.policy_count[XFRM_POLICY_FWD ]); + si->inscnt =READ_ONCE (net->xfrm.policy_count[XFRM_POLICY_IN +XFRM_POLICY_MAX ]); + si->outscnt =READ_ONCE (net->xfrm.policy_count[XFRM_POLICY_OUT +XFRM_POLICY_MAX ]); + si->fwdscnt =READ_ONCE (net->xfrm.policy_count[XFRM_POLICY_FWD +XFRM_POLICY_MAX ]); si->spdhcnt = net->xfrm.policy_idx_hmask; si->spdhmcnt = xfrm_policy_hashmax; }
@@ -2318,7 +2318,7 @@ static void __xfrm_policy_link(struct xfrm_policy *pol, int dir) }list_add (&pol->walk.all, &net->xfrm.policy_all); - net->xfrm.policy_count[dir]++; +WRITE_ONCE (net->xfrm.policy_count[dir], net->xfrm.policy_count[dir] +1 );xfrm_pol_hold (pol); }
@@ -2337,7 +2337,7 @@ static struct xfrm_policy *__xfrm_policy_unlink(struct xfrm_policy *pol, }list_del_init (&pol->walk.all); - net->xfrm.policy_count[dir]--; +WRITE_ONCE (net->xfrm.policy_count[dir], net->xfrm.policy_count[dir] -1 );return pol; }
@@ -3222,7 +3222,7 @@ struct dst_entry *xfrm_lookup_with_ifid(struct net *net,/* To accelerate a bit... */ if (!if_id && ((dst_orig->flags &DST_NOXFRM ) || - !net->xfrm.policy_count[XFRM_POLICY_OUT ])) + !READ_ONCE (net->xfrm.policy_count[XFRM_POLICY_OUT ]))) goto nopol; xdst =xfrm_bundle_lookup (net, fl, family, dir, &xflo, if_id);
@@ -3296,7 +3296,7 @@ struct dst_entry *xfrm_lookup_with_ifid(struct net *net, nopol:if ((!dst_orig->dev || !(dst_orig->dev->flags &IFF_LOOPBACK )) && - net->xfrm.policy_default[dir] ==XFRM_USERPOLICY_BLOCK ) { +READ_ONCE (net->xfrm.policy_default[dir]) ==XFRM_USERPOLICY_BLOCK ) { err = -EPERM ; goto error; }
@@ -3750,7 +3750,7 @@ int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb,const bool is_crypto_offload = sp && (xfrm_input_state (skb)->xso.type ==XFRM_DEV_OFFLOAD_CRYPTO ); -if (net->xfrm.policy_default[dir] ==XFRM_USERPOLICY_BLOCK ) { +if (READ_ONCE (net->xfrm.policy_default[dir]) ==XFRM_USERPOLICY_BLOCK ) {XFRM_INC_STATS (net,LINUX_MIB_XFRMINNOPOLS );return 0 ; }
net/xfrm/xfrm_user.c +9 -9
@@ -2485,9 +2485,9 @@ static int xfrm_notify_userpolicy(struct net *net) } up =nlmsg_data (nlh); - up->in = net->xfrm.policy_default[XFRM_POLICY_IN ]; - up->fwd = net->xfrm.policy_default[XFRM_POLICY_FWD ]; - up->out = net->xfrm.policy_default[XFRM_POLICY_OUT ]; + up->in =READ_ONCE (net->xfrm.policy_default[XFRM_POLICY_IN ]); + up->fwd =READ_ONCE (net->xfrm.policy_default[XFRM_POLICY_FWD ]); + up->out =READ_ONCE (net->xfrm.policy_default[XFRM_POLICY_OUT ]);nlmsg_end (skb, nlh);
@@ -2511,13 +2511,13 @@ static int xfrm_set_default(struct sk_buff *skb, struct nlmsghdr *nlh,struct xfrm_userpolicy_default *up =nlmsg_data (nlh);if (xfrm_userpolicy_is_valid (up->in)) - net->xfrm.policy_default[XFRM_POLICY_IN ] = up->in; +WRITE_ONCE (net->xfrm.policy_default[XFRM_POLICY_IN ], up->in);if (xfrm_userpolicy_is_valid (up->fwd)) - net->xfrm.policy_default[XFRM_POLICY_FWD ] = up->fwd; +WRITE_ONCE (net->xfrm.policy_default[XFRM_POLICY_FWD ], up->fwd);if (xfrm_userpolicy_is_valid (up->out)) - net->xfrm.policy_default[XFRM_POLICY_OUT ] = up->out; +WRITE_ONCE (net->xfrm.policy_default[XFRM_POLICY_OUT ], up->out);rt_genid_bump_all (net);
@@ -2547,9 +2547,9 @@ static int xfrm_get_default(struct sk_buff *skb, struct nlmsghdr *nlh, } r_up =nlmsg_data (r_nlh); - r_up->in = net->xfrm.policy_default[XFRM_POLICY_IN ]; - r_up->fwd = net->xfrm.policy_default[XFRM_POLICY_FWD ]; - r_up->out = net->xfrm.policy_default[XFRM_POLICY_OUT ]; + r_up->in =READ_ONCE (net->xfrm.policy_default[XFRM_POLICY_IN ]); + r_up->fwd =READ_ONCE (net->xfrm.policy_default[XFRM_POLICY_FWD ]); + r_up->out =READ_ONCE (net->xfrm.policy_default[XFRM_POLICY_OUT ]);nlmsg_end (r_skb, r_nlh);return nlmsg_unicast (xfrm_net_nlsk (net, skb), r_skb, portid);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1093/2077 xfrm: validate selector family and prefixlen during match
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 40f0b1047918539f0b0f795ac65e35336b4c2c78 ]
syzbot reported a shift-out-of-bounds in xfrm_selector_match() due to AF_UNSPEC selector with large prefixlen (e.g. 128) matched against IPv4 flow (when XFRM_STATE_AF_UNSPEC is set).
Fix this by:
- Rejecting mismatched families in xfrm_selector_match.
- Returning false in addr4_match if prefixlen > 32.
- Returning false in addr_match if prefixlen > 128 (prevents overflow).
--- include/net/xfrm.h | 7 +++++++ net/xfrm/xfrm_policy.c | 3 +++ 2 files changed, 10 insertions(+)
include/net/xfrm.h +7 -0
@@ -943,6 +943,9 @@ static inline bool addr_match(const void *token1, const void *token2,unsigned int pdw;unsigned int pbi; +if (prefixlen >128 ) +return false; + pdw = prefixlen >>5 ;/* num of whole u32 in prefix */ pbi = prefixlen &0x1f ;/* num of bits in incomplete u32 in prefix */
@@ -967,6 +970,10 @@ static inline bool addr4_match(__be32 a1, __be32 a2, u8 prefixlen)/* C99 6.5.7 (3): u32 << 32 is undefined behaviour */ if (sizeof (long ) ==4 && prefixlen ==0 )return true; + +if (prefixlen >32 ) +return false; +return !((a1 ^ a2) &htonl (~0UL << (32 - prefixlen))); }
net/xfrm/xfrm_policy.c +3 -0
@@ -242,6 +242,9 @@ __xfrm6_selector_match(const struct xfrm_selector *sel, const struct flowi *fl)bool xfrm_selector_match (const struct xfrm_selector *sel,const struct flowi *fl,unsigned short family) { +if (family != sel->family && sel->family !=AF_UNSPEC ) +return false; +switch (family) {case AF_INET :return __xfrm4_selector_match (sel, fl);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1094/2077 perf machine: Use snprintf() for guestmount path construction
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit fe63d3bca288c5bb983304efd5fc3a5ff3183403 ]
machines__findnew() and machines__create_guest_kernel_maps() use sprintf() to build paths by prepending symbol_conf.guestmount. Both write into PATH_MAX stack buffers, but guestmount comes from user configuration and is not length-checked. A guestmount path at or near PATH_MAX causes a stack buffer overflow.
Switch to snprintf() with sizeof() to prevent overflow. The subsequent access()/fopen() calls will fail on a truncated path.
--- tools/perf/util/machine.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tools/perf/util/machine.c +4 -4
@@ -327,7 +327,7 @@ struct machine *machines__findnew(struct machines *machines, pid_t pid)if ((pid !=HOST_KERNEL_ID ) && (pid !=DEFAULT_GUEST_KERNEL_ID ) && (symbol_conf.guestmount)) { -sprintf (path,"%s/%d" , symbol_conf.guestmount, pid); +snprintf (path,sizeof (path),"%s/%d" , symbol_conf.guestmount, pid);if (access (path,R_OK )) {static struct strlist *seen;
@@ -1239,9 +1239,9 @@ int machines__create_guest_kernel_maps(struct machines *machines) namelist[i]->d_name);continue ; } -sprintf (path,"%s/%s/proc/kallsyms" , - symbol_conf.guestmount, - namelist[i]->d_name); +snprintf (path,sizeof (path),"%s/%s/proc/kallsyms" , + symbol_conf.guestmount, + namelist[i]->d_name); ret =access (path,R_OK );if (ret) {pr_debug ("Can't access file %s\n" , path);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1095/2077 perf cs-etm: Validate num_cpu before metadata allocation
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 312d91329b8fc6989a916a3f9a12d0674167b7e4 ]
cs_etm__process_auxtrace_info_full() reads num_cpu from untrusted perf.data and uses it to allocate the metadata pointer array:
metadata = zalloc(sizeof(*metadata) * num_cpu);
On 32-bit, sizeof(*metadata) is 4, so num_cpu = 0x40000000 overflows the multiplication to 0, causing zalloc(0) to return a valid zero-sized allocation followed by out-of-bounds writes in the population loop.
Fix by computing priv_size early and using it to bound num_cpu: each CPU needs at least one u64 metadata entry, so num_cpu cannot exceed the total number of u64 entries in the event's private data area.
--- tools/perf/util/cs-etm.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
tools/perf/util/cs-etm.c +12 -0
@@ -3431,6 +3431,18 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event,/* First the global part */ ptr = (u64 *) auxtrace_info->priv; num_cpu = ptr[CS_PMU_TYPE_CPUS ] &0xffffffff ; + +/* +* Bound num_cpu by the event size: the global header consumes +* CS_ETM_HEADER_SIZE bytes, and each CPU needs at least one u64 +* metadata entry after that. +*/ + priv_size = total_size - event_header_size -INFO_HEADER_SIZE - +CS_ETM_HEADER_SIZE ; +if (num_cpu <=0 || priv_size <=0 || + num_cpu > priv_size / (int )sizeof (u64)) +return -EINVAL ; + metadata =zalloc (sizeof (*metadata) * num_cpu);if (!metadata)return -ENOMEM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1096/2077 perf cs-etm: Require full global header in auxtrace_info size check
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 78d8ba680126f3545e8d0fba667e12d79fd4353b ]
cs_etm__process_auxtrace_info() checks that header.size covers event_header_size + INFO_HEADER_SIZE (16 bytes total), but then accesses ptr[CS_PMU_TYPE_CPUS] at offset 24 from the start of the event. A crafted 16-byte auxtrace_info event passes the size check but reads out-of-bounds.
Include CS_ETM_HEADER_SIZE in the minimum size check so that the global header entries (version, pmu_type_cpus, snapshot) are guaranteed to fit within the event.
--- tools/perf/util/cs-etm-base.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/util/cs-etm-base.c +3 -1
@@ -170,7 +170,9 @@ int cs_etm__process_auxtrace_info(union perf_event *event,u64 *ptr =NULL ;u64 hdr_version; -if (auxtrace_info->header.size < (event_header_size +INFO_HEADER_SIZE )) +/* Ensure priv[] is large enough for the global header entries */ +if (auxtrace_info->header.size < (event_header_size +INFO_HEADER_SIZE + +CS_ETM_HEADER_SIZE ))return -EINVAL ;/* First the global part */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1097/2077 perf cs-etm: Bounds-check CPU in cs_etm__get_queue()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 9a989e60cc6e29d98aed2087425cba53bf4b392d ]
cs_etm__get_queue() indexes etm->queues.queue_array[cpu] without validating that cpu is within nr_queues. When processing AUX_OUTPUT_HW_ID events, the cpu value comes from untrusted perf.data trace payload and flows through cs_etm__process_trace_id_v0_1() and cs_etm__queue_aux_fragment() without bounds checking, allowing an out-of-bounds read with a crafted file.
Add a bounds check in cs_etm__get_queue() and NULL checks in all callers.
Also add NULL checks for queue_array[i].priv in the queue iteration loops in cs_etm__map_trace_id_v0() and cs_etm__process_trace_id_v0_1() — after auxtrace_queues__grow() new entries are zero-initialized so .priv can be NULL. Add a get_cpu_data() NULL check in cs_etm__process_trace_id_v0_1(), matching the existing check in cs_etm__process_trace_id_v0().
--- tools/perf/util/cs-etm.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-)
tools/perf/util/cs-etm.c +23 -2
@@ -292,8 +292,11 @@ static struct cs_etm_queue *cs_etm__get_queue(struct cs_etm_auxtrace *etm, int c {if (etm->per_thread_decoding)return etm->queues.queue_array[0 ].priv; -else -return etm->queues.queue_array[cpu].priv; + +if (cpu <0 || cpu >= (int )etm->queues.nr_queues) +return NULL ; + +return etm->queues.queue_array[cpu].priv; } static int cs_etm__map_trace_id_v0(struct cs_etm_auxtrace *etm, u8 trace_chan_id,
@@ -306,6 +309,9 @@ static int cs_etm__map_trace_id_v0(struct cs_etm_auxtrace *etm, u8 trace_chan_id* queue associated with that CPU so only one decoder is made. */ etmq =cs_etm__get_queue (etm, cpu_metadata[CS_ETM_CPU ]); +if (!etmq) +return -EINVAL ; +if (etmq->format ==UNFORMATTED )return cs_etm__insert_trace_id_node (etmq, trace_chan_id, cpu_metadata);
@@ -318,6 +324,9 @@ static int cs_etm__map_trace_id_v0(struct cs_etm_auxtrace *etm, u8 trace_chan_idint ret; etmq = etm->queues.queue_array[i].priv; +if (!etmq) +continue ; + ret =cs_etm__insert_trace_id_node (etmq, trace_chan_id, cpu_metadata);if (ret)
@@ -358,6 +367,9 @@ static int cs_etm__process_trace_id_v0_1(struct cs_etm_auxtrace *etm, int cpu,u32 sink_id =FIELD_GET (CS_AUX_HW_ID_SINK_ID_MASK , hw_id);u8 trace_id =FIELD_GET (CS_AUX_HW_ID_TRACE_ID_MASK , hw_id); +if (!etmq) +return -EINVAL ; +/* * Check sink id hasn't changed in per-cpu mode. In per-thread mode, * let it pass for now until an actual overlapping trace ID is hit. In
@@ -375,6 +387,9 @@ static int cs_etm__process_trace_id_v0_1(struct cs_etm_auxtrace *etm, int cpu,for (unsigned int i =0 ; i < etm->queues.nr_queues; ++i) {struct cs_etm_queue *other_etmq = etm->queues.queue_array[i].priv; +if (!other_etmq) +continue ; +/* Different sinks, skip */ if (other_etmq->sink_id != etmq->sink_id)continue ;
@@ -396,6 +411,9 @@ static int cs_etm__process_trace_id_v0_1(struct cs_etm_auxtrace *etm, int cpu, } cpu_data =get_cpu_data (etm, cpu); +if (!cpu_data) +return -EINVAL ; + ret =cs_etm__insert_trace_id_node (etmq, trace_id, cpu_data);if (ret)return ret;
@@ -3144,6 +3162,9 @@ static int cs_etm__queue_aux_fragment(struct perf_session *session, off_t file_o aux_offset + aux_size <= auxtrace_event->offset + auxtrace_event->size) {struct cs_etm_queue *etmq =cs_etm__get_queue (etm, auxtrace_event->cpu); +if (!etmq) +return -EINVAL ; +/* * If this AUX event was inside this buffer somewhere, create a new auxtrace event * based on the sizes of the aux event, and queue that fragment.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1098/2077 perf c2c: Free format list entries when c2c_hists__init() fails
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 61a21d11afd8dd83b2260ae00541bed62a843219 ]
When c2c_hists__init() fails partway through hpp_list__parse(), dynamically allocated format structures that were already added to hists->list are leaked because he__get_c2c_hists() frees the hists container without first unregistering the format entries.
Call perf_hpp__reset_output_field() before freeing the hists container on the error path, matching what c2c_he_free() already does on the normal destruction path.
--- tools/perf/builtin-c2c.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/builtin-c2c.c +1 -0
@@ -222,6 +222,7 @@ he__get_c2c_hists(struct hist_entry *he, ret =c2c_hists__init (hists, sort, nr_header_lines, env);if (ret) { +perf_hpp__reset_output_field (&hists->list); c2c_he->hists =NULL ;free (hists);return NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1099/2077 perf c2c: Fix hist entry and format list leaks in c2c_he_free()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit fe68cf349fb343c0a7cb6c4fe6c3de4f4afe8d1c ]
c2c_he_free() calls hists__delete_entries() which only walks the output-sorted entries tree. During c2c resort, when cacheline entries are merged and the redundant entry is freed, the inner hists have not been output-resorted yet, so hists->entries is empty. The actual inner hist_entry objects live in entries_in_array[] and entries_collapsed, which are never walked, leaking all inner hist_entry objects for every merged cacheline.
Additionally, the dynamically allocated format entries on hists->list are never unregistered or freed.
Fix both issues by switching to hists__delete_all_entries() which walks all rb_root trees, and calling perf_hpp__reset_output_field() to clean up format entries.
--- tools/perf/builtin-c2c.c | 2 +- tools/perf/util/hist.c | 2 +- tools/perf/util/hist.h | 1 + 3 files changed, 3 insertions(+), 2 deletions(-)
tools/perf/builtin-c2c.c +1 -1
@@ -180,7 +180,7 @@ static void c2c_he_free(void *he) c2c_he = container_of(he, struct c2c_hist_entry, he);if (c2c_he->hists) { -hists__delete_entries (&c2c_he->hists->hists); +hists__delete_all_entries (&c2c_he->hists->hists);perf_hpp__reset_output_field (&c2c_he->hists->list);zfree (&c2c_he->hists); }
tools/perf/util/hist.c +1 -1
@@ -3041,7 +3041,7 @@ static void hists__delete_remaining_entries(struct rb_root_cached *root) } } -static void hists__delete_all_entries (struct hists *hists) +void hists__delete_all_entries (struct hists *hists) {hists__delete_entries (hists);hists__delete_remaining_entries (&hists->entries_in_array[0 ]);
tools/perf/util/hist.h +1 -0
@@ -392,6 +392,7 @@ int hists__collapse_resort(struct hists *hists, struct ui_progress *prog);void hists__decay_entries (struct hists *hists,bool zap_user,bool zap_kernel);void hists__delete_entries (struct hists *hists); +void hists__delete_all_entries (struct hists *hists);void hists__output_recalc_col_len (struct hists *hists,int max_rows);struct hist_entry *hists__get_entry (struct hists *hists,int idx);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1100/2077 perf bpf: Validate array presence before casting BPF prog info pointers
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 5ebf4137d23a4fd6c0cc6a6fb766ee60d2b09193 ]
Several functions cast bpf_prog_info fields (jited_ksyms, jited_func_lens, jited_prog_insns) from u64 to pointers and dereference them. These fields are only valid pointers if bpil_offs_to_addr() converted their file offsets to addresses, which only happens when the corresponding PERF_BPIL_* bits are set in info_linear->arrays.
A crafted perf.data can leave these bits unset while setting non-zero counts and offset values, causing the functions to dereference raw file offsets as pointers.
Add array bitmask validation to all perf.data processing paths:
- __bpf_event__print_bpf_prog_info(): check JITED_KSYMS and JITED_FUNC_LENS (changed to take struct perf_bpil *)
- machine__process_bpf_event_load(): check JITED_KSYMS
- bpf_read(): check JITED_INSNS before memcpy from jited_prog_insns
- dso__disassemble_filename(): check JITED_INSNS before returning jited_prog_insns pointer
--- tools/perf/util/bpf-event.c | 20 +++++++++++++++++--- tools/perf/util/bpf-event.h | 4 ++-- tools/perf/util/dso.c | 10 ++++++++++ tools/perf/util/header.c | 3 +-- 4 files changed, 30 insertions(+), 7 deletions(-)
tools/perf/util/bpf-event.c +17 -3
@@ -59,6 +59,10 @@ static int machine__process_bpf_event_load(struct machine *machine,return 0 ; info_linear = info_node->info_linear; +/* jited_ksyms is only valid if bpil_offs_to_addr() converted it */ +if (!(info_linear->arrays & (1UL <<PERF_BPIL_JITED_KSYMS ))) +return 0 ; +for (i =0 ; i < info_linear->info.nr_jited_ksyms; i++) {u64 *addrs = (u64 *)(uintptr_t )(info_linear->info.jited_ksyms);u64 addr = addrs[i];
@@ -959,12 +963,15 @@ int evlist__add_bpf_sb_event(struct evlist *evlist, struct perf_env *env)return evlist__add_sb_event (evlist, &attr, bpf_event__sb_cb, env); } -void __bpf_event__print_bpf_prog_info (struct bpf_prog_info *info, +void __bpf_event__print_bpf_prog_info (struct perf_bpil *info_linear,struct perf_env *env,FILE *fp) { -__u32 *prog_lens = (__u32 *)(uintptr_t )(info->jited_func_lens); -__u64 *prog_addrs = (__u64 *)(uintptr_t )(info->jited_ksyms); +struct bpf_prog_info *info = &info_linear->info; +__u64 required_arrays = (1UL <<PERF_BPIL_JITED_KSYMS ) | + (1UL <<PERF_BPIL_JITED_FUNC_LENS ); +__u32 *prog_lens; +__u64 *prog_addrs;char name[KSYM_NAME_LEN ];struct btf *btf =NULL ;u32 sub_prog_cnt, i;
@@ -974,6 +981,13 @@ void __bpf_event__print_bpf_prog_info(struct bpf_prog_info *info, sub_prog_cnt != info->nr_jited_func_lens)return ; +/* Ensure the arrays were present and converted by bpil_offs_to_addr() */ +if ((info_linear->arrays & required_arrays) != required_arrays) +return ; + + prog_lens = (__u32 *)(uintptr_t )(info->jited_func_lens); + prog_addrs = (__u64 *)(uintptr_t )(info->jited_ksyms); +if (info->btf_id) {struct btf_node *node;
tools/perf/util/bpf-event.h +2 -2
@@ -40,7 +40,7 @@ struct btf_node {int machine__process_bpf (struct machine *machine,union perf_event *event,struct perf_sample *sample);int evlist__add_bpf_sb_event (struct evlist *evlist,struct perf_env *env); -void __bpf_event__print_bpf_prog_info (struct bpf_prog_info *info, +void __bpf_event__print_bpf_prog_info (struct perf_bpil *info_linear,struct perf_env *env,FILE *fp);void bpf_metadata_free (struct bpf_metadata *metadata);
@@ -58,7 +58,7 @@ static inline int evlist__add_bpf_sb_event(struct evlist *evlist __maybe_unused,return 0 ; } -static inline void __bpf_event__print_bpf_prog_info (struct bpf_prog_info *info__maybe_unused , +static inline void __bpf_event__print_bpf_prog_info (struct perf_bpil *info_linear__maybe_unused ,struct perf_env *env__maybe_unused ,FILE *fp__maybe_unused ) {
tools/perf/util/dso.c +10 -0
@@ -880,6 +880,12 @@ static ssize_t bpf_read(struct dso *dso, u64 offset, char *data)return -1 ; } +/* jited_prog_insns is only valid if bpil_offs_to_addr() converted it */ +if (!(node->info_linear->arrays & (1UL <<PERF_BPIL_JITED_INSNS ))) { +dso__data (dso)->status =DSO_DATA_STATUS_ERROR ; +return -1 ; + } + len = node->info_linear->info.jited_prog_len; buf = (u8 *)(uintptr_t )node->info_linear->info.jited_prog_insns;
@@ -1988,6 +1994,10 @@ const u8 *dso__read_symbol(struct dso *dso, const char *symfs_filename,return NULL ; } info_linear = info_node->info_linear; +if (!(info_linear->arrays & (1UL <<PERF_BPIL_JITED_INSNS ))) { + errno =SYMBOL_ANNOTATE_ERRNO__BPF_MISSING_BTF ; +return NULL ; + }assert (len <= info_linear->info.jited_prog_len); *out_buf_len = len;return (const u8 *)(uintptr_t )(info_linear->info.jited_prog_insns);
tools/perf/util/header.c +1 -2
@@ -2058,8 +2058,7 @@ static void print_bpf_prog_info(struct feat_fd *ff __maybe_unused, FILE *fp) node = rb_entry(next, struct bpf_prog_info_node, rb_node); next =rb_next (&node->rb_node); -__bpf_event__print_bpf_prog_info (&node->info_linear->info, - env, fp); +__bpf_event__print_bpf_prog_info (node->info_linear, env, fp); }up_read (&env->bpf_progs.lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1101/2077 perf dso: Set standard errno on decompression failure
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 1a5f9334a45a6b0c1cd7341cc72a3b87adad1d27 ]
dso__get_filename() sets errno to a negative custom DSO_LOAD_ERRNO value when kernel module decompression fails:
errno = *dso__load_errno(dso); /* e.g. -9996 */
The caller __open_dso() then computes fd = -errno, producing a large positive value (9996) that looks like a valid file descriptor. This can cause close_data_fd() to close an unrelated fd used by another subsystem.
Set errno to EIO instead. The detailed error code is already stored in dso__load_errno(dso) for diagnostic messages.
--- tools/perf/util/dso.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
tools/perf/util/dso.c +7 -1
@@ -600,7 +600,13 @@ static char *dso__get_filename(struct dso *dso, const char *root_dir,size_t len =sizeof (newpath);if (dso__decompress_kmodule_path (dso, name, newpath, len) <0 ) { - errno = *dso__load_errno (dso); +/* +* Use a standard errno value, not the negative custom +* DSO_LOAD_ERRNO stored in dso__load_errno(dso): +* __open_dso() computes fd = -errno, so a negative +* errno produces a positive fd that looks valid. +*/ + errno =EIO ; goto out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1102/2077 ASoC: tlv320aic3x: restrict CLKDIV bypass Q values in dual-rate mode
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sen Wang <[email protected]>
[ Upstream commit fdf043f5f3bae150b678feae3d7bb1beed87ec14 ]
The datasheet documents that when the PLL is disabled and dual-rate mode is enabled, only Q values {4, 8, 9, 12, 16} are valid for the CLKDIV bypass path; all other Q values produce invalid bitclock output.
The existing loop iterates Q from 2 to 17 without this restriction, causing silent audio failure when an out-of-spec Q is picked.
Restrict the Q search to the allowed set in dual-rate mode.
--- sound/soc/codecs/tlv320aic3x.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
sound/soc/codecs/tlv320aic3x.c +19 -6
@@ -1049,11 +1049,13 @@ static int aic3x_hw_params(struct snd_pcm_substream *substream,struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) { + static const u8 dual_rate_q[] = {4, 8, 9, 12, 16};struct snd_soc_component *component = dai->component;struct aic3x_priv *aic3x =snd_soc_component_get_drvdata (component);int codec_clk =0 , bypass_pll =0 , fsref, last_clk =0 ;u8 data, j, r, p, pll_q, pll_p =1 , pll_r =1 , pll_j =1 ;u16 d, pll_d =1 ; +bool dual_rate;int clk;int width = aic3x->slot_width;
@@ -1079,14 +1081,25 @@ static int aic3x_hw_params(struct snd_pcm_substream *substream,/* Fsref can be 44100 or 48000 */ fsref = (params_rate (params) %11025 ==0 ) ?44100 :48000 ; + dual_rate =params_rate (params) >=64000 ;/* Try to find a value for Q which allows us to bypass the PLL and * generate CODEC_CLK directly. */ -for (pll_q =2 ; pll_q <18 ; pll_q++) -if (aic3x->sysclk / (128 * pll_q) == fsref) { - bypass_pll =1 ; -break ; +if (dual_rate) { +for (int i =0 ; i <ARRAY_SIZE (dual_rate_q); i++) { + pll_q = dual_rate_q[i]; +if (aic3x->sysclk / (128 * pll_q) == fsref) { + bypass_pll =1 ; +break ; + } } + }else { +for (pll_q =2 ; pll_q <18 ; pll_q++) +if (aic3x->sysclk / (128 * pll_q) == fsref) { + bypass_pll =1 ; +break ; + } + }if (bypass_pll) { pll_q &=0xf ;
@@ -1106,13 +1119,13 @@ static int aic3x_hw_params(struct snd_pcm_substream *substream,* right DAC to right channel input */ data = (LDAC2LCH |RDAC2RCH ); data |= (fsref ==44100 ) ?FSREF_44100 :FSREF_48000 ; -if (params_rate (params) >=64000 ) +if (dual_rate) data |=DUAL_RATE_MODE ;snd_soc_component_write (component,AIC3X_CODEC_DATAPATH_REG , data);/* codec sample rate select */ data = (fsref *20 ) /params_rate (params); -if (params_rate (params) <64000 ) +if (!dual_rate) data /=2 ; data /=5 ; data -=2 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1103/2077 drm/amdkfd: Avoid double-unpin of DOORBELL/MMIO BOs on free
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yunxiang Li <[email protected]>
[ Upstream commit 3f0cc1735273a57c5116710cf0202e12152f59cc ]
amdgpu_amdkfd_gpuvm_free_memory_of_gpu() unpinned DOORBELL and MMIO remap BOs (which are pinned at allocation time) before checking whether the BO is still mapped to the GPU. When the BO is still mapped, the function returns -EBUSY and leaves the BO alive, but it has already been unpinned. The BO is then unpinned again when it is finally freed during process teardown, triggering a ttm_bo_unpin() underflow warning:
WARNING: CPU: 18 PID: 15066 at ttm/ttm_bo.c:650 amdttm_bo_unpin+0x6d/0x80 [amdttm] Workqueue: kfd_process_wq kfd_process_wq_release [amdgpu] RIP: 0010:amdttm_bo_unpin+0x6d/0x80 [amdttm] Call Trace: amdgpu_bo_unpin+0x1a/0x90 [amdgpu] amdgpu_amdkfd_gpuvm_unpin_bo+0x31/0xb0 [amdgpu] amdgpu_amdkfd_gpuvm_free_memory_of_gpu+0x3bf/0x460 [amdgpu] kfd_process_free_outstanding_kfd_bos+0xd4/0x170 [amdgpu] kfd_process_wq_release+0x109/0x1b0 [amdgpu] process_one_work+0x1e2/0x3b0 worker_thread+0x50/0x3a0 kthread+0xdd/0x100 ret_from_fork+0x29/0x50
Move the unpin after the mapped_to_gpu_memory check so it only happens once we are committed to freeing the BO.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +9 -7
@@ -1914,13 +1914,6 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(mutex_lock (&mem->lock); -/* Unpin MMIO/DOORBELL BO's that were pinned during allocation */ -if (mem->alloc_flags & - (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | -KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) { -amdgpu_amdkfd_gpuvm_unpin_bo (mem->bo); - } - mapped_to_gpu_memory = mem->mapped_to_gpu_memory; is_imported = mem->is_imported;mutex_unlock (&mem->lock);
@@ -1934,6 +1927,15 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(return -EBUSY ; } +/* At this point the BO is guaranteed to be freed, so unpin the +* MMIO/DOORBELL BOs that were pinned during allocation. +*/ +if (mem->alloc_flags & + (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL | +KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) { +amdgpu_amdkfd_gpuvm_unpin_bo (mem->bo); + } +/* Make sure restore workers don't access the BO any more */ mutex_lock (&process_info->lock);if (!list_empty (&mem->validate_list))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1104/2077 drm/amdgpu: initialize iter.start in amdgpu_devcoredump_format
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qiang Yu <[email protected]>
[ Upstream commit 1c2d7a656655a50bd1b7227fb26d173959a1955d ]
This fixes read /sys/class/drm/cardN/device/devcoredump/data return empty content sometimes.
amdgpu_devcoredump_format() leaves struct drm_print_iterator's .start field uninitialized on the stack before passing it to drm_coredump_printer(). __drm_puts_coredump() compares the running .offset against .start to decide whether to skip or copy each chunk:
if (iterator->offset < iterator->start) {
if (iterator->offset + len <= iterator->start) {
iterator->offset += len;
return;
}
...
}--- drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c +1 -0
@@ -229,6 +229,7 @@ amdgpu_devcoredump_format(char *buffer, size_t count, struct amdgpu_coredump_inf sizing_pass = buffer ==NULL ; iter.data = buffer; + iter.start =0 ; iter.offset =0 ; iter.remain = count;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1105/2077 drm/amd/display: Skip PHY SSC reduction on some 8K panels
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Roman Li <[email protected]>
[ Upstream commit fe7945d092a1d3c340febc2ab176cee50d0f6c80 ]
[Why]
Some 8K displays cannot tolerate the reduced phy ssc value at high link utilization and show corruption or black screen.
[How]
Add an EDID panel-id quirk to utilize existing skip_phy_ssc_reduction flag.
To pass the link into the quirk handler, change the signature of apply_edid_quirks() to take link as an argument. The dev local in dm_helpers_parse_edid_caps() becomes unused and is removed.
--- .../drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +10 -3
@@ -95,8 +95,11 @@ static u32 edid_extract_panel_id(struct edid *edid) (u32 )EDID_PRODUCT_ID (edid); } -static void apply_edid_quirks (struct drm_device *dev,struct edid *edid,struct dc_edid_caps *edid_caps) +static void apply_edid_quirks (struct dc_link *link,struct edid *edid, +struct dc_edid_caps *edid_caps) { +struct amdgpu_dm_connector *aconnector = link->priv; +struct drm_device *dev = aconnector->base.dev;uint32_t panel_id =edid_extract_panel_id (edid);switch (panel_id) {
@@ -126,6 +129,11 @@ static void apply_edid_quirks(struct drm_device *dev, struct edid *edid, structdrm_dbg_driver (dev,"Disabling VSC on monitor with panel id %X\n" , panel_id); edid_caps->panel_patch.disable_colorimetry = true;break ; +/* Workaround for monitors that get corrupted by the PHY SSC reduction */ +case drm_edid_encode_panel_id ('D' ,'E' ,'L' ,0x4147 ): +drm_dbg_driver (dev,"Skip PHY SSC reduction on panel id %X\n" , panel_id); + link->wa_flags.skip_phy_ssc_reduction = true; +break ;default :return ; }
@@ -147,7 +155,6 @@ enum dc_edid_status dm_helpers_parse_edid_caps( {struct amdgpu_dm_connector *aconnector = link->priv;struct drm_connector *connector = &aconnector->base; -struct drm_device *dev = connector->dev;struct edid *edid_buf = edid ? (struct edid *) edid->raw_edid :NULL ;struct cea_sad *sads;int sad_count =-1 ;
@@ -181,7 +188,7 @@ enum dc_edid_status dm_helpers_parse_edid_caps(if (edid_caps->edid_hdmi)populate_hdmi_info_from_connector (&connector->display_info.hdmi, edid_caps); -apply_edid_quirks (dev, edid_buf, edid_caps); +apply_edid_quirks (link, edid_buf, edid_caps); sad_count =drm_edid_to_sad ((struct edid *) edid->raw_edid, &sads);if (sad_count <=0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1106/2077 drm/amd/display: Fix mem_type change detection for async flips
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthew Schwartz <[email protected]>
[ Upstream commit 8e792f018e10e68f488f279fbd4f38009a2e066d ]
[Why]amdgpu_dm_crtc_mem_type_changed() fetches the "old" and "new" plane state with two drm_atomic_get_plane_state() calls, which both return the new state. It compares a state against itself, so it never detects a mem_type change and never rejects the async flip.
On DCN 3.0.1, this shows up as intermittent corruption when a single DCC plane is scanned out with immediate flips under gamescope and its buffer moves between the VRAM carveout and GTT.
[How]
Use drm_atomic_get_old_plane_state() and drm_atomic_get_new_plane_state() to compare the actual old and new states. These return NULL rather than an error pointer for a plane that is not part of the commit, so the IS_ERR() check becomes a NULL check that skips those planes, such as an unmodified cursor still in the CRTC's plane_mask.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +4 -6
@@ -12553,13 +12553,11 @@ static bool amdgpu_dm_crtc_mem_type_changed(struct drm_device *dev,struct drm_plane_state *new_plane_state, *old_plane_state;drm_for_each_plane_mask (plane, dev, crtc_state->plane_mask) { - new_plane_state =drm_atomic_get_plane_state (state, plane); - old_plane_state =drm_atomic_get_plane_state (state, plane); + new_plane_state =drm_atomic_get_new_plane_state (state, plane); + old_plane_state =drm_atomic_get_old_plane_state (state, plane); -if (IS_ERR (new_plane_state) ||IS_ERR (old_plane_state)) { -drm_err (dev,"Failed to get plane state for plane %s\n" , plane->name); -return false; - } +if (!old_plane_state || !new_plane_state) +continue ;if (old_plane_state->fb && new_plane_state->fb &&get_mem_type (old_plane_state->fb) !=get_mem_type (new_plane_state->fb))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1107/2077 drm/amdkfd: fix list_del corruption in kfd_criu_resume_svm
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mario Limonciello <[email protected]>
[ Upstream commit 8fa5655da368d0306c03e9dc9cda8ae2a7840926 ]
The cleanup tail of kfd_criu_resume_svm() walks svms->criu_svm_metadata_list and kfree()s each struct criu_svm_metadata without removing it from the list. The list head is left pointing at freed kmalloc-96 objects.
A second AMDKFD_IOC_CRIU_OP from the same process re-enters: list_empty() reads the dangling ->next (use-after-free), the loop walks freed entries, and each is kfree()'d again (double-free). This is reachable by an unprivileged render-group user via /dev/kfd with no capabilities required.
Add list_del() before the kfree() so the list is properly emptied. The list_for_each_entry_safe() iterator already caches the next pointer, so unlinking during the walk is safe.
--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +1 -0
@@ -4115,6 +4115,7 @@ int kfd_criu_resume_svm(struct kfd_process *p)list_for_each_entry_safe (criu_svm_md, next, &svms->criu_svm_metadata_list, list) {pr_debug ("freeing criu_svm_md[]\n\tstart: 0x%llx\n" , criu_svm_md->data.start_addr); +list_del (&criu_svm_md->list);kfree (criu_svm_md); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1108/2077 drm/amdgpu: initialize irq.lock spinlock earlier
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thadeu Lima de Souza Cascardo <[email protected]>
[ Upstream commit a2b270c0ecf6d95bcd14ef4c20d0301a88143ff5 ]
If there is an early failure during amdgpu probe, like missing firmware, it will end up calling amdgpu_irq_disable_all, which takes irq.lock spinlock without it being initialized.
Initializing irq.lock earlier at amdgpu_device_init fixes the issue.
[ 79.334079] INFO: trying to register non-static key. [ 79.334081] The code is fine but needs lockdep annotation, or maybe [ 79.334083] you didn't initialize this object before use? [ 79.334084] turning off the locking correctness validator. [ 79.334088] CPU: 2 UID: 0 PID: 1819 Comm: bash Not tainted 7.1.0-rc5-gfd06300b2348 #96 PREEMPT 8e8f461221633dae3c832d6689eaf0546c0ed4cd [ 79.334092] Hardware name: Valve Jupiter/Jupiter, BIOS F7A0133 08/05/2024 [ 79.334094] Call Trace: [ 79.334095] <TASK> [ 79.334097] dump_stack_lvl+0x5d/0x80 [ 79.334103] register_lock_class+0x7af/0x7c0 [ 79.334109] __lock_acquire+0x416/0x2610 [ 79.334114] lock_acquire+0xcf/0x310 [ 79.334117] ? amdgpu_irq_disable_all+0x3b/0xf0 [amdgpu c88bab43d391d519ad0d5c8e5a099b4aceefa180] [ 79.334503] ? _raw_spin_lock_irqsave+0x53/0x60 [ 79.334508] _raw_spin_lock_irqsave+0x3f/0x60 [ 79.334510] ? amdgpu_irq_disable_all+0x3b/0xf0 [amdgpu c88bab43d391d519ad0d5c8e5a099b4aceefa180] [ 79.334881] amdgpu_irq_disable_all+0x3b/0xf0 [amdgpu c88bab43d391d519ad0d5c8e5a099b4aceefa180] [ 79.335240] amdgpu_device_fini_hw+0x90/0x32c [amdgpu c88bab43d391d519ad0d5c8e5a099b4aceefa180] [ 79.335704] amdgpu_driver_load_kms.cold+0x22/0x44 [amdgpu c88bab43d391d519ad0d5c8e5a099b4aceefa180] [ 79.336159] amdgpu_pci_probe+0x204/0x440 [amdgpu c88bab43d391d519ad0d5c8e5a099b4aceefa180] [ 79.336494] local_pci_probe+0x3c/0x80 [ 79.336500] pci_call_probe+0x55/0x2e0 [ 79.336505] ? _raw_spin_unlock+0x2d/0x50 [ 79.336508] ? pci_match_device+0x157/0x180 [ 79.336512] pci_device_probe+0x9b/0x170 [ 79.336516] really_probe+0xd5/0x370 [ 79.336521] __driver_probe_device+0x84/0x150 [ 79.336525] device_driver_attach+0x47/0xb0 [ 79.336528] bind_store+0x73/0xc0 [ 79.336531] kernfs_fop_write_iter+0x176/0x250 [ 79.336536] vfs_write+0x24d/0x560 [ 79.336542] ksys_write+0x71/0xe0 [ 79.336546] do_syscall_64+0x122/0x710 [ 79.336550] ? do_syscall_64+0xd1/0x710 [ 79.336553] entry_SYSCALL_64_after_hwframe+0x4b/0x53 [ 79.336557] RIP: 0033:0x7f92fd675006 [ 79.336561] Code: 5d e8 41 8b 93 08 03 00 00 59 5e 48 83 f8 fc 75 19 83 e2 39 83 fa 08 75 11 e8 26 ff ff ff 66 0f 1f 44 00 00 48 8b 45 10 0f 05 <48> 8b 5d f8 c9 c3 0f 1f 40 00 f3 0f 1e fa 55 48 89 e5 48 83 ec 08 [ 79.336562] RSP: 002b:00007ffe4fa867a0 EFLAGS: 00000202 ORIG_RAX: 0000000000000001 [ 79.336565] RAX: ffffffffffffffda RBX: 000000000000000d RCX: 00007f92fd675006 [ 79.336567] RDX: 000000000000000d RSI: 000055b2dfce59b0 RDI: 0000000000000001 [ 79.336568] RBP: 00007ffe4fa867c0 R08: 0000000000000000 R09: 0000000000000000 [ 79.336569] R10: 0000000000000000 R11: 0000000000000202 R12: 000000000000000d [ 79.336570] R13: 000055b2dfce59b0 R14: 00007f92fd7ca5c0 R15: 000055b2dfdbaf70 [ 79.336574] </TASK>
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -0
@@ -3747,6 +3747,8 @@ int amdgpu_device_init(struct amdgpu_device *adev,mutex_init (&adev->gfx.workload_profile_mutex);mutex_init (&adev->vcn.workload_profile_mutex); +spin_lock_init (&adev->irq.lock); +amdgpu_device_init_apu_flags (adev); r =amdgpu_device_check_arguments (adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +0 -2
@@ -309,8 +309,6 @@ int amdgpu_irq_init(struct amdgpu_device *adev)unsigned int irq, flags;int r; -spin_lock_init (&adev->irq.lock); -/* Enable MSI if not disabled by module parameter */ adev->irq.msi_enabled = false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1109/2077 net: ethernet: mtk_eth_soc: fix supported_interface set after phylink_create
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Marangi <[email protected]>
[ Upstream commit e4b4d8410c7ccea25f4b332a077c6b9f5d263228 ]
Everything configured in phylink_config it's assumed to be set before calling phylink_create() to permit correct parsing of all the different modes and capabilities.
Commit 51cf06ddafc9 ("net: ethernet: mtk_eth_soc: add support for MT7988 internal 2.5G PHY") while introducing support for 2.5G phy for MT7988, probably due to an auto-rebase, placed the configuration of the INTERNAL interface mode for the supported_interfaces for phylink_config right after phylink_create() introducing a possible problem with supported interfaces parsing.
While this doesn't currently create any problem/bug, move setting this bit before phylink_create() to prevent any possible regression in future code change in phylink core.
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +5 -5
@@ -4960,6 +4960,11 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)if (MTK_HAS_CAPS (eth->soc->caps,MTK_SOC_MT7628 )) mac_ops = &rt5350_phylink_ops; +if (MTK_HAS_CAPS (mac->hw->soc->caps,MTK_2P5GPHY ) && + id ==MTK_GMAC2_ID ) +__set_bit (PHY_INTERFACE_MODE_INTERNAL , + mac->phylink_config.supported_interfaces); + phylink =phylink_create (&mac->phylink_config,of_fwnode_handle (mac->of_node), phy_mode, mac_ops);
@@ -4970,11 +4975,6 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np) mac->phylink = phylink; -if (MTK_HAS_CAPS (mac->hw->soc->caps,MTK_2P5GPHY ) && - id ==MTK_GMAC2_ID ) -__set_bit (PHY_INTERFACE_MODE_INTERNAL , - mac->phylink_config.supported_interfaces); -SET_NETDEV_DEV (eth->netdev[id], eth->dev); eth->netdev[id]->watchdog_timeo =5 *HZ ; eth->netdev[id]->netdev_ops = &mtk_netdev_ops;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1110/2077 selftests/ftrace: Fix trace_marker_raw test on 64K page kernels
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tianchen Ding <[email protected]>
[ Upstream commit 65f26d15f7db80b0a3f995c518cdddb50e6dea99 ]
On ARM64 kernels with 64K pages, the trace_marker_raw test fails because bash's printf builtin uses stdio buffering which splits output into multiple small write() calls to the tracefs file. Since each individual write is within TRACE_MARKER_MAX_SIZE (4096), they all succeed, causing the "too big" write test to incorrectly pass.
Fix by writing through dd with iflag=fullblock to guarantee a single atomic write() syscall to trace_marker_raw.
--- .../ftrace/test.d/00basic/trace_marker_raw.tc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
tools/testing/selftests/ftrace/test.d/00basic/trace_marker_raw.tc +11 -3
@@ -36,15 +36,23 @@ make_str() { data=`printf -- 'X%.0s' $(seq $cnt)` - printf "${val}${data}" + # Return escape-sequence text (e.g. "\003\000..."); the caller + # converts to binary. Shell command substitution strips NUL bytes, + # so the binary form cannot survive being captured into a variable. + printf '%s' "${val}${data}" } write_buffer() { id=$1 size=$2 - # write the string into the raw marker - make_str $id $size > trace_marker_raw + str=`make_str $id $size` + len=`printf "$str" | wc -c` + # Pipe through dd to ensure a single atomic write() syscall + # on architectures with 64K pages, where shell's printf builtin + # uses stdio buffering which may split the output into multiple + # writes. + printf "$str" | dd of=trace_marker_raw bs=$len iflag=fullblock }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1111/2077 octeontx2-pf: Fix leak of SQ timestamp buffer on teardown
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ratheesh Kannoth <[email protected]>
[ Upstream commit a056db30de92945ff8ee6033096678bfbae878e3 ]
The send-queue timestamp ring is allocated with qmem_alloc() when timestamping is used, but otx2_free_sq_res() never freed sq->timestamps, leaking that memory across ifdown and device removal. Add the missing qmem_free() alongside the other SQ companion buffers.
--- drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +1 -0
@@ -1578,6 +1578,7 @@ static void otx2_free_sq_res(struct otx2_nic *pf)qmem_free (pf->dev, sq->sqe_ring);qmem_free (pf->dev, sq->cpt_resp);qmem_free (pf->dev, sq->tso_hdrs); +qmem_free (pf->dev, sq->timestamps);kfree (sq->sg);kfree (sq->sqb_ptrs); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1112/2077 octeontx2-af: npc: Log successful MCAM drop-on-non-hit install at debug level
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ratheesh Kannoth <[email protected]>
[ Upstream commit 4f6ac65e81625165257131ec2574bb6bb09bd7d8 ]
npc_install_mcam_drop_rule() used dev_err() after a successful rvu_mbox_handler_npc_mcam_write_entry() call, so normal installs appeared as errors in dmesg. Use dev_dbg() for the success path and keep dev_err() for real failures.
--- drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c +1 -1
@@ -2215,7 +2215,7 @@ int npc_install_mcam_drop_rule(struct rvu *rvu, int mcam_idx, u16 *counter_idx,return err; } -dev_err (rvu->dev, +dev_dbg (rvu->dev,"%s: Installed single drop on non hit rule at %d, cntr=%d\n" , __func__, mcam_idx, req.cntr);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1113/2077 net: psample: fix info leak in PSAMPLE_ATTR_DATA
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Kicinski <[email protected]>
[ Upstream commit aedd02af1f8b0bceb7f42f5a21c41634ca9ed390 ]
psample open codes nla_put() presumably to avoid wiping the data with 0s just to override it with packet data. This open coding is missing clearing the pad, however, each netlink attr is padded to 4B and data_len may not be divisible by 4B.
--- net/psample/psample.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/psample/psample.c +4 -2
@@ -476,15 +476,17 @@ void psample_sample_packet(struct psample_group *group, goto error;if (data_len) { -int nla_len =nla_total_size (data_len); +int nla_len =nla_attr_size (data_len);struct nlattr *nla; nla =skb_put (nl_skb, nla_len); nla->nla_type =PSAMPLE_ATTR_DATA ; - nla->nla_len =nla_attr_size (data_len); + nla->nla_len = nla_len;if (skb_copy_bits (skb,0 ,nla_data (nla), data_len)) goto error; + +skb_put_zero (nl_skb,nla_padlen (data_len)); }#ifdef CONFIG_INET
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1114/2077 sctp: hold socket lock when dumping endpoints in sctp_diag
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xin Long <[email protected]>
[ Upstream commit 7d8297e26b4e20b5d1c3c3fe51fe81a1c7fbc823 ]
SCTP_DIAG endpoint dumping was traversing endpoint address lists without holding lock_sock(), while those lists could change concurrently via socket operations (e.g., bindx changes). This creates a race where nla_reserve() counts addresses under RCU protection, but the subsequent copy may see fewer entries, potentially leaking uninitialized memory to userspace.
Fix this by:
- Taking a reference on each endpoint during hash traversal
- Moving socket operations (lock_sock()) outside read_lock_bh()
- Serializing address list access during dump
- Reworking sctp_for_each_endpoint() to support restart-based traversal with (net, pos) tracking
Also:
- Add WARN_ON_ONCE() for inconsistent address counts
- Fix idiag_states filtering for LISTEN vs association cases
- Skip dumping endpoints being freed (ep->base.dead)
- Move dump position tracking into iterator, removing cb->args[4] and its comment for sctp_ep_dump().,
- Update the comment for cb->args[4] and remove the comment for unused cb->args[5] for sctp_sock_dump().
Note: traversal is restart-based and may re-scan buckets multiple times, but this is acceptable due to small bucket sizes and required to support sleeping-safe callbacks.
This issue was reported by Nico Yip (@_cyeaa_) working with TrendAI Zero Day Initiative.
--- include/net/sctp/sctp.h | 3 +- net/sctp/diag.c | 67 ++++++++++++++++++++--------------------- net/sctp/socket.c | 29 +++++++++++++----- 3 files changed, 56 insertions(+), 43 deletions(-)
include/net/sctp/sctp.h +2 -1
@@ -111,7 +111,8 @@ int sctp_transport_lookup_process(sctp_callback_t cb, struct net *net, const union sctp_addr *paddr, void *p, int dif);int sctp_transport_traverse_process (sctp_callback_t cb,sctp_callback_t cb_done,struct net *net,int *pos,void *p); -int sctp_for_each_endpoint (int (*cb)(struct sctp_endpoint *,void *),void *p); +int sctp_for_each_endpoint (int (*cb)(struct sctp_endpoint *,void *), +struct net *net,int *pos,void *p);int sctp_get_sctp_info (struct sock *sk,struct sctp_association *asoc,struct sctp_info *info);
net/sctp/diag.c +32 -35
121 lines not on this page · raw message
net/sctp/socket.c +22 -7
@@ -5369,24 +5369,39 @@ struct sctp_transport *sctp_transport_get_idx(struct net *net, }int sctp_for_each_endpoint (int (*cb)(struct sctp_endpoint *,void *), -void *p) { -int err =0 ; -int hash =0 ; -struct sctp_endpoint *ep; +struct net *net,int *pos,void *p) { +int err, hash =0 , idx =0 , start;struct sctp_hashbucket *head; +struct sctp_endpoint *ep;for (head = sctp_ep_hashtable; hash < sctp_ep_hashsize; hash++, head++) { + start = idx; +again:read_lock_bh (&head->lock);sctp_for_each_hentry (ep, &head->chain) { - err =cb (ep, p); -if (err) +if (sock_net (ep->base.sk) != net) +continue ; +if (idx++ >= *pos) { +sctp_endpoint_hold (ep);break ; + } }read_unlock_bh (&head->lock); + +if (ep) { + err =cb (ep, p); +sctp_endpoint_put (ep); +if (err) +return err; + (*pos)++; + + idx = start; + goto again; + } } -return err; +return 0 ; }EXPORT_SYMBOL_GPL (sctp_for_each_endpoint);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1115/2077 ALSA: usb-audio: qcom: reject stream disable with no active interface
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
[ Upstream commit bdb640be82e645e2828731648f485224d0c2587b ]
handle_uaudio_stream_req() resolves an interface index with info_idx_from_ifnum(), which returns -EINVAL when no interface matches. The enable branch and the response: cleanup label both guard against a negative index, but the disable branch does not: it forms info = &uadev[pcm_card_num].info[info_idx] and dereferences it.
uadev[].info is a pointer allocated only when a stream is first enabled, so a negative info_idx on the disable path is unsafe in two ways:
- If the card was never enabled, .info is NULL and &info[-EINVAL] is a wild pointer; reading info->data_ep_pipe faults (kernel oops).
- If the card was enabled at least once (.info allocated) and the disable names an interface that does not match, &info[-EINVAL] points before the allocation; info->data_ep_pipe / info->sync_ep_pipe are an out-of-bounds slab read and, when non-zero, an out-of-bounds 4-byte write (both pipe fields are cleared to 0). That is memory corruption, not just a NULL dereference.
The request is reachable from unprivileged local userspace over AF_QIPCRTR. Reject a disable request with no resolved interface, matching the guard the enable path already has.
--- sound/usb/qcom/qc_audio_offload.c | 5 +++++ 1 file changed, 5 insertions(+)
sound/usb/qcom/qc_audio_offload.c +5 -0
@@ -1647,6 +1647,11 @@ static void handle_uaudio_stream_req(struct qmi_handle *handle, subs->opened =0 ; } }else { +if (info_idx <0 ) { + ret = -EINVAL ; + goto response; + } + info = &uadev[pcm_card_num].info[info_idx];if (info->data_ep_pipe) { ep = usb_pipe_endpoint(uadev[pcm_card_num].udev,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1116/2077 ALSA: usb-audio: qcom: clear opened when stream enable fails
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
[ Upstream commit 3c7af07943b2718087ae791cad450af5cf646d90 ]
On enable, subs->opened is set before the service_interval is validated; an invalid interval jumps to the response label without clearing it, so the substream is wedged at -EBUSY until a disable or disconnect.
Clear subs->opened on the enable error path.
--- sound/usb/qcom/qc_audio_offload.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
sound/usb/qcom/qc_audio_offload.c +6 -1
@@ -1625,8 +1625,13 @@ static void handle_uaudio_stream_req(struct qmi_handle *handle,if (req_msg->service_interval_valid) { ret =get_data_interval_from_si (subs, req_msg->service_interval); -if (ret == -EINVAL ) +if (ret == -EINVAL ) { +if (req_msg->enable) { +guard (mutex)(&chip->mutex); + subs->opened =0 ; + } goto response; + } datainterval = ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1117/2077 PCI: iproc: Restore .map_irq() for the platform bus driver
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Tomlinson <[email protected]>
[ Upstream commit 3c2e6cc6affa8acdb99a580be1f8f297edf54204 ]
Commit b64aa11eb2dd ("PCI: Set bridge map_irq and swizzle_irq to default functions") moved the assignment of default .map_irq() callback to devm_of_pci_bridge_init() and removed the initialization of 'iproc_pcie::map_irq' in platform bus driver. This led to the callback getting assigned the NULL pointer for platform bus driver, thereby breaking the INTx functionality, since 'iproc_pcie::map_irq' overrides the 'pci_host_bridge::map_irq' callback in iproc_pcie_setup().
This issue only affected the iproc platform bus driver as this driver relies on the default callback for non-PAXC controllers. iproc-brcm driver was already providing the custom mapping function, so it was unaffected.
Restore the original (and intended) behaviour to use the default map_irq function by removing the local 'iproc_pcie::map_irq' pointer and directly assigning the 'pci_host_bridge::map_irq' callback in iproc-bcma driver. This ensures that the default 'map_irq' callback is used for platform bus driver and only iproc-brcm driver overrides it with a custom one.
--- drivers/pci/controller/pcie-iproc-bcma.c | 2 +- drivers/pci/controller/pcie-iproc-platform.c | 2 +- drivers/pci/controller/pcie-iproc.c | 1 - drivers/pci/controller/pcie-iproc.h | 2 -- 4 files changed, 2 insertions(+), 5 deletions(-)
drivers/pci/controller/pcie-iproc-bcma.c +1 -1
@@ -64,7 +64,7 @@ static int iproc_bcma_pcie_probe(struct bcma_device *bdev)if (ret)return ret; - pcie->map_irq = iproc_bcma_pcie_map_irq; + bridge->map_irq = iproc_bcma_pcie_map_irq;bcma_set_drvdata (bdev, pcie);
drivers/pci/controller/pcie-iproc-platform.c +1 -1
@@ -98,7 +98,7 @@ static int iproc_pltfm_pcie_probe(struct platform_device *pdev)switch (pcie->type) {case IPROC_PCIE_PAXC :case IPROC_PCIE_PAXC_V2 : - pcie->map_irq =NULL ; + bridge->map_irq =NULL ;break ;default :break ;
drivers/pci/controller/pcie-iproc.c +0 -1
@@ -1502,7 +1502,6 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res) host->ops = &iproc_pcie_ops; host->sysdata = pcie; - host->map_irq = pcie->map_irq; ret =pci_host_probe (host);if (ret <0 ) {
drivers/pci/controller/pcie-iproc.h +0 -2
@@ -61,7 +61,6 @@ struct iproc_msi;* @base_addr: PCIe host controller register base physical address * @mem: host bridge memory window resource * @phy: optional PHY device that controls the Serdes -* @map_irq: function callback to map interrupts * @ep_is_internal: indicates an internal emulated endpoint device is connected * @iproc_cfg_read: indicates the iProc config read function should be used * @rej_unconfig_pf: indicates the root complex needs to detect and reject
@@ -91,7 +90,6 @@ struct iproc_pcie {phys_addr_t base_addr;struct resource mem;struct phy *phy; -int (*map_irq)(const struct pci_dev *,u8 ,u8 );bool ep_is_internal;bool iproc_cfg_read;bool rej_unconfig_pf;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1118/2077 spi: rpc-if: Use correct device for hardware reinitialization on resume
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Quang Nguyen <[email protected]>
[ Upstream commit 7b25dbafa2fce50b1a48c1d057adb35da3563f9b ]
rpcif_spi_resume() currently passes the SPI controller device to rpcif_hw_init(), but the function should be called with the RPC interface device.
Retrieve the rpcif private data from the SPI controller and pass rpc->dev instead. Also propagate the return value of rpcif_hw_init() so that a failure during resume is properly reported rather than silently ignored.
--- drivers/spi/spi-rpc-if.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/spi/spi-rpc-if.c +5 -1
@@ -206,8 +206,12 @@ static int rpcif_spi_suspend(struct device *dev)static int rpcif_spi_resume (struct device *dev) {struct spi_controller *ctlr =dev_get_drvdata (dev); +struct rpcif *rpc =spi_controller_get_devdata (ctlr); +int ret; -rpcif_hw_init (dev, false); + ret =rpcif_hw_init (rpc->dev, false); +if (ret) +return ret;return spi_controller_resume (ctlr); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1119/2077 virtio-net: fix len check in receive_big()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiang Mei <[email protected]>
[ Upstream commit 9e5ad06ea826322ce8c58b4a68442a96f600c3c4 ]
receive_big() bounds the device-announced length by (big_packets_num_skbfrags + 1) * PAGE_SIZE. That is still too loose:add_recvbuf_big() sets sg[1] to start at offset sizeof(struct padded_vnet_hdr) into the first page, so the chain actually carries hdr_len + (PAGE_SIZE - sizeof(padded_vnet_hdr)) + big_packets_num_skbfrags * PAGE_SIZE bytes -- 20 bytes less than the check allows for the common hdr_len == 12 case.
A malicious virtio backend can announce a len in that gap. page_to_skb() then walks one frag past the page chain, storing a NULL page->private into skb_shinfo()->frags[MAX_SKB_FRAGS], which is both an out-of-bounds write past the static frag array and a NULL frag handed up the rx path.
Bound len by the size add_recvbuf_big() actually advertised.
--- drivers/net/virtio_net.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/net/virtio_net.c +6 -3
@@ -1999,15 +1999,18 @@ static struct sk_buff *receive_big(struct net_device *dev, struct virtnet_rq_stats *stats) {struct page *page = buf; +unsigned long max_len;struct sk_buff *skb; + max_len = (vi->big_packets_num_skbfrags +1 ) *PAGE_SIZE - +sizeof (struct padded_vnet_hdr ) + vi->hdr_len; +/* Make sure that len does not exceed the size allocated in * add_recvbuf_big. */ -if (unlikely (len > (vi->big_packets_num_skbfrags +1 ) *PAGE_SIZE )) { +if (unlikely (len > max_len)) {pr_debug ("%s: rx error: len %u exceeds allocated size %lu\n" , - dev->name, len, - (vi->big_packets_num_skbfrags +1 ) *PAGE_SIZE ); + dev->name, len, max_len); goto err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1120/2077 dpaa2-switch: fix VLAN upper check not rejecting bridge join
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ioana Ciornei <[email protected]>
[ Upstream commit ed2294f94e34e97342850c40b320833d881c3819 ]
The blamed commit refactored the prechangeupper event handling but failed to actually return an error in case dpaa2_switch_prevent_bridging_with_8021q_upper() detected a 802.1q upper on a port which tries to join a bridge. Fix this by returning err instead of 0.
--- drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c +1 -1
@@ -2177,7 +2177,7 @@ dpaa2_switch_prechangeupper_sanity_checks(struct net_device *netdev,if (err) {NL_SET_ERR_MSG_MOD (extack,"Cannot join a bridge while VLAN uppers are present" ); -return 0 ; +return err; }netdev_for_each_lower_dev (upper_dev, other_dev, iter) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1121/2077 devlink: Fix parent ref leak in devl_rate_node_create()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cosmin Ratiu <[email protected]>
[ Upstream commit ba45106342bbdd905651cb9fcefb8c11871d4c25 ]
In the original commit the function bails out on kstrdup failure, forgetting to decrement the refcnt of the parent.
Fix that by moving the parent refcnt setting after kstrdup.
--- net/devlink/rate.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
net/devlink/rate.c +5 -5
@@ -725,11 +725,6 @@ devl_rate_node_create(struct devlink *devlink, void *priv, char *node_name,if (!rate_node)return ERR_PTR (-ENOMEM ); -if (parent) { - rate_node->parent = parent; -refcount_inc (&rate_node->parent->refcnt); - } - rate_node->type =DEVLINK_RATE_TYPE_NODE ; rate_node->devlink = devlink; rate_node->priv = priv;
@@ -740,6 +735,11 @@ devl_rate_node_create(struct devlink *devlink, void *priv, char *node_name,return ERR_PTR (-ENOMEM ); } +if (parent) { + rate_node->parent = parent; +refcount_inc (&rate_node->parent->refcnt); + } +refcount_set (&rate_node->refcnt,1 );list_add (&rate_node->list, &devlink->rate_list);devlink_rate_notify (rate_node,DEVLINK_CMD_RATE_NEW );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1122/2077 devlink: Fix parent ref leak on tc-bw failure
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cosmin Ratiu <[email protected]>
[ Upstream commit ba81a8b80f042038b9f73a4e5bb135de890b59bb ]
When a node is created via rate-new with tc-bw and a parent node, devlink_nl_rate_set() executes the sequence of ops. It bails out on the first failure and doesn't rollback anything. For most things that is fine (setting some numbers), but the parent set can leak if there's another failure after that.
That is precisely what happens when parent setting isn't the last block in the function. After the referenced "Fixes" commit, when tc-bw fails to be set the function bails out after having set the parent and incremented its refcount.
There are two callers:
- devlink_nl_rate_set_doit() is fine, it just reports the error.
- but devlink_nl_rate_new_doit() frees the newly created node and leaks the parent refcnt.
Fix that by reordering the blocks so parent setting is last and adding a comment explaining this so future modification preserve the ordering (hopefully).
--- net/devlink/rate.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
net/devlink/rate.c +9 -6
@@ -486,16 +486,19 @@ static int devlink_nl_rate_set(struct devlink_rate *devlink_rate, devlink_rate->tx_weight = weight; } - nla_parent = attrs[DEVLINK_ATTR_RATE_PARENT_NODE_NAME ]; -if (nla_parent) { - err =devlink_nl_rate_parent_node_set (devlink_rate, info, - nla_parent); +if (attrs[DEVLINK_ATTR_RATE_TC_BWS ]) { + err =devlink_nl_rate_tc_bw_set (devlink_rate, info);if (err)return err; } -if (attrs[DEVLINK_ATTR_RATE_TC_BWS ]) { - err =devlink_nl_rate_tc_bw_set (devlink_rate, info); +/* Keep parent setting last because it takes a reference. This function +* has no rollback, so failing after taking the ref would leak it. +*/ + nla_parent = attrs[DEVLINK_ATTR_RATE_PARENT_NODE_NAME ]; +if (nla_parent) { + err =devlink_nl_rate_parent_node_set (devlink_rate, info, + nla_parent);if (err)return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1123/2077 net: airoha: fix foe_check_time allocation size
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wayen Yan <[email protected]>
[ Upstream commit 5c121ee635680c93d7074becf14cfbaac140f80d ]
foe_check_time is declared as u16 pointer but was allocated with only ppe_num_entries bytes instead of ppe_num_entries * sizeof(u16).
When airoha_ppe_foe_verify_entry() is called with hash >= ppe_num_entries/2, it writes beyond the allocated buffer, causing heap buffer overflow and potential kernel crash.
--- drivers/net/ethernet/airoha/airoha_ppe.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/airoha/airoha_ppe.c +2 -1
@@ -1578,7 +1578,8 @@ int airoha_ppe_init(struct airoha_eth *eth)return -ENOMEM ; } - ppe->foe_check_time =devm_kzalloc (eth->dev, ppe_num_entries, + ppe->foe_check_time =devm_kzalloc (eth->dev, + ppe_num_entries *sizeof (*ppe->foe_check_time),GFP_KERNEL );if (!ppe->foe_check_time)return -ENOMEM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1124/2077 net: macb: add TX stall timeout callback to recover from lost TSTART write
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lukasz Raczylo <[email protected]>
[ Upstream commit e438ec3e9e95cd3f49a8120e5f63ae3f9606e6fa ]
The MACB found in the Raspberry Pi RP1 suffers from sporadic stalls on the TX queue.
While the exact root cause is not yet fully understood, it is likely related to a hardware issue where a TSTART write to the NCR register is missed, preventing the transmission from being kicked off.
Implement a timeout callback to handle TX queue stalls, triggering the existing restart mechanism to recover.
--- drivers/net/ethernet/cadence/macb_main.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/net/ethernet/cadence/macb_main.c +8 -0
@@ -4522,6 +4522,13 @@ static int macb_setup_tc(struct net_device *dev, enum tc_setup_type type, } } +static void macb_tx_timeout (struct net_device *dev,unsigned int q) +{ +struct macb *bp =netdev_priv (dev); + +macb_tx_restart (&bp->queues[q]); +} +static const struct net_device_ops macb_netdev_ops = { .ndo_open = macb_open, .ndo_stop = macb_close,
@@ -4540,6 +4547,7 @@ static const struct net_device_ops macb_netdev_ops = { .ndo_hwtstamp_set = macb_hwtstamp_set, .ndo_hwtstamp_get = macb_hwtstamp_get, .ndo_setup_tc = macb_setup_tc, + .ndo_tx_timeout = macb_tx_timeout, };/* Configure peripheral capabilities according to device tree
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1125/2077 flow_dissector: check device type before reading ETH_ADDRS
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yun Zhou <[email protected]>
[ Upstream commit bf6e8af2c8be77489bedeae9f8a9654cb710e500 ]
__skb_flow_dissect() unconditionally reads 12 bytes from eth_hdr(skb) when FLOW_DISSECTOR_KEY_ETH_ADDRS is requested. This assumes the skb has a valid Ethernet header at mac_header, which is not always the case.
The problem can be triggered by:
1. Creating a TUN device in L3 mode (IFF_TUN, hard_header_len=0)
2. Attaching a multiq qdisc with a flower filter matching on eth_src
3. Sending a packet through AF_PACKET
Since TUN in L3 mode has no link-layer header, mac_header points to the L3 data area. The flow dissector reads 12 bytes of uninitialized skb memory, which then propagates through fl_set_masked_key() and is used as a rhashtable lookup key in __fl_lookup(), as reported by KMSAN.
Rejecting the filter in the control path (at tc filter add time) is not feasible because TC filter blocks can be shared between arbitrary devices -- a filter installed on an Ethernet device may later classify packets on a headerless device through a shared block. The device association is not fixed at filter creation time.
Fix this by gating the memcpy on dev->type == ARPHRD_ETHER, which ensures only true Ethernet-framed packets have their addresses read. This is more precise than the previous hard_header_len >= 12 check, which would incorrectly pass for non-Ethernet link types like IPoIB (ARPHRD_INFINIBAND, hard_header_len=24) and FDDI (hard_header_len=21) whose L2 headers are not in Ethernet format. Additionally check skb_mac_header_was_set() to guard against the pathological case where mac_header is the unset sentinel (~0U), which would cause eth_hdr() to return a wild pointer.
For the act_mirred redirect case (Ethernet packet redirected to a non-Ethernet device sharing a TC block), zeroing the key is the correct
behavior: the packet is now being classified on the target device, where Ethernet address matching is not semantically meaningful.
Note: on non-Ethernet devices, the zeroed key will match a filter configured with all-zero MAC addresses. This is an improvement over the previous behavior where uninitialized memory could randomly match any filter.
--- net/core/flow_dissector.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
net/core/flow_dissector.c +10 -2
@@ -1173,13 +1173,21 @@ bool __skb_flow_dissect(const struct net *net,if (dissector_uses_key (flow_dissector,FLOW_DISSECTOR_KEY_ETH_ADDRS )) { -struct ethhdr *eth =eth_hdr (skb);struct flow_dissector_key_eth_addrs *key_eth_addrs; key_eth_addrs =skb_flow_dissector_target (flow_dissector,FLOW_DISSECTOR_KEY_ETH_ADDRS , target_container); -memcpy (key_eth_addrs, eth,sizeof (*key_eth_addrs)); +/* TC filter blocks can be shared across devices with +* different link types, so we cannot validate this +* when the filter is installed -- check at dissect time. +*/ +if (skb && skb->dev && + skb->dev->type ==ARPHRD_ETHER && +skb_mac_header_was_set (skb)) +memcpy (key_eth_addrs,eth_hdr (skb),sizeof (*key_eth_addrs)); +else +memset (key_eth_addrs,0 ,sizeof (*key_eth_addrs)); } if (dissector_uses_key(flow_dissector,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1126/2077 netconsole: dont drop the last byte of a full-sized message
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Breno Leitao <[email protected]>
[ Upstream commit c0ebe492329a4d29592e2240df17e56724849f1f ]
nt->buf is exactly MAX_PRINT_CHUNK bytes, but scnprintf() reserves one byte for its NUL terminator, so a non-fragmented payload of exactly MAX_PRINT_CHUNK loses its last byte (emitted as a stray NUL in the release path). Grow nt->buf to MAX_PRINT_CHUNK + 1 and bound the scnprintf() calls with sizeof(nt->buf); the transmitted length stays capped at MAX_PRINT_CHUNK.
Alternatively, nt->buf could be left at MAX_PRINT_CHUNK and the NUL byte reserved by routing exactly-MAX_PRINT_CHUNK payloads to fragmentation ('len < MAX_PRINT_CHUNK'), at the cost of fragmenting those messages. But it would look less sane, thus the current approach.
--- drivers/net/netconsole.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/net/netconsole.c +7 -5
@@ -184,8 +184,10 @@ struct netconsole_target {bool extended;bool release;struct netpoll np; -/* protected by target_list_lock */ -char buf[MAX_PRINT_CHUNK ]; +/* protected by target_list_lock; +1 gives scnprintf() room for its +* NUL terminator so a full MAX_PRINT_CHUNK payload is not truncated +*/ +char buf[MAX_PRINT_CHUNK +1 ];struct work_struct resume_wq; };
@@ -1692,7 +1694,7 @@ static void send_msg_no_fragmentation(struct netconsole_target *nt,if (release_len) { release =init_utsname ()->release; -scnprintf (nt->buf,MAX_PRINT_CHUNK ,"%s,%.*s" , release, +scnprintf (nt->buf,sizeof (nt->buf),"%s,%.*s" , release, msg_len, msg); msg_len += release_len; }else {
@@ -1701,12 +1703,12 @@ static void send_msg_no_fragmentation(struct netconsole_target *nt,if (userdata) msg_len +=scnprintf (&nt->buf[msg_len], -MAX_PRINT_CHUNK - msg_len,"%s" , +sizeof (nt->buf) - msg_len,"%s" , userdata);if (sysdata) msg_len +=scnprintf (&nt->buf[msg_len], -MAX_PRINT_CHUNK - msg_len,"%s" , +sizeof (nt->buf) - msg_len,"%s" , sysdata);send_udp (nt, nt->buf, msg_len);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1127/2077 selftests: vlan_bridge_binding: Fix flaky operational state check
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ido Schimmel <[email protected]>
[ Upstream commit 4045f1c3d68ef4b589ae2587e6ff66ce8017daf2 ]
check_operstate() busy waits for up to one second for the operational state to change to the expected state. This is not enough since carrier loss events can be delayed by the kernel for up to one second (see __linkwatch_run_queue()), leading to sporadic failures.
Fix by increasing the busy wait period to two seconds.
--- tools/testing/selftests/net/vlan_bridge_binding.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/net/vlan_bridge_binding.sh +1 -1
@@ -64,7 +64,7 @@ check_operstate() local expect=$1; shift local operstate - operstate=$(busywait 1000 \ + operstate=$(busywait 2000 \ operstate_is "$dev" "$expect") check_err $? "Got operstate of $operstate, expected $expect" }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1128/2077 eth: fbnic: take netif_addr_lock_bh() around rx mode address programming
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Zahka <[email protected]>
[ Upstream commit 96e7f9122aae0ed000ee321f324b812a447906d9 ]
When __fbnic_set_rx_mode() is called from contexts other than .ndo_set_rx_mode_async(), the uc and mc addr lists are accessed without the addr lock that __hw_addr_sync_dev() and __hw_addr_unsync_dev() require. Wrap these unprotected accesses with netif_addr_lock_bh(). fbnic_clear_rx_mode() has similar issues.
--- drivers/net/ethernet/meta/fbnic/fbnic_netdev.c | 7 ++++++- drivers/net/ethernet/meta/fbnic/fbnic_pci.c | 4 ++++ drivers/net/ethernet/meta/fbnic/fbnic_rpc.c | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-)
drivers/net/ethernet/meta/fbnic/fbnic_netdev.c +6 -1
@@ -262,8 +262,11 @@ static int fbnic_set_mac(struct net_device *netdev, void *p)eth_hw_addr_set (netdev, addr->sa_data); -if (netif_running (netdev)) +if (netif_running (netdev)) { +netif_addr_lock_bh (netdev);__fbnic_set_rx_mode (fbn->fbd, &netdev->uc, &netdev->mc); +netif_addr_unlock_bh (netdev); + }return 0 ; }
@@ -308,8 +311,10 @@ void fbnic_clear_rx_mode(struct fbnic_dev *fbd)/* Write updates to hardware */ fbnic_write_macda (fbd); +netif_addr_lock_bh (netdev);__dev_uc_unsync (netdev,NULL );__dev_mc_unsync (netdev,NULL ); +netif_addr_unlock_bh (netdev); } static int fbnic_hwtstamp_get(struct net_device *netdev,
drivers/net/ethernet/meta/fbnic/fbnic_pci.c +4 -0
@@ -135,7 +135,9 @@ void fbnic_up(struct fbnic_net *fbn)fbnic_rss_reinit_hw (fbn->fbd, fbn); +netif_addr_lock_bh (fbn->netdev);__fbnic_set_rx_mode (fbn->fbd, &fbn->netdev->uc, &fbn->netdev->mc); +netif_addr_unlock_bh (fbn->netdev);/* Enable Tx/Rx processing */ fbnic_napi_enable (fbn);
@@ -180,7 +182,9 @@ static int fbnic_fw_config_after_crash(struct fbnic_dev *fbd) }fbnic_rpc_reset_valid_entries (fbd); +netif_addr_lock_bh (fbd->netdev);__fbnic_set_rx_mode (fbd, &fbd->netdev->uc, &fbd->netdev->mc); +netif_addr_unlock_bh (fbd->netdev);return 0 ; }
drivers/net/ethernet/meta/fbnic/fbnic_rpc.c +2 -0
@@ -244,7 +244,9 @@ void fbnic_bmc_rpc_check(struct fbnic_dev *fbd)if (fbd->fw_cap.need_bmc_tcam_reinit) {fbnic_bmc_rpc_init (fbd); +netif_addr_lock_bh (fbd->netdev);__fbnic_set_rx_mode (fbd, &fbd->netdev->uc, &fbd->netdev->mc); +netif_addr_unlock_bh (fbd->netdev); fbd->fw_cap.need_bmc_tcam_reinit = false; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1129/2077 ALSA: usb-audio: Kill MIDI 2.0 URBs before freeing endpoints
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit f199c8a8bdd54296d3458777e70fe82a78bd9817 ]
MIDI 2.0 input URBs are started during snd_usb_midi_v2_create(). A later setup failure can still jump to snd_usb_midi_v2_free(), which currently frees each endpoint and its coherent URB buffers without first stopping the submitted URBs. A completion can then dereference the embedded URB context and endpoint state after they have been freed, or try to resubmit from the stale endpoint.
This was observed as a KASAN slab-use-after-free in input_urb_complete().
The buggy scenario involves two paths, with each column showing the order within that path:
probe error path: USB completion path:
1. start_input_streams() submits 1. The HCD still owns a
input URBs. submitted input URB.
2. A later setup helper returns 2. input_urb_complete() runs
an error. with urb->context in ep.
3. snd_usb_midi_v2_free() frees 3. The completion reads ep
endpoint storage and URB buffers. state and can requeue URBs.
Make the endpoint destructor follow the same teardown ordering used for disconnect when the endpoint has not already been disconnected: publish ep->disconnected, kill the URBs synchronously, and drain the endpoint before freeing URB buffers and endpoint storage. The guard avoids repeating the stop sequence after the normal snd_usb_midi_v2_disconnect_all() path, while still synchronizing the direct MIDI 2.0 create-error free path.
Validation reproduced this kernel report:
BUG: KASAN: slab-use-after-free in input_urb_complete+0x37/0x1b0 Workqueue: usb_hub_wq hub_event RIP: 0010:_raw_spin_unlock_irq+0x2e/0x50 Read of size 8 Call trace: dump_stack_lvl+0x77/0xb0 print_report+0xce/0x5f0 input_urb_complete+0x37/0x1b0 (sound/usb/midi2.c:186) srso_alias_return_thunk+0x5/0xfbef5 __virt_addr_valid+0x19f/0x330 kasan_report+0xe0/0x110 __usb_hcd_giveback_urb+0x112/0x1d0 dummy_timer+0xaaa/0x19a0 lock_is_held_type+0x9a/0x110 __lock_acquire+0x467/0x28b0 mark_held_locks+0x40/0x70 _raw_spin_unlock_irqrestore+0x44/0x60 lockdep_hardirqs_on_prepare+0xbb/0x1a0 __hrtimer_run_queues+0x101/0x520 hrtimer_run_softirq+0xd0/0x130 handle_softirqs+0x15b/0x670 __irq_exit_rcu+0xd0/0x170 irq_exit_rcu+0xe/0x20 sysvec_apic_timer_interrupt+0x6c/0x80 asm_sysvec_apic_timer_interrupt+0x1a/0x20
--- sound/usb/midi2.c | 5 +++++ 1 file changed, 5 insertions(+)
sound/usb/midi2.c +5 -0
@@ -470,6 +470,11 @@ static int create_midi2_endpoint(struct snd_usb_midi2_interface *umidi,static void free_midi2_endpoint (struct snd_usb_midi2_endpoint *ep) {list_del (&ep->list); +if (!ep->disconnected) { + ep->disconnected =1 ; +kill_midi_urbs (ep, false); +drain_urb_queue (ep); + }free_midi_urbs (ep);kfree (ep); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1130/2077 netfilter: flowtable: fix and simplify IP6IP6 tunnel handling
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Bianconi <[email protected]>
[ Upstream commit f4c2d8668d85ed125985da663c824a9c25498257 ]
Fix nf_flow_ip6_tunnel_proto() to use pskb_may_pull() instead of skb_header_pointer() to ensure the outer IPv6 header is in the skb headroom, which is required for subsequent packet processing. Move ctx->offset update inside the IPPROTO_IPV6 conditional block since it should only be adjusted when an IP6IP6 tunnel is actually detected. Simplify the rx path by removing ipv6_skip_exthdr() and checking ip6h->nexthdr directly, as the flowtable fast path only handles simple IP6IP6 encapsulation without extension headers.
Drop the tunnel encapsulation limit destination option support from the tx path to match, since the rx path no longer handles extension headers. Remove the encap_limit parameter from nf_flow_offload_ipv6_forward(), nf_flow_tunnel_ip6ip6_push() and nf_flow_tunnel_v6_push(), along with the ipv6_tel_txoption struct and related headroom/MTU adjustments.
--- net/ipv6/ip6_tunnel.c | 7 ++ net/netfilter/nf_flow_table_ip.c | 80 +++++-------------- .../selftests/net/netfilter/nft_flowtable.sh | 8 +- 3 files changed, 30 insertions(+), 65 deletions(-)
net/ipv6/ip6_tunnel.c +7 -0
@@ -1850,6 +1850,13 @@ static int ip6_tnl_fill_forward_path(struct net_device_path_ctx *ctx,struct dst_entry *dst;int err; +if (!(t->parms.flags &IP6_TNL_F_IGN_ENCAP_LIMIT )) { +/* encaplimit option is currently not supported is +* sw-acceleration path. +*/ +return -EOPNOTSUPP ; + } + dst =ip6_route_output (dev_net (ctx->dev),NULL , &fl6);if (!dst->error) { path->type =DEV_PATH_TUN ;
net/netfilter/nf_flow_table_ip.c +19 -61
173 lines not on this page · raw message
tools/testing/selftests/net/netfilter/nft_flowtable.sh +4 -4
@@ -592,7 +592,7 @@ ip -net "$nsr1" link set tun0 up ip -net "$nsr1" addr add 192.168.100.1/24 dev tun0 ip netns exec "$nsr1" sysctl net.ipv4.conf.tun0.forwarding=1 > /dev/null -ip -net "$nsr1" link add name tun6 type ip6tnl local fee1:2::1 remote fee1:2::2 +ip -net "$nsr1" link add name tun6 type ip6tnl local fee1:2::1 remote fee1:2::2 encaplimit none ip -net "$nsr1" link set tun6 up ip -net "$nsr1" addr add fee1:3::1/64 dev tun6 nodad
@@ -601,7 +601,7 @@ ip -net "$nsr2" link set tun0 up ip -net "$nsr2" addr add 192.168.100.2/24 dev tun0 ip netns exec "$nsr2" sysctl net.ipv4.conf.tun0.forwarding=1 > /dev/null -ip -net "$nsr2" link add name tun6 type ip6tnl local fee1:2::2 remote fee1:2::1 || ret=1 +ip -net "$nsr2" link add name tun6 type ip6tnl local fee1:2::2 remote fee1:2::1 encaplimit none || ret=1 ip -net "$nsr2" link set tun6 up ip -net "$nsr2" addr add fee1:3::2/64 dev tun6 nodad
@@ -651,7 +651,7 @@ ip -net "$nsr1" route change default via 192.168.200.2 ip netns exec "$nsr1" sysctl net.ipv4.conf.tun0/10.forwarding=1 > /dev/null ip netns exec "$nsr1" nft -a insert rule inet filter forward 'meta oif tun0.10 accept' -ip -net "$nsr1" link add name tun6.10 type ip6tnl local fee1:4::1 remote fee1:4::2 +ip -net "$nsr1" link add name tun6.10 type ip6tnl local fee1:4::1 remote fee1:4::2 encaplimit none ip -net "$nsr1" link set tun6.10 up ip -net "$nsr1" addr add fee1:5::1/64 dev tun6.10 nodad ip -6 -net "$nsr1" route delete default
@@ -670,7 +670,7 @@ ip -net "$nsr2" addr add 192.168.200.2/24 dev tun0.10 ip -net "$nsr2" route change default via 192.168.200.1 ip netns exec "$nsr2" sysctl net.ipv4.conf.tun0/10.forwarding=1 > /dev/null -ip -net "$nsr2" link add name tun6.10 type ip6tnl local fee1:4::2 remote fee1:4::1 || ret=1 +ip -net "$nsr2" link add name tun6.10 type ip6tnl local fee1:4::2 remote fee1:4::1 encaplimit none || ret=1 ip -net "$nsr2" link set tun6.10 up ip -net "$nsr2" addr add fee1:5::2/64 dev tun6.10 nodad ip -6 -net "$nsr2" route delete default
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1131/2077 arm64: static_call: include asm/insns.h
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnd Bergmann <[email protected]>
[ Upstream commit 998d4d789d2d625e1d8c77c1b6c3951e30e81bb0 ]
I came a cross a missing declaration in a randconfig build:
arch/arm64/kernel/static_call.c:16:5: error: call to undeclared function 'aarch64_insn_adrp_get_offset'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
16 | aarch64_insn_adrp_get_offset(le32_to_cpup(tramp + 4)) +
| ^Include the header that contains this definition explicitly, rather than relying on it to come indirectly through another header.
--- arch/arm64/kernel/static_call.c | 1 + 1 file changed, 1 insertion(+)
arch/arm64/kernel/static_call.c +1 -0
@@ -2,6 +2,7 @@#include <linux/static_call.h> #include <linux/memory.h> #include <asm/text-patching.h> +#include <asm/insn.h> void arch_static_call_transform (void *site,void *tramp,void *func,bool tail) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1132/2077 arm64/hw_breakpoint: reject unaligned watchpoints that would truncate BAS
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Breno Leitao <[email protected]>
[ Upstream commit 4cc70f75853bebac022334b6a86b953348072f74 ]
hw_breakpoint_arch_parse() positions the BAS bit pattern in hw->ctrl.len with
offset = hw->address & alignment_mask; /* 0..7 */ hw->ctrl.len <<= offset;
ctrl.len is an 8-bit bitfield (struct arch_hw_breakpoint_ctrl::len is u32 :8), so the shift silently drops any bits past bit 7. For non-compat AArch64 watchpoints the offset is unbounded relative to ctrl.len: a perf_event_open(PERF_TYPE_BREAKPOINT) caller asking for HW_BREAKPOINT_W with bp_addr=page+1 and bp_len=HW_BREAKPOINT_LEN_8 ends up with 0xff << 1 = 0x1fe, stored as 0xfe. The kernel programs WCR.BAS=0xfe and the hardware watches bytes [1..7] instead of the requested [1..8] -- the eighth byte is silently dropped. The syscall still returns success, leaving userspace to discover the gap by empirical probing.
The same class affects HW_BREAKPOINT_LEN_{2,4} when offset pushes the high BAS bit past bit 7 (e.g. LEN_4 with offset=5 yields 0xe0 instead of 0x1e0). No memory-safety impact -- the value is masked into 8 bits before encoding -- but debuggers and perf users observe missed events on bytes they thought they were watching.
The AArch32 branch immediately above already rejects unrepresentable (offset, len) combinations via an explicit switch. Mirror that for the non-compat branch by checking that the shifted pattern fits in the BAS field, returning -EINVAL when it does not.
GDB and similar debuggers are unaffected by the stricter check. aarch64_linux_set_debug_regs() already treats EINVAL on NT_ARM_HW_WATCH as a downgrade signal: it clears kernel_supports_any_contiguous_range, calls aarch64_downgrade_regs() to round the BAS up to a legacy 0x01/03/0f/ff mask with an aligned base, and retries -- the same fallback path that PR-20207 introduced. The new -EINVAL is therefore reachable only from a raw perf_event_open() that pairs an unaligned base with an oversized bp_len, which is precisely the bug.
Reproducer:
struct perf_event_attr a = {
.type = PERF_TYPE_BREAKPOINT, .size = sizeof(a),
.bp_type = HW_BREAKPOINT_W,
.bp_addr = (uintptr_t)(buf + 1),
.bp_len = HW_BREAKPOINT_LEN_8,
.exclude_kernel = 1, .exclude_hv = 1, };
int fd = perf_event_open(&a, 0, -1, -1, 0);
/* before this fix: succeeds, watches 7 bytes (buf+1..buf+7) */
/* after this fix: fails with EINVAL */
--- arch/arm64/kernel/hw_breakpoint.c | 9 +++++++++ 1 file changed, 9 insertions(+)
arch/arm64/kernel/hw_breakpoint.c +9 -0
@@ -559,6 +559,15 @@ int hw_breakpoint_arch_parse(struct perf_event *bp,else alignment_mask =0x7 ; offset = hw->address & alignment_mask; + +/* +* BAS is an 8-bit field in WCR/BCR; the shift below would +* silently drop the high bits of ctrl.len when offset + len +* exceeds 8, programming hardware to watch fewer bytes than +* the user requested. +*/ +if (((u32 )hw->ctrl.len << offset) >ARM_BREAKPOINT_LEN_8 ) +return -EINVAL ; } hw->address &= ~alignment_mask;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1133/2077 thermal: intel: Fix dangling resources on thermal_throttle_online() failure
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ricardo Neri <[email protected]>
[ Upstream commit b91d287fa7a1ba0727eed5823c6ee4924ee5fa31 ]
The function thermal_throttle_add_dev() may fail and abort a CPU hotplug online operation. Since the failure occurs within the online callback, thermal_throttle_online(), the CPU hotplug framework does not invoke the corresponding offline callback. As a result, the hardware and software resources set up during the failed operation are not torn down.
Since only thermal_throttle_add_dev() can fail, call it before setting up the rest of the resources.
--- drivers/thermal/intel/therm_throt.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/thermal/intel/therm_throt.c +6 -1
@@ -529,8 +529,13 @@ static int thermal_throttle_online(unsigned int cpu) {struct thermal_state *state = &per_cpu (thermal_state, cpu);struct device *dev =get_cpu_device (cpu); +int err;u32 l; + err =thermal_throttle_add_dev (dev, cpu); +if (err) +return err; + state->package_throttle.level =PACKAGE_LEVEL ; state->core_throttle.level =CORE_LEVEL ;
@@ -548,7 +553,7 @@ static int thermal_throttle_online(unsigned int cpu) l =apic_read (APIC_LVTTHMR );apic_write (APIC_LVTTHMR , l & ~APIC_LVT_MASKED ); -return thermal_throttle_add_dev (dev, cpu); +return err; }static int thermal_throttle_offline (unsigned int cpu)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1134/2077 ACPI: resource: Amend kernel-doc style
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andy Shevchenko <[email protected]>
[ Upstream commit 78ad5c7722b7bed9d35ffc5b45eb0f12e2c22fee ]
The functions are referred as func() in the kernel-doc. The % (percent) character makes the rendering for constants as described in the respective documentation. Amend all these.
--- drivers/acpi/resource.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/acpi/resource.c +3 -3
@@ -871,7 +871,7 @@ bool acpi_dev_resource_interrupt(struct acpi_resource *ares, int index,EXPORT_SYMBOL_GPL (acpi_dev_resource_interrupt);/** -* acpi_dev_free_resource_list - Free resource from %acpi_dev_get_resources(). +* acpi_dev_free_resource_list - Free resource from acpi_dev_get_resources(). * @list: The head of the resource list to free. */ void acpi_dev_free_resource_list (struct list_head *list)
@@ -991,7 +991,7 @@ static int __acpi_dev_get_resources(struct acpi_device *adev,* * The resultant struct resource objects are put on the list pointed to by * @list, that must be empty initially, as members of struct resource_entry -* objects. Callers of this routine should use %acpi_dev_free_resource_list() to +* objects. Callers of this routine should use acpi_dev_free_resource_list() to * free that list. * * The number of resources in the output list is returned on success, an error
@@ -1032,7 +1032,7 @@ static int is_memory(struct acpi_resource *ares, void *not_used)* The resultant struct resource objects are put on the list pointed to * by @list, that must be empty initially, as members of struct * resource_entry objects. Callers of this routine should use -* %acpi_dev_free_resource_list() to free that list. +* acpi_dev_free_resource_list() to free that list. * * The number of resources in the output list is returned on success, * an error code reflecting the error condition is returned otherwise.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1135/2077 ACPI: IPMI: Fix inverted interface check in ipmi_bmc_gone()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xu Rao <[email protected]>
[ Upstream commit 71b57aca295d61276a60e131d8f62b0cc7cf1a35 ]
Before commit a1a69b297e47 ("ACPI / IPMI: Fix race caused by the unprotected ACPI IPMI user"), ipmi_bmc_gone() skipped entries whose interface number did not match the SMI being removed, then killed the matching entry:
if (ipmi_device->ipmi_ifnum != iface) continue; __ipmi_dev_kill(ipmi_device);
That commit folded the removal block into the existing non-match test while converting the object lifetime handling, but left the comparison unchanged. The old != meant "continue past this entry"; after the refactor it meant "kill this entry".
As a result, a single ACPI IPMI interface is never removed when its SMI disappears. If multiple interfaces are tracked, the first interface whose number differs from iface is removed instead, while the interface that actually disappeared remains on driver_data.ipmi_devices. The stale entry is not marked dead and can continue to be selected for ACPI IPMI transactions. It can also prevent the same ACPI handle from being registered again.
Change the comparison to == so ipmi_bmc_gone() removes exactly the interface reported as gone by the SMI watcher. This restores the pre-a1a69b297e47 behavior and is the correct interface matching logic.
--- drivers/acpi/acpi_ipmi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/acpi_ipmi.c +1 -1
@@ -490,7 +490,7 @@ static void ipmi_bmc_gone(int iface)mutex_lock (&driver_data.ipmi_lock);list_for_each_entry_safe (iter, temp, &driver_data.ipmi_devices, head) { -if (iter->ipmi_ifnum != iface) { +if (iter->ipmi_ifnum == iface) { ipmi_device = iter;__ipmi_dev_kill (iter);break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1136/2077 ieee802154: Restore initial state on failed device_rename() in cfg802154_switch_netns()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ivan Abramov <[email protected]>
[ Upstream commit a2e06b4bef20b59446d5088e938c2be53cc4e6c6 ]
Currently, the return value of device_rename() is not acted upon.
To avoid an inconsistent state in case of failure, roll back the changes made before the device_rename() call.
Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
--- net/ieee802154/core.c | 45 ++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 20 deletions(-)
net/ieee802154/core.c +25 -20
@@ -233,31 +233,36 @@ int cfg802154_switch_netns(struct cfg802154_registered_device *rdev, wpan_dev->netdev->netns_immutable = true; } -if (err) { -/* failed -- clean up to old netns */ - net =wpan_phy_net (&rdev->wpan_phy); - -list_for_each_entry_continue_reverse (wpan_dev, - &rdev->wpan_dev_list, - list) { -if (!wpan_dev->netdev) -continue ; - wpan_dev->netdev->netns_immutable = false; - err =dev_change_net_namespace (wpan_dev->netdev, net, -"wpan%d" ); -WARN_ON (err); - wpan_dev->netdev->netns_immutable = true; - } - -return err; - } - -wpan_phy_net_set (&rdev->wpan_phy, net); +if (err) + goto errout; err =device_rename (&rdev->wpan_phy.dev,dev_name (&rdev->wpan_phy.dev));WARN_ON (err); +if (err) + goto errout; + +wpan_phy_net_set (&rdev->wpan_phy, net); +return 0 ; + +errout: +/* failed -- clean up to old netns */ + net =wpan_phy_net (&rdev->wpan_phy); + +list_for_each_entry_continue_reverse (wpan_dev, + &rdev->wpan_dev_list, + list) { +if (!wpan_dev->netdev) +continue ; + wpan_dev->netdev->netns_immutable = false; + err =dev_change_net_namespace (wpan_dev->netdev, net, +"wpan%d" ); +WARN_ON (err); + wpan_dev->netdev->netns_immutable = true; + } + +return err; }void cfg802154_dev_free (struct cfg802154_registered_device *rdev)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1137/2077 ieee802154: Avoid calling WARN_ON() on -ENOMEM in cfg802154_switch_netns()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ivan Abramov <[email protected]>
[ Upstream commit 0569f67ed6a7af838e2141da93c68e6b6013f483 ]
It's pointless to call WARN_ON() in case of an allocation failure in dev_change_net_namespace() and device_rename(), since it only leads to useless splats caused by deliberate fault injections, so avoid it.
Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
--- net/ieee802154/core.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
net/ieee802154/core.c +5 -3
@@ -228,8 +228,10 @@ int cfg802154_switch_netns(struct cfg802154_registered_device *rdev,continue ; wpan_dev->netdev->netns_immutable = false; err =dev_change_net_namespace (wpan_dev->netdev, net,"wpan%d" ); -if (err) +if (err) { +WARN_ON (err && err != -ENOMEM );break ; + } wpan_dev->netdev->netns_immutable = true; }
@@ -237,7 +239,7 @@ int cfg802154_switch_netns(struct cfg802154_registered_device *rdev, goto errout; err =device_rename (&rdev->wpan_phy.dev,dev_name (&rdev->wpan_phy.dev)); -WARN_ON (err); +WARN_ON (err && err != -ENOMEM );if (err) goto errout;
@@ -258,7 +260,7 @@ int cfg802154_switch_netns(struct cfg802154_registered_device *rdev, wpan_dev->netdev->netns_immutable = false; err =dev_change_net_namespace (wpan_dev->netdev, net,"wpan%d" ); -WARN_ON (err); +WARN_ON (err && err != -ENOMEM ); wpan_dev->netdev->netns_immutable = true; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1138/2077 ieee802154: Remove WARN_ON() in cfg802154_pernet_exit()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ivan Abramov <[email protected]>
[ Upstream commit e69ed6fc9fb3b386b5fcdb9f51623f122cee2ebd ]
There's no need to call WARN_ON() in cfg802154_pernet_exit(), since every point of failure in cfg802154_switch_netns() is covered with WARN_ON(), so remove it.
Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
--- net/ieee802154/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ieee802154/core.c +1 -1
@@ -358,7 +358,7 @@ static void __net_exit cfg802154_pernet_exit(struct net *net)rtnl_lock ();list_for_each_entry (rdev, &cfg802154_rdev_list, list) {if (net_eq (wpan_phy_net (&rdev->wpan_phy), net)) -WARN_ON (cfg802154_switch_netns (rdev, &init_net)); +cfg802154_switch_netns (rdev, &init_net); }rtnl_unlock (); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1139/2077 ieee802154: fix kernel-infoleak in dgram_recvmsg()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aleksandr Nogikh <[email protected]>
[ Upstream commit 4db86f8ab11b5a41bfc36680be837e6ac1375ec6 ]
KMSAN reported a kernel-infoleak in move_addr_to_user():
BUG: KMSAN: kernel-infoleak in instrument_copy_to_user include/linux/instrumented.h:131 [inline] BUG: KMSAN: kernel-infoleak in _inline_copy_to_user include/linux/uaccess.h:205 [inline] BUG: KMSAN: kernel-infoleak in _copy_to_user+0xcc/0x120 lib/usercopy.c:26 instrument_copy_to_user include/linux/instrumented.h:131 [inline] _inline_copy_to_user include/linux/uaccess.h:205 [inline] _copy_to_user+0xcc/0x120 lib/usercopy.c:26 copy_to_user include/linux/uaccess.h:236 [inline] move_addr_to_user+0x2e7/0x440 net/socket.c:302 ____sys_recvmsg+0x232/0x610 net/socket.c:2925 ... Uninit was stored to memory at: ieee802154_addr_to_sa include/net/ieee802154_netdev.h:369 [inline] dgram_recvmsg+0xa09/0xbe0 net/ieee802154/socket.c:739
The issue occurs because the pan_id field of struct ieee802154_addr is left uninitialized when the address mode is IEEE802154_ADDR_NONE. The execution flow is as follows:
1. __ieee802154_rx_handle_packet() declares a local struct ieee802154_hdr hdr on the stack.
2. ieee802154_hdr_pull() calls ieee802154_hdr_get_addr() to parse the source and destination addresses into this structure.
3. If the address mode is IEEE802154_ADDR_NONE, ieee802154_hdr_get_addr() previously only set the mode field, leaving the pan_id field containing uninitialized stack memory.
4. This uninitialized pan_id is later copied into a struct sockaddr_ieee802154 in dgram_recvmsg() via ieee802154_addr_to_sa().
5. Finally, move_addr_to_user() copies the socket address structure to user space, leaking the uninitialized bytes.
Fix this by using memset to zero out the address structure in ieee802154_hdr_get_addr() when the mode is IEEE802154_ADDR_NONE.
--- net/ieee802154/header_ops.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
net/ieee802154/header_ops.c +6 -3
@@ -173,10 +173,13 @@ ieee802154_hdr_get_addr(const u8 *buf, int mode, bool omit_pan, {int pos =0 ; - addr->mode = mode; - -if (mode ==IEEE802154_ADDR_NONE ) +if (mode ==IEEE802154_ADDR_NONE ) { +memset (addr,0 ,sizeof (*addr)); + addr->mode =IEEE802154_ADDR_NONE ;return 0 ; + } + + addr->mode = mode;if (!omit_pan) {memcpy (&addr->pan_id, buf + pos,2 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1140/2077 mac802154: Prevent overwrite return code in mac802154_perform_association()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Robertus Diawan Chris <[email protected]>
[ Upstream commit 649147cb3f8b3c0c9aeba5d89d69a6ef221c12c2 ]
When assoc_status not equal to IEEE802154_ASSOCIATION_SUCCESSFUL, the return value assigned to either "-ERANGE" or "-EPERM" but this return value will be overwritten to 0 after exiting the conditional scope. So, jump to clear_assoc label to preserve the return value when assoc_status not equal to IEEE802154_ASSOCIATION_SUCCESSFUL.
This is reported by Coverity Scan as "Unused value".
--- net/mac802154/scan.c | 1 + 1 file changed, 1 insertion(+)
net/mac802154/scan.c +1 -0
@@ -594,6 +594,7 @@ int mac802154_perform_association(struct ieee802154_sub_if_data *sdata,"Negative ASSOC RESP received from %8phC: %s\n" , &ceaddr, local->assoc_status ==IEEE802154_PAN_AT_CAPACITY ? "PAN at capacity" : "access denied"); + goto clear_assoc; } ret =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1141/2077 md/raid1: fix writes_pending and barrier reference leaks on write failures
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abd-Alrhman Masalkhi <[email protected]>
[ Upstream commit 8e065a1602511282fc0da2dc89445e0eb71a681c ]
raid1_make_request() acquires a writes_pending reference with md_write_start() before calling raid1_write_request(). Several failure paths in raid1_write_request() complete the bio and return without reaching the normal write completion path, causing the corresponding md_write_end() to be skipped.
Make raid1_write_request() return a status indicating whether the write request was successfully queued. This allows raid1_make_request() to call md_write_end() when raid1_write_request() fails.
Additionally, if wait_blocked_rdev() fails after wait_barrier() succeeds, the associated barrier reference is not released.
Call allow_barrier() before returning from that path to keep the barrier accounting balanced.
--- drivers/md/raid1.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/md/raid1.c +12 -7
@@ -1501,7 +1501,7 @@ static void raid1_start_write_behind(struct mddev *mddev, struct r1bio *r1_bio, } -static void raid1_write_request (struct mddev *mddev,struct bio *bio, +static bool raid1_write_request (struct mddev *mddev,struct bio *bio,int max_write_sectors) {struct r1conf *conf = mddev->private;
@@ -1512,6 +1512,7 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio,int max_sectors;bool write_behind = false;bool is_discard = (bio_op (bio) ==REQ_OP_DISCARD ); +sector_t sector = bio->bi_iter.bi_sector;if (mddev_is_clustered (mddev) && mddev->cluster_ops->area_resyncing(mddev, WRITE,
@@ -1519,7 +1520,7 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio,if (bio->bi_opf &REQ_NOWAIT ) {bio_wouldblock_error (bio); -return ; +return false; }wait_event_idle (conf->wait_barrier, !mddev->cluster_ops->area_resyncing(mddev, WRITE,
@@ -1535,12 +1536,13 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio,if (!wait_barrier (conf, bio->bi_iter.bi_sector, bio->bi_opf &REQ_NOWAIT )) {bio_wouldblock_error (bio); -return ; +return false; }if (!wait_blocked_rdev (mddev, bio)) {bio_wouldblock_error (bio); -return ; +allow_barrier (conf, sector); +return false; } r1_bio =alloc_r1bio (mddev, bio);
@@ -1699,7 +1701,8 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio,/* In case raid1d snuck in to freeze_array */ wake_up_barrier (conf); -return ; +return true; + err_handle:for (k =0 ; k < i; k++) {if (r1_bio->bios[k]) {
@@ -1709,6 +1712,7 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio, }raid_end_bio_io (r1_bio); +return false; }static bool raid1_make_request (struct mddev *mddev,struct bio *bio)
@@ -1732,8 +1736,9 @@ static bool raid1_make_request(struct mddev *mddev, struct bio *bio)if (bio_data_dir (bio) ==READ )raid1_read_request (mddev, bio, sectors,NULL );else { -md_write_start (mddev,bio); -raid1_write_request (mddev, bio, sectors); +md_write_start (mddev, bio); +if (!raid1_write_request (mddev, bio, sectors)) +md_write_end (mddev); }return true; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1142/2077 md/raid10: fix writes_pending leak on write request failures
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abd-Alrhman Masalkhi <[email protected]>
[ Upstream commit e045d6ed33f8faa3e3dd6dc33c62ec01e3ad275d ]
raid10_make_request() acquires a writes_pending reference with md_write_start() before dispatching write requests. Several failure paths in raid10_write_request() complete the bio and return without reaching the normal write completion path, causing the corresponding md_write_end() to be skipped.
Make raid10_write_request() return a status indicating whether the write request was successfully queued. This allows raid10_make_request() to release the writes_pending reference with md_write_end() when a write request fails.
--- drivers/md/raid10.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)
drivers/md/raid10.c +15 -8
@@ -1349,7 +1349,7 @@ static void wait_blocked_dev(struct mddev *mddev, struct r10bio *r10_bio) } } -static void raid10_write_request (struct mddev *mddev,struct bio *bio, +static bool raid10_write_request (struct mddev *mddev,struct bio *bio,struct r10bio *r10_bio) {struct r10conf *conf = mddev->private;
@@ -1365,7 +1365,7 @@ static void raid10_write_request(struct mddev *mddev, struct bio *bio,/* Bail out if REQ_NOWAIT is set for the bio */ if (bio->bi_opf &REQ_NOWAIT ) {bio_wouldblock_error (bio); -return ; +return false; }for (;;) { prepare_to_wait(&conf->wait_barrier,
@@ -1381,7 +1381,7 @@ static void raid10_write_request(struct mddev *mddev, struct bio *bio, sectors = r10_bio->sectors;if (!regular_request_wait (mddev, conf, bio, sectors)) {free_r10bio (r10_bio); -return ; +return false; } if (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) &&
@@ -1398,7 +1398,7 @@ static void raid10_write_request(struct mddev *mddev, struct bio *bio,if (bio->bi_opf &REQ_NOWAIT ) {allow_barrier (conf);bio_wouldblock_error (bio); -return ; +return false; }mddev_add_trace_msg (conf->mddev,"raid10 wait reshape metadata" );
@@ -1514,7 +1514,8 @@ static void raid10_write_request(struct mddev *mddev, struct bio *bio,raid10_write_one_disk (mddev, r10_bio, bio, true, i); }one_write_done (r10_bio); -return ; +return true; + err_handle:for (k =0 ; k < i; k++) {int d = r10_bio->devs[k].devnum;
@@ -1532,10 +1533,12 @@ static void raid10_write_request(struct mddev *mddev, struct bio *bio, }raid_end_bio_io (r10_bio); +return false; } -static void __make_request (struct mddev *mddev,struct bio *bio,int sectors) +static bool __make_request (struct mddev *mddev,struct bio *bio,int sectors) { +bool ret;struct r10conf *conf = mddev->private;struct r10bio *r10_bio;
@@ -1551,10 +1554,13 @@ static void __make_request(struct mddev *mddev, struct bio *bio, int sectors)memset (r10_bio->devs,0 ,sizeof (r10_bio->devs[0 ]) * conf->geo.raid_disks); + ret = true;if (bio_data_dir (bio) ==READ )raid10_read_request (mddev, bio, r10_bio);else -raid10_write_request (mddev, bio, r10_bio); + ret =raid10_write_request (mddev, bio, r10_bio); + +return ret; }static void raid_end_discard_bio (struct r10bio *r10bio)
@@ -1900,7 +1906,8 @@ static bool raid10_make_request(struct mddev *mddev, struct bio *bio) sectors = chunk_sects - (bio->bi_iter.bi_sector & (chunk_sects -1 )); -__make_request (mddev, bio, sectors); +if (!__make_request (mddev, bio, sectors)) +md_write_end (mddev);/* In case raid10d snuck in to freeze_array */ wake_up_barrier (conf);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1143/2077 md/raid10: fix writes_pending and barrier reference leaks on discard failures
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abd-Alrhman Masalkhi <[email protected]>
[ Upstream commit 393d687131d8aa8c7e4de2cb494438e145d20fc2 ]
raid10_make_request() acquires a writes_pending reference with md_write_start() before calling raid10_handle_discard(). Several failure paths in raid10_handle_discard() complete the bio and return without releasing the corresponding reference, causing md_write_end() to be skipped.
Call md_write_end() before returning from these failure paths to keep writes_pending accounting balanced.
Additionally, discard split allocation failures can occur after wait_barrier() succeeds. Those paths return without calling allow_barrier(), leaking the associated barrier reference.
Release the barrier before returning from those paths.
--- drivers/md/raid10.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/md/raid10.c +5 -0
@@ -1639,6 +1639,7 @@ static int raid10_handle_discard(struct mddev *mddev, struct bio *bio)if (!wait_barrier (conf, bio->bi_opf &REQ_NOWAIT )) {bio_wouldblock_error (bio); +md_write_end (mddev);return 0 ; }
@@ -1681,6 +1682,8 @@ static int raid10_handle_discard(struct mddev *mddev, struct bio *bio)if (IS_ERR (split)) { bio->bi_status =errno_to_blk_status (PTR_ERR (split));bio_endio (bio); +md_write_end (mddev); +allow_barrier (conf);return 0 ; }
@@ -1698,6 +1701,8 @@ static int raid10_handle_discard(struct mddev *mddev, struct bio *bio)if (IS_ERR (split)) { bio->bi_status =errno_to_blk_status (PTR_ERR (split));bio_endio (bio); +md_write_end (mddev); +allow_barrier (conf);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1144/2077 md/raid1: honor REQ_NOWAIT when waiting for behind writes
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abd-Alrhman Masalkhi <[email protected]>
[ Upstream commit a286cb88ddb26c5f4377859d8e77233d9181eb82 ]
raid1 supports REQ_NOWAIT reads by avoiding waits in the barrier path through wait_read_barrier(). However, a read can still block on a WriteMostly device when the array uses a bitmap and there are outstanding behind writes.
In that case raid1 unconditionally calls wait_behind_writes(), which may sleep until all behind writes complete. As a result, a REQ_NOWAIT read can block despite the caller explicitly requesting non-blocking behavior.
This ensures that raid1 consistently honors REQ_NOWAIT reads across all paths that may otherwise wait for behind writes.
--- drivers/md/md-bitmap.c | 9 +++++++-- drivers/md/md-bitmap.h | 2 +- drivers/md/md-llbitmap.c | 13 ++++++++----- drivers/md/md.c | 2 +- drivers/md/raid1.c | 10 +++++++--- 5 files changed, 24 insertions(+), 12 deletions(-)
drivers/md/md-bitmap.c +7 -2
@@ -2063,18 +2063,23 @@ static void bitmap_end_behind_write(struct mddev *mddev) bitmap->mddev->bitmap_info.max_write_behind); } -static void bitmap_wait_behind_writes (struct mddev *mddev) +static bool bitmap_wait_behind_writes (struct mddev *mddev,bool nowait) {struct bitmap *bitmap = mddev->bitmap;/* wait for behind writes to complete */ if (bitmap &&atomic_read (&bitmap->behind_writes) >0 ) { +if (nowait) +return false; +pr_debug ("md:%s: behind writes in progress - waiting to stop.\n" ,mdname (mddev));/* need to kick something here to make sure I/O goes? */ wait_event (bitmap->behind_wait,atomic_read (&bitmap->behind_writes) ==0 ); } + +return true; }static void bitmap_destroy (struct mddev *mddev)
@@ -2084,7 +2089,7 @@ static void bitmap_destroy(struct mddev *mddev)if (!bitmap)/* there was no bitmap */ return ; -bitmap_wait_behind_writes (mddev); +bitmap_wait_behind_writes (mddev, false);if (!test_bit (MD_SERIALIZE_POLICY , &mddev->flags))mddev_destroy_serial_pool (mddev,NULL );
drivers/md/md-bitmap.h +1 -1
@@ -98,7 +98,7 @@ struct bitmap_operations {void (*start_behind_write)(struct mddev *mddev);void (*end_behind_write)(struct mddev *mddev); -void (*wait_behind_writes)(struct mddev *mddev); +bool (*wait_behind_writes)(struct mddev *mddev,bool nowait);md_bitmap_fn *start_write;md_bitmap_fn *end_write;
drivers/md/md-llbitmap.c +8 -5
@@ -1574,16 +1574,19 @@ static void llbitmap_end_behind_write(struct mddev *mddev)wake_up (&llbitmap->behind_wait); } -static void llbitmap_wait_behind_writes (struct mddev *mddev) +static bool llbitmap_wait_behind_writes (struct mddev *mddev,bool nowait) {struct llbitmap *llbitmap = mddev->bitmap; -if (!llbitmap) -return ; +if (llbitmap &&atomic_read (&llbitmap->behind_writes) >0 ) { +if (nowait) +return false; -wait_event (llbitmap->behind_wait, -atomic_read (&llbitmap->behind_writes) ==0 ); +wait_event (llbitmap->behind_wait, +atomic_read (&llbitmap->behind_writes) ==0 ); + } +return true; }static ssize_t bits_show (struct mddev *mddev,char *page)
drivers/md/md.c +1 -1
@@ -7049,7 +7049,7 @@ EXPORT_SYMBOL_GPL(md_stop_writes);static void mddev_detach (struct mddev *mddev) {if (md_bitmap_enabled (mddev, false)) - mddev->bitmap_ops->wait_behind_writes (mddev); + mddev->bitmap_ops->wait_behind_writes (mddev, false);if (mddev->pers && mddev->pers->quiesce && !is_md_suspended (mddev)) { mddev->pers->quiesce (mddev,1 ); mddev->pers->quiesce (mddev,0 );
drivers/md/raid1.c +7 -3
@@ -1341,6 +1341,7 @@ static void raid1_read_request(struct mddev *mddev, struct bio *bio,int max_sectors;int rdisk;bool r1bio_existed = !!r1_bio; +bool nowait = bio->bi_opf &REQ_NOWAIT ;/* * An md cloned bio indicates we are in the error path.
@@ -1360,8 +1361,7 @@ static void raid1_read_request(struct mddev *mddev, struct bio *bio,* Still need barrier for READ in case that whole * array is frozen. */ -if (!wait_read_barrier (conf, bio->bi_iter.bi_sector, - bio->bi_opf &REQ_NOWAIT )) { +if (!wait_read_barrier (conf, bio->bi_iter.bi_sector, nowait)) {bio_wouldblock_error (bio);return ; }
@@ -1402,7 +1402,11 @@ static void raid1_read_request(struct mddev *mddev, struct bio *bio,* over-take any writes that are 'behind' */ mddev_add_trace_msg (mddev,"raid1 wait behind writes" ); - mddev->bitmap_ops->wait_behind_writes (mddev); +if (!mddev->bitmap_ops->wait_behind_writes (mddev, nowait)) { +bio_wouldblock_error (bio); +set_bit (R1BIO_Returned, &r1_bio->state); + goto err_handle; + } }if (max_sectors <bio_sectors (bio)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1145/2077 md/raid1: free r1_bio when REQ_NOWAIT is set and read would block on retry
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abd-Alrhman Masalkhi <[email protected]>
[ Upstream commit 69ad6ce47f9bf2b9fe0ed69b042db993d33bbf12 ]
When a read is retried, raid1_read_request() may be called with a pre-allocated r1_bio. If wait_read_barrier() fails for a REQ_NOWAIT read, the bio is completed and the function returns immediately. In this case the existing r1_bio is leaked.
This fixes a leak of pre-allocated r1_bio structures for retried reads.
--- drivers/md/raid1.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/md/raid1.c +6 -0
@@ -1363,6 +1363,12 @@ static void raid1_read_request(struct mddev *mddev, struct bio *bio,*/ if (!wait_read_barrier (conf, bio->bi_iter.bi_sector, nowait)) {bio_wouldblock_error (bio); + +if (r1bio_existed) { +set_bit (R1BIO_Returned, &r1_bio->state); +raid_end_bio_io (r1_bio); + } +return ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1146/2077 netfilter: ipset: Dont use test_bit() in lockless RCU readers in hash types
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jozsef Kadlecsik <[email protected]>
[ Upstream commit e4b4984e28c16406ecb318444dea4a8bf47def3e ]
Sashiko pointed out that there are a few lockless RCU readers using test_bit() which is a relaxed atomic operation and provides no memory barrier guarantees. Use test_bit_acquire() instead where the operation may run parallel with add/del/gc, i.e. is not one from the next cases
- protected by region lock
- in a set destroy phase
- in a new/temporary set creation phase
--- net/netfilter/ipset/ip_set_hash_gen.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
net/netfilter/ipset/ip_set_hash_gen.h +5 -5
@@ -689,7 +689,7 @@ mtype_resize(struct ip_set *set, bool retried)continue ; pos =smp_load_acquire (&n->pos);for (j =0 ; j < pos; j++) { -if (!test_bit (j, n->used)) +if (!test_bit_acquire (j, n->used))continue ; data =ahash_data (n, j, dsize);if (SET_ELEM_EXPIRED (set, data))
@@ -826,7 +826,7 @@ mtype_ext_size(struct ip_set *set, u32 *elements, size_t *ext_size)continue ; pos =smp_load_acquire (&n->pos);for (j =0 ; j < pos; j++) { -if (!test_bit (j, n->used)) +if (!test_bit_acquire (j, n->used))continue ; data =ahash_data (n, j, set->dsize);if (!SET_ELEM_EXPIRED (set, data))
@@ -1201,7 +1201,7 @@ mtype_test_cidrs(struct ip_set *set, struct mtype_elem *d,continue ; pos =smp_load_acquire (&n->pos);for (i =0 ; i < pos; i++) { -if (!test_bit (i, n->used)) +if (!test_bit_acquire (i, n->used))continue ; data =ahash_data (n, i, set->dsize);if (!mtype_data_equal (data, d, &multi))
@@ -1259,7 +1259,7 @@ mtype_test(struct ip_set *set, void *value, const struct ip_set_ext *ext, } pos =smp_load_acquire (&n->pos);for (i =0 ; i < pos; i++) { -if (!test_bit (i, n->used)) +if (!test_bit_acquire (i, n->used))continue ; data =ahash_data (n, i, set->dsize);if (!mtype_data_equal (data, d, &multi))
@@ -1396,7 +1396,7 @@ mtype_list(const struct ip_set *set,continue ; pos =smp_load_acquire (&n->pos);for (i =0 ; i < pos; i++) { -if (!test_bit (i, n->used)) +if (!test_bit_acquire (i, n->used))continue ; e =ahash_data (n, i, set->dsize);if (SET_ELEM_EXPIRED (set, e))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1147/2077 netfilter: ipset: Dont use test_bit() in lockless RCU readers in bitmap types
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jozsef Kadlecsik <[email protected]>
[ Upstream commit 1171192ac9af46ddf65caf4162f1b64c58ae37f4 ]
The pair of the patch "netfilter: ipset: Don't use test_bit() in lockless RCU readers in hash types" for the bitmap types.
--- net/netfilter/ipset/ip_set_bitmap_gen.h | 4 +++- net/netfilter/ipset/ip_set_bitmap_ip.c | 2 +- net/netfilter/ipset/ip_set_bitmap_ipmac.c | 2 +- net/netfilter/ipset/ip_set_bitmap_port.c | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-)
net/netfilter/ipset/ip_set_bitmap_gen.h +3 -1
@@ -165,6 +165,7 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,ip_set_init_skbinfo (ext_skbinfo (x, set), ext);/* Activate element */ +smp_mb__before_atomic ();set_bit (e->id, map->members); set->elements++;
@@ -219,7 +220,7 @@ mtype_list(const struct ip_set *set,cond_resched_rcu (); id = cb->args[IPSET_CB_ARG0 ]; x =get_ext (set, map, id); - if (!test_bit(id, map->members) || + if (!test_bit_acquire(id, map->members) || (SET_WITH_TIMEOUT(set) && #ifdef IP_SET_BITMAP_STORED_TIMEOUT mtype_is_filled(x) &&
@@ -278,6 +279,7 @@ mtype_gc(struct timer_list *t) x =get_ext (set, map, id);if (ip_set_timeout_expired (ext_timeout (x, set))) {clear_bit (id, map->members); +smp_mb__after_atomic ();ip_set_ext_destroy (set, x); set->elements--; }
net/netfilter/ipset/ip_set_bitmap_ip.c +1 -1
@@ -67,7 +67,7 @@ static int bitmap_ip_do_test(const struct bitmap_ip_adt_elem *e, struct bitmap_ip *map, size_t dsize) { - return !!test_bit(e->id, map->members); + return !!test_bit_acquire(e->id, map->members); } static int
net/netfilter/ipset/ip_set_bitmap_ipmac.c +1 -1
@@ -86,7 +86,7 @@ bitmap_ipmac_do_test(const struct bitmap_ipmac_adt_elem *e, {const struct bitmap_ipmac_elem *elem; -if (!test_bit (e->id, map->members)) +if (!test_bit_acquire (e->id, map->members))return 0 ; elem =get_const_elem (map->extensions, e->id, dsize);if (e->add_mac && elem->filled ==MAC_FILLED )
net/netfilter/ipset/ip_set_bitmap_port.c +1 -1
@@ -58,7 +58,7 @@ static int bitmap_port_do_test(const struct bitmap_port_adt_elem *e, const struct bitmap_port *map, size_t dsize) { - return !!test_bit(e->id, map->members); + return !!test_bit_acquire(e->id, map->members); } static int
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1148/2077 netfilter: ipset: fix order of kfree_rcu() and rcu_assign_pointer()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jozsef Kadlecsik <[email protected]>
[ Upstream commit 3ca9982a8882470aa0ac4e8bb9a552b181d1efcd ]
Sashiko pointed out that kfree_rcu() was called before rcu_assign_pointer() in handling the comment extension. Fix the order so that rcu_assign_pointer() called first.
--- net/netfilter/ipset/ip_set_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/ipset/ip_set_core.c +2 -2
@@ -351,8 +351,8 @@ ip_set_init_comment(struct ip_set *set, struct ip_set_comment *comment,if (unlikely (c)) { set->ext_size -=sizeof (*c) +strlen (c->str) +1 ; -kfree_rcu (c, rcu);rcu_assign_pointer (comment->c,NULL ); +kfree_rcu (c, rcu); }if (!len)return ;
@@ -393,8 +393,8 @@ ip_set_comment_free(struct ip_set *set, void *ptr)if (unlikely (!c))return ; set->ext_size -=sizeof (*c) +strlen (c->str) +1 ; -kfree_rcu (c, rcu);rcu_assign_pointer (comment->c,NULL ); +kfree_rcu (c, rcu); }typedef void (*destroyer )(struct ip_set *,void *);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1149/2077 netfilter: ipset: make sure gc is properly stopped
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jozsef Kadlecsik <[email protected]>
[ Upstream commit 4a597a87e2e2f608edb6be2c510dc826b4fdfb53 ]
Sashiko noticed that when destroying a set,cancel_delayed_work_sync() was called while gc
calls queue_delayed_work() unconditionally which
can lead not to properly shutting down the gc.
--- net/netfilter/ipset/ip_set_hash_gen.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/ipset/ip_set_hash_gen.h +1 -1
@@ -606,7 +606,7 @@ mtype_cancel_gc(struct ip_set *set)struct htype *h = set->data;if (SET_WITH_TIMEOUT (set)) -cancel_delayed_work_sync (&h->gc.dwork); +disable_delayed_work_sync (&h->gc.dwork); } static int
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1150/2077 netfilter: nft_payload: reject offsets exceeding 65535 bytes
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit 213be32f46a29ca15a314df06c3424ecffd6c90a ]
Large offsets were rejected based on netlink policy, but blamed commit removed the policy without updating nft_payload_inner_init() to use the truncation-check helper.
Silent truncation is not a problem, but not wanted either, so add a check.
--- net/netfilter/nft_payload.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
net/netfilter/nft_payload.c +13 -3
@@ -224,11 +224,17 @@ static int nft_payload_init(const struct nft_ctx *ctx, const struct nlattr * const tb[]) {struct nft_payload *priv =nft_expr_priv (expr); +u32 offset; +int err; priv->base =ntohl (nla_get_be32 (tb[NFTA_PAYLOAD_BASE ])); - priv->offset =ntohl (nla_get_be32 (tb[NFTA_PAYLOAD_OFFSET ])); priv->len =ntohl (nla_get_be32 (tb[NFTA_PAYLOAD_LEN ])); + err =nft_parse_u32_check (tb[NFTA_PAYLOAD_OFFSET ],U16_MAX , &offset); +if (err <0 ) +return err; + priv->offset = offset; +return nft_parse_register_store (ctx, tb[NFTA_PAYLOAD_DREG ], &priv->dreg,NULL ,NFT_DATA_VALUE , priv->len);
@@ -621,7 +627,8 @@ static int nft_payload_inner_init(const struct nft_ctx *ctx, const struct nlattr * const tb[]) {struct nft_payload *priv =nft_expr_priv (expr); -u32 base; +u32 base, offset; +int err;if (!tb[NFTA_PAYLOAD_BASE ] || !tb[NFTA_PAYLOAD_OFFSET ] || !tb[NFTA_PAYLOAD_LEN ] || !tb[NFTA_PAYLOAD_DREG ])
@@ -639,8 +646,11 @@ static int nft_payload_inner_init(const struct nft_ctx *ctx, } priv->base = base; - priv->offset =ntohl (nla_get_be32 (tb[NFTA_PAYLOAD_OFFSET ])); priv->len =ntohl (nla_get_be32 (tb[NFTA_PAYLOAD_LEN ])); + err =nft_parse_u32_check (tb[NFTA_PAYLOAD_OFFSET ],U16_MAX , &offset); +if (err <0 ) +return err; + priv->offset = offset; return nft_parse_register_store(ctx, tb[NFTA_PAYLOAD_DREG], &priv->dreg, NULL, NFT_DATA_VALUE,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1151/2077 netfilter: nft_meta_bridge: add validate callback for get operations
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit bff1c8b49a9cb5c04af20f4e7d43bf4af5863bc6 ]
Blamed commit added NFT_META_BRI_IIFHWADDR to the set validate callback, yet this is a get operation.
Add a get validate callback and move the NFT_META_BRI_IIFHWADDR key there.
AFAICS this is harmless, NFT_META_BRI_IIFHWADDR can deal with a NULL input device and the set handler ignores a NFT_META_BRI_IIFHWADDR operation, but it allows to read 4 bytes off bridge skb->cb[].
--- include/net/netfilter/nft_meta.h | 2 ++ net/bridge/netfilter/nft_meta_bridge.c | 19 ++++++++++++++++++- net/netfilter/nft_meta.c | 5 +++-- 3 files changed, 23 insertions(+), 3 deletions(-)
include/net/netfilter/nft_meta.h +2 -0
@@ -40,6 +40,8 @@ void nft_meta_set_eval(const struct nft_expr *expr,void nft_meta_set_destroy (const struct nft_ctx *ctx,const struct nft_expr *expr); +int nft_meta_get_validate (const struct nft_ctx *ctx, +const struct nft_expr *expr);int nft_meta_set_validate (const struct nft_ctx *ctx,const struct nft_expr *expr);
net/bridge/netfilter/nft_meta_bridge.c +18 -1
@@ -107,12 +107,30 @@ static int nft_meta_bridge_get_init(const struct nft_ctx *ctx, NULL, NFT_DATA_VALUE, len); } +static int nft_meta_bridge_get_validate (const struct nft_ctx *ctx, +const struct nft_expr *expr) +{ +struct nft_meta *priv =nft_expr_priv (expr); +unsigned int hooks; + +switch (priv->key) { +case NFT_META_BRI_IIFHWADDR : + hooks =1 <<NF_BR_PRE_ROUTING ; +break ; +default : +return nft_meta_get_validate (ctx, expr); + } + +return nft_chain_validate_hooks (ctx->chain, hooks); +} +static struct nft_expr_type nft_meta_bridge_type;static const struct nft_expr_ops nft_meta_bridge_get_ops = { .type = &nft_meta_bridge_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_meta )), .eval = nft_meta_bridge_get_eval, .init = nft_meta_bridge_get_init, + .validate = nft_meta_bridge_get_validate, .dump = nft_meta_get_dump, };
@@ -168,7 +186,6 @@ static int nft_meta_bridge_set_validate(const struct nft_ctx *ctx,switch (priv->key) {case NFT_META_BRI_BROUTE : -case NFT_META_BRI_IIFHWADDR : hooks =1 <<NF_BR_PRE_ROUTING ;break ;default :
net/netfilter/nft_meta.c +3 -2
@@ -635,8 +635,8 @@ static int nft_meta_get_validate_xfrm(const struct nft_ctx *ctx)#endif } -static int nft_meta_get_validate (const struct nft_ctx *ctx, -const struct nft_expr *expr) +int nft_meta_get_validate (const struct nft_ctx *ctx, +const struct nft_expr *expr) {const struct nft_meta *priv =nft_expr_priv (expr);
@@ -652,6 +652,7 @@ static int nft_meta_get_validate(const struct nft_ctx *ctx,return 0 ; } +EXPORT_SYMBOL_GPL (nft_meta_get_validate);int nft_meta_set_validate (const struct nft_ctx *ctx,const struct nft_expr *expr)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1152/2077 netfilter: nft_flow_offload: zero device address for non-ether case
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit e409c23c2d0630f3b95efd12428b2e58800b7645 ]
LLM points out that the skip causes unitialised stack array to propagate down into dev_fill_forward_path(). Its not clear to me that there is a guarantee that a later ctx.dev->netdev_ops->ndo_fill_forward_path() would always fix this up.
--- net/netfilter/nf_flow_table_path.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/netfilter/nf_flow_table_path.c +3 -1
@@ -53,8 +53,10 @@ static int nft_dev_fill_forward_path(const struct nf_flow_route *route,struct neighbour *n;u8 nud_state; -if (!nft_is_valid_ether_device (dev)) +if (!nft_is_valid_ether_device (dev)) { +eth_zero_addr (ha); goto out; + } n =dst_neigh_lookup (dst_cache, daddr);if (!n)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1153/2077 netfilter: nf_reject: skip iphdr options when looking for icmp header
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit af8d6ae09c0a5f8b8a0d5680203c74b3c1daa85b ]
Not a big deal but this hould have used the real ip header length and not the base header size. As-is, if there are options then nf_skb_is_icmp_unreach() result will be random.
--- net/ipv4/netfilter/nf_reject_ipv4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/netfilter/nf_reject_ipv4.c +1 -1
@@ -89,7 +89,7 @@ static bool nf_skb_is_icmp_unreach(const struct sk_buff *skb)if (iph->protocol !=IPPROTO_ICMP )return false; - thoff =skb_network_offset (skb) +sizeof (*iph); + thoff =skb_network_offset (skb) +ip_hdrlen (skb); tp = skb_header_pointer(skb, thoff + offsetof(struct icmphdr, type),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1154/2077 netfilter: nft_meta_bridge: fix NFT_META_BRI_IIFPVID stack leak
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit 27dd2997746d54ebc079bb13161cc1bdd401d4a6 ]
This needs to test for nonzero retval.
--- net/bridge/netfilter/nft_meta_bridge.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/bridge/netfilter/nft_meta_bridge.c +3 -1
@@ -44,7 +44,9 @@ static void nft_meta_bridge_get_eval(const struct nft_expr *expr,if (!br_dev || !br_vlan_enabled (br_dev)) goto err; -br_vlan_get_pvid_rcu (in, &p_pvid); +if (br_vlan_get_pvid_rcu (in, &p_pvid)) + goto err; +nft_reg_store16 (dest, p_pvid);return ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1155/2077 tpm_crb: Check ACPI_COMPANION() against NULL during probe
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]>
[ Upstream commit ddd33806b8911fa2ef849e8bbbab1e3fcb26adc0 ]
Every platform driver can be forced to match a device that doesn't match its list of device IDs because of device_match_driver_override(), so platform drivers that rely on the existence of a device's ACPI companion object need to verify its presence.
Accordingly, add a requisite ACPI_COMPANION() check against NULL to the tpm_crb driver.
--- drivers/char/tpm/tpm_crb.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm_crb.c +5 -1
@@ -786,8 +786,8 @@ static int crb_map_pluton(struct device *dev, struct crb_priv *priv,static int crb_acpi_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev; -struct acpi_device *device =ACPI_COMPANION (dev);struct acpi_table_tpm2 *buf; +struct acpi_device *device;struct crb_priv *priv;struct tpm_chip *chip;struct tpm2_crb_smc *crb_smc;
@@ -797,6 +797,10 @@ static int crb_acpi_probe(struct platform_device *pdev)u32 sm;int rc; + device =ACPI_COMPANION (dev); +if (!device) +return -ENODEV ; + status =acpi_get_table (ACPI_SIG_TPM2 ,1 , (struct acpi_table_header **) &buf);if (ACPI_FAILURE (status) || buf->header.length <sizeof (*buf)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1156/2077 mailbox: imx: Forward the timeout/ error in imx_mu_generic_tx()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Andrzej Siewior <[email protected]>
[ Upstream commit 82ef9a635d7130ca27ec9dd88c16afc39c83a4e8 ]
imx_mu_generic_tx() for the IMX_MU_TYPE_TXDB_V2 type polls on a register which may timeout and is recognized as an error. This error is siltently dropped and not dropped to the caller.
Forward the error to the caller.
--- drivers/mailbox/imx-mailbox.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mailbox/imx-mailbox.c +2 -1
@@ -227,6 +227,7 @@ static int imx_mu_generic_tx(struct imx_mu_priv *priv,u32 val;int ret, count; + ret =0 ;switch (cp->type) {case IMX_MU_TYPE_TX :imx_mu_write (priv, *arg, priv->dcfg->xTR + cp->idx *4 );
@@ -259,7 +260,7 @@ static int imx_mu_generic_tx(struct imx_mu_priv *priv,return -EINVAL ; } -return 0 ; +return ret; } static int imx_mu_generic_rx(struct imx_mu_priv *priv,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1157/2077 irqchip/crossbar: Fix parent domain resource leak
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bhargav Joshi <[email protected]>
[ Upstream commit a1074dd62faa6572921d387e8a21589ccea00efc ]
irq_domain_alloc_irqs_parent() is called in allocate_gic_irq() but irq_domain_free_irqs_parent() is never called which causes a resource leak.
Fix this by calling irq_domain_free_irqs_parent() in crossbar_domain_free().
--- drivers/irqchip/irq-crossbar.c | 1 + 1 file changed, 1 insertion(+)
drivers/irqchip/irq-crossbar.c +1 -0
@@ -163,6 +163,7 @@ static void crossbar_domain_free(struct irq_domain *domain, unsigned int virq, cb->write (d->hwirq, cb->safe_map); }raw_spin_unlock (&cb->lock); +irq_domain_free_irqs_parent (domain, virq, nr_irqs); } static int crossbar_domain_translate(struct irq_domain *d,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1158/2077 alloc_tag: fix use-after-free in /proc/allocinfo after module unload
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hao Ge <[email protected]>
[ Upstream commit 2956268efc457cb05d29c1bf94de1e8e684d7bbc ]
allocinfo_start() only reinitializes the codetag iterator at position 0. For subsequent reads (position > 0), it reuses cached iterator state from the previous batch. allocinfo_stop() drops mod_lock between read batches, which allows module unload to complete and free the module memory that the cached iterator still references:
CPU0 (read) CPU1 (rmmod)
---- ----
allocinfo_start(pos=0)
down_read(mod_lock)
allocinfo_show()
...
allocinfo_stop()
up_read(mod_lock)
codetag_unload_module()
kfree(cmod)
release_module_tags()
...
free_mod_mem()
allocinfo_start(pos=N)
down_read(mod_lock)
// reuses cached iter, skips re-init
allocinfo_show()
ct->filename <-- UAFAfter free_mod_mem() frees the module's .rodata, allocinfo_show() dereferences ct->filename, ct->function which point there.
Save the iterator state in allocinfo_next() and resume from it in allocinfo_start() with codetag_next_ct(), which detects module removal via idr_find() returning NULL and skips to the next module.
--- lib/alloc_tag.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
lib/alloc_tag.c +7 -2
@@ -45,6 +45,7 @@ int alloc_tag_ref_offs;struct allocinfo_private {struct codetag_iterator iter; +struct codetag_iterator reported_iter;bool print_header; };
@@ -58,16 +59,20 @@ static void *allocinfo_start(struct seq_file *m, loff_t *pos)if (node ==0 ) { priv->print_header = true; priv->iter =codetag_get_ct_iter (alloc_tag_cttype); -codetag_next_ct (&priv->iter); + }else { + priv->iter = priv->reported_iter; } +codetag_next_ct (&priv->iter);return priv->iter.ct ? priv :NULL ; }static void *allocinfo_next (struct seq_file *m,void *arg,loff_t *pos) {struct allocinfo_private *priv = (struct allocinfo_private *)arg; -struct codetag *ct =codetag_next_ct (&priv->iter); +struct codetag *ct; + priv->reported_iter = priv->iter; + ct =codetag_next_ct (&priv->iter); (*pos)++;if (!ct)return NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1159/2077 selftests/mm: restore default nr_hugepages value via exit trap in charge_reserved_hugetlb.sh
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sayali Patil <[email protected]>
[ Upstream commit a3f66e9b6e4dad38444656ffc28c28c33a4d4e1f ]
Patch series "selftests/mm: fix failures and robustness improvements", v7.
Powerpc systems with a 64K base page size exposed several issues while running mm selftests. Some tests assume specific hugetlb configurations, use incorrect interfaces, or fail instead of skipping when the required kernel features are not available.
This series fixes these issues and improves test robustness.
This patch (of 13):
cleanup() resets nr_hugepages to 0 on every invocation, while the test reconfigures it again in the next iteration. This leads to repeated allocation and freeing of large numbers of hugepages, especially when the original value is high.
Additionally, with set -e, failures in earlier cleanup steps (e.g., rmdir or umount returning EBUSY while background activity is still ongoing) can cause the script to exit before restoring the original value, leaving the system in a modified state.
Introduce a trap on EXIT, INT, and TERM to restore the original nr_hugepages value once at script termination. This avoids unnecessary allocation churn and ensures the original value is reliably restored on all exit paths.
--- tools/testing/selftests/mm/charge_reserved_hugetlb.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
tools/testing/selftests/mm/charge_reserved_hugetlb.sh +1 -2
@@ -17,6 +17,7 @@ if ! command -v killall >/dev/null 2>&1; then fi nr_hugepgs=$(cat /proc/sys/vm/nr_hugepages) +trap 'echo "$nr_hugepgs" > /proc/sys/vm/nr_hugepages' EXIT INT TERM fault_limit_file=limit_in_bytes reservation_limit_file=rsvd.limit_in_bytes
@@ -70,7 +71,6 @@ function cleanup() { if [[ -e $cgroup_path/hugetlb_cgroup_test2 ]]; then rmdir $cgroup_path/hugetlb_cgroup_test2 fi - echo 0 >/proc/sys/vm/nr_hugepages echo CLEANUP DONE }
@@ -599,4 +599,3 @@ if [[ $do_umount ]]; then rmdir $cgroup_path fi -echo "$nr_hugepgs" > /proc/sys/vm/nr_hugepages
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1160/2077 selftests/mm: fix hugetlb pathname construction in charge_reserved_hugetlb.sh
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sayali Patil <[email protected]>
[ Upstream commit 404c04e010da2edc93cada07d4d50deda12a68e4 ]
The charge_reserved_hugetlb.sh script assumes hugetlb cgroup memory interface file names use the "<size>MB" format
(e.g. hugetlb.1024MB.current).
This assumption breaks on systems with larger huge pages such as 1GB, where the kernel exposes normalized units:
hugetlb.1GB.current
hugetlb.1GB.max
hugetlb.1GB.rsvd.max
...As a result, the script attempts to access files like hugetlb.1024MB.current, which do not exist when the kernel reports the size in GB.
Normalize the huge page size and construct the pathname using the appropriate unit (MB or GB), matching the hugetlb controller naming.
--- .../selftests/mm/charge_reserved_hugetlb.sh | 42 +++++++++++++------ 1 file changed, 29 insertions(+), 13 deletions(-)
tools/testing/selftests/mm/charge_reserved_hugetlb.sh +29 -13
@@ -94,6 +94,15 @@ function get_machine_hugepage_size() { } MB=$(get_machine_hugepage_size) +if (( MB >= 1024 )); then + # For 1GB hugepages + UNIT="GB" + MB_DISPLAY=$((MB / 1024)) +else + # For 2MB hugepages + UNIT="MB" + MB_DISPLAY=$MB +fi function setup_cgroup() { local name="$1"
@@ -103,11 +112,12 @@ function setup_cgroup() { mkdir $cgroup_path/$name echo writing cgroup limit: "$cgroup_limit" - echo "$cgroup_limit" >$cgroup_path/$name/hugetlb.${MB}MB.$fault_limit_file + echo "$cgroup_limit" > \ + $cgroup_path/$name/hugetlb.${MB_DISPLAY}${UNIT}.$fault_limit_file echo writing reservation limit: "$reservation_limit" echo "$reservation_limit" > \ - $cgroup_path/$name/hugetlb.${MB}MB.$reservation_limit_file + $cgroup_path/$name/hugetlb.${MB_DISPLAY}${UNIT}.$reservation_limit_file if [ -e "$cgroup_path/$name/cpuset.cpus" ]; then echo 0 >$cgroup_path/$name/cpuset.cpus
@@ -142,7 +152,7 @@ function wait_for_file_value() { function wait_for_hugetlb_memory_to_get_depleted() { local cgroup="$1" - local path="$cgroup_path/$cgroup/hugetlb.${MB}MB.$reservation_usage_file" + local path="$cgroup_path/$cgroup/hugetlb.${MB_DISPLAY}${UNIT}.$reservation_usage_file" wait_for_file_value "$path" "0" }
@@ -150,7 +160,7 @@ function wait_for_hugetlb_memory_to_get_depleted() { function wait_for_hugetlb_memory_to_get_reserved() { local cgroup="$1" local size="$2" - local path="$cgroup_path/$cgroup/hugetlb.${MB}MB.$reservation_usage_file" + local path="$cgroup_path/$cgroup/hugetlb.${MB_DISPLAY}${UNIT}.$reservation_usage_file" wait_for_file_value "$path" "$size" }
@@ -158,7 +168,7 @@ function wait_for_hugetlb_memory_to_get_reserved() { function wait_for_hugetlb_memory_to_get_written() { local cgroup="$1" local size="$2" - local path="$cgroup_path/$cgroup/hugetlb.${MB}MB.$fault_usage_file" + local path="$cgroup_path/$cgroup/hugetlb.${MB_DISPLAY}${UNIT}.$fault_usage_file" wait_for_file_value "$path" "$size" }
@@ -180,8 +190,8 @@ function write_hugetlbfs_and_get_usage() { hugetlb_difference=0 reserved_difference=0 - local hugetlb_usage=$cgroup_path/$cgroup/hugetlb.${MB}MB.$fault_usage_file - local reserved_usage=$cgroup_path/$cgroup/hugetlb.${MB}MB.$reservation_usage_file + local hugetlb_usage=$cgroup_path/$cgroup/hugetlb.${MB_DISPLAY}${UNIT}.$fault_usage_file + local reserved_usage=$cgroup_path/$cgroup/hugetlb.${MB_DISPLAY}${UNIT}.$reservation_usage_file local hugetlb_before=$(cat $hugetlb_usage) local reserved_before=$(cat $reserved_usage)
@@ -312,8 +322,10 @@ function run_test() { cleanup_hugetlb_memory "hugetlb_cgroup_test" - local final_hugetlb=$(cat $cgroup_path/hugetlb_cgroup_test/hugetlb.${MB}MB.$fault_usage_file) - local final_reservation=$(cat $cgroup_path/hugetlb_cgroup_test/hugetlb.${MB}MB.$reservation_usage_file) + local final_hugetlb=$(cat \ + $cgroup_path/hugetlb_cgroup_test/hugetlb.${MB_DISPLAY}${UNIT}.$fault_usage_file) + local final_reservation=$(cat \ + $cgroup_path/hugetlb_cgroup_test/hugetlb.${MB_DISPLAY}${UNIT}.$reservation_usage_file) echo $hugetlb_difference echo $reserved_difference
@@ -369,10 +381,14 @@ function run_multiple_cgroup_test() { reservation_failed1=$reservation_failed oom_killed1=$oom_killed - local cgroup1_hugetlb_usage=$cgroup_path/hugetlb_cgroup_test1/hugetlb.${MB}MB.$fault_usage_file - local cgroup1_reservation_usage=$cgroup_path/hugetlb_cgroup_test1/hugetlb.${MB}MB.$reservation_usage_file - local cgroup2_hugetlb_usage=$cgroup_path/hugetlb_cgroup_test2/hugetlb.${MB}MB.$fault_usage_file - local cgroup2_reservation_usage=$cgroup_path/hugetlb_cgroup_test2/hugetlb.${MB}MB.$reservation_usage_file + local cgroup1_hugetlb_usage=\ + $cgroup_path/hugetlb_cgroup_test1/hugetlb.${MB_DISPLAY}${UNIT}.$fault_usage_file + local cgroup1_reservation_usage=\ + $cgroup_path/hugetlb_cgroup_test1/hugetlb.${MB_DISPLAY}${UNIT}.$reservation_usage_file + local cgroup2_hugetlb_usage=\ + $cgroup_path/hugetlb_cgroup_test2/hugetlb.${MB_DISPLAY}${UNIT}.$fault_usage_file + local cgroup2_reservation_usage=\ + $cgroup_path/hugetlb_cgroup_test2/hugetlb.${MB_DISPLAY}${UNIT}.$reservation_usage_file local usage_before_second_write=$(cat $cgroup1_hugetlb_usage) local reservation_usage_before_second_write=$(cat $cgroup1_reservation_usage)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1161/2077 selftests/mm: restore default nr_hugepages value via exit trap in hugetlb_reparenting_test.sh
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sayali Patil <[email protected]>
[ Upstream commit 7f9c0920ff3debae3cb4d60260e3daf56ab68395 ]
The test modifies nr_hugepages during execution and restores it from cleanup() and again reconfigure it setup, which is invoked multiple times across test flow. This can lead to repeated allocation/freeing of hugepages.
With set -e, failures in cleanup (e.g., rmdir/umount) can also cause early exit before restoring the original value at the end.
Move restoration of the original nr_hugepages value to a trap handler registered for EXIT, INT, and TERM signals so it is always restored on all exit paths. This also avoids unnecessary allocation churn across repeated cleanup/setup cycles.
--- tools/testing/selftests/mm/hugetlb_reparenting_test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/mm/hugetlb_reparenting_test.sh +2 -2
@@ -12,6 +12,8 @@ if [[ $(id -u) -ne 0 ]]; then fi nr_hugepgs=$(cat /proc/sys/vm/nr_hugepages) +trap 'echo "$nr_hugepgs" > /proc/sys/vm/nr_hugepages' EXIT INT TERM + usage_file=usage_in_bytes if [[ "$1" == "-cgroup-v2" ]]; then
@@ -56,7 +58,6 @@ function cleanup() { rmdir "$CGROUP_ROOT"/a/b 2>/dev/null rmdir "$CGROUP_ROOT"/a 2>/dev/null rmdir "$CGROUP_ROOT"/test1 2>/dev/null - echo $nr_hugepgs >/proc/sys/vm/nr_hugepages set -e }
@@ -240,4 +241,3 @@ if [[ $do_umount ]]; then rm -rf $CGROUP_ROOT fi -echo "$nr_hugepgs" > /proc/sys/vm/nr_hugepages
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1162/2077 selftests/mm: fix hugetlb pathname construction in hugetlb_reparenting_test.sh
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sayali Patil <[email protected]>
[ Upstream commit 76f9a212a0a93572a28b58d9869e9187c4022342 ]
The hugetlb_reparenting_test.sh script constructs hugetlb cgroup memory interface file names based on the configured huge page size. The script formats the size only in MB units, which causes mismatches on systems using larger huge pages where the kernel exposes normalized units (e.g. "1GB" instead of "1024MB").
As a result, the test fails to locate the corresponding cgroup files when 1GB huge pages are configured.
Update the script to detect the huge page size and select the appropriate unit (MB or GB) so that the constructed paths match the kernel's hugetlb controller naming.
Also print an explicit "Fail" message when a test failure occurs to improve result visibility.
--- .../selftests/mm/hugetlb_reparenting_test.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
tools/testing/selftests/mm/hugetlb_reparenting_test.sh +12 -2
@@ -48,6 +48,13 @@ function get_machine_hugepage_size() { } MB=$(get_machine_hugepage_size) +if (( MB >= 1024 )); then + UNIT="GB" + MB_DISPLAY=$((MB / 1024)) +else + UNIT="MB" + MB_DISPLAY=$MB +fi function cleanup() { echo cleanup
@@ -88,6 +95,7 @@ function assert_with_retry() { if [[ $elapsed -ge $timeout ]]; then echo "actual = $((${actual%% *} / 1024 / 1024)) MB" echo "expected = $((${expected%% *} / 1024 / 1024)) MB" + echo FAIL cleanup exit 1 fi
@@ -108,11 +116,13 @@ function assert_state() { fi assert_with_retry "$CGROUP_ROOT/a/memory.$usage_file" "$expected_a" - assert_with_retry "$CGROUP_ROOT/a/hugetlb.${MB}MB.$usage_file" "$expected_a_hugetlb" + assert_with_retry \ + "$CGROUP_ROOT/a/hugetlb.${MB_DISPLAY}${UNIT}.$usage_file" "$expected_a_hugetlb" if [[ -n "$expected_b" && -n "$expected_b_hugetlb" ]]; then assert_with_retry "$CGROUP_ROOT/a/b/memory.$usage_file" "$expected_b" - assert_with_retry "$CGROUP_ROOT/a/b/hugetlb.${MB}MB.$usage_file" "$expected_b_hugetlb" + assert_with_retry \ + "$CGROUP_ROOT/a/b/hugetlb.${MB_DISPLAY}${UNIT}.$usage_file" "$expected_b_hugetlb" fi }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1163/2077 selftests/mm: fix cgroup task placement and drop memory.current checks in hugetlb_reparenting_test.sh
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sayali Patil <[email protected]>
[ Upstream commit 7bbdc459527075c4d0b96133de25a53822397af0 ]
The test currently moves the calling shell ($$) into the target cgroup before executing write_to_hugetlbfs. This results in the shell and any intermediate allocations being charged to the cgroup, introducing noise and nondeterminism in accounting. It also requires moving the shell back to the root cgroup after execution.
Spawn a helper process that joins the target cgroup and exec()'s write_to_hugetlbfs. This ensures that only the workload is accounted to the cgroup and avoids unintended charging from the shell.
The test currently validates both hugetlb usage and memory.current. However, memory.current includes internal memcg allocations and per-CPU batched accounting (MEMCG_CHARGE_BATCH), which are not synchronized and can vary across systems, leading to non-deterministic results.
Since hugetlb memory is accounted via hugetlb.<size>.current, memory.current is not a reliable indicator here. Drop memory.current checks and rely only on hugetlb controller statistics for stable and accurate validation.
--- .../selftests/mm/hugetlb_reparenting_test.sh | 42 ++++++++----------- 1 file changed, 18 insertions(+), 24 deletions(-)
tools/testing/selftests/mm/hugetlb_reparenting_test.sh +18 -24
@@ -105,22 +105,17 @@ function assert_with_retry() { } function assert_state() { - local expected_a="$1" - local expected_a_hugetlb="$2" - local expected_b="" + local expected_a_hugetlb="$1" local expected_b_hugetlb="" - if [ ! -z ${3:-} ] && [ ! -z ${4:-} ]; then - expected_b="$3" - expected_b_hugetlb="$4" + if [ ! -z ${2:-} ]; then + expected_b_hugetlb="$2" fi - assert_with_retry "$CGROUP_ROOT/a/memory.$usage_file" "$expected_a" assert_with_retry \ "$CGROUP_ROOT/a/hugetlb.${MB_DISPLAY}${UNIT}.$usage_file" "$expected_a_hugetlb" - if [[ -n "$expected_b" && -n "$expected_b_hugetlb" ]]; then - assert_with_retry "$CGROUP_ROOT/a/b/memory.$usage_file" "$expected_b" + if [[ -n "$expected_b_hugetlb" ]]; then assert_with_retry \ "$CGROUP_ROOT/a/b/hugetlb.${MB_DISPLAY}${UNIT}.$usage_file" "$expected_b_hugetlb" fi
@@ -154,18 +149,17 @@ write_hugetlbfs() { local size="$3" if [[ $cgroup2 ]]; then - echo $$ >$CGROUP_ROOT/$cgroup/cgroup.procs + cg_file="$CGROUP_ROOT/$cgroup/cgroup.procs" else echo 0 >$CGROUP_ROOT/$cgroup/cpuset.mems echo 0 >$CGROUP_ROOT/$cgroup/cpuset.cpus - echo $$ >"$CGROUP_ROOT/$cgroup/tasks" - fi - ./write_to_hugetlbfs -p "$path" -s "$size" -m 0 -o - if [[ $cgroup2 ]]; then - echo $$ >$CGROUP_ROOT/cgroup.procs - else - echo $$ >"$CGROUP_ROOT/tasks" + cg_file="$CGROUP_ROOT/$cgroup/tasks" fi + + # Spawn helper to join cgroup before exec to ensure correct cgroup accounting + bash -c 'echo $$ > "$1"; exec ./write_to_hugetlbfs -p "$2" -s "$3" -m 0 -o' _ \ + "$cg_file" "$path" "$size" & pid=$! + wait "$pid" echo }
@@ -203,21 +197,21 @@ if [[ ! $cgroup2 ]]; then write_hugetlbfs a "$MNT"/test $size echo Assert memory charged correctly for parent use. - assert_state 0 $size 0 0 + assert_state $size 0 write_hugetlbfs a/b "$MNT"/test2 $size echo Assert memory charged correctly for child use. - assert_state 0 $(($size * 2)) 0 $size + assert_state $(($size * 2)) $size rmdir "$CGROUP_ROOT"/a/b echo Assert memory reparent correctly. - assert_state 0 $(($size * 2)) + assert_state $(($size * 2)) rm -rf "$MNT"/* umount "$MNT" echo Assert memory uncharged correctly. - assert_state 0 0 + assert_state 0 cleanup fi
@@ -231,16 +225,16 @@ echo write write_hugetlbfs a/b "$MNT"/test2 $size echo Assert memory charged correctly for child only use. -assert_state 0 $(($size)) 0 $size +assert_state $(($size)) $size rmdir "$CGROUP_ROOT"/a/b echo Assert memory reparent correctly. -assert_state 0 $size +assert_state $size rm -rf "$MNT"/* umount "$MNT" echo Assert memory uncharged correctly. -assert_state 0 0 +assert_state 0 cleanup
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1164/2077 selftests/mm: size tmpfs according to PMD page size in split_huge_page_test
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sayali Patil <[email protected]>
[ Upstream commit a2dde8a065d5c8d63b53b1c8f035017e4aeac0c2 ]
The split_file_backed_thp() test mounts a tmpfs with a fixed size of "4m". This works on systems with smaller PMD page sizes, but fails on configurations where the PMD huge page size is larger (e.g. 16MB).
On such systems, the fixed 4MB tmpfs is insufficient to allocate even a single PMD-sized THP, causing the test to fail.
Fix this by sizing the tmpfs dynamically based on the runtime pmd_pagesize, allocating space for two PMD-sized pages.
Before patch:
running ./split_huge_page_test /tmp/xfs_dir_YTrI5E
--------------------------------------------------
TAP version 13
1..55
ok 1 Split zero filled huge pages successful
ok 2 Split huge pages to order 0 successful
ok 3 Split huge pages to order 2 successful
ok 4 Split huge pages to order 3 successful
ok 5 Split huge pages to order 4 successful
ok 6 Split huge pages to order 5 successful
ok 7 Split huge pages to order 6 successful
ok 8 Split huge pages to order 7 successful
ok 9 Split PTE-mapped huge pages successful
Please enable pr_debug in split_huge_pages_in_file() for more info. Failed to write data to testing file: Success (0)
Bail out! Error occurred
Planned tests != run tests (55 != 9)
Totals: pass:9 fail:0 xfail:0 xpass:0 skip:0 error:0
[FAIL]
After patch:
running ./split_huge_page_test /tmp/xfs_dir_bMvj6o
--------------------------------------------------
TAP version 13
1..55
ok 1 Split zero filled huge pages successful
ok 2 Split huge pages to order 0 successful
ok 3 Split huge pages to order 2 successful
ok 4 Split huge pages to order 3 successful
ok 5 Split huge pages to order 4 successful
ok 6 Split huge pages to order 5 successful
ok 7 Split huge pages to order 6 successful
ok 8 Split huge pages to order 7 successful
ok 9 Split PTE-mapped huge pages successful
Please enable pr_debug in split_huge_pages_in_file() for more info. Please check dmesg for more information
ok 10 File-backed THP split to order 0 test done
Please enable pr_debug in split_huge_pages_in_file() for more info. Please check dmesg for more information
ok 11 File-backed THP split to order 1 test done
Please enable pr_debug in split_huge_pages_in_file() for more info. Please check dmesg for more information
ok 12 File-backed THP split to order 2 test done
...
ok 55 Split PMD-mapped pagecache folio to order 7 at
in-folio offset 128 passed
Totals: pass:55 fail:0 xfail:0 xpass:0 skip:0 error:0 [PASS]
ok 1 split_huge_page_test /tmp/xfs_dir_bMvj6o
--- tools/testing/selftests/mm/split_huge_page_test.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/testing/selftests/mm/split_huge_page_test.c +4 -1
@@ -470,6 +470,8 @@ static void split_file_backed_thp(int order)char tmpfs_template[] ="/tmp/thp_split_XXXXXX" ;const char *tmpfs_loc =mkdtemp (tmpfs_template);char testfile[INPUT_MAX ]; +unsigned long size =2 * pmd_pagesize; +char opts[64 ];ssize_t num_written, num_read;char *file_buf1, *file_buf2;uint64_t pgoff_start =0 , pgoff_end =1024 ;
@@ -489,7 +491,8 @@ static void split_file_backed_thp(int order) file_buf1[i] = (char )i;memset (file_buf2,0 , pmd_pagesize); - status =mount ("tmpfs" , tmpfs_loc,"tmpfs" ,0 ,"huge=always,size=4m" ); +snprintf (opts,sizeof (opts),"huge=always,size=%lu" , size); + status =mount ("tmpfs" , tmpfs_loc,"tmpfs" ,0 , opts);if (status)ksft_exit_fail_msg ("Unable to create a tmpfs for testing\n" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1165/2077 selftests/mm: free dynamically allocated PMD-sized buffers in split_huge_page_test
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sayali Patil <[email protected]>
[ Upstream commit e5d3e1422e92d54e28e81fad8bfc7c1ecb41a353 ]
Dynamically allocated buffers of PMD size for file-backed THP operations (file_buf1 and file_buf2) were not freed on the success path and some failure paths. Since the function is called repeatedly in a loop for each split order, this can cause significant memory leaks.
On architectures with large PMD sizes, repeated leaks could exhaust system memory and trigger the OOM killer during test execution.
Ensure all allocated buffers are freed to maintain stable repeated test runs.
--- .../selftests/mm/split_huge_page_test.c | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-)
tools/testing/selftests/mm/split_huge_page_test.c +16 -6
@@ -473,12 +473,15 @@ static void split_file_backed_thp(int order)unsigned long size =2 * pmd_pagesize;char opts[64 ];ssize_t num_written, num_read; -char *file_buf1, *file_buf2; +char *file_buf1 =NULL , *file_buf2 =NULL ;uint64_t pgoff_start =0 , pgoff_end =1024 ;int i;ksft_print_msg ("Please enable pr_debug in split_huge_pages_in_file() for more info.\n" ); +if (!tmpfs_loc) +ksft_exit_fail_msg ("mkdtemp failed\n" ); + file_buf1 = (char *)malloc (pmd_pagesize); file_buf2 = (char *)malloc (pmd_pagesize);
@@ -494,8 +497,10 @@ static void split_file_backed_thp(int order)snprintf (opts,sizeof (opts),"huge=always,size=%lu" , size); status =mount ("tmpfs" , tmpfs_loc,"tmpfs" ,0 , opts); -if (status) -ksft_exit_fail_msg ("Unable to create a tmpfs for testing\n" ); +if (status) { +ksft_print_msg ("Unable to create a tmpfs for testing\n" ); + goto out; + } status =snprintf (testfile,INPUT_MAX ,"%s/thp_file" , tmpfs_loc);if (status >=INPUT_MAX ) {
@@ -547,10 +552,13 @@ static void split_file_backed_thp(int order) status =umount (tmpfs_loc);if (status) { -rmdir (tmpfs_loc); -ksft_exit_fail_msg ("Unable to umount %s\n" , tmpfs_loc); +ksft_print_msg ("Unable to umount %s\n" , tmpfs_loc); + goto out; } +free (file_buf1); +free (file_buf2); + status =rmdir (tmpfs_loc);if (status)ksft_exit_fail_msg ("cannot remove tmp dir: %s\n" ,strerror (errno));
@@ -563,8 +571,10 @@ static void split_file_backed_thp(int order)close (fd); cleanup:umount (tmpfs_loc); -rmdir (tmpfs_loc); out: +free (file_buf1); +free (file_buf2); +rmdir (tmpfs_loc);ksft_exit_fail_msg ("Error occurred\n" ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1166/2077 selftest/mm: register existing mapping with userfaultfd in hugetlb-mremap
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sayali Patil <[email protected]>
[ Upstream commit 1df31d5ef58dc6bdf0f2a8b809152d835c60b28e ]
Previously, register_region_with_uffd() created a new anonymous mapping and overwrote the address supplied by the caller before registering the range with userfaultfd.
As a result, userfaultfd was applied to an unrelated anonymous mapping instead of the hugetlb region used by the test.
Remove the extra mmap() and register the caller-provided address range directly using UFFDIO_REGISTER_MODE_MISSING, so that faults are generated for the hugetlb mapping used by the test.
This ensures userfaultfd operates on the actual hugetlb test region and validates the expected fault handling.
Before patch:
running ./hugetlb-mremap
-------------------------
TAP version 13
1..1
Map haddr: Returned address is 0x7eaa40000000 Map daddr: Returned address is 0x7daa40000000 Map vaddr: Returned address is 0x7faa40000000 Address returned by mmap() = 0x7fff9d000000
Mremap: Returned address is 0x7faa40000000 First hex is 0
First hex is 3020100
ok 1 Read same data
Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0 [PASS]
ok 1 hugetlb-mremap
After patch:
running ./hugetb-mremap
-------------------------
TAP version 13
1..1
Map haddr: Returned address is 0x7eaa40000000
Map daddr: Returned address is 0x7daa40000000
Map vaddr: Returned address is 0x7faa40000000 Registered memory at address 0x7eaa40000000 with userfaultfd
Mremap: Returned address is 0x7faa40000000
First hex is 0
First hex is 3020100
ok 1 Read same data
Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0 [PASS]
ok 1 hugetlb-mremap
--- tools/testing/selftests/mm/hugepage-mremap.c | 21 +++++--------------- 1 file changed, 5 insertions(+), 16 deletions(-)
tools/testing/selftests/mm/hugepage-mremap.c +5 -16
@@ -85,25 +85,14 @@ static void register_region_with_uffd(char *addr, size_t len)if (ioctl (uffd,UFFDIO_API , &uffdio_api) ==-1 )ksft_exit_fail_msg ("ioctl-UFFDIO_API: %s\n" ,strerror (errno)); -/* Create a private anonymous mapping. The memory will be -* demand-zero paged--that is, not yet allocated. When we -* actually touch the memory, it will be allocated via -* the userfaultfd. -*/ - - addr =mmap (NULL , len,PROT_READ |PROT_WRITE , -MAP_PRIVATE |MAP_ANONYMOUS ,-1 ,0 ); -if (addr ==MAP_FAILED ) -ksft_exit_fail_msg ("mmap: %s\n" ,strerror (errno)); - -ksft_print_msg ("Address returned by mmap() = %p\n" , addr); - -/* Register the memory range of the mapping we just created for -* handling by the userfaultfd object. In mode, we request to track -* missing pages (i.e., pages that have not yet been faulted in). +/* Register the passed memory range for handling by the userfaultfd object. +* In mode, we request to track missing pages +* (i.e., pages that have not yet been faulted in). */ if (uffd_register (uffd, addr, len, true, false, false))ksft_exit_fail_msg ("ioctl-UFFDIO_REGISTER: %s\n" ,strerror (errno)); + +ksft_print_msg ("Registered memory at address %p with userfaultfd\n" , addr); }int main (int argc,char *argv[])
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1167/2077 selftests/mm: ensure destination is hugetlb-backed in hugetlb-mremap
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sayali Patil <[email protected]>
[ Upstream commit f20ca8972e83f111c4300c60d74314568c8964bc ]
The hugetlb-mremap selftest reserves the destination address using a anonymous base-page mapping before calling mremap() with MREMAP_FIXED, while the source region is hugetlb-backed.
When remapping a hugetlb mapping into a base-page VMA may fail with:
mremap: Device or resource busy
This is observed on powerpc hash MMU systems where slice constraints and page size incompatibilities prevent the remap.
Ensure the destination region is created using MAP_HUGETLB so that both source and destination VMAs are hugetlb-backed and compatible.
Update the FLAGS macro to include MAP_HUGETLB | MAP_SHARED so that both mappings are hugetlb-backed and compatible. Also use the macro for the mmap() calls to avoid repeating the flag combination.
This ensures the test reliably exercises hugetlb mremap instead of failing due to VMA type mismatch.
--- tools/testing/selftests/mm/hugepage-mremap.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
tools/testing/selftests/mm/hugepage-mremap.c +4 -7
@@ -31,7 +31,7 @@#define MB_TO_BYTES (x) (x * 1024 * 1024)#define PROTECTION (PROT_READ | PROT_WRITE | PROT_EXEC) -#define FLAGS (MAP_SHARED | MAP_ANONYMOUS) +#define FLAGS (MAP_HUGETLB | MAP_SHARED)static void check_bytes (char *addr) {
@@ -121,23 +121,20 @@ int main(int argc, char *argv[])/* mmap to a PUD aligned address to hopefully trigger pmd sharing. */ unsigned long suggested_addr =0x7eaa40000000 ; -void *haddr =mmap ((void *)suggested_addr, length,PROTECTION , -MAP_HUGETLB |MAP_SHARED |MAP_POPULATE , fd,0 ); +void *haddr =mmap ((void *)suggested_addr, length,PROTECTION ,FLAGS , fd,0 );ksft_print_msg ("Map haddr: Returned address is %p\n" , haddr);if (haddr ==MAP_FAILED )ksft_exit_fail_msg ("mmap1: %s\n" ,strerror (errno));/* mmap again to a dummy address to hopefully trigger pmd sharing. */ suggested_addr =0x7daa40000000 ; -void *daddr =mmap ((void *)suggested_addr, length,PROTECTION , -MAP_HUGETLB |MAP_SHARED |MAP_POPULATE , fd,0 ); +void *daddr =mmap ((void *)suggested_addr, length,PROTECTION ,FLAGS , fd,0 );ksft_print_msg ("Map daddr: Returned address is %p\n" , daddr);if (daddr ==MAP_FAILED )ksft_exit_fail_msg ("mmap3: %s\n" ,strerror (errno)); suggested_addr =0x7faa40000000 ; -void *vaddr = -mmap ((void *)suggested_addr, length,PROTECTION ,FLAGS ,-1 ,0 ); +void *vaddr =mmap ((void *)suggested_addr, length,PROTECTION ,FLAGS , fd,0 );ksft_print_msg ("Map vaddr: Returned address is %p\n" , vaddr);if (vaddr ==MAP_FAILED )ksft_exit_fail_msg ("mmap2: %s\n" ,strerror (errno));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1168/2077 selftests/mm: skip uffd-stress test when nr_pages_per_cpu is zero
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sayali Patil <[email protected]>
[ Upstream commit f3bd00507f226a419125df6064632bcbd47d8e70 ]
uffd-stress currently fails when the computed nr_pages_per_cpu evaluates to zero:
nr_pages_per_cpu = bytes / page_size / nr_parallel
This can occur on systems with large hugepage sizes (e.g. 1GB) and a high number of CPUs, where the total allocated memory is sufficient overall but not enough to provide at least one page per cpu.
In such cases, the failure is due to insufficient test resources rather than incorrect kernel behaviour. Update the test to treat this condition as a test skip instead of reporting an error.
--- tools/testing/selftests/mm/uffd-stress.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
tools/testing/selftests/mm/uffd-stress.c +2 -3
@@ -491,9 +491,8 @@ int main(int argc, char **argv) gopts->nr_pages_per_cpu = bytes / gopts->page_size / gopts->nr_parallel;if (!gopts->nr_pages_per_cpu) { -_err ("pages_per_cpu = 0, cannot test (%lu / %lu / %lu)" , - bytes, gopts->page_size, gopts->nr_parallel); -usage (); +ksft_exit_skip ("pages_per_cpu = 0, cannot test (%zu / %lu / %lu)\n" , + bytes, gopts->page_size, gopts->nr_parallel); } bounces =atoi (argv[3 ]);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1169/2077 selftests/mm: run_vmtests.sh: free memory if available memory is low
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mike Rapoport (Microsoft) <[email protected]>
[ Upstream commit 157adc22f01cdd0c0dc1b9e4389ed2377d9b69d3 ]
Currently when running THP and HugeTLB tests, if HAVE_HUGEPAGES is set run_test() drops caches, compacts memory and runs the test. But if HAVE_HUGEPAGES is not set it skips the tests entirely, even if THP tests have nothing to do with HAVE_HUGEPAGES.
Replace the check if HAVE_HUGEPAGES is set with a check of how much memory is available. If there is less than 256 MB of available memory, drop caches and run compaction and then continue to run a test regardless of HAVE_HUGEPAGES value.
Stable-dep-of: 90c132f8379b ("selftests/mm: move hwpoison setup into run_test() and silence modprobe output for memory-failure category")
--- tools/testing/selftests/mm/run_vmtests.sh | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
tools/testing/selftests/mm/run_vmtests.sh +6 -12
@@ -234,19 +234,17 @@ pretty_name() { # Usage: run_test [test binary] [arbitrary test arguments...] run_test() { if test_selected ${CATEGORY}; then - local skip=0 - # On memory constrainted systems some tests can fail to allocate hugepages. # perform some cleanup before the test for a higher success rate. if [ ${CATEGORY} == "thp" -o ${CATEGORY} == "hugetlb" ]; then - if [ "${HAVE_HUGEPAGES}" = "1" ]; then + mem_kb=$(awk '/MemAvailable/ {print $2}' /proc/meminfo) + mem_Mb=$((mem_kb / 1024)) + + if (( $mem_Mb < 256 )); then echo 3 > /proc/sys/vm/drop_caches sleep 2 echo 1 > /proc/sys/vm/compact_memory sleep 2 - else - echo "hugepages not supported" | tap_prefix - skip=1 fi fi
@@ -255,12 +253,8 @@ run_test() { local sep=$(echo -n "$title" | tr "[:graph:][:space:]" -) printf "%s\n%s\n%s\n" "$sep" "$title" "$sep" | tap_prefix - if [ "${skip}" != "1" ]; then - ("$@" 2>&1) | tap_prefix - local ret=${PIPESTATUS[0]} - else - local ret=$ksft_skip - fi + ("$@" 2>&1) | tap_prefix + local ret=${PIPESTATUS[0]} count_total=$(( count_total + 1 )) if [ $ret -eq 0 ]; then count_pass=$(( count_pass + 1 ))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1170/2077 selftests/mm: move hwpoison setup into run_test() and silence modprobe output for memory-failure category
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sayali Patil <[email protected]>
[ Upstream commit 90c132f8379b788a0482dbeabc884d3ae5d82205 ]
run_vmtests.sh contains special handling to ensure the hwpoison_inject module is available for the memory-failure tests. This logic was implemented outside of run_test(), making the setup category-specific but managed globally.
Move the hwpoison_inject handling into run_test() and restrict it to the memory-failure category so that:
1. the module is checked and loaded only when memory-failure tests run,
2. the test is skipped if the module or the debugfs interface (/sys/kernel/debug/hwpoison/) is not available.
3. the module is unloaded after the test if it was loaded by the script.
This localizes category-specific setup and makes the test flow consistent with other per-category preparations.
While updating this logic, fix the module availability check. The script previously used:
modprobe -R hwpoison_inject
The -R option prints the resolved module name to stdout, causing every run to print:
hwpoison_inject
in the test output, even when no action is required, introducing unnecessary noise.
Replace this with:
modprobe -n hwpoison_inject
which verifies that the module is loadable without producing output, keeping the selftest logs clean and consistent.
Also, ensure that skipped tests do not override a previously recorded failure. A skipped test currently sets exitcode to ksft_skip even if a prior test has failed, which can mask failures in the final exit status. Update the logic to only set exitcode to ksft_skip when no failure has been recorded.
--- tools/testing/selftests/mm/run_vmtests.sh | 62 +++++++++++++++-------- 1 file changed, 41 insertions(+), 21 deletions(-)
tools/testing/selftests/mm/run_vmtests.sh +41 -21
@@ -234,6 +234,9 @@ pretty_name() { # Usage: run_test [test binary] [arbitrary test arguments...] run_test() { if test_selected ${CATEGORY}; then + local skip=0 + local LOADED_HWPOISON_INJECT_MOD=0 + # On memory constrainted systems some tests can fail to allocate hugepages. # perform some cleanup before the test for a higher success rate. if [ ${CATEGORY} == "thp" -o ${CATEGORY} == "hugetlb" ]; then
@@ -248,13 +251,45 @@ run_test() { fi fi + # Ensure hwpoison_inject is available for memory-failure tests + if [ "${CATEGORY}" = "memory-failure" ]; then + # Try to load hwpoison_inject if not present. + HWPOISON_DIR=/sys/kernel/debug/hwpoison/ + if [ ! -d "$HWPOISON_DIR" ]; then + if ! modprobe -n hwpoison_inject > /dev/null 2>&1; then + echo "Module hwpoison_inject not found, skipping..." \ + | tap_prefix + skip=1 + else + modprobe hwpoison_inject > /dev/null 2>&1 + LOADED_HWPOISON_INJECT_MOD=1 + if [ ! -d "$HWPOISON_DIR" ]; then + echo "hwpoison debugfs interface not present" \ + | tap_prefix + skip=1 + fi + fi + fi + + fi + local test=$(pretty_name "$*") local title="running $*" local sep=$(echo -n "$title" | tr "[:graph:][:space:]" -) printf "%s\n%s\n%s\n" "$sep" "$title" "$sep" | tap_prefix - ("$@" 2>&1) | tap_prefix - local ret=${PIPESTATUS[0]} + if [ $skip -eq 1 ]; then + local ret=$ksft_skip + else + ("$@" 2>&1) | tap_prefix + local ret=${PIPESTATUS[0]} + fi + + # Unload hwpoison_inject if we loaded it + if [ "${LOADED_HWPOISON_INJECT_MOD}" = "1" ]; then + modprobe -r hwpoison_inject > /dev/null 2>&1 + fi + count_total=$(( count_total + 1 )) if [ $ret -eq 0 ]; then count_pass=$(( count_pass + 1 ))
@@ -264,7 +299,9 @@ run_test() { count_skip=$(( count_skip + 1 )) echo "[SKIP]" | tap_prefix echo "ok ${count_total} ${test} # SKIP" | tap_output - exitcode=$ksft_skip + if [ $exitcode -eq 0 ]; then + exitcode=$ksft_skip + fi else count_fail=$(( count_fail + 1 )) echo "[FAIL]" | tap_prefix
@@ -525,24 +562,7 @@ CATEGORY="page_frag" run_test ./test_page_frag.sh nonaligned CATEGORY="rmap" run_test ./rmap -# Try to load hwpoison_inject if not present. -HWPOISON_DIR=/sys/kernel/debug/hwpoison/ -if [ ! -d "$HWPOISON_DIR" ]; then - if ! modprobe -q -R hwpoison_inject; then - echo "Module hwpoison_inject not found, skipping..." - else - modprobe hwpoison_inject > /dev/null 2>&1 - LOADED_MOD=1 - fi -fi - -if [ -d "$HWPOISON_DIR" ]; then - CATEGORY="memory-failure" run_test ./memory-failure -fi - -if [ -n "${LOADED_MOD}" ]; then - modprobe -r hwpoison_inject > /dev/null 2>&1 -fi +CATEGORY="memory-failure" run_test ./memory-failure if [ "${HAVE_HUGEPAGES}" = 1 ]; then echo "$orig_nr_hugepgs" > /proc/sys/vm/nr_hugepages
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1171/2077 selftests/mm: clarify alternate unmapping in compaction_test
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sayali Patil <[email protected]>
[ Upstream commit 69ba1d76d93ab818245333cf400928477ba72053 ]
Add a comment explaining that every other entry in the list is unmapped to intentionally create fragmentation with locked pages before invoking check_compaction().
--- tools/testing/selftests/mm/compaction_test.c | 3 +++ 1 file changed, 3 insertions(+)
tools/testing/selftests/mm/compaction_test.c +3 -0
@@ -261,6 +261,9 @@ int main(int argc, char **argv) mem_fragmentable_MB -=MAP_SIZE_MB ; } +/* Unmap every other entry in the list to create fragmentation with +* locked pages before invoking check_compaction(). +*/ for (entry = list; entry !=NULL ; entry = entry->next) {munmap (entry->map,MAP_SIZE );if (!entry->next)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1172/2077 selftests/mm: allow PUD-level entries in compound testcase of hmm tests
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sayali Patil <[email protected]>
[ Upstream commit 224ed0e019b122d08580362abe57574a78f2b5fa ]
Patch series "selftests/mm: assorted fixes for hmm-tests", v3.
This series fixes a few issues in hmm-tests that show up when page-size and huge-page configuration differ from the hardcoded assumptions the tests were written for (PMD/THP sizing, default hugepage size, and related cases).
It also includes a fix to exclusive_cow: the test ignored the return value of fork(), so both parent and child ran the same teardown path.
This patch (of 3):
The HMM compound testcase currently assumes only PMD-level mappings and fails on systems where default_hugepagesz=1G is set, because the region is then reported by the device at PUD level.
Determine the mapping level (PMD or PUD) the device reports for the first page of the range and require every page to match that level exactly via ASSERT_EQ(). This accepts PUD-level mappings while preserving the expected/observed protection values printed on failure, and rejects a fragmented mapping that mixes PMD- and PUD-level entries within the same range (which a per-page OR check would have let pass).
--- tools/testing/selftests/mm/hmm-tests.c | 32 +++++++++++++++++++------- 1 file changed, 24 insertions(+), 8 deletions(-)
tools/testing/selftests/mm/hmm-tests.c +24 -8
@@ -1599,8 +1599,8 @@ TEST_F(hmm2, snapshot) }/* -* Test the hmm_range_fault() HMM_PFN_PMD flag for large pages that -* should be mapped by a large page table entry. +* Test the hmm_range_fault() handling of large pages (PMD or PUD) +* that should be mapped by a large page table entry. */ TEST_F(hmm, compound) {
@@ -1610,6 +1610,7 @@ TEST_F(hmm, compound)unsigned long default_hsize =default_huge_page_size ();int *ptr;unsigned char *m; +unsigned char prot;int ret;unsigned long i;
@@ -1646,11 +1647,20 @@ TEST_F(hmm, compound)ASSERT_EQ (ret,0 );ASSERT_EQ (buffer->cpages, npages); -/* Check what the device saw. */ +/* +* Check what the device saw. The region is backed by a single huge +* page that the device reports either at PMD or at PUD level depending +* on the configured default hugepage size. Determine that level from +* the first page and require every page in the range to match it +* exactly, so that a fragmented mapping mixing levels (or a missing +* large-page bit) is still caught and reported with its actual value. +*/ m = buffer->mirror; + prot =HMM_DMIRROR_PROT_WRITE | + ((m[0 ] &HMM_DMIRROR_PROT_PUD ) ?HMM_DMIRROR_PROT_PUD : +HMM_DMIRROR_PROT_PMD );for (i =0 ; i < npages; ++i) -ASSERT_EQ (m[i],HMM_DMIRROR_PROT_WRITE | -HMM_DMIRROR_PROT_PMD ); +ASSERT_EQ (m[i], prot);/* Make the region read-only. */ ret =mprotect (buffer->ptr, size,PROT_READ );
@@ -1661,11 +1671,17 @@ TEST_F(hmm, compound)ASSERT_EQ (ret,0 );ASSERT_EQ (buffer->cpages, npages); -/* Check what the device saw. */ +/* +* Check what the device saw after mprotect(PROT_READ). Same +* approach as above: determine the mapping level from the first +* page and require every page to match it exactly. +*/ m = buffer->mirror; + prot =HMM_DMIRROR_PROT_READ | + ((m[0 ] &HMM_DMIRROR_PROT_PUD ) ?HMM_DMIRROR_PROT_PUD : +HMM_DMIRROR_PROT_PMD );for (i =0 ; i < npages; ++i) -ASSERT_EQ (m[i],HMM_DMIRROR_PROT_READ | -HMM_DMIRROR_PROT_PMD ); +ASSERT_EQ (m[i], prot);munmap (buffer->ptr, buffer->size); buffer->ptr =NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1173/2077 selftests/mm: remove hardcoded THP sizing assumptions in hmm tests
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sayali Patil <[email protected]>
[ Upstream commit 8edb0e769ce2a996774df83485781dd9f4bc2d44 ]
migrate_partial_unmap_fault() and migrate_remap_fault() use hardcoded offsets based on a 2MB PMD size. Similarly, benchmark_thp_migration() assumes a fixed 2MB THP size when generating test buffer sizes.
Derive offsets and test sizes from the runtime PMD page size returned by read_pmd_pagesize(). If unavailable, fall back to TWOMEG. This allows the tests to adapt correctly on systems where PMD-sized THP differs from 2MB. Also replace the fixed 1MB unmap size with a PMD-relative value derived from the runtime PMD size.
On systems with larger PMD sizes, computed test buffer sizes can exceed INT_MAX. Skip such test cases to avoid overflow.
--- tools/testing/selftests/mm/hmm-tests.c | 62 ++++++++++++++++++-------- 1 file changed, 43 insertions(+), 19 deletions(-)
tools/testing/selftests/mm/hmm-tests.c +43 -19
@@ -21,6 +21,7 @@#include <strings.h> #include <time.h> #include <pthread.h> +#include <limits.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/mman.h>
@@ -2348,12 +2349,21 @@ TEST_F(hmm, migrate_partial_unmap_fault)struct hmm_buffer *buffer;unsigned long npages;unsigned long size =read_pmd_pagesize (); +unsigned long unmap_size; +unsigned long offsets[3 ];unsigned long i;void *old_ptr;void *map;int *ptr;int ret, j, use_thp; -int offsets[] = {0 ,512 *ONEKB ,ONEMEG }; + +if (!size) + size =TWOMEG ; + + unmap_size = size /2 ; + offsets[0 ] =0 ; + offsets[1 ] = size /4 ; + offsets[2 ] = size /2 ;for (use_thp =0 ; use_thp <2 ; ++use_thp) {for (j =0 ; j <ARRAY_SIZE (offsets); ++j) {
@@ -2395,12 +2405,12 @@ TEST_F(hmm, migrate_partial_unmap_fault)for (i =0 , ptr = buffer->mirror; i < size /sizeof (*ptr); ++i)ASSERT_EQ (ptr[i], i); -munmap (buffer->ptr + offsets[j],ONEMEG ); +munmap (buffer->ptr + offsets[j], unmap_size);/* Fault pages back to system memory and check them. */ for (i =0 , ptr = buffer->ptr; i < size /sizeof (*ptr); ++i)if (i *sizeof (int ) < offsets[j] || - i *sizeof (int ) >= offsets[j] +ONEMEG ) + i *sizeof (int ) >= offsets[j] + unmap_size)ASSERT_EQ (ptr[i], i); buffer->ptr = old_ptr;
@@ -2414,12 +2424,19 @@ TEST_F(hmm, migrate_remap_fault)struct hmm_buffer *buffer;unsigned long npages;unsigned long size =read_pmd_pagesize (); +unsigned long offsets[3 ];unsigned long i;void *old_ptr, *new_ptr =NULL ;void *map;int *ptr;int ret, j, use_thp, dont_unmap, before; -int offsets[] = {0 ,512 *ONEKB ,ONEMEG }; + +if (!size) + size =TWOMEG ; + + offsets[0 ] =0 ; + offsets[1 ] = size /4 ; + offsets[2 ] = size /2 ;for (before =0 ; before <2 ; ++before) {for (dont_unmap =0 ; dont_unmap <2 ; ++dont_unmap) {
@@ -2822,38 +2839,45 @@ static inline int run_migration_benchmark(int fd, int use_thp, size_t buffer_siz TEST_F_TIMEOUT(hmm, benchmark_thp_migration, 120) {struct benchmark_results thp_results, regular_results; -size_t thp_size =2 *1024 *1024 ;/* 2MB - typical THP size */ +size_t thp_size =read_pmd_pagesize ();int iterations =5 ; +if (!thp_size) + thp_size =TWOMEG ; +printf ("\nHMM THP Migration Benchmark\n" );printf ("---------------------------\n" );printf ("System page size: %ld bytes\n" ,sysconf (_SC_PAGESIZE));/* Test different buffer sizes */ size_t test_sizes[] = { - thp_size /4 ,/* 512KB - smaller than THP */ - thp_size /2 ,/* 1MB - half THP */ - thp_size,/* 2MB - single THP */ - thp_size *2 ,/* 4MB - two THPs */ - thp_size *4 ,/* 8MB - four THPs */ - thp_size *8 ,/* 16MB - eight THPs */ - thp_size *128 ,/* 256MB - one twenty eight THPs */ + thp_size /4 ,/* quarter THP */ + thp_size /2 ,/* half THP */ + thp_size,/* single THP */ + thp_size *2 ,/* two THPs */ + thp_size *4 ,/* four THPs */ + thp_size *8 ,/* eight THPs */ + thp_size *128 ,/* one twenty eight THPs */ };static const char *const test_names[] = { -"Small Buffer (512KB)" , -"Half THP Size (1MB)" , -"Single THP Size (2MB)" , -"Two THP Size (4MB)" , -"Four THP Size (8MB)" , -"Eight THP Size (16MB)" , -"One twenty eight THP Size (256MB)" +"Small Buffer" , +"Half THP Size" , +"Single THP Size" , +"Two THP Size" , +"Four THP Size" , +"Eight THP Size" , +"One twenty eight THP Size" };int num_tests =ARRAY_SIZE (test_sizes);/* Run all tests */ for (int i =0 ; i < num_tests; i++) { +/* Skip test sizes exceeding INT_MAX to avoid overflow */ +if (test_sizes[i] >INT_MAX ) +break ; +/* Test with THP */ ASSERT_EQ (run_migration_benchmark (self->fd,1 , test_sizes[i], iterations, &thp_results),0 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1174/2077 selftests/mm: fix exclusive_cow test fork() handling
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aboorva Devarajan <[email protected]>
[ Upstream commit cea5702144615878600d3a39b5d8b3cc34719012 ]
The test ignores the return value of fork(), so both the parent and the (newly created) child run the COW verification loops and then call hmm_buffer_free() before returning into the kselftest harness, which _exit()s each side. This duplicated teardown sequence has been observed to manifest as a SIGSEGV in the test child, e.g.:
hmm-tests[360141]: segfault (11) at 0 nip 10006964 lr 1000ac3c code 1 in hmm-tests[6964,10000000+30000]
Fix this by adopting the same fork()-then-wait pattern already used by the nearby anon_write_child / anon_write_child_shared tests in this file: the child performs the COW verification and then _exit(0)s so it does not run the test teardown, while the parent independently verifies COW, waits for the child, and only then frees the buffer.
--- tools/testing/selftests/mm/hmm-tests.c | 31 +++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-)
tools/testing/selftests/mm/hmm-tests.c +28 -3
@@ -1882,6 +1882,8 @@ TEST_F(hmm, exclusive_cow)unsigned long i;int *ptr;int ret; +pid_t pid; +int status; npages =ALIGN (HMM_BUFFER_SIZE , self->page_size) >> self->page_shift;ASSERT_NE (npages,0 );
@@ -1910,14 +1912,37 @@ TEST_F(hmm, exclusive_cow)ASSERT_EQ (ret,0 );ASSERT_EQ (buffer->cpages, npages); -fork (); + pid =fork (); +if (pid ==-1 ) +ASSERT_EQ (pid,0 ); -/* Fault pages back to system memory and check them. */ +if (pid ==0 ) { +/* +* Child verifies COW independently, then _exit(0)s so it does +* not run the test teardown. A failed ASSERT_* here makes the +* harness abort() the child, so the parent sees +* !WIFEXITED(status) below and fails in turn. +*/ +for (i =0 , ptr = buffer->ptr; i < size /sizeof (*ptr); ++i) +ASSERT_EQ (ptr[i]++, i); + +for (i =0 , ptr = buffer->ptr; i < size /sizeof (*ptr); ++i) +ASSERT_EQ (ptr[i], i +1 ); + +_exit (0 ); + } + +/* Parent: also increment to verify COW works for both processes. */ for (i =0 , ptr = buffer->ptr; i < size /sizeof (*ptr); ++i)ASSERT_EQ (ptr[i]++, i);for (i =0 , ptr = buffer->ptr; i < size /sizeof (*ptr); ++i) -ASSERT_EQ (ptr[i], i+1 ); +ASSERT_EQ (ptr[i], i +1 ); + +/* Parent: wait for child and then free the buffer. */ +ASSERT_EQ (waitpid (pid, &status,0 ), pid); +ASSERT_TRUE (WIFEXITED (status)); +ASSERT_EQ (WEXITSTATUS (status),0 );hmm_buffer_free (buffer); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1175/2077 net: marvell: prestera: initialize err in prestera_port_sfp_bind
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruoyu Wang <[email protected]>
[ Upstream commit 62b01f72d93c7bc8fde3b2e5b5f783eca5f53324 ]
prestera_port_sfp_bind() returns err after walking the ports node. If no child node matches the port's front-panel id, err is never assigned.
Initialize err to 0 because absence of a matching optional port device tree node is not an error. In that case no phylink is created and port creation should continue with port->phy_link left NULL. Errors from malformed matched nodes and phylink_create() still propagate.
--- drivers/net/ethernet/marvell/prestera/prestera_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/marvell/prestera/prestera_main.c +1 -1
@@ -373,7 +373,7 @@ static int prestera_port_sfp_bind(struct prestera_port *port)struct device_node *ports, *node;struct fwnode_handle *fwnode;struct phylink *phy_link; -int err; +int err =0 ;if (!sw->np)return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1176/2077 tipc: fix use-after-free of the discoverer in tipc_disc_rcv()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
[ Upstream commit 1579342d71133da7f00daa02c75cebec7372097b ]
bearer_disable() frees b->disc with tipc_disc_delete()'s plain kfree(), but tipc_disc_rcv() still dereferences b->disc in RX softirq under rcu_read_lock() (tipc_udp_recv -> tipc_rcv -> tipc_disc_rcv).
L2 bearers are safe thanks to the synchronize_net() in tipc_disable_l2_media(), but the UDP bearer defers that call to the cleanup_bearer() workqueue, so the discoverer is freed with no grace period:
BUG: KASAN: slab-use-after-free in tipc_disc_rcv (net/tipc/discover.c:149) Read of size 8 at addr ffff88802348b728 by task poc_tipc/184 <IRQ> tipc_disc_rcv (net/tipc/discover.c:149) tipc_rcv (net/tipc/node.c:2126) tipc_udp_recv (net/tipc/udp_media.c:391) udp_rcv (net/ipv4/udp.c:2643) ip_local_deliver_finish (net/ipv4/ip_input.c:241) </IRQ> Freed by task 181: kfree (mm/slub.c:6565) bearer_disable (net/tipc/bearer.c:418) tipc_nl_bearer_disable (net/tipc/bearer.c:1001)
The bearer is freed with kfree_rcu(); free the discoverer the same way. Add an rcu_head to struct tipc_discoverer and free it and its skb from an RCU callback.
Because the RCU callback (tipc_disc_free_rcu) lives in module text, a call_rcu() that is still pending when the tipc module is unloaded would invoke a freed function. Add an rcu_barrier() to tipc_exit() after the bearer subsystem has been torn down, so all pending discoverer callbacks have run before the module text goes away.
Reachable from an unprivileged user namespace: the TIPCv2 genl family is netnsok and its bearer commands have no GENL_ADMIN_PERM. Needs CONFIG_TIPC and CONFIG_TIPC_MEDIA_UDP.
--- net/tipc/core.c | 5 +++++ net/tipc/discover.c | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-)
net/tipc/core.c +5 -0
@@ -218,6 +218,11 @@ static void __exit tipc_exit(void)unregister_pernet_device (&tipc_net_ops);tipc_unregister_sysctl (); +/* TODO: Wait for all timers that called call_rcu() to finish before +* calling rcu_barrier(). +*/ +rcu_barrier (); +pr_info ("Deactivated\n" ); }
net/tipc/discover.c +12 -2
@@ -58,6 +58,7 @@* @skb: request message to be (repeatedly) sent * @timer: timer governing period between requests * @timer_intv: current interval between requests (in ms) +* @rcu: RCU head for deferred freeing */ struct tipc_discoverer {u32 bearer_id;
@@ -69,6 +70,7 @@ struct tipc_discoverer {struct sk_buff *skb;struct timer_list timer;unsigned long timer_intv; +struct rcu_head rcu; };/**
@@ -382,6 +384,15 @@ int tipc_disc_create(struct net *net, struct tipc_bearer *b,return 0 ; } +static void tipc_disc_free_rcu (struct rcu_head *rp) +{ + struct tipc_discoverer *d = container_of(rp, struct tipc_discoverer, + rcu); + +kfree_skb (d->skb); +kfree (d); +} +/** * tipc_disc_delete - destroy object sending periodic link setup requests * @d: ptr to link dest structure
@@ -389,8 +400,7 @@ int tipc_disc_create(struct net *net, struct tipc_bearer *b,void tipc_disc_delete (struct tipc_discoverer *d) {timer_shutdown_sync (&d->timer); -kfree_skb (d->skb); -kfree (d); +call_rcu (&d->rcu, tipc_disc_free_rcu); }/**
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1177/2077 net: dst_metadata: fix false-positive memcpy overflow in tun_dst_unclone
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ilya Maximets <[email protected]>
[ Upstream commit 4c6d43db2a4d2cef3921e885cf34798f790d34ea ]
kmalloc_flex() in metadata_dst_alloc() sets __counted_by for the structure to the options_len, which is then initialized to zero. Later, we're initializing the structure by copying the tunnel info together with the options, and this triggers a warning for a potential memcpy overflow, since the compiler estimates that the options can't fit into the structure, even though the memory for them is actually allocated.
memcpy: detected buffer overflow: 104 byte write of buffer size 96
WARNING: CPU: X PID: Y at lib/string_helpers.c:1036 __fortify_report skb_tunnel_info_unclone+0x179/0x190 geneve_xmit+0x7fe/0xe00
The issue is triggered when built with clang and source fortification.
Fix that by doing the copy in two stages: first - the main data with the options_len, then the options. This way the correct length should be known at the time of the copy.
It would be better if the options_len never changed after allocation, but the allocation code is a little separate from the initialization and it would be awkward and potentially dangerous to return a struct with options_len set to a non-zero value from the metadata_dst_alloc().
Another option would be to use ip_tunnel_info_opts_set(), but it is doing too many unnecessary operations for the use case here.
--- include/net/dst_metadata.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
include/net/dst_metadata.h +5 -2
@@ -164,8 +164,11 @@ static inline struct metadata_dst *tun_dst_unclone(struct sk_buff *skb)if (!new_md)return ERR_PTR (-ENOMEM ); -memcpy (&new_md->u.tun_info, &md_dst->u.tun_info, -sizeof (struct ip_tunnel_info ) + md_size); +/* Copy in two stages to keep the __counted_by happy. */ + new_md->u.tun_info = md_dst->u.tun_info; +memcpy (ip_tunnel_info_opts (&new_md->u.tun_info), +ip_tunnel_info_opts (&md_dst->u.tun_info), md_size); +#ifdef CONFIG_DST_CACHE /* Unclone the dst cache if there is one */ if (new_md->u.tun_info.dst_cache.cache) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1178/2077 net: ethernet: mtk_ppe: Fix rhashtable leak in mtk_ppe_init error paths
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wayen Yan <[email protected]>
[ Upstream commit 41782770be567abc6509169d0ffdada31c783a66 ]
In mtk_ppe_init(), when accounting is enabled, the error paths for dmam_alloc_coherent(mib) and devm_kzalloc(acct) failures return NULL directly, bypassing the err_free_l2_flows label that destroys the rhashtable initialized earlier.
While this leak only occurs during probe (not runtime) and the leaked memory is minimal (an empty rhash table), fixing it ensures proper error path cleanup consistency.
Fix by changing the two return NULL statements to goto err_free_l2_flows.
--- drivers/net/ethernet/mediatek/mtk_ppe.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/mediatek/mtk_ppe.c +2 -2
@@ -918,7 +918,7 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int index) mib =dmam_alloc_coherent (ppe->dev,MTK_PPE_ENTRIES *sizeof (*mib), &ppe->mib_phys,GFP_KERNEL );if (!mib) -return NULL ; + goto err_free_l2_flows; ppe->mib_table = mib;
@@ -926,7 +926,7 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int index) GFP_KERNEL);if (!acct) -return NULL ; + goto err_free_l2_flows; ppe->acct_table = acct; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1179/2077 octeontx2-af: npc: cn20k: fix NPC defrag
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ratheesh Kannoth <[email protected]>
[ Upstream commit 48b67c0e8af65acd59d81ddaedd3442b5e4c27b7 ]
npc_defrag_alloc_free_slots() always passed NPC_MCAM_KEY_X2 into __npc_subbank_alloc(), which must match sb->key_type, so defrag never allocated replacement slots on X4 banks. Pass the subbank key type for bank 0, and only extend the search into bank 1 for X2 (X4 MCAM indices are confined to b0b..b0t).
--- drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/cn20k/npc.c +6 -3
@@ -3542,15 +3542,18 @@ static int npc_defrag_alloc_free_slots(struct rvu *rvu, alloc_cnt2 =0 ; rc =__npc_subbank_alloc (rvu, sb, -NPC_MCAM_KEY_X2 , sb->b0b, + f->key_type, sb->b0b, sb->b0t,NPC_MCAM_LOWER_PRIO , false, cnt, save, cnt, true, &alloc_cnt1); -if (alloc_cnt1 < cnt) { +/* X4 entries only occupy bank 0 (b0b..b0t); see npc_subbank_idx_2_mcam_idx(). +* X2 uses both halves of the subbank, so spill into bank 1 if needed. +*/ +if (alloc_cnt1 < cnt && f->key_type ==NPC_MCAM_KEY_X2 ) { rc = __npc_subbank_alloc(rvu, sb, - NPC_MCAM_KEY_X2, sb->b1b, + f->key_type, sb->b1b, sb->b1t, NPC_MCAM_LOWER_PRIO, false, cnt - alloc_cnt1,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1180/2077 octeontx2-af: mcs: Fix unsupported secy stats read
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Geetha sowjanya <[email protected]>
[ Upstream commit d4b7440f7316e76f013f57d8b6da069a1b9c34e7 ]
Secy control stats counter doesn't exist for CNF10KB platform. Skip reading this respective register for CNF10KB silicon while fetching secy stats.
--- drivers/net/ethernet/marvell/octeontx2/af/mcs.c | 6 +++--- drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/mcs.c +3 -3
@@ -120,13 +120,13 @@ void mcs_get_rx_secy_stats(struct mcs *mcs, struct mcs_secy_stats *stats, int id reg =MCSX_CSE_RX_MEM_SLAVE_INPKTSSECYUNTAGGEDX (id); stats->pkt_untaged_cnt =mcs_reg_read (mcs, reg); - reg =MCSX_CSE_RX_MEM_SLAVE_INPKTSSECYCTLX (id); - stats->pkt_ctl_cnt =mcs_reg_read (mcs, reg); -if (mcs->hw->mcs_blks >1 ) { reg =MCSX_CSE_RX_MEM_SLAVE_INPKTSSECYNOTAGX (id); stats->pkt_notag_cnt =mcs_reg_read (mcs, reg); +return ; } + reg =MCSX_CSE_RX_MEM_SLAVE_INPKTSSECYCTLX (id); + stats->pkt_ctl_cnt =mcs_reg_read (mcs, reg); } void mcs_get_flowid_stats(struct mcs *mcs, struct mcs_flowid_stats *stats,
drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c +2 -1
@@ -482,10 +482,11 @@ static int rvu_dbg_mcs_rx_secy_stats_display(struct seq_file *filp, void *unusedseq_printf (filp,"secy%d: Tagged ctrl pkts: %lld\n" , secy_id, stats.pkt_tagged_ctl_cnt);seq_printf (filp,"secy%d: Untaged pkts: %lld\n" , secy_id, stats.pkt_untaged_cnt); -seq_printf (filp,"secy%d: Ctrl pkts: %lld\n" , secy_id, stats.pkt_ctl_cnt);if (mcs->hw->mcs_blks >1 )seq_printf (filp,"secy%d: pkts notag: %lld\n" , secy_id, stats.pkt_notag_cnt); +else +seq_printf (filp,"secy%d: Ctrl pkts: %lld\n" , secy_id, stats.pkt_ctl_cnt); }mutex_unlock (&mcs->stats_lock);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1181/2077 octeontx2-pf: Clear stats of all resources when freeing resources
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Subbaraya Sundeep <[email protected]>
[ Upstream commit fd4460721fb4062ef470ecdfdaedadfe7e415c09 ]
When all MCS resources mapped to a PF are being freed then clear stats of all those resources too.
--- drivers/net/ethernet/marvell/octeontx2/nic/cn10k_macsec.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/marvell/octeontx2/nic/cn10k_macsec.c +1 -0
@@ -182,6 +182,7 @@ static void cn10k_mcs_free_rsrc(struct otx2_nic *pfvf, enum mcs_direction dir, clear_req->id = hw_rsrc_id; clear_req->type = type; clear_req->dir = dir; + clear_req->all = all; req =otx2_mbox_alloc_msg_mcs_free_resources (mbox);if (!req)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1182/2077 octeontx2-pf: mcs: Fix mcs resources free on PF shutdown
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Geetha sowjanya <[email protected]>
[ Upstream commit 450d0e90b10393bd9f50c127875a9fdd4cc81c30 ]
On PF shutdown, the current driver free mcs hardware resources though mcs resources are not allocated to it. This patch checks the mcs resources status and if resources are allocated then only sends mailbox message to free them.
--- .../net/ethernet/marvell/octeontx2/nic/cn10k_macsec.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/cn10k_macsec.c +7 -2
@@ -1777,11 +1777,16 @@ int cn10k_mcs_init(struct otx2_nic *pfvf)void cn10k_mcs_free (struct otx2_nic *pfvf) { +struct cn10k_mcs_cfg *cfg = pfvf->macsec_cfg; +if (!test_bit (CN10K_HW_MACSEC , &pfvf->hw.cap_flag))return ; -cn10k_mcs_free_rsrc (pfvf,MCS_TX ,MCS_RSRC_TYPE_SECY ,0 , true); -cn10k_mcs_free_rsrc (pfvf,MCS_RX ,MCS_RSRC_TYPE_SECY ,0 , true); +if (!list_empty (&cfg->txsc_list)) { +cn10k_mcs_free_rsrc (pfvf,MCS_TX ,MCS_RSRC_TYPE_SECY ,0 , true); +cn10k_mcs_free_rsrc (pfvf,MCS_RX ,MCS_RSRC_TYPE_SECY ,0 , true); + } +kfree (pfvf->macsec_cfg); pfvf->macsec_cfg =NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1183/2077 net: emac: Fix NULL pointer dereference in emac_probe
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit f623d38fe6c4e8c40b23f42cc6fe6963fa49997b ]
Move devm_request_irq() after devm_platform_ioremap_resource() so that dev->emacp is mapped before the interrupt handler can fire. An early interrupt hitting emac_irq() would dereference the NULL dev->emacp and crash.
Also remove redundant error message. devm_platform_ioremap_resource() already returns an error message with dev_err_probe().
--- drivers/net/ethernet/ibm/emac/core.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/net/ethernet/ibm/emac/core.c +6 -7
@@ -3035,6 +3035,12 @@ static int emac_probe(struct platform_device *ofdev)if (err) goto err_gone; + dev->emacp =devm_platform_ioremap_resource (ofdev,0 ); +if (IS_ERR (dev->emacp)) { + err =PTR_ERR (dev->emacp); + goto err_gone; + } +/* Setup error IRQ handler */ dev->emac_irq =platform_get_irq (ofdev,0 ); err = devm_request_irq(&ofdev->dev, dev->emac_irq, emac_irq, 0, "EMAC",
@@ -3047,13 +3053,6 @@ static int emac_probe(struct platform_device *ofdev) ndev->irq = dev->emac_irq; - dev->emacp =devm_platform_ioremap_resource (ofdev,0 ); -if (IS_ERR (dev->emacp)) { -dev_err (&ofdev->dev,"can't map device registers" ); - err =PTR_ERR (dev->emacp); - goto err_gone; - } -/* Wait for dependent devices */ err =emac_wait_deps (dev);if (err)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1184/2077 net/sched: act_ct: fix nf_connlabels leak on two error paths
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
[ Upstream commit 16e088016f38cf728a0de709c3335cc5a3850476 ]
tcf_ct_fill_params() calls nf_connlabels_get() (setting put_labels) when TCA_CT_LABELS is present, but two later error sites use a bare return instead of "goto err", skipping the err: nf_connlabels_put() cleanup. They also precede the "p->put_labels = put_labels" assignment, so the tcf_ct_params_free() fallback does not release the count either. Each failed RTM_NEWACTION on these paths leaks one nf_connlabels reference:net->ct.labels_used is incremented and never released. The action is reachable with CAP_NET_ADMIN over the netns, i.e. from an unprivileged user namespace on default-userns kernels.
Impact: an unprivileged user with CAP_NET_ADMIN over a network namespace (e.g. via user namespaces) leaks one nf_connlabels reference per failed RTM_NEWACTION on the two error paths; net->ct.labels_used is never released.
The err: label is safe to reach from both sites: p->tmpl is still NULL there (kzalloc'd, not yet assigned) and nf_ct_put(NULL) is a no-op, so no inline release is needed.
--- net/sched/act_ct.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/sched/act_ct.c +4 -2
@@ -1295,7 +1295,8 @@ static int tcf_ct_fill_params(struct net *net,if (tb[TCA_CT_ZONE ]) {if (!IS_ENABLED (CONFIG_NF_CONNTRACK_ZONES )) {NL_SET_ERR_MSG_MOD (extack,"Conntrack zones isn't enabled." ); -return -EOPNOTSUPP ; + err = -EOPNOTSUPP ; + goto err; } tcf_ct_set_key_val(tb,
@@ -1308,7 +1309,8 @@ static int tcf_ct_fill_params(struct net *net, tmpl =nf_ct_tmpl_alloc (net, &zone,GFP_KERNEL );if (!tmpl) {NL_SET_ERR_MSG_MOD (extack,"Failed to allocate conntrack template" ); -return -ENOMEM ; + err = -ENOMEM ; + goto err; } p->tmpl = tmpl;if (tb[TCA_CT_HELPER_NAME ]) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1185/2077 net: airoha: Fix skb->priority underflow in airoha_dev_select_queue()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wayen Yan <[email protected]>
[ Upstream commit 86e51aa24686cc95bb35613059e8b94b9b81e3f0 ]
In airoha_dev_select_queue(), the expression:
queue = (skb->priority - 1) % AIROHA_NUM_QOS_QUEUES;
implicitly converts to unsigned arithmetic: when skb->priority is 0 (the default for unclassified traffic), (0u - 1u) wraps to UINT_MAX, and UINT_MAX % 8 = 7, routing default best-effort packets to the highest-priority QoS queue. This causes QoS inversion where the majority of traffic on a PON gateway starves actual high-priority flows (VoIP, gaming, etc.).
The "- 1" offset was a leftover from the ETS offload implementation that has since been removed. The correct mapping is a direct modulo:
queue = skb->priority % AIROHA_NUM_QOS_QUEUES;
This maps priority 0 → queue 0 (lowest), priority 7 → queue 7 (highest), with higher priorities wrapping around. This is the standard Linux sk_prio → HW queue mapping used by other drivers.
--- drivers/net/ethernet/airoha/airoha_eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/airoha/airoha_eth.c +1 -1
@@ -1933,7 +1933,7 @@ static u16 airoha_dev_select_queue(struct net_device *dev, struct sk_buff *skb,*/ channel =netdev_uses_dsa (dev) ?skb_get_queue_mapping (skb) : port->id; channel = channel %AIROHA_NUM_QOS_CHANNELS ; - queue = (skb->priority -1 ) %AIROHA_NUM_QOS_QUEUES ;/* QoS queue */ + queue = skb->priority %AIROHA_NUM_QOS_QUEUES ; queue = channel *AIROHA_NUM_QOS_QUEUES + queue;return queue < dev->num_tx_queues ? queue :0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1186/2077 ipv6: ndisc: fix NULL deref in accept_untracked_na()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
[ Upstream commit d186e942365acece7c56d39da05dd63bf95b280a ]
accept_untracked_na() re-fetches the inet6_dev with __in6_dev_get(dev) and dereferences idev->cnf.accept_untracked_na without a NULL check, even though its only caller ndisc_recv_na() already fetched and NULL-checked idev for the same device.
Both reads of dev->ip6_ptr run in the same RCU read-side critical section, but a concurrent addrconf_ifdown() can clear dev->ip6_ptr between them: lowering the MTU below IPV6_MIN_MTU calls addrconf_ifdown() without the synchronize_net() that orders the unregister path, so the re-fetch returns NULL and oopses:
BUG: KASAN: null-ptr-deref in ndisc_recv_na (net/ipv6/ndisc.c:974) Read of size 4 at addr 0000000000000364 Call Trace: <IRQ> ndisc_recv_na (net/ipv6/ndisc.c:974) icmpv6_rcv (net/ipv6/icmp.c:1193) ip6_protocol_deliver_rcu (net/ipv6/ip6_input.c:479) ip6_input_finish (net/ipv6/ip6_input.c:534) ip6_input (net/ipv6/ip6_input.c:545) ip6_mc_input (net/ipv6/ip6_input.c:635) ipv6_rcv (net/ipv6/ip6_input.c:351) </IRQ>
It is reachable by an unprivileged user via a network namespace.
Pass the caller's already validated idev instead of re-fetching it; the idev stays alive for the whole RCU critical section, so it is safe even after dev->ip6_ptr has been cleared.
--- net/ipv6/ndisc.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
net/ipv6/ndisc.c +3 -5
@@ -967,10 +967,8 @@ static enum skb_drop_reason ndisc_recv_ns(struct sk_buff *skb)return reason; } -static int accept_untracked_na (struct net_device *dev,struct in6_addr *saddr) +static int accept_untracked_na (struct inet6_dev *idev,struct in6_addr *saddr) { -struct inet6_dev *idev =__in6_dev_get (dev); -switch (READ_ONCE (idev->cnf.accept_untracked_na)) {case 0 :/* Don't accept untracked na (absent in neighbor cache) */ return 0 ;
@@ -980,7 +978,7 @@ static int accept_untracked_na(struct net_device *dev, struct in6_addr *saddr)* same subnet as an address configured on the interface that * received the na */ -return !!ipv6_chk_prefix (saddr, dev); +return !!ipv6_chk_prefix (saddr, idev->dev);default :return 0 ; }
@@ -1078,7 +1076,7 @@ static enum skb_drop_reason ndisc_recv_na(struct sk_buff *skb)*/ new_state = msg->icmph.icmp6_solicited ?NUD_REACHABLE :NUD_STALE ;if (!neigh && lladdr && idev &&READ_ONCE (idev->cnf.forwarding)) { -if (accept_untracked_na (dev, saddr)) { +if (accept_untracked_na (idev, saddr)) { neigh =neigh_create (&nd_tbl, &msg->target, dev); new_state =NUD_STALE ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1187/2077 ipv6: ioam: fix type confusion of dst_entry
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiayuan Chen <[email protected]>
[ Upstream commit 9ed19e11d2146076d117d51a940643990118449b ]
IOAM uses a dummy dst_entry(null_dst) to mark that the destination should not be changed after the transformation. This dst is stored in the IOAM lwt state and may be passed to dst_cache_set_ip6().
However, the IPv6 dst cache path eventually calls rt6_get_cookie(), which treats the dst_entry as part of a struct rt6_info. Since the null_dst was embedded directly as a struct dst_entry in struct ioam6_lwt, this resulted in an invalid cast and rt6_get_cookie() reading fields from the wrong object.
In practice, the wrong cookie is not used while dst->obsolete is zero, but rt6_get_cookie() may also access per-cpu value when rt->sernum is zero. In this case, rt->sernum aliases ioam6_lwt::cache::reset_ts, which can become zero, making this a potential invalid pointer access.
Fix this by embedding a full struct rt6_info for the dummy IPv6 route and passing its dst member to the dst APIs.
--- net/ipv6/ioam6_iptunnel.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/ipv6/ioam6_iptunnel.c +4 -4
@@ -35,7 +35,7 @@ struct ioam6_lwt_freq { };struct ioam6_lwt { -struct dst_entry null_dst; +struct rt6_info null_rt;struct dst_cache cache;struct ioam6_lwt_freq freq;atomic_t pkt_cnt;
@@ -176,7 +176,7 @@ static int ioam6_build_state(struct net *net, struct nlattr *nla,* it is stored in the cache. Then, +1/-1 each time we read the cache * and release it. Long story short, we're fine. */ -dst_init (&ilwt->null_dst,NULL ,NULL ,DST_OBSOLETE_NONE ,DST_NOCOUNT ); +dst_init (&ilwt->null_rt.dst,NULL ,NULL ,DST_OBSOLETE_NONE ,DST_NOCOUNT );atomic_set (&ilwt->pkt_cnt,0 ); ilwt->freq.k = freq_k;
@@ -360,7 +360,7 @@ static int ioam6_output(struct net *net, struct sock *sk, struct sk_buff *skb)/* This is how we notify that the destination does not change after * transformation and that we need to use orig_dst instead of the cache */ -if (dst == &ilwt->null_dst) { +if (dst == &ilwt->null_rt.dst) {dst_release (dst); dst = orig_dst;
@@ -429,7 +429,7 @@ static int ioam6_output(struct net *net, struct sock *sk, struct sk_buff *skb)local_bh_disable ();if (orig_dst->lwtstate == dst->lwtstate)dst_cache_set_ip6 (&ilwt->cache, - &ilwt->null_dst, &fl6.saddr); + &ilwt->null_rt.dst, &fl6.saddr);else dst_cache_set_ip6 (&ilwt->cache, dst, &fl6.saddr);local_bh_enable ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1188/2077 dpaa2-switch: do not accept VLAN uppers while bridged
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ioana Ciornei <[email protected]>
[ Upstream commit d07d80b6a129a44538cda1549b7acf95154fb197 ]
The dpaa2-switch driver does not support VLAN uppers while its ports are bridged. This scenario tried to be prevented by rejecting a bridge join while VLAN uppers exist but the reverse order was still possible.
This patches adds a check so that the dpaa2-switch also does not accept VLAN uppers while bridged.
--- drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c +8 -0
@@ -2198,6 +2198,7 @@ dpaa2_switch_prechangeupper_sanity_checks(struct net_device *netdev,static int dpaa2_switch_port_prechangeupper (struct net_device *netdev,struct netdev_notifier_changeupper_info *info) { +struct ethsw_port_priv *port_priv;struct netlink_ext_ack *extack;struct net_device *upper_dev;int err;
@@ -2216,6 +2217,13 @@ static int dpaa2_switch_port_prechangeupper(struct net_device *netdev,if (!info->linking)dpaa2_switch_port_pre_bridge_leave (netdev); + }else if (is_vlan_dev (upper_dev)) { + port_priv =netdev_priv (netdev); +if (port_priv->fdb->bridge_dev) { +NL_SET_ERR_MSG_MOD (extack, +"Cannot accept VLAN uppers while bridged" ); +return -EOPNOTSUPP ; + } }return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1189/2077 rtc: abx80x: fix the RTC_VL_CLR clearing all status flags
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Antoni Pokusinski <[email protected]>
[ Upstream commit 419719c514252a2dbb2e2976f564c83417dd6d0a ]
The RTC_VL_CLR ioctl intends to clear only the battery low flag (BLF), however the current implementation writes 0 to the status register, clearing all status bits.
Fix this by writing back the masked status value so that only BLF is cleared, preserving other status flags.
--- drivers/rtc/rtc-abx80x.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/rtc/rtc-abx80x.c +2 -1
@@ -545,7 +545,8 @@ static int abx80x_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) status &= ~ABX8XX_STATUS_BLF ; - tmp =i2c_smbus_write_byte_data (client,ABX8XX_REG_STATUS ,0 ); + tmp =i2c_smbus_write_byte_data (client,ABX8XX_REG_STATUS , + status);if (tmp <0 )return tmp;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1190/2077 rtc: ds1307: handle oscillator stop flag for ds1337/ds1339/ds3231
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ronan Dalton <[email protected]>
[ Upstream commit a091e1ba3b68cabc9caedafc6f81d9fe9b3b2200 ]
Prior to commit 48458654659c ("rtc: ds1307: remove clear of oscillator stop flag (OSF) in probe"), the oscillator stop flag (OSF) bit was checked during device probe for the ds1337, ds1339, ds1341, and ds3231 chips; if it was set, it would be cleared and a warning would be logged saying "SET TIME!". Since that commit, the OSF bit is no longer cleared, but the warning is still printed.
Directly following that commit, there was no way to get rid of this warning because nothing cleared the OSF bit on these chips.
The commit associated with the previous commit, 523923cfd5d6 ("rtc:
ds1307: handle oscillator stop flag (OSF) for ds1341"), made proper use of the OSF when getting and setting the time in the RTC. However, the other RTC variants ds1337, ds1339 and ds3231 didn't have a corresponding change made.
Given that the OSF bit is no longer cleared at probe time when it is set, the remaining three chips should have the same handling as the ds1341 chip has for the OSF bit.
Fix the issue on the ds1337, ds1339 and ds3231 chips by applying the same logic as the ds1341 has to these chips.
Note that any devices brought up between the first referenced commit and this one may begin mistrusting the time reported by the RTC until it is set again, if the bit was never explicitly cleared.
Note that only the ds1339 was tested with this change, but the datasheets for the other chips contain essentially identical descriptions of the OSF bit so the same change should work.
--- drivers/rtc/rtc-ds1307.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-)
drivers/rtc/rtc-ds1307.c +17 -11
@@ -269,6 +269,16 @@ static int ds1307_get_time(struct device *dev, struct rtc_time *t)if (tmp &DS1338_BIT_OSF )return -EINVAL ;break ; +case ds_1337: +case ds_1339: +case ds_1341: +case ds_3231: + ret =regmap_read (ds1307->regmap,DS1337_REG_STATUS , &tmp); +if (ret) +return ret; +if (tmp &DS1337_BIT_OSF ) +return -EINVAL ; +break ;case ds_1340:if (tmp & DS1340_BIT_nEOSC)return -EINVAL ;
@@ -279,13 +289,6 @@ static int ds1307_get_time(struct device *dev, struct rtc_time *t)if (tmp &DS1340_BIT_OSF )return -EINVAL ;break ; -case ds_1341: - ret =regmap_read (ds1307->regmap,DS1337_REG_STATUS , &tmp); -if (ret) -return ret; -if (tmp &DS1337_BIT_OSF ) -return -EINVAL ; -break ;case ds_1388: ret =regmap_read (ds1307->regmap,DS1388_REG_FLAG , &tmp);if (ret)
@@ -380,14 +383,17 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)regmap_update_bits (ds1307->regmap,DS1307_REG_CONTROL ,DS1338_BIT_OSF ,0 );break ; -case ds_1340: -regmap_update_bits (ds1307->regmap,DS1340_REG_FLAG , -DS1340_BIT_OSF ,0 ); -break ; +case ds_1337: +case ds_1339:case ds_1341: +case ds_3231:regmap_update_bits (ds1307->regmap,DS1337_REG_STATUS ,DS1337_BIT_OSF ,0 );break ; +case ds_1340: +regmap_update_bits (ds1307->regmap,DS1340_REG_FLAG , +DS1340_BIT_OSF ,0 ); +break ;case ds_1388:regmap_update_bits (ds1307->regmap,DS1388_REG_FLAG ,DS1388_BIT_OSF ,0 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1191/2077 bpf: Fix stack slot index in nospec checks
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nuoqi Gui <[email protected]>
[ Upstream commit d1d53aa30ab3b5ae89161c9cc840b3f7489ad386 ]
check_stack_write_fixed_off() computes the byte slot for a fixed-offset stack write as -off - 1, and records each written byte in slot_type[] with (slot - i) % BPF_REG_SIZE.
The Spectre v4 sanitization pre-check uses slot_type[i] instead. For a 4-byte write at fp-8 after the lower half of fp-8 has been zeroed, the pre-check scans bytes 0..3 and sees STACK_ZERO while the actual write updates bytes 7..4. That can leave the second half-slot write without nospec_result even though the bytes being overwritten still require sanitization.
Use the same slot index in the sanitization pre-check that the write path uses when updating slot_type[].
--- kernel/bpf/verifier.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/bpf/verifier.c +2 -1
@@ -3836,7 +3836,8 @@ static int check_stack_write_fixed_off(struct bpf_verifier_env *env,bool sanitize = reg &&is_spillable_regtype (reg->type);for (i =0 ; i < size; i++) { -u8 type = state->stack[spi].slot_type[i]; +u8 type = state->stack[spi].slot_type[(slot - i) % +BPF_REG_SIZE ];if (type !=STACK_MISC && type !=STACK_ZERO ) { sanitize = true;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1192/2077 bpf: Fix partial copy of non-linear test_run output
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sun Jian <[email protected]>
[ Upstream commit b5f3534268e3f91c9d3e9dc79ee5a32555880ee9 ]
For non-linear test_run output, bpf_test_finish() derives the linear data copy length from copy_size - frag_size. This only matches the linear data length when copy_size is the full packet size.
When userspace provides a short data_out buffer, copy_size is clamped to that buffer size. If copy_size is smaller than frag_size, the computed length becomes negative and bpf_test_finish() returns -ENOSPC before copying the packet prefix or updating data_size_out.
Compute the linear data length from the packet layout instead, and clamp the linear copy length to copy_size. This preserves the expected partial-copy semantics: return -ENOSPC, copy the packet prefix that fits in data_out, and report the full packet length through data_size_out.
--- net/bpf/test_run.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
net/bpf/test_run.c +2 -6
@@ -453,12 +453,8 @@ static int bpf_test_finish(const union bpf_attr *kattr, }if (data_out) { -int len = sinfo ? copy_size - frag_size : copy_size; - -if (len <0 ) { - err = -ENOSPC ; - goto out; - } +u32 head_len = size - frag_size; +u32 len =min (copy_size, head_len);if (copy_to_user (data_out, data, len)) goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1193/2077 bpftool: Fix vmlinux BTF leak in cgroup commands
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yichong Chen <[email protected]>
[ Upstream commit bda6a7308ef8e79cfbb7d09e48e1c7ffaa522269 ]
bpftool cgroup show and tree call libbpf_find_kernel_btf() to resolve attach_btf names, but never release the returned BTF object.
For cgroup tree, do_show_tree_fn() is called once for each cgroup visited by nftw(). When more than one cgroup has attached programs, each callback overwrites btf_vmlinux with a new object and loses the previous allocation.
Load vmlinux BTF only once during a tree walk and release it when cgroup show or tree completes. Reset btf_vmlinux_id at the same time so batch mode starts with clean state.
--- tools/bpf/bpftool/cgroup.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
tools/bpf/bpftool/cgroup.c +13 -1
@@ -78,6 +78,13 @@ static unsigned int query_flags;static struct btf *btf_vmlinux;static __u32 btf_vmlinux_id; +static void free_btf_vmlinux (void ) +{ +btf__free (btf_vmlinux); + btf_vmlinux =NULL ; + btf_vmlinux_id =0 ; +} +static enum bpf_attach_type parse_attach_type (const char *str) {const char *attach_type_str;
@@ -388,6 +395,8 @@ static int do_show(int argc, char **argv)if (json_output)jsonw_end_array (json_wtr); +free_btf_vmlinux (); + exit_cgroup:close (cgroup_fd); exit:
@@ -437,7 +446,9 @@ static int do_show_tree_fn(const char *fpath, const struct stat *sb,printf ("%s\n" , fpath); } - btf_vmlinux =libbpf_find_kernel_btf (); +if (!btf_vmlinux) + btf_vmlinux =libbpf_find_kernel_btf (); +for (i =0 ; i <ARRAY_SIZE (cgroup_attach_types); i++)show_bpf_progs (cgroup_fd, cgroup_attach_types[i], ftw->level);
@@ -540,6 +551,7 @@ static int do_show_tree(int argc, char **argv)if (json_output)jsonw_end_array (json_wtr); +free_btf_vmlinux ();free (cgroup_alloced);return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1194/2077 bpf: zero-initialize the fib lookup flow struct
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Avinash Duduskar <[email protected]>
[ Upstream commit 0dfcb68a6a5ac517b22dff6a1f01cb4f126dfc57 ]
bpf_ipv4_fib_lookup() and bpf_ipv6_fib_lookup() build the flow key on the stack with a bare "struct flowi4 fl4;" / "struct flowi6 fl6;" and fill it field by field, but never set flowi4_l3mdev / flowi6_l3mdev.
On the non-DIRECT path the lookup goes through the fib rules whenever the netns has custom rules, which a VRF installs:
bpf_ipv4_fib_lookup() -> fib_lookup() -> __fib_lookup() -> l3mdev_update_flow() reads !fl->flowi_l3mdev -> fib_rules_lookup() -> fib_rule_match() -> l3mdev_fib_rule_match() uses fl->flowi_l3mdev
l3mdev_update_flow() resolves the l3mdev master from the ingress device only while the field is still zero. Left at a nonzero stack value the resolution is skipped, and l3mdev_fib_rule_match() then tests that value as an ifindex, so the VRF master is not resolved and the rule fails to
match: an ingress enslaved to a VRF can fail to select its table. FIB rules matching on an L3 master device (l3mdev_fib_rule_iif_match()/ _oif_match()) read the same value, so an "ip rule iif/oif <vrf>" mismatches the same way.
Zero-initialize the whole flow struct rather than adding one more field assignment, so any flowi field added later is covered too. ip_route_input_slow() likewise zeroes the field before its input lookup.
CONFIG_INIT_STACK_ALL_ZERO masks this by default, but it depends on compiler support (CC_HAS_AUTO_VAR_INIT_ZERO), so INIT_STACK_NONE builds, including older toolchains that fall back to it, are exposed. Built with INIT_STACK_ALL_PATTERN, a plain bpf_fib_lookup (no VLAN, no DIRECT) over a VRF slave whose destination is routed only in the VRF table returns BPF_FIB_LKUP_RET_NOT_FWDED, and resolves with this patch. On the default config the lookup succeeds either way, so ordinary testing does not catch the bug.
--- net/core/filter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/filter.c +2 -2
@@ -6182,7 +6182,7 @@ static int bpf_ipv4_fib_lookup(struct net *net, struct bpf_fib_lookup *params,struct in_device *in_dev;struct net_device *dev;struct fib_result res; -struct flowi4 fl4; +struct flowi4 fl4 = {};u32 mtu =0 ;int err;
@@ -6322,7 +6322,7 @@ static int bpf_ipv6_fib_lookup(struct net *net, struct bpf_fib_lookup *params,struct neighbour *neigh;struct net_device *dev;struct inet6_dev *idev; -struct flowi6 fl6; +struct flowi6 fl6 = {};int strict =0 ;int oif, err;u32 mtu =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1195/2077 bpf: Fix BPF_PROG_ASSOC_STRUCT_OPS last field check
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thiébaud Weksteen <[email protected]>
[ Upstream commit 8405c4626460503027461652f96d8bb10c2a9173 ]
When struct prog_assoc_struct_ops was added, BPF_PROG_ASSOC_STRUCT_OPS_LAST_FIELD referenced prog_fd instead of the actual last field, flags.
--- kernel/bpf/syscall.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/syscall.c +1 -1
@@ -6208,7 +6208,7 @@ static int prog_stream_read(union bpf_attr *attr)return ret; } -#define BPF_PROG_ASSOC_STRUCT_OPS_LAST_FIELD prog_assoc_struct_ops.prog_fd +#define BPF_PROG_ASSOC_STRUCT_OPS_LAST_FIELD prog_assoc_struct_ops.flagsstatic int prog_assoc_struct_ops (union bpf_attr *attr) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1196/2077 bpf: Fix effective prog array index with BPF_F_PREORDER
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amery Hung <[email protected]>
[ Upstream commit f08aaee3152d0dfc578b3f2586932d82062701dd ]
replace_effective_prog() and purge_effective_progs() located the slot in the effective array by walking the program hlist and counting entries linearly. That count does not match the array layout: compute_effective_ progs() places BPF_F_PREORDER programs at the front (ancestor cgroup first, attach order within a cgroup) and the rest after them (descendant cgroup first). So when a preorder program is present, the linear hlist position no longer equals the program's index in the effective array.
For replace_effective_prog() (bpf_link_update()) this overwrote the wrong slot, corrupting the effective order. For purge_effective_progs(), it could dummy out a slot belonging to a different program and leave the detached program in the array while bpf_prog_put() drops its reference, i.e. a use-after-free.
Fix both by replaying compute_effective_progs()'s placement (including the per-cgroup preorder reversal) in a shared effective_prog_pos() helper. Identify the entry by its struct bpf_prog_list pointer rather than by (prog, link) value, so the lookup resolves to exactly the attachment the syscall selected even when the same bpf_prog is attached to several cgroups in the hierarchy.
--- kernel/bpf/cgroup.c | 108 +++++++++++++++++++++++++------------------- 1 file changed, 62 insertions(+), 46 deletions(-)
kernel/bpf/cgroup.c +62 -46
@@ -939,19 +939,65 @@ static int cgroup_bpf_attach(struct cgroup *cgrp,return ret; } +static int effective_prog_pos (struct cgroup *cgrp, +enum cgroup_bpf_attach_type atype, +struct bpf_prog_list *target_pl) +{ +int cnt =0 , preorder_cnt =0 , fstart, bstart, init_bstart, pos =-1 ; +struct bpf_prog_list *pl; +struct cgroup *p = cgrp; + +/* count effective programs to find where the preorder region ends */ +do { +if (cnt ==0 || (p->bpf.flags[atype] &BPF_F_ALLOW_MULTI )) + cnt +=prog_list_length (&p->bpf.progs[atype], &preorder_cnt); + p =cgroup_parent (p); + }while (p); + +/* replay compute_effective_progs() placement and record target's slot */ + cnt =0 ; + p = cgrp; + fstart = preorder_cnt; + bstart = preorder_cnt -1 ; +do { +if (cnt >0 && !(p->bpf.flags[atype] &BPF_F_ALLOW_MULTI )) +continue ; + + init_bstart = bstart; +hlist_for_each_entry (pl, &p->bpf.progs[atype], node) { +if (!prog_list_prog (pl)) +continue ; + +if (pl->flags &BPF_F_PREORDER ) { +if (pl == target_pl) + pos = bstart; + bstart--; + }else { +if (pl == target_pl) + pos = fstart; + fstart++; + } + cnt++; + } + +/* reverse pre-ordering progs at this cgroup level */ +if (pos >= bstart +1 && pos <= init_bstart) + pos = bstart +1 + init_bstart - pos; + }while ((p =cgroup_parent (p))); + +return pos; +} +/* Swap updated BPF program for given link in effective program arrays across * all descendant cgroups. This function is guaranteed to succeed. */ static void replace_effective_prog (struct cgroup *cgrp,enum cgroup_bpf_attach_type atype, -struct bpf_cgroup_link *link) +struct bpf_prog_list *pl) {struct bpf_prog_array_item *item;struct cgroup_subsys_state *css;struct bpf_prog_array *progs; -struct bpf_prog_list *pl; -struct hlist_head *head; -struct cgroup *cg;int pos;css_for_each_descendant_pre (css, &cgrp->self) {
@@ -960,27 +1006,15 @@ static void replace_effective_prog(struct cgroup *cgrp,if (percpu_ref_is_zero (&desc->bpf.refcnt))continue ; -/* find position of link in effective progs array */ -for (pos =0 , cg = desc; cg; cg =cgroup_parent (cg)) { -if (pos && !(cg->bpf.flags[atype] &BPF_F_ALLOW_MULTI )) -continue ; + pos =effective_prog_pos (desc, atype, pl); +if (WARN_ON_ONCE (pos <0 )) +continue ; - head = &cg->bpf.progs[atype]; -hlist_for_each_entry (pl, head, node) { -if (!prog_list_prog (pl)) -continue ; -if (pl->link == link) - goto found; - pos++; - } - } -found: -BUG_ON (!cg); progs =rcu_dereference_protected ( desc->bpf.effective[atype],lockdep_is_held (&cgroup_mutex)); item = &progs->items[pos]; -WRITE_ONCE (item->prog, link->link.prog); +WRITE_ONCE (item->prog, pl->link->link.prog); } }
@@ -1024,7 +1058,7 @@ static int __cgroup_bpf_replace(struct cgroup *cgrp, cgrp->bpf.revisions[atype] +=1 ; old_prog =xchg (&link->link.prog, new_prog); -replace_effective_prog (cgrp, atype, link); +replace_effective_prog (cgrp, atype, pl);bpf_prog_put (old_prog);return 0 ; }
@@ -1091,19 +1125,14 @@ static struct bpf_prog_list *find_detach_entry(struct hlist_head *progs,* recomputing the array in place. * * @cgrp: The cgroup which descendants to travers -* @prog: A program to detach or NULL -* @link: A link to detach or NULL +* @pl: The prog_list entry being detached * @atype: Type of detach operation */ -static void purge_effective_progs (struct cgroup *cgrp,struct bpf_prog *prog, -struct bpf_cgroup_link *link, +static void purge_effective_progs (struct cgroup *cgrp,struct bpf_prog_list *pl,enum cgroup_bpf_attach_type atype) {struct cgroup_subsys_state *css;struct bpf_prog_array *progs; -struct bpf_prog_list *pl; -struct hlist_head *head; -struct cgroup *cg;int pos;/* recompute effective prog array in place */
@@ -1113,24 +1142,11 @@ static void purge_effective_progs(struct cgroup *cgrp, struct bpf_prog *prog,if (percpu_ref_is_zero (&desc->bpf.refcnt))continue ; -/* find position of link or prog in effective progs array */ -for (pos =0 , cg = desc; cg; cg =cgroup_parent (cg)) { -if (pos && !(cg->bpf.flags[atype] &BPF_F_ALLOW_MULTI )) -continue ; - - head = &cg->bpf.progs[atype]; -hlist_for_each_entry (pl, head, node) { -if (!prog_list_prog (pl)) -continue ; -if (pl->prog == prog && pl->link == link) - goto found; - pos++; - } - } - + pos =effective_prog_pos (desc, atype, pl);/* no link or prog match, skip the cgroup of this layer */ -continue ; -found: +if (pos <0 ) +continue ; + progs =rcu_dereference_protected ( desc->bpf.effective[atype],lockdep_is_held (&cgroup_mutex));
@@ -1196,7 +1212,7 @@ static int __cgroup_bpf_detach(struct cgroup *cgrp, struct bpf_prog *prog,/* if update effective array failed replace the prog with a dummy prog*/ pl->prog = old_prog; pl->link = link; -purge_effective_progs (cgrp, old_prog, link, atype); +purge_effective_progs (cgrp, pl, atype); }/* now can actually delete it from this cgroup list */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1197/2077 power: sequencing: fix ABBA deadlock in pwrseq_device_unregister()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bartosz Golaszewski <[email protected]>
[ Upstream commit 2d5a7d406ecece5837af1e278ffbbf6c0315560a ]
The pwrseq core takes three locks in consistent order everywhere:
pwrseq_sem -> pwrseq->rw_lock -> pwrseq->state_lock
pwrseq_get() -> pwrseq_match_device() takes pwrseq_sem for reading, then rw_lock for reading. pwrseq_power_on()/pwrseq_power_off() take rw_lock for reading and then state_lock.
pwrseq_device_unregister() is the only exception, it takes: state_lock, then rw_lock for writing and finally pwrseq_sem for writing. This created two potential ABBA deadlock situations that sashiko pointed out.
- pwrseq_power_on/off() take rw_lock for reading then state_lock, while pwrseq_unregister() takes state_lock then rw_lock for writing
- pwrseq_get() takes pwrseq_sem for reading then rw_lock for reading, while pwrseq_unregister() takes rw_lock for writing then pwrseq_sem for writing
Reorder the unregister path to taking pwrseq_sem for writing -> rw_lock for writing and drop the state_lock entirely. This is safe as enable_count is only ever written under rw_lock held for read (via pwrseq_unit_enable()/disable(), reached only from pwrseq_power_on/off()), so holding rw_lock for writing already excludes every other writer and reader and the active-users WARN() stays race-free without state_lock.
--- drivers/power/sequencing/core.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/power/sequencing/core.c +6 -3
@@ -543,15 +543,18 @@ void pwrseq_device_unregister(struct pwrseq_device *pwrseq)struct device *dev = &pwrseq->dev;struct pwrseq_target *target; - scoped_guard(mutex, &pwrseq->state_lock) { + scoped_guard(rwsem_write, &pwrseq_sem) {guard (rwsem_write)(&pwrseq->rw_lock); +/* +* Holding rw_lock for write excludes all power on/off callers +* (they hold it for read), so it's safe to read enable_count +* here without taking the state_lock. +*/ list_for_each_entry (target, &pwrseq->targets, list)WARN (target->unit->enable_count,"REMOVING POWER SEQUENCER WITH ACTIVE USERS\n" ); -guard (rwsem_write)(&pwrseq_sem); -device_del (dev); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1198/2077 gpiolib: initialize return value in gpiochip_set_multiple()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruoyu Wang <[email protected]>
[ Upstream commit 99dfa46baba29513d1094c8f30bc86c6ef88543a ]
gpiochip_set_multiple() falls back to setting lines one by one when the chip does not provide set_multiple(). If the fallback path receives an empty mask, the loop is skipped and ret is returned without being initialized.
Initialize ret to 0 so an empty mask is treated as a successful no-op.
--- drivers/gpio/gpiolib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpiolib.c +1 -1
@@ -3786,7 +3786,7 @@ static int gpiochip_set_multiple(struct gpio_chip *gc, unsigned long *mask, unsigned long *bits) { unsigned int i; -int ret; +int ret =0 ;lockdep_assert_held (&gc->gpiodev->srcu);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1199/2077 drm/edid: fix OOB read in drm_parse_tiled_block()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiang Mei <[email protected]>
[ Upstream commit faaa1e1155833e7d4ce7e3cfaf64c0d636b190db ]
drm_parse_tiled_block() casts the DisplayID block to a struct displayid_tiled_block and reads the full fixed layout up to tile->topology_id[7] without checking block->num_bytes. The DisplayID iterator only validates the declared payload length, so a crafted EDID can advertise a tiled-display block (tag DATA_BLOCK_TILED_DISPLAY, or DATA_BLOCK_2_TILED_DISPLAY_TOPOLOGY for v2.0) with a small num_bytes at the end of a DisplayID extension. The read then runs past the end of the exact-sized kmemdup()'d EDID allocation, a heap out-of-bounds read.
Reject blocks shorter than the spec's 22-byte tiled payload before reading the fixed struct, as drm_parse_vesa_mso_data() already does.
BUG: KASAN: slab-out-of-bounds in drm_edid_connector_update Read of size 2 at addr ffff888010077700 by task exploit/147 dump_stack_lvl (lib/dump_stack.c:94 ...) print_report (mm/kasan/report.c:378 ...) kasan_report (mm/kasan/report.c:595) drm_edid_connector_update (drivers/gpu/drm/drm_edid.c:7581) bochs_connector_helper_get_modes (drivers/gpu/drm/tiny/bochs.c:574) drm_helper_probe_single_connector_modes (drivers/gpu/drm/drm_probe_helper.c:426) status_store (drivers/gpu/drm/drm_sysfs.c:219) ... vfs_write (fs/read_write.c:595 fs/read_write.c:688) ksys_write (fs/read_write.c:740)
--- drivers/gpu/drm/drm_edid.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/gpu/drm/drm_edid.c +8 -0
@@ -7575,6 +7575,14 @@ static void drm_parse_tiled_block(struct drm_connector *connector,u8 num_v_tile, num_h_tile;struct drm_tile_group *tg; +/* tiled block payload per spec: cap 1 + topo 3 + size 4 + bezel 5 + id 9 = 22 */ +if (block->num_bytes <22 ) { +drm_dbg_kms (connector->dev, +"[CONNECTOR:%d:%s] Unexpected tiled block size %u\n" , + connector->base.id, connector->name, block->num_bytes); +return ; + } + w = tile->tile_size[0 ] | tile->tile_size[1 ] <<8 ; h = tile->tile_size[2 ] | tile->tile_size[3 ] <<8 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1200/2077 erofs: handle 48-bit blocks_hi for compressed inodes
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhan Xusheng <[email protected]>
[ Upstream commit 803d09a554055aba160a62abd1e4b1260b899dc1 ]
Combine i_nb.blocks_hi with i_u.blocks_lo when computing inode->i_blocks for compressed inodes, mirroring the startblk_hi handling for unencoded inodes a few lines above. Also evaluate the shift in u64 to avoid truncation.
--- fs/erofs/inode.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/erofs/inode.c +3 -2
@@ -191,8 +191,9 @@ static int erofs_read_inode(struct inode *inode) err = -EFSCORRUPTED ; goto err_out; }else { - inode->i_blocks =le32_to_cpu (copied.i_u.blocks_lo) << - (sb->s_blocksize_bits -9 ); + inode->i_blocks = (le32_to_cpu (copied.i_u.blocks_lo) | + ((u64 )le16_to_cpu (copied.i_nb.blocks_hi) <<32 )) << + (sb->s_blocksize_bits -9 ); }if (vi->datalayout ==EROFS_INODE_CHUNK_BASED ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1201/2077 ASoC: cs530x: Fix expected MCLK rates for CS5302/4/8
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ahmad Fatoum <[email protected]>
[ Upstream commit cf81b260916c92cf610c907d41627a175e86e37d ]
When this driver was first added, it accepted rates of 24.56 MHz and 22.572 MHz for the MCLK when PLL bypass is enabled.
These rates seem to have no basis in the datasheets and were thus replaced with 45.1584 MHz and 49.152 MHz, respectively, in commit e7ab858390f2 ("ASoC: cs530x: Correct MCLK reference frequency values").
While the new rates are indeed correct for the CS4xxx ICs[0][1][2][3], they are incorrect for the CS530x ICs the driver was originally written to support as the MCLK frequencies are halved there[4][5][6].
Fix this by checking against the correct type-appropriate rates.
While at it, drop the CS530X_SYSCLK_REF_* macros. They arguably confuse more than they help, especially as they are not applicable to the cs5302/4/8.
[0]: https://statics.cirrus.com/pubs/proDatasheet/CS4282P_DS1318F1.pdf
[1]: https://statics.cirrus.com/pubs/proDatasheet/CS4302P_DS1315F1.pdf
[2]: https://statics.cirrus.com/pubs/proDatasheet/CS4304P_DS1316F1.pdf
[3]: https://statics.cirrus.com/pubs/proDatasheet/CS4308P_DS1317F1.pdf
[4]: https://statics.cirrus.com/pubs/proDatasheet/CS5302P_DS1312F1.pdf
[5]: https://statics.cirrus.com/pubs/proDatasheet/CS5304P_DS1313F1.pdf
[6]: https://statics.cirrus.com/pubs/proDatasheet/CS5308P_DS1314F1.pdf
--- sound/soc/codecs/cs530x.c | 29 ++++++++++++++++++++++++----- sound/soc/codecs/cs530x.h | 6 ------ 2 files changed, 24 insertions(+), 11 deletions(-)
sound/soc/codecs/cs530x.c +24 -5
@@ -1093,6 +1093,29 @@ static int cs530x_component_probe(struct snd_soc_component *component)return 0 ; } +static bool cs530x_mclk_freq_is_valid (struct cs530x_priv *cs530x, +unsigned int freq) +{ +/* +* All these chips support 48 kHz- and 44.1 kHz-related sample rates, +* but they differ in what MCLK frequency is required for achieving +* the sample rate. +*/ +switch (cs530x->devtype) { +case CS4282 : +case CS4302 : +case CS4304 : +case CS4308 : +return freq ==49152000 || freq ==45158400 ; +case CS5302 : +case CS5304 : +case CS5308 : +return freq ==24576000 || freq ==22579200 ; + } + +return false; +} +static int cs530x_set_sysclk (struct snd_soc_component *component,int clk_id,int source,unsigned int freq,int dir) {
@@ -1101,11 +1124,7 @@ static int cs530x_set_sysclk(struct snd_soc_component *component, int clk_id,switch (source) {case CS530X_SYSCLK_SRC_MCLK : -switch (freq) { -case CS530X_SYSCLK_REF_45_1MHZ : -case CS530X_SYSCLK_REF_49_1MHZ : -break ; -default : +if (!cs530x_mclk_freq_is_valid (cs530x, freq)) {dev_err (component->dev,"Invalid MCLK source rate %d\n" , freq);return -EINVAL ; }
sound/soc/codecs/cs530x.h +0 -6
@@ -200,12 +200,6 @@/* IN_VOL_CTL5 and OUT_VOL_CTL5 */ #define CS530X_INOUT_VU BIT(0) -/* MCLK Reference Source Frequency */ -/* 41KHz related */ -#define CS530X_SYSCLK_REF_45_1MHZ 45158400 -/* 48KHz related */ -#define CS530X_SYSCLK_REF_49_1MHZ 49152000 -/* System Clock Source */ #define CS530X_SYSCLK_SRC_MCLK 0#define CS530X_SYSCLK_SRC_PLL 1
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1202/2077 PCI: endpoint: pci-epf-vntb: Add check to detect db_count value of 0
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manivannan Sadhasivam <[email protected]>
[ Upstream commit 33bd1ea748bc897c4d13437284e08c658e8d1340 ]
epf_ntb->db_count value should be within 1 to MAX_DB_COUNT. Current code only checks for the upper bound, while the lower bound is unchecked. This can cause a lot of issues in the driver if the user passes 'db_count' as 0.
Add a check for 0 also. While at it, remove the redundant 'db_count' assignment.
--- drivers/pci/endpoint/functions/pci-epf-vntb.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/pci/endpoint/functions/pci-epf-vntb.c +3 -6
@@ -483,7 +483,6 @@ static int epf_ntb_configure_interrupt(struct epf_ntb *ntb) {const struct pci_epc_features *epc_features;struct device *dev; -u32 db_count;int ret; dev = &ntb->epf->dev;
@@ -495,14 +494,12 @@ static int epf_ntb_configure_interrupt(struct epf_ntb *ntb)return -EINVAL ; } - db_count = ntb->db_count; -if (db_count >MAX_DB_COUNT ) { -dev_err (dev,"DB count cannot be more than %d\n" ,MAX_DB_COUNT ); +if (!ntb->db_count || ntb->db_count >MAX_DB_COUNT ) { +dev_err (dev,"DB count %d out of range (1 - %d)\n" , + ntb->db_count,MAX_DB_COUNT );return -EINVAL ; } - ntb->db_count = db_count; -if (epc_features->msi_capable) { ret = pci_epc_set_msi(ntb->epf->epc, ntb->epf->func_no,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1203/2077 PCI: endpoint: pci-epf-ntb: Add check to detect db_count value of 0
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manivannan Sadhasivam <[email protected]>
[ Upstream commit d1db6d7c2485ee475a04d8354fbb5b26ea10d978 ]
epf_ntb->db_count value should be within 1 to MAX_DB_COUNT. Current code only checks for the upper bound, while the lower bound is unchecked. This can cause a lot of issues in the driver if the user passes 'db_count' as 0.
Add a check for 0 also. While at it, remove the redundant 'db_count' variable from epf_ntb_configure_interrupt().
--- drivers/pci/endpoint/functions/pci-epf-ntb.c | 21 ++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
drivers/pci/endpoint/functions/pci-epf-ntb.c +11 -10
@@ -559,12 +559,15 @@ static int epf_ntb_configure_db(struct epf_ntb *ntb,struct pci_epc *epc;int ret; -if (db_count >MAX_DB_COUNT ) -return -EINVAL ; - ntb_epc = ntb->epc[type]; epc = ntb_epc->epc; +if (!db_count || db_count >MAX_DB_COUNT ) { +dev_err (&epc->dev,"DB count %d out of range (1 - %d)\n" , + db_count,MAX_DB_COUNT ); +return -EINVAL ; + } +if (msix) ret =epf_ntb_configure_msix (ntb, type, db_count);else
@@ -1278,7 +1281,6 @@ static int epf_ntb_configure_interrupt(struct epf_ntb *ntb,u8 func_no, vfunc_no;struct pci_epc *epc;struct device *dev; -u32 db_count;int ret; ntb_epc = ntb->epc[type];
@@ -1296,17 +1298,16 @@ static int epf_ntb_configure_interrupt(struct epf_ntb *ntb, func_no = ntb_epc->func_no; vfunc_no = ntb_epc->vfunc_no; - db_count = ntb->db_count; -if (db_count >MAX_DB_COUNT ) { -dev_err (dev,"DB count cannot be more than %d\n" ,MAX_DB_COUNT ); +if (!ntb->db_count || ntb->db_count >MAX_DB_COUNT ) { +dev_err (dev,"DB count %d out of range (1 - %d)\n" , + ntb->db_count,MAX_DB_COUNT );return -EINVAL ; } - ntb->db_count = db_count; epc = ntb_epc->epc;if (msi_capable) { - ret =pci_epc_set_msi (epc, func_no, vfunc_no, db_count); + ret =pci_epc_set_msi (epc, func_no, vfunc_no, ntb->db_count);if (ret) {dev_err (dev,"%s intf: MSI configuration failed\n" ,pci_epc_interface_string (type));
@@ -1315,7 +1316,7 @@ static int epf_ntb_configure_interrupt(struct epf_ntb *ntb, }if (msix_capable) { - ret =pci_epc_set_msix (epc, func_no, vfunc_no, db_count, + ret =pci_epc_set_msix (epc, func_no, vfunc_no, ntb->db_count, ntb_epc->msix_bar, ntb_epc->msix_table_offset);if (ret) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1204/2077 PCI: endpoint: pci-epf-vntb: Document legacy MSI doorbell offset
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Koichiro Den <[email protected]>
[ Upstream commit 6a7db4fcc6c23b1d25e676400d764bdcb7dc1ccb ]
vntb_epf_peer_db_set() raises an MSI interrupt to notify the RC side of a doorbell event. pci_epc_raise_irq(..., PCI_IRQ_MSI, interrupt_num) takes a 1-based MSI interrupt number.
The ntb_hw_epf driver reserves MSI #1 for link events, so doorbells would naturally start at MSI #2 (doorbell bit 0 -> MSI #2). However, pci-epf-vntb has historically applied an extra offset and mapped doorbell bit 0 to MSI #3. This matches the legacy behavior of ntb_hw_epf and has been preserved since commit e35f56bb0330 ("PCI: endpoint: Support NTB transfer between RC and EP").
This offset has not surfaced as a functional issue because:
- ntb_hw_epf typically allocates enough MSI vectors, so the off-by-one still hits a valid MSI vector, and
- ntb_hw_epf does not implement .db_vector_count()/.db_vector_mask(), so client drivers such as ntb_transport effectively ignore the vector number and schedule all QPs.
Correcting the MSI number would break interoperability with peers running older kernels.
Document the legacy offset to avoid confusion when enabling per-db-vector handling.
Stable-dep-of: 91fb4488cd61 ("PCI: endpoint: pci-epf-vntb: Report 0-based doorbell vector via ntb_db_event()")
--- drivers/pci/endpoint/functions/pci-epf-vntb.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
drivers/pci/endpoint/functions/pci-epf-vntb.c +19 -0
@@ -1364,6 +1364,25 @@ static int vntb_epf_peer_db_set(struct ntb_dev *ndev, u64 db_bits) func_no = ntb->epf->func_no; vfunc_no = ntb->epf->vfunc_no; +/* +* pci_epc_raise_irq() for MSI expects a 1-based interrupt number. +* ffs() returns a 1-based index (bit 0 -> 1). interrupt_num has already +* been computed as ffs(db_bits) + 1 above. Adding one more +1 when +* calling pci_epc_raise_irq() therefore results in: +* +* doorbell bit 0 -> MSI #3 +* +* Legacy mapping (kept for compatibility): +* +* MSI #1 : link event (reserved) +* MSI #2 : unused (historical offset) +* MSI #3 : doorbell bit 0 (DB#0) +* MSI #4 : doorbell bit 1 (DB#1) +* ... +* +* Do not change this mapping to avoid breaking interoperability with +* older peers. +*/ ret =pci_epc_raise_irq (ntb->epf->epc, func_no, vfunc_no,PCI_IRQ_MSI , interrupt_num +1 );if (ret)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1205/2077 PCI: endpoint: pci-epf-vntb: Defer pci_epc_raise_irq() out of atomic context
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Koichiro Den <[email protected]>
[ Upstream commit 18355c1e986582aaff2c488b1a2ce79bac8f3cf9 ]
The NTB .peer_db_set() callback may be invoked from atomic context. pci-epf-vntb currently calls pci_epc_raise_irq() directly, but pci_epc_raise_irq() may sleep (it takes epc->lock).
Avoid sleeping in atomic context by coalescing doorbell bits into an atomic64 pending mask and raising MSIs from a work item. Limit the amount of work per run to avoid monopolizing the workqueue under a doorbell storm.
Clear stale pending bits before enabling the work item and after disabling it during cleanup. Also mask requested doorbells against the currently valid doorbell mask before queueing work, and iterate the pending u64 with __ffs64() so high doorbell bits are handled correctly.
Stable-dep-of: 91fb4488cd61 ("PCI: endpoint: pci-epf-vntb: Report 0-based doorbell vector via ntb_db_event()")
--- drivers/pci/endpoint/functions/pci-epf-vntb.c | 112 +++++++++++++----- 1 file changed, 85 insertions(+), 27 deletions(-)
drivers/pci/endpoint/functions/pci-epf-vntb.c +85 -27
@@ -37,6 +37,7 @@*/ #include <linux/atomic.h> +#include <linux/bitops.h> #include <linux/delay.h> #include <linux/io.h> #include <linux/module.h>
@@ -69,6 +70,9 @@ static struct workqueue_struct *kpcintb_workqueue;#define MAX_DB_COUNT 32#define MAX_MW 4 +/* Limit per-work execution to avoid monopolizing kworker on doorbell storms. */ +#define VNTB_PEER_DB_WORK_BUDGET 5 +enum epf_ntb_bar {BAR_CONFIG ,BAR_DB ,
@@ -129,6 +133,8 @@ struct epf_ntb {u32 spad_count;u64 mws_size[MAX_MW ];atomic64_t db; +atomic64_t peer_db_pending; +struct work_struct peer_db_work;u32 vbus_number;u16 vntb_pid;u16 vntb_vid;
@@ -917,6 +923,9 @@ static int epf_ntb_epc_init(struct epf_ntb *ntb)INIT_DELAYED_WORK (&ntb->cmd_handler, epf_ntb_cmd_handler);queue_work (kpcintb_workqueue, &ntb->cmd_handler.work); +atomic64_set (&ntb->peer_db_pending,0 ); +enable_work (&ntb->peer_db_work); +return 0 ; err_write_header:
@@ -940,6 +949,8 @@ static int epf_ntb_epc_init(struct epf_ntb *ntb)static void epf_ntb_epc_cleanup (struct epf_ntb *ntb) {disable_delayed_work_sync (&ntb->cmd_handler); +disable_work_sync (&ntb->peer_db_work); +atomic64_set (&ntb->peer_db_pending,0 );epf_ntb_mw_bar_clear (ntb, ntb->num_mws);epf_ntb_db_bar_clear (ntb);epf_ntb_config_sspad_bar_clear (ntb);
@@ -1354,41 +1365,84 @@ static int vntb_epf_peer_spad_write(struct ntb_dev *ndev, int pidx, int idx, u32return 0 ; } -static int vntb_epf_peer_db_set (struct ntb_dev *ndev,u64 db_bits) +static void vntb_epf_peer_db_work (struct work_struct *work) { -u32 interrupt_num =ffs (db_bits) +1 ; -struct epf_ntb *ntb =ntb_ndev (ndev); + struct epf_ntb *ntb = container_of(work, struct epf_ntb, peer_db_work); +struct pci_epf *epf = ntb->epf; +unsigned int budget =VNTB_PEER_DB_WORK_BUDGET ;u8 func_no, vfunc_no; +unsigned int db_bit; +u32 interrupt_num; +u64 db_bits;int ret; - func_no = ntb->epf->func_no; - vfunc_no = ntb->epf->vfunc_no; +if (!epf || !epf->epc) +return ; + + func_no = epf->func_no; + vfunc_no = epf->vfunc_no;/* -* pci_epc_raise_irq() for MSI expects a 1-based interrupt number. -* ffs() returns a 1-based index (bit 0 -> 1). interrupt_num has already -* been computed as ffs(db_bits) + 1 above. Adding one more +1 when -* calling pci_epc_raise_irq() therefore results in: -* -* doorbell bit 0 -> MSI #3 -* -* Legacy mapping (kept for compatibility): -* -* MSI #1 : link event (reserved) -* MSI #2 : unused (historical offset) -* MSI #3 : doorbell bit 0 (DB#0) -* MSI #4 : doorbell bit 1 (DB#1) -* ... -* -* Do not change this mapping to avoid breaking interoperability with -* older peers. +* Drain doorbells from peer_db_pending in snapshots (atomic64_xchg()). +* Limit the number of snapshots handled per run so we don't monopolize +* the workqueue under a doorbell storm. */ - ret =pci_epc_raise_irq (ntb->epf->epc, func_no, vfunc_no, -PCI_IRQ_MSI , interrupt_num +1 ); -if (ret) -dev_err (&ntb->ntb.dev,"Failed to raise IRQ\n" ); +while (budget--) { + db_bits =atomic64_xchg (&ntb->peer_db_pending,0 ); +if (!db_bits) +return ; + +while (db_bits) { +/* +* pci_epc_raise_irq() for MSI expects a 1-based +* interrupt number. db_bit is zero-based, so add 3 to +* preserve the historical slot offset. +* +* Legacy mapping (kept for compatibility): +* +* MSI #1 : link event (reserved) +* MSI #2 : unused (historical offset) +* MSI #3 : doorbell bit 0 (DB#0) +* MSI #4 : doorbell bit 1 (DB#1) +* ... +* +* Do not change this mapping to avoid breaking +* interoperability with older peers. +*/ + db_bit =__ffs64 (db_bits); + interrupt_num = db_bit +3 ; + db_bits &= ~BIT_ULL (db_bit); + + ret =pci_epc_raise_irq (epf->epc, func_no, vfunc_no, +PCI_IRQ_MSI , interrupt_num); +if (ret) +dev_err (&ntb->ntb.dev, +"Failed to raise IRQ for interrupt_num %u: %d\n" , + interrupt_num, ret); + } + } -return ret; +if (atomic64_read (&ntb->peer_db_pending)) +queue_work (kpcintb_workqueue, &ntb->peer_db_work); +} + +static int vntb_epf_peer_db_set (struct ntb_dev *ndev,u64 db_bits) +{ +struct epf_ntb *ntb =ntb_ndev (ndev); + + db_bits &=vntb_epf_db_valid_mask (ndev); +if (!db_bits) +return 0 ; + +/* +* .peer_db_set() may be called from atomic context. pci_epc_raise_irq() +* can sleep (it takes epc->lock), so defer MSI raising to process +* context. Doorbell requests are coalesced in peer_db_pending. +*/ +atomic64_or (db_bits, &ntb->peer_db_pending); +queue_work (kpcintb_workqueue, &ntb->peer_db_work); + +return 0 ; }static u64 vntb_epf_db_read (struct ntb_dev *ndev)
@@ -1635,6 +1689,10 @@ static int epf_ntb_probe(struct pci_epf *epf, ntb->epf = epf; ntb->vbus_number =0xff ; +INIT_WORK (&ntb->peer_db_work, vntb_epf_peer_db_work); +disable_work (&ntb->peer_db_work); +atomic64_set (&ntb->peer_db_pending,0 ); +/* Initially, no bar is assigned */ for (i =0 ; i <VNTB_BAR_NUM ; i++) ntb->epf_ntb_bar[i] =NO_BAR ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1206/2077 PCI: endpoint: pci-epf-vntb: Report 0-based doorbell vector via ntb_db_event()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Koichiro Den <[email protected]>
[ Upstream commit 91fb4488cd615a39360bc4160a10cb3236189ba1 ]
ntb_db_event() expects the vector number to be relative to the first doorbell vector starting at 0.
pci-epf-vntb reserves vector 0 for link events and uses higher vector indices for doorbells. By passing the raw slot index to ntb_db_event(), it effectively assumes that doorbell 0 maps to vector 1.
However, because the host uses a legacy slot layout and writes doorbell 0 into the third slot, doorbell 0 ultimately appears as vector 2 from the NTB core perspective.
Adjust pci-epf-vntb to:
- skip the unused second slot, and
- report doorbells as 0-based vectors (DB#0 -> vector 0).
This change does not introduce a behavioral difference until .db_vector_count()/.db_vector_mask() are implemented, because without those callbacks NTB clients effectively ignore the vector number.
--- drivers/pci/endpoint/functions/pci-epf-vntb.c | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-)
drivers/pci/endpoint/functions/pci-epf-vntb.c +16 -9
@@ -83,6 +83,12 @@ enum epf_ntb_bar { VNTB_BAR_NUM, }; +enum epf_irq_slot { +EPF_IRQ_LINK =0 , +EPF_IRQ_RESERVED_DB ,/* Historically skipped slot */ +EPF_IRQ_DB_START , +}; +/* * +--------------------------------------------------+ Base * | |
@@ -267,10 +273,11 @@ static void epf_ntb_cmd_handler(struct work_struct *work) ntb = container_of(work, struct epf_ntb, cmd_handler.work); -for (i =1 ; i < ntb->db_count && !ntb->msi_doorbell; i++) { +for (i =EPF_IRQ_DB_START ; i < ntb->db_count && !ntb->msi_doorbell; + i++) {if (ntb->epf_db[i]) { -atomic64_or (1 << (i -1 ), &ntb->db); -ntb_db_event (&ntb->ntb, i); +atomic64_or (1 << (i -EPF_IRQ_DB_START ), &ntb->db); +ntb_db_event (&ntb->ntb, i -EPF_IRQ_DB_START ); ntb->epf_db[i] =0 ; } }
@@ -336,10 +343,10 @@ static irqreturn_t epf_ntb_doorbell_handler(int irq, void *data)struct epf_ntb *ntb = data;int i; -for (i =1 ; i < ntb->db_count; i++) +for (i =EPF_IRQ_DB_START ; i < ntb->db_count; i++)if (irq == ntb->epf->db_msg[i].virq) { -atomic64_or (1 << (i -1 ), &ntb->db); -ntb_db_event (&ntb->ntb, i); +atomic64_or (1 << (i -EPF_IRQ_DB_START ), &ntb->db); +ntb_db_event (&ntb->ntb, i -EPF_IRQ_DB_START ); }return IRQ_HANDLED ;
@@ -1395,8 +1402,8 @@ static void vntb_epf_peer_db_work(struct work_struct *work)while (db_bits) {/* * pci_epc_raise_irq() for MSI expects a 1-based -* interrupt number. db_bit is zero-based, so add 3 to -* preserve the historical slot offset. +* interrupt number. The first usable doorbell starts +* at EPF_IRQ_DB_START in the legacy slot layout. * * Legacy mapping (kept for compatibility): *
@@ -1410,7 +1417,7 @@ static void vntb_epf_peer_db_work(struct work_struct *work)* interoperability with older peers. */ db_bit =__ffs64 (db_bits); - interrupt_num = db_bit +3 ; + interrupt_num = db_bit +EPF_IRQ_DB_START +1 ; db_bits &= ~BIT_ULL (db_bit); ret = pci_epc_raise_irq(epf->epc, func_no, vfunc_no,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1207/2077 bpf: Preserve pointer spill metadata during half-slot cleanup
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nuoqi Gui <[email protected]>
[ Upstream commit 3a354149bceacadbcf7d7b4766f5ef26a85892ab ]
__clean_func_state() cleans dead stack slots in 4-byte halves. When the high half of a STACK_SPILL slot is dead and the low half remains live, cleanup converts the live low half to STACK_MISC or STACK_ZERO and clears the saved spilled_ptr metadata.
That conversion is safe only for scalar spills. For a pointer spill, this metadata clear lets a later 32-bit fill from the still-live half avoid the normal non-scalar register-fill check and be treated as an ordinary scalar stack read.
Leave non-scalar spill slots intact in this half-live shape. This is conservative for pruning and preserves the existing check_stack_read_fixed_off() rejection path for partial fills from pointer spills.
--- kernel/bpf/states.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
kernel/bpf/states.c +7 -6
@@ -437,12 +437,10 @@ static void __clean_func_state(struct bpf_verifier_env *env,continue ;/* -* Only destroy spilled_ptr when hi half is dead. -* If hi half is still live with STACK_SPILL, the -* spilled_ptr metadata is needed for correct state -* comparison in stacksafe(). -* is_spilled_reg() is using slot_type[7], but -* is_spilled_scalar_after() check either slot_type[0] or [4] +* Only scalar spills can be degraded to raw stack bytes +* when their high half is dead. Pointer spills need the +* saved spilled_ptr metadata so partial fills keep +* rejecting as non-scalar register fills. */ if (!hi_live) {struct bpf_reg_state *spill = &st->stack[i].spilled_ptr;
@@ -450,6 +448,9 @@ static void __clean_func_state(struct bpf_verifier_env *env,if (lo_live && stype ==STACK_SPILL ) {u8 val =STACK_MISC ; +if (spill->type !=SCALAR_VALUE ) +continue ; +/* * 8 byte spill of scalar 0 where half slot is dead * should become STACK_ZERO in lo 4 bytes.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1208/2077 ice: fix FDIR CTRL VSI resource leak in ice_reset_all_vfs()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dawid Osuchowski <[email protected]>
[ Upstream commit ebbe8868cf473f698e0fbaf436d2618b2bcda806 ]
Resetting all VFs causes resource leak on VFs with FDIR filters enabled as CTRL VSIs are only invalidated and not freed. Fix by using ice_vf_ctrl_vsi_release() instead of ice_vf_ctrl_invalidate_vsi() which aligns behavior with the ice_reset_vf() function.
Reproduction:
echo 1 > /sys/class/net/$pf/device/sriov_numvfs ethtool -N $vf flow-type ether proto 0x9000 action 0 echo 1 > /sys/class/net/$pf/device/reset
--- drivers/net/ethernet/intel/ice/ice_vf_lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_vf_lib.c +1 -1
@@ -801,7 +801,7 @@ void ice_reset_all_vfs(struct ice_pf *pf)* setup only when VF creates its first FDIR rule. */ if (vf->ctrl_vsi_idx !=ICE_NO_VSI ) -ice_vf_ctrl_invalidate_vsi (vf); +ice_vf_ctrl_vsi_release (vf);ice_vf_pre_vsi_rebuild (vf);if (ice_vf_rebuild_vsi (vf)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1209/2077 ice: fix AQ error code comparison in ice_set_pauseparam()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lukasz Czapnik <[email protected]>
[ Upstream commit 2bf7744bc3221a63b95c76c94eab1dad832fa401 ]
Fix unreachable code: the conditionals in ice_set_pauseparam() used the bitwise-AND operator suggesting aq_failures is a bitmap, but it is actually an enum, making the third condition logically unreachable.
Replace the if-else ladder with a switch statement. Also move the aq_failures initialization to the variable declaration and remove the redundant zeroing from ice_set_fc().
--- drivers/net/ethernet/intel/ice/ice_common.c | 1 - drivers/net/ethernet/intel/ice/ice_ethtool.c | 12 ++++++++---- 2 files changed, 8 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/ice/ice_common.c +0 -1
@@ -3882,7 +3882,6 @@ ice_set_fc(struct ice_port_info *pi, u8 *aq_failures, bool ena_auto_link_update)if (!pi || !aq_failures)return -EINVAL ; - *aq_failures =0 ; hw = pi->hw; pcaps =kzalloc_obj (*pcaps);
drivers/net/ethernet/intel/ice/ice_ethtool.c +8 -4
@@ -3508,7 +3508,7 @@ ice_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)struct ice_vsi *vsi = np->vsi;struct ice_hw *hw = &pf->hw;struct ice_port_info *pi; -u8 aq_failures; +u8 aq_failures =0 ;bool link_up;u32 is_an;int err;
@@ -3579,18 +3579,22 @@ ice_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)/* Set the FC mode and only restart AN if link is up */ err =ice_set_fc (pi, &aq_failures, link_up); -if (aq_failures &ICE_SET_FC_AQ_FAIL_GET ) { +switch (aq_failures) { +case ICE_SET_FC_AQ_FAIL_GET :netdev_info (netdev,"Set fc failed on the get_phy_capabilities call with err %d aq_err %s\n" , err,libie_aq_str (hw->adminq.sq_last_status)); err = -EAGAIN ; - }else if (aq_failures &ICE_SET_FC_AQ_FAIL_SET ) { +break ; +case ICE_SET_FC_AQ_FAIL_SET :netdev_info (netdev,"Set fc failed on the set_phy_config call with err %d aq_err %s\n" , err,libie_aq_str (hw->adminq.sq_last_status)); err = -EAGAIN ; - }else if (aq_failures &ICE_SET_FC_AQ_FAIL_UPDATE ) { +break ; +case ICE_SET_FC_AQ_FAIL_UPDATE :netdev_info (netdev,"Set fc failed on the get_link_info call with err %d aq_err %s\n" , err,libie_aq_str (hw->adminq.sq_last_status)); err = -EAGAIN ; +break ; }return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1210/2077 ice: call netif_keep_dst() once when entering switchdev mode
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marcin Szycik <[email protected]>
[ Upstream commit c0d00c882bc432990d57052a659f9a8bd1f60687 ]
netif_keep_dst() only needs to be called once for the uplink VSI, not once for each port representor. Move it from ice_eswitch_setup_repr() to ice_eswitch_enable_switchdev().
--- drivers/net/ethernet/intel/ice/ice_eswitch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/ice/ice_eswitch.c +2 -2
@@ -117,8 +117,6 @@ static int ice_eswitch_setup_repr(struct ice_pf *pf, struct ice_repr *repr)if (!repr->dst)return -ENOMEM ; -netif_keep_dst (uplink_vsi->netdev); - dst = repr->dst; dst->u.port_info.port_id = vsi->vsi_num; dst->u.port_info.lower_dev = uplink_vsi->netdev;
@@ -312,6 +310,8 @@ static int ice_eswitch_enable_switchdev(struct ice_pf *pf)if (ice_eswitch_br_offloads_init (pf)) goto err_br_offloads; +netif_keep_dst (uplink_vsi->netdev); + pf->eswitch.is_running = true;return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1211/2077 rtc: isl1208: Balance enable_irq_wake() with disable_irq_wake() on cleanup
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Madieu <[email protected]>
[ Upstream commit 1afe4f19d6ad404621150f0e91feeccf12fb1037 ]
isl1208_setup_irq() calls enable_irq_wake() after a successful IRQ request, but the driver has no remove path that balances it. The driver is devm-only, so on unbind devm releases the IRQ - but enable_irq_wake() is not undone by IRQ release, so the wake count for that IRQ stays incremented.
Each rebind therefore leaks one wake reference; the leak doubles for the chip variant that has a separate evdet IRQ, since isl1208_setup_irq() is then called twice during probe.
Register a devm action that calls disable_irq_wake() per IRQ. While at it, check enable_irq_wake()'s return value:
on failure, propagate the error rather than silently registering a disable action for an IRQ whose wake state was never enabled.
--- drivers/rtc/rtc-isl1208.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/rtc/rtc-isl1208.c +14 -1
@@ -822,6 +822,11 @@ static const struct nvmem_config isl1208_nvmem_config = { .reg_write = isl1208_nvmem_write, }; +static void isl1208_disable_irq_wake_action (void *data) +{ +disable_irq_wake ((unsigned long )data); +} +static int isl1208_setup_irq (struct i2c_client *client,int irq) { int rc = devm_request_threaded_irq(&client->dev, irq, NULL,
@@ -831,7 +836,15 @@ static int isl1208_setup_irq(struct i2c_client *client, int irq) client);if (!rc) {device_init_wakeup (&client->dev, true); -enable_irq_wake (irq); + rc =enable_irq_wake (irq); +if (rc) +return rc; + + rc =devm_add_action_or_reset (&client->dev, + isl1208_disable_irq_wake_action, + (void *)(unsigned long )irq); +if (rc) +return rc; }else { dev_err(&client->dev, "Unable to request irq %d, no alarm support\n",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1212/2077 ice: dpll: set pointers to NULL after kfree in ice_dpll_deinit_info
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: ZhaoJinming <[email protected]>
[ Upstream commit a903afff66d7379c6ece42bd18b2a17f4c79d1a9 ]
ice_dpll_deinit_info() calls kfree() on several pf->dplls fields (inputs, outputs, eec.input_prio, pps.input_prio) but does not set the pointers to NULL afterward. This leaves dangling pointers in the pf->dplls structure.
While not currently exploitable through existing code paths, this is unsafe because:
1. If ice_dpll_init_info() is called again after a deinit (e.g. during driver recovery), and a subsequent allocation within init fails, the error path will jump to deinit_info and call ice_dpll_deinit_info() again. Since some pointers still hold the old freed addresses, this would result in a double-free.
2. Any future code that checks these pointers before use or after free would be unprotected against use-after-free.
Follow the common kernel convention of setting pointers to NULL after kfree() so that:
- kfree(NULL) is a safe no-op, preventing double-free
- NULL checks on these pointers become meaningful
This is a preparatory fix for a subsequent patch that routes additional error paths in ice_dpll_init_info() to the deinit_info label.
--- drivers/net/ethernet/intel/ice/ice_dpll.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/ethernet/intel/ice/ice_dpll.c +4 -0
@@ -4249,9 +4249,13 @@ ice_dpll_init_pins_info(struct ice_pf *pf, enum ice_dpll_pin_type pin_type)static void ice_dpll_deinit_info (struct ice_pf *pf) {kfree (pf->dplls.inputs); + pf->dplls.inputs =NULL ;kfree (pf->dplls.outputs); + pf->dplls.outputs =NULL ;kfree (pf->dplls.eec.input_prio); + pf->dplls.eec.input_prio =NULL ;kfree (pf->dplls.pps.input_prio); + pf->dplls.pps.input_prio =NULL ; }/**
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1213/2077 ice: dpll: fix memory leak in ice_dpll_init_info error paths
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: ZhaoJinming <[email protected]>
[ Upstream commit 20da495f2df0fd4adc435d3d621366e8c807539c ]
Several error return paths in ice_dpll_init_info() directly return without freeing previously allocated resources, causing memory leaks:
- When de->input_prio allocation fails, d->inputs is leaked
- When dp->input_prio allocation fails, d->inputs and de->input_prio are leaked
- When ice_get_cgu_rclk_pin_info() fails, all previously allocated inputs/outputs/input_prio are leaked
- When ice_dpll_init_pins_info(RCLK_INPUT) fails, same resources are leaked
Fix this by jumping to the deinit_info label which properly calls ice_dpll_deinit_info() to free all allocated resources.
--- drivers/net/ethernet/intel/ice/ice_dpll.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/net/ethernet/intel/ice/ice_dpll.c +10 -6
@@ -4347,12 +4347,16 @@ static int ice_dpll_init_info(struct ice_pf *pf, bool cgu) alloc_size =sizeof (*de->input_prio) * d->num_inputs; de->input_prio =kzalloc (alloc_size,GFP_KERNEL ); -if (!de->input_prio) -return -ENOMEM ; +if (!de->input_prio) { + ret = -ENOMEM ; + goto deinit_info; + } dp->input_prio =kzalloc (alloc_size,GFP_KERNEL ); -if (!dp->input_prio) -return -ENOMEM ; +if (!dp->input_prio) { + ret = -ENOMEM ; + goto deinit_info; + } ret =ice_dpll_init_pins_info (pf,ICE_DPLL_PIN_TYPE_INPUT );if (ret)
@@ -4377,12 +4381,12 @@ static int ice_dpll_init_info(struct ice_pf *pf, bool cgu) ret =ice_get_cgu_rclk_pin_info (&pf->hw, &d->base_rclk_idx, &pf->dplls.rclk.num_parents);if (ret) -return ret; + goto deinit_info;for (i =0 ; i < pf->dplls.rclk.num_parents; i++) pf->dplls.rclk.parent_idx[i] = d->base_rclk_idx + i; ret =ice_dpll_init_pins_info (pf,ICE_DPLL_PIN_TYPE_RCLK_INPUT );if (ret) -return ret; + goto deinit_info; de->mode =DPLL_MODE_AUTOMATIC ; dp->mode =DPLL_MODE_AUTOMATIC ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1214/2077 i40e: Fix i40e_debug() to use struct i40e_hw argument
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mohamed Khalfella <[email protected]>
[ Upstream commit 798f94603eb0737033861efd320a9159f382a7c5 ]
i40e_debug() macro takes struct i40e_hw *h as first argument. But the macro body uses hw instead of h. This has been working so far because hw happens to be the name of the variable in the context where the macro is expanded. Fix the macro to use the passed argument.
--- drivers/net/ethernet/intel/i40e/i40e_debug.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/i40e/i40e_debug.h +1 -1
@@ -42,7 +42,7 @@ struct device *i40e_hw_to_dev(struct i40e_hw *hw);#define i40e_debug (h, m, s, ...) \ do { \ if (((m) & (h)->debug_mask)) \ - dev_info(i40e_hw_to_dev(hw), s, ##__VA_ARGS__); \ + dev_info(i40e_hw_to_dev(h), s, ##__VA_ARGS__); \ } while (0)#endif /* _I40E_DEBUG_H_ */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1215/2077 e1000e: Reconfigure PLL clock gate timeout and re-enable K1 on Meteor Lake
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dima Ruinskiy <[email protected]>
[ Upstream commit 578294b8b60d2c630991f221838f9ec61ae89df0 ]
Commit 3c7bf5af21960 ("e1000e: Introduce private flag to disable K1") disabled K1 by default on Meteor Lake and newer systems due to packet loss observed on various platforms. However, disabling K1 caused an increase in power consumption.
To mitigate this, reconfigure the PLL clock gate value so that K1 can remain enabled without incurring the additional power consumption. Re-enable K1 by default, but keep the private flag to support disabling it via ethtool. Additionally, introduce a DMI quirk table, so that K1 may be disabled by default on known problematic systems. Currently, this includes the Dell Pro 16 Plus, where the issue has been reported to persist despite the changes to the PLL lock timeout.
--- drivers/net/ethernet/intel/e1000e/ich8lan.c | 3 +++ drivers/net/ethernet/intel/e1000e/netdev.c | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/e1000e/ich8lan.c +3 -0
@@ -1594,6 +1594,9 @@ static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw) phy_reg &= ~I217_PLL_CLOCK_GATE_MASK ;if (speed ==SPEED_100 || speed ==SPEED_10 ) phy_reg |=0x3E8 ; +else if (hw->mac.type == e1000_pch_mtp || + hw->mac.type == e1000_pch_ptp) + phy_reg |=0x1D5 ;else phy_reg |=0xFA ;e1e_wphy_locked (hw,I217_PLL_CLOCK_GATE_REG , phy_reg);
drivers/net/ethernet/intel/e1000e/netdev.c +14 -1
@@ -25,6 +25,7 @@#include <linux/pm_runtime.h> #include <linux/prefetch.h> #include <linux/suspend.h> +#include <linux/dmi.h> #include "e1000.h" #define CREATE_TRACE_POINTS
@@ -58,6 +59,17 @@ static const struct e1000_info *e1000_info_tbl[] = { [board_pch_ptp] = &e1000_pch_ptp_info, }; +static const struct dmi_system_id disable_k1_list[] = { + { + .ident ="Dell Pro 16 Plus PB16250" , + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Dell Inc." ), +DMI_MATCH (DMI_PRODUCT_NAME ,"Dell Pro 16 Plus PB16250" ), + }, + }, + {} +}; +struct e1000_reg_info {u32 ofs;char *name;
@@ -7670,7 +7682,8 @@ static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent)/* init PTP hardware clock */ e1000e_ptp_init (adapter); -if (hw->mac.type >= e1000_pch_mtp) +/* disable K1 by default on known problematic systems */ +if (hw->mac.type >= e1000_pch_mtp &&dmi_check_system (disable_k1_list)) adapter->flags2 |=FLAG2_DISABLE_K1 ;/* reset the hardware with the new settings */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1216/2077 rtc: msc313: fix NULL deref in shared IRQ handler at probe
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stepan Ionichev <[email protected]>
[ Upstream commit a369f48be8de426a7d2bca18dbd46c2ad1138803 ]
msc313_rtc_probe() calls devm_request_irq() with IRQF_SHARED and &pdev->dev as the cookie, but platform_set_drvdata() is only called later after the clock setup. With a shared IRQ line, another device on the same line can trigger the handler in that window. The handler does dev_get_drvdata() on the cookie, gets NULL, and dereferences priv->rtc_base in interrupt context.
Pass priv as the cookie directly so the handler reads it from dev_id without the lookup, removing the dependency on probe order.
--- drivers/rtc/rtc-msc313.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/rtc/rtc-msc313.c +2 -2
@@ -160,7 +160,7 @@ static const struct rtc_class_ops msc313_rtc_ops = {static irqreturn_t msc313_rtc_interrupt (s32 irq,void *dev_id) { -struct msc313_rtc *priv =dev_get_drvdata (dev_id); +struct msc313_rtc *priv = dev_id;u16 reg; reg =readw (priv->rtc_base +REG_RTC_STATUS_INT );
@@ -206,7 +206,7 @@ static int msc313_rtc_probe(struct platform_device *pdev) priv->rtc_dev->range_max =U32_MAX ; ret =devm_request_irq (dev, irq, msc313_rtc_interrupt,IRQF_SHARED , -dev_name (&pdev->dev), &pdev->dev); +dev_name (&pdev->dev), priv);if (ret) {dev_err (dev,"Could not request IRQ\n" );return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1217/2077 bpf: Guard conntrack opts error writes
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yiyang Chen <[email protected]>
[ Upstream commit 6f6183a39533d727deaa5061cadae6dd9e6744d0 ]
The conntrack lookup and allocation kfuncs take an opts pointer together with an opts__sz argument. The verifier checks only the memory range described by opts__sz, but the wrappers unconditionally write opts->error whenever the internal lookup or allocation helper returns an error.
For an invalid size smaller than the end of opts->error, that write can land outside the verifier-checked range. Keep returning NULL for invalid arguments, but only report the error through opts->error when the supplied size includes the field.
This preserves error reporting for the supported 12-byte and 16-byte layouts, and for other invalid sizes that still include opts->error.
--- net/netfilter/nf_conntrack_bpf.c | 35 ++++++++++++-------------------- 1 file changed, 13 insertions(+), 22 deletions(-)
net/netfilter/nf_conntrack_bpf.c +13 -22
@@ -65,6 +65,15 @@ enum { NF_BPF_CT_OPTS_SZ = 16, }; +static void *bpf_ct_opts_result (struct bpf_ct_opts *opts,u32 opts__sz,void *ret) +{ +if (!IS_ERR (ret)) +return ret; + if (opts__sz >= offsetofend(struct bpf_ct_opts, error)) + opts->error =PTR_ERR (ret); +return NULL ; +} +static int bpf_nf_ct_tuple_parse (struct bpf_sock_tuple *bpf_tuple,u32 tuple_len,u8 protonum,u8 dir,struct nf_conntrack_tuple *tuple)
@@ -297,12 +306,7 @@ bpf_xdp_ct_alloc(struct xdp_md *xdp_ctx, struct bpf_sock_tuple *bpf_tuple, nfct =__bpf_nf_ct_alloc_entry (dev_net (ctx->rxq->dev), bpf_tuple, tuple__sz, opts, opts__sz,10 ); -if (IS_ERR (nfct)) { - opts->error =PTR_ERR (nfct); -return NULL ; - } - -return (struct nf_conn___init *)nfct; +return (struct nf_conn___init *)bpf_ct_opts_result (opts, opts__sz, nfct); }/* bpf_xdp_ct_lookup - Lookup CT entry for the given tuple, and acquire a
@@ -331,11 +335,7 @@ bpf_xdp_ct_lookup(struct xdp_md *xdp_ctx, struct bpf_sock_tuple *bpf_tuple, caller_net =dev_net (ctx->rxq->dev); nfct =__bpf_nf_ct_lookup (caller_net, bpf_tuple, tuple__sz, opts, opts__sz); -if (IS_ERR (nfct)) { - opts->error =PTR_ERR (nfct); -return NULL ; - } -return nfct; +return bpf_ct_opts_result (opts, opts__sz, nfct); }/* bpf_skb_ct_alloc - Allocate a new CT entry
@@ -363,12 +363,7 @@ bpf_skb_ct_alloc(struct __sk_buff *skb_ctx, struct bpf_sock_tuple *bpf_tuple, net = skb->dev ?dev_net (skb->dev) :sock_net (skb->sk); nfct =__bpf_nf_ct_alloc_entry (net, bpf_tuple, tuple__sz, opts, opts__sz,10 ); -if (IS_ERR (nfct)) { - opts->error =PTR_ERR (nfct); -return NULL ; - } - -return (struct nf_conn___init *)nfct; +return (struct nf_conn___init *)bpf_ct_opts_result (opts, opts__sz, nfct); }/* bpf_skb_ct_lookup - Lookup CT entry for the given tuple, and acquire a
@@ -397,11 +392,7 @@ bpf_skb_ct_lookup(struct __sk_buff *skb_ctx, struct bpf_sock_tuple *bpf_tuple, caller_net = skb->dev ?dev_net (skb->dev) :sock_net (skb->sk); nfct =__bpf_nf_ct_lookup (caller_net, bpf_tuple, tuple__sz, opts, opts__sz); -if (IS_ERR (nfct)) { - opts->error =PTR_ERR (nfct); -return NULL ; - } -return nfct; +return bpf_ct_opts_result (opts, opts__sz, nfct); }/* bpf_ct_insert_entry - Add the provided entry into a CT map
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1218/2077 selftests/bpf: Cover small conntrack opts error writes
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yiyang Chen <[email protected]>
[ Upstream commit 38ba6d43af3844ae502092ee9dcc47214e82acb8 ]
Add a conntrack kfunc regression check for opts__sz values that do not cover opts->error. The BPF program initializes opts->error with a guard value, calls the lookup and allocation kfuncs with opts__sz set to sizeof(opts->netns_id), and verifies that the guard is still intact after the kfunc returns NULL.
Without the conntrack wrapper guard, the kfunc error path overwrites that guard with -EINVAL even though the verifier checked only the first four bytes of the options object.
--- .../testing/selftests/bpf/prog_tests/bpf_nf.c | 6 +++++ .../testing/selftests/bpf/progs/test_bpf_nf.c | 26 +++++++++++++++++++ 2 files changed, 32 insertions(+)
tools/testing/selftests/bpf/prog_tests/bpf_nf.c +6 -0
@@ -5,6 +5,8 @@#include "test_bpf_nf.skel.h" #include "test_bpf_nf_fail.skel.h" +#define CT_OPTS_ERROR_GUARD 0x12345678 +static char log_buf[1024 *1024 ];struct {
@@ -119,6 +121,10 @@ static void test_bpf_nf_ct(int mode)ASSERT_EQ (skel->bss->test_einval_reserved_new, -EINVAL ,"Test EINVAL for reserved in new struct not set to 0" );ASSERT_EQ (skel->bss->test_einval_netns_id, -EINVAL ,"Test EINVAL for netns_id < -1" );ASSERT_EQ (skel->bss->test_einval_len_opts, -EINVAL ,"Test EINVAL for len__opts != NF_BPF_CT_OPTS_SZ" ); +ASSERT_EQ (skel->bss->test_einval_len_opts_small_lookup,CT_OPTS_ERROR_GUARD , +"Test no error write for lookup opts__sz before error field" ); +ASSERT_EQ (skel->bss->test_einval_len_opts_small_alloc,CT_OPTS_ERROR_GUARD , +"Test no error write for alloc opts__sz before error field" );ASSERT_EQ (skel->bss->test_eproto_l4proto, -EPROTO ,"Test EPROTO for l4proto != TCP or UDP" );ASSERT_EQ (skel->bss->test_enonet_netns_id, -ENONET ,"Test ENONET for bad but valid netns_id" );ASSERT_EQ (skel->bss->test_enoent_lookup, -ENOENT ,"Test ENOENT for failed lookup" );
tools/testing/selftests/bpf/progs/test_bpf_nf.c +26 -0
@@ -10,6 +10,8 @@#define EINVAL 22#define ENOENT 2 +#define CT_OPTS_ERROR_GUARD 0x12345678 +#define NF_CT_ZONE_DIR_ORIG (1 << IP_CT_DIR_ORIGINAL)#define NF_CT_ZONE_DIR_REPL (1 << IP_CT_DIR_REPLY)
@@ -19,6 +21,8 @@ int test_einval_reserved = 0;int test_einval_reserved_new =0 ;int test_einval_netns_id =0 ;int test_einval_len_opts =0 ; +int test_einval_len_opts_small_lookup =0 ; +int test_einval_len_opts_small_alloc =0 ;int test_eproto_l4proto =0 ;int test_enonet_netns_id =0 ;int test_enoent_lookup =0 ;
@@ -124,6 +128,28 @@ nf_ct_test(struct nf_conn *(*lookup_fn)(void *, struct bpf_sock_tuple *, u32,else test_einval_len_opts = opts_def.error; + opts_def.error =CT_OPTS_ERROR_GUARD ; + ct =lookup_fn (ctx, &bpf_tuple,sizeof (bpf_tuple.ipv4), &opts_def, +sizeof (opts_def.netns_id)); +if (ct) { +bpf_ct_release (ct); + test_einval_len_opts_small_lookup = -EINVAL ; + }else { + test_einval_len_opts_small_lookup = opts_def.error; + } + + opts_def.error =CT_OPTS_ERROR_GUARD ; + ct =alloc_fn (ctx, &bpf_tuple,sizeof (bpf_tuple.ipv4), &opts_def, +sizeof (opts_def.netns_id)); +if (ct) { + ct =bpf_ct_insert_entry (ct); +if (ct) +bpf_ct_release (ct); + test_einval_len_opts_small_alloc = -EINVAL ; + }else { + test_einval_len_opts_small_alloc = opts_def.error; + } + opts_def.l4proto =IPPROTO_ICMP ; ct =lookup_fn (ctx, &bpf_tuple,sizeof (bpf_tuple.ipv4), &opts_def,sizeof (opts_def));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1219/2077 ksmbd: fix use-after-free of conn->preauth_info in concurrent SMB2 NEGOTIATE
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gil Portnoy <[email protected]>
[ Upstream commit 0c054227479ed7e36ebccb3a558bc0ef698264f6 ]
conn->preauth_info is shared connection state (struct preauth_integrity_info, kmalloc-96) that is allocated and freed by the SMB2 NEGOTIATE handler and read by the response send path.
smb2_handle_negotiate() allocates conn->preauth_info, and on a deassemble_neg_contexts() failure kfrees it and sets it to NULL. Both the allocation and the free/NULL happen under ksmbd_conn_lock(conn) (the connection srv_mutex), which is held across the whole handler body.
The response send path smb3_preauth_hash_rsp(), called from the send:
block of __handle_ksmbd_work(), reads conn->preauth_info and dereferences conn->preauth_info->Preauth_HashValue (via ksmbd_gen_preauth_integrity_hash()) without taking conn_lock. When a client drives two SMB2 NEGOTIATE requests on the same connection, one worker can free conn->preauth_info on the failing-negotiate path while a concurrent send-path worker is reading it, producing a slab use-after-free read (KASAN-confirmed).
The send-path read tested conn->preauth_info for NULL but raced with the free that occurs between the NULL check and the dereference, so the NULL guard alone does not close the window.
Serialize the NEGOTIATE-branch read in smb3_preauth_hash_rsp() under ksmbd_conn_lock(conn) and re-check conn->preauth_info inside the lock. Because the negotiate handler holds conn_lock across its kfree + NULL assignment, a reader that also takes conn_lock either runs fully before the allocation or fully after the NULL store, and can never observe the freed-but-not-yet-NULLed pointer. ksmbd_gen_preauth_integrity_hash() takes no locks itself (it only computes a SHA-512 over the buffer), so no lock-ordering inversion is introduced, and conn_lock is a sleepable mutex which is safe on this send path (it already performs network I/O).
--- fs/smb/server/smb2pdu.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
fs/smb/server/smb2pdu.c +7 -4
@@ -9220,10 +9220,13 @@ void smb3_preauth_hash_rsp(struct ksmbd_work *work)WORK_BUFFERS (work, req, rsp); -if (le16_to_cpu (req->Command) ==SMB2_NEGOTIATE_HE && - conn->preauth_info) -ksmbd_gen_preauth_integrity_hash (conn, work->response_buf, - conn->preauth_info->Preauth_HashValue); +if (le16_to_cpu (req->Command) ==SMB2_NEGOTIATE_HE ) { +ksmbd_conn_lock (conn); +if (conn->preauth_info) +ksmbd_gen_preauth_integrity_hash (conn, work->response_buf, + conn->preauth_info->Preauth_HashValue); +ksmbd_conn_unlock (conn); + }if (le16_to_cpu (rsp->Command) ==SMB2_SESSION_SETUP_HE && sess) {__u8 *hash_value;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1220/2077 ipv6: Fix null-ptr-deref in fib6_nh_mtu_change().
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiang Mei <[email protected]>
[ Upstream commit 46c3b8191aad3d032776bf3bebf03efdf5f4b905 ]
fib6_nh_mtu_change() re-fetches idev via __in6_dev_get(arg->dev) and dereferences idev->cnf.mtu6 without a NULL check. addrconf_ifdown() clears dev->ip6_ptr with RCU_INIT_POINTER() after rt6_disable_ip() has released tb6_lock, so the RA-driven MTU walk can observe a NULL idev and oops. The caller rt6_mtu_change_route() guards its own __in6_dev_get(), but this re-fetch is unguarded; nexthop-backed routes survive addrconf_ifdown()'s flush, so the walk still reaches it after ip6_ptr is nulled.
Return 0 when idev is NULL, matching rt6_mtu_change_route() and the fib6_mtu() fix in commit 5ad509c1fdad ("ipv6: Fix null-ptr-deref in fib6_mtu().").
Oops: general protection fault, ... KASAN: null-ptr-deref in range
[0x00000000000002a8-0x00000000000002af]
RIP: 0010:fib6_nh_mtu_change+0x203/0x990
rt6_mtu_change_route+0x141/0x1d0
__fib6_clean_all+0xd0/0x160
rt6_mtu_change+0xb4/0x100
ndisc_router_discovery+0x24b5/0x2cb0
icmpv6_rcv+0x12e9/0x1710
ipv6_rcv+0x39b/0x410--- net/ipv6/route.c | 3 +++ 1 file changed, 3 insertions(+)
net/ipv6/route.c +3 -0
@@ -5053,6 +5053,9 @@ static int fib6_nh_mtu_change(struct fib6_nh *nh, void *_arg)struct inet6_dev *idev =__in6_dev_get (arg->dev);u32 mtu = f6i->fib6_pmtu; +if (!idev) +return 0 ; +if (mtu >= arg->mtu || (mtu < arg->mtu && mtu == idev->cnf.mtu6))fib6_metric_set (f6i,RTAX_MTU , arg->mtu);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1221/2077 eth: bnxt: improve the timing of stats
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Kicinski <[email protected]>
[ Upstream commit 40529e58629baa9ce72143cb46cf1b3d2ca0d465 ]
Kernel selftests wait 1.25x of the promised stats refresh time (as read from ethtool -c). bnxt reports 1sec by default, but the stats update process has two steps. First device DMAs the new values, then the service task performs update in full-width SW counters. So the worst case delay is actually 2x.
Note that the behavior is different for ring stats and port stats. Port stats are fetched synchronously by the service worker, so there's no risk of doubling up the delay there.
The problem of stale stats impacts not only tests but real workloads which monitor egress bandwidth of a NIC. The inaccuracy causes double counting in the next cycle and spurious overload alarms.
Try to read from the DMA buffer more aggressively, to mitigate timing issues between DMA and service task. The SW update should be cheap.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 48 ++++++++++++++++++- drivers/net/ethernet/broadcom/bnxt/bnxt.h | 5 ++ .../net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 1 + 3 files changed, 53 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +47 -1
@@ -10530,7 +10530,7 @@ static void bnxt_accumulate_stats(struct bnxt_stats_mem *stats) stats->hw_masks, stats->len / 8, false); } -static void bnxt_accumulate_all_stats (struct bnxt *bp) +static void bnxt_accumulate_ring_stats (struct bnxt *bp) {struct bnxt_stats_mem *ring0_stats;bool ignore_zero = false;
@@ -10553,6 +10553,10 @@ static void bnxt_accumulate_all_stats(struct bnxt *bp) ring0_stats->hw_masks, ring0_stats->len / 8, ignore_zero); } +} + +static void bnxt_accumulate_port_stats (struct bnxt *bp) +{if (bp->flags &BNXT_FLAG_PORT_STATS ) {struct bnxt_stats_mem *stats = &bp->port_stats;__le64 *hw_stats = stats->hw_stats;
@@ -10575,6 +10579,41 @@ static void bnxt_accumulate_all_stats(struct bnxt *bp) } } +static void bnxt_accumulate_all_stats (struct bnxt *bp) +{ +bnxt_accumulate_ring_stats (bp); +bnxt_accumulate_port_stats (bp); +} + +/* Re-accumulate ring stats from DMA buffers if stale. +* uAPIs for reading sw_stats should call this first. +* +* We promise user space update frequency of bp->stats_coal_ticks but +* the update is a two step process - first device updates the DMA buffer, +* then we have to update from that buffer to driver stats in the service work. +* Worst case we would be 2x off from the desired frequency. +* Sync the stats sooner, if stale. The 20% threshold was chosen arbitrarily. +* +* Ideally we would split the user-configured time into two portions, +* i.e. also lower the DMA period by the 20%. But the DMA timer seems to have +* too coarse granularity to play such tricks. +*/ +void bnxt_sync_ring_stats (struct bnxt *bp) +{ +unsigned long stale; + +if (!netif_running (bp->dev) || !bp->stats_coal_ticks) +return ; + +spin_lock (&bp->stats_lock); + stale =usecs_to_jiffies (bp->stats_coal_ticks /5 ); +if (time_after_eq (jiffies, bp->stats_updated_jiffies + stale)) { +bnxt_accumulate_ring_stats (bp); + bp->stats_updated_jiffies = jiffies; + } +spin_unlock (&bp->stats_lock); +} +static int bnxt_hwrm_port_qstats (struct bnxt *bp,u8 flags) {struct hwrm_port_qstats_input *req;
@@ -13573,6 +13612,7 @@ bnxt_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)return ; } +bnxt_sync_ring_stats (bp);bnxt_get_ring_stats (bp, stats);bnxt_add_prev_stats (bp, stats);
@@ -14754,7 +14794,10 @@ static void bnxt_sp_task(struct work_struct *work)if (test_and_clear_bit (BNXT_PERIODIC_STATS_SP_EVENT , &bp->sp_event)) {bnxt_hwrm_port_qstats (bp,0 );bnxt_hwrm_port_qstats_ext (bp,0 ); +spin_lock (&bp->stats_lock);bnxt_accumulate_all_stats (bp); + bp->stats_updated_jiffies = jiffies; +spin_unlock (&bp->stats_lock); }if (test_and_clear_bit (BNXT_LINK_CHNG_SP_EVENT , &bp->sp_event)) {
@@ -15496,6 +15539,7 @@ static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev)INIT_DELAYED_WORK (&bp->fw_reset_task, bnxt_fw_reset_task);spin_lock_init (&bp->ntp_fltr_lock); +spin_lock_init (&bp->stats_lock);#if BITS_PER_LONG ==32 spin_lock_init (&bp->db_lock);#endif
@@ -16064,6 +16108,7 @@ static void bnxt_get_queue_stats_rx(struct net_device *dev, int i,if (!bp->bnapi)return ; +bnxt_sync_ring_stats (bp); cpr = &bp->bnapi[i]->cp_ring; sw = cpr->stats.sw_stats;
@@ -16092,6 +16137,7 @@ static void bnxt_get_queue_stats_tx(struct net_device *dev, int i,if (!bp->tx_ring)return ; +bnxt_sync_ring_stats (bp); bnapi = bp->tx_ring[bp->tx_ring_map[i]].bnapi; sw = bnapi->cp_ring.stats.sw_stats;
drivers/net/ethernet/broadcom/bnxt/bnxt.h +5 -0
@@ -2621,6 +2621,10 @@ struct bnxt {#define BNXT_MIN_STATS_COAL_TICKS 250000#define BNXT_MAX_STATS_COAL_TICKS 1000000 +/* Protects stats_updated_jiffies and writes to sw_stats */ +spinlock_t stats_lock; +unsigned long stats_updated_jiffies; +struct work_struct sp_task;unsigned long sp_event;#define BNXT_RX_MASK_SP_EVENT 0
@@ -3029,6 +3033,7 @@ void bnxt_reenable_sriov(struct bnxt *bp);void bnxt_close_nic (struct bnxt *,bool ,bool );void bnxt_get_ring_drv_stats (struct bnxt *bp,struct bnxt_total_ring_drv_stats *stats); +void bnxt_sync_ring_stats (struct bnxt *bp);bool bnxt_rfs_capable (struct bnxt *bp,bool new_rss_ctx);int bnxt_dbg_hwrm_rd_reg (struct bnxt *bp,u32 reg_off,u16 num_words,u32 *reg_buf);
drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c +1 -0
@@ -606,6 +606,7 @@ static void bnxt_get_ethtool_stats(struct net_device *dev, goto skip_ring_stats; } +bnxt_sync_ring_stats (bp); tpa_stats =bnxt_get_num_tpa_ring_stats (bp);for (i =0 ; i < bp->cp_nr_rings; i++) {struct bnxt_napi *bnapi = bp->bnapi[i];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1222/2077 ipv4: fib: Dont ignore error route in local/main tables.
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
[ Upstream commit b72f0db64205d9ce462038ba995d5d31eff32dc1 ]
When CONFIG_IP_MULTIPLE_TABLES is enabled but no rule is added, fib_lookup() performs route lookup directly on two tables.
Since the first lookup does not properly bail out, the result of an error route in the merged local/main table could be overwritten by another route in the default table:
# unshare -n
# ip link set lo up
# ip route add 192.168.0.0/24 dev lo table 253
# ip route add unreachable 192.168.0.0/24
# ip route get 192.168.0.1
192.168.0.1 dev lo table default uid 0
cache <local>Once a random rule is added, the error route is respected:
# ip rule add table 0 # ip rule del table 0 # ip route get 192.168.0.1 RTNETLINK answers: No route to host
Let's fix the inconsistent behaviour.
--- include/net/ip_fib.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
include/net/ip_fib.h +3 -4
@@ -375,7 +375,7 @@ static inline int fib_lookup(struct net *net, struct flowi4 *flp, struct fib_result *res, unsigned int flags) {struct fib_table *tb; -int err = -ENETUNREACH ; +int err = -EAGAIN ; flags |=FIB_LOOKUP_NOREF ;if (net->ipv4.fib_has_custom_rules)
@@ -389,17 +389,16 @@ static inline int fib_lookup(struct net *net, struct flowi4 *flp,if (tb) err =fib_table_lookup (tb, flp, res, flags); -if (!err) +if (err != -EAGAIN ) goto out; tb =rcu_dereference_rtnl (net->ipv4.fib_default);if (tb) err =fib_table_lookup (tb, flp, res, flags); -out:if (err == -EAGAIN ) err = -ENETUNREACH ; - +out:rcu_read_unlock ();return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1223/2077 md/raid5: use stripe state snapshot in break_stripe_batch_list()
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chen Cheng <[email protected]>
[ Upstream commit 9b249f5ffbeda24c57e6c56ed896c5ca4fc70549 ]
The patch just suppress KCSAN noise. No functional change.
RAID-5 can group multi full-stripe-write aka stripe_head into a batch aka batch_list, with one head_sh leading them. Call break_stripe_batch_list() when the batch is finished, or, a stripe has to be dropped out of the batch.
break_stripe_batch_list() reads stripe state several times while request paths can update thost state words concurrently with lockless bitops, which reported by KCSAN.
Use a snapshot to guarantees that the value used for warning, copying, and handle checks is internally consistent at current read moment.
KCSAN report:
==============================================
BUG: KCSAN: data-race in __add_stripe_bio / break_stripe_batch_list
write (marked) to 0xffff8e89d4f0b988 of 8 bytes by task 4323 on cpu 3:
__add_stripe_bio+0x35e/0x400 raid5_make_request+0x6ac/0x2930 md_handle_request+0x4a2/0xa40 md_submit_bio+0x109/0x1a0 __submit_bio+0x2ec/0x390 submit_bio_noacct_nocheck+0x457/0x710 submit_bio_noacct+0x2a7/0xc20 submit_bio+0x56/0x250 blkdev_direct_IO+0x54c/0xda0 blkdev_write_iter+0x38f/0x570 aio_write+0x22b/0x490 io_submit_one+0xa51/0xf70
read to 0xffff8e89d4f0b988 of 8 bytes by task 4290 on cpu 4:
break_stripe_batch_list+0x3ce/0x480 handle_stripe_clean_event+0x720/0x9b0 handle_stripe+0x32fb/0x4500 handle_active_stripes.isra.0+0x6e0/0xa50 raid5d+0x7e0/0xba0
Stable-dep-of: 55b77337bdd0 ("md/raid5: avoid R5_Overlap races while breaking stripe batches")
--- drivers/md/raid5.c | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-)
drivers/md/raid5.c +26 -19
@@ -4837,31 +4837,35 @@ static void break_stripe_batch_list(struct stripe_head *head_sh, {struct stripe_head *sh, *next;int i; +unsigned long state;list_for_each_entry_safe (sh, next, &head_sh->batch_list, batch_list) {list_del_init (&sh->batch_list); -WARN_ONCE (sh->state & ((1 <<STRIPE_ACTIVE ) | - (1 <<STRIPE_SYNCING ) | - (1 <<STRIPE_REPLACED ) | - (1 <<STRIPE_DELAYED ) | - (1 <<STRIPE_BIT_DELAY ) | - (1 <<STRIPE_FULL_WRITE ) | - (1 <<STRIPE_BIOFILL_RUN ) | - (1 <<STRIPE_COMPUTE_RUN ) | - (1 <<STRIPE_DISCARD ) | - (1 <<STRIPE_BATCH_READY ) | - (1 <<STRIPE_BATCH_ERR )), -"stripe state: %lx\n" , sh->state); -WARN_ONCE (head_sh->state & ((1 <<STRIPE_DISCARD ) | - (1 <<STRIPE_REPLACED )), -"head stripe state: %lx\n" , head_sh->state); + state =READ_ONCE (sh->state); +WARN_ONCE (state & ((1 <<STRIPE_ACTIVE ) | + (1 <<STRIPE_SYNCING ) | + (1 <<STRIPE_REPLACED ) | + (1 <<STRIPE_DELAYED ) | + (1 <<STRIPE_BIT_DELAY ) | + (1 <<STRIPE_FULL_WRITE ) | + (1 <<STRIPE_BIOFILL_RUN ) | + (1 <<STRIPE_COMPUTE_RUN ) | + (1 <<STRIPE_DISCARD ) | + (1 <<STRIPE_BATCH_READY ) | + (1 <<STRIPE_BATCH_ERR )), +"stripe state: %lx\n" , state); + + state =READ_ONCE (head_sh->state); +WARN_ONCE (state & ((1 <<STRIPE_DISCARD ) | + (1 <<STRIPE_REPLACED )), +"head stripe state: %lx\n" , state);set_mask_bits (&sh->state, ~(STRIPE_EXPAND_SYNC_FLAGS | (1 <<STRIPE_PREREAD_ACTIVE ) | (1 <<STRIPE_ON_UNPLUG_LIST )), - head_sh->state & (1 <<STRIPE_INSYNC )); + state & (1 <<STRIPE_INSYNC )); sh->check_state = head_sh->check_state; sh->reconstruct_state = head_sh->reconstruct_state;
@@ -4874,8 +4878,9 @@ static void break_stripe_batch_list(struct stripe_head *head_sh, sh->dev[i].flags = head_sh->dev[i].flags & (~((1 << R5_WriteError) | (1 << R5_Overlap))); } -if (handle_flags ==0 || - sh->state & handle_flags) + + state =READ_ONCE (sh->state); +if (handle_flags ==0 || (state & handle_flags))set_bit (STRIPE_HANDLE , &sh->state);raid5_release_stripe (sh); }
@@ -4885,7 +4890,9 @@ static void break_stripe_batch_list(struct stripe_head *head_sh,for (i =0 ; i < head_sh->disks; i++)if (test_and_clear_bit (R5_Overlap, &head_sh->dev[i].flags))wake_up_bit (&head_sh->dev[i].flags, R5_Overlap); -if (head_sh->state & handle_flags) + + state =READ_ONCE (head_sh->state); +if (state & handle_flags)set_bit (STRIPE_HANDLE , &head_sh->state); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1224/2077 md/raid5: avoid R5_Overlap races while breaking stripe batches
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chen Cheng <[email protected]>
[ Upstream commit 55b77337bdd088c77461588e5ec094421b89911b ]
KCSAN report a race in break_stripe_batch_list() vs. raid5_make_request() on sh->dev[i].flags (plain word write vs. atomic bit op)..
and .. one possible scenario is:
CPU1 CPU2break_stripe_batch_list(sh1)
-> handle sh2
-> lock(sh2)
-> sh2->batch_head = NULL
-> unlock(sh2)
-> test_and_clear_bit(R5_Overlap, sh2->dev[i].flags) -> wake_up_bit(sh2->dev[i].flags)
raid5_make_request()
-> add_all_stripe_bios(sh2)
-> lock(sh2)
-> stripe_bio_overlaps(sh2) returns true
batch_head is NULL, so new bio overlap
exist bio on sh2 -> true
-> set_bit(R5_Overlap, sh2->dev[i].flags)
-> unlock(sh2)
-> wait_on_bit(sh2->dev[i].flags)-> sh2->dev[i].flags = sh1->dev[i].flags & ~R5_Overlap
No wait_up_bit(), CPU2 could be wait_on_bit() forever...
Fix by :
- Expand the protect zone.
- Use batch_head's device flag's snaphot when no held head_sh->stripe_lock.
- Move sh/head_sh->batch_head = NULL to the end of protected zone , and , any concurrent add_all_stripe_bios() grabs sh->stripe_lock now either:
- see batch_head != null, and , is rejected by stripe_bio_overlaps() under the lock (no R5_Overlap wait ) , or ,
- sees batch_head == NULL, only after dev[i].flags has already been set and the prior R5_Overlap waiters worken.
KCSAN report:
================================================
BUG: KCSAN: data-race in break_stripe_batch_list / raid5_make_request
write (marked) to 0xffff8e89c8117548 of 8 bytes by task 4042 on cpu 0:
raid5_make_request+0xea0/0x2930
md_handle_request+0x4a2/0xa40
md_submit_bio+0x109/0x1a0
__submit_bio+0x2ec/0x390
submit_bio_noacct_nocheck+0x457/0x710
submit_bio_noacct+0x2a7/0xc20
submit_bio+0x56/0x250
blkdev_direct_IO+0x54c/0xda0
blkdev_write_iter+0x38f/0x570
aio_write+0x22b/0x490
io_submit_one+0xa51/0xf70
__x64_sys_io_submit+0xf7/0x220
x64_sys_call+0x1907/0x1c60
do_syscall_64+0x130/0x570
entry_SYSCALL_64_after_hwframe+0x76/0x7e read to 0xffff8e89c8117548 of 8 bytes by task 4010 on cpu 5:
break_stripe_batch_list+0x249/0x480
handle_stripe_clean_event+0x720/0x9b0
handle_stripe+0x32fb/0x4500
handle_active_stripes.isra.0+0x6e0/0xa50
raid5d+0x7e0/0xba0
md_thread+0x15a/0x2d0
kthread+0x1e3/0x220
ret_from_fork+0x37a/0x410
ret_from_fork_asm+0x1a/0x30 value changed: 0x0000000000000019 -> 0x0000000000000099 --> R5_Overlap
--- drivers/md/raid5.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/md/raid5.c +5 -5
@@ -4870,14 +4870,14 @@ static void break_stripe_batch_list(struct stripe_head *head_sh, sh->check_state = head_sh->check_state; sh->reconstruct_state = head_sh->reconstruct_state;spin_lock_irq (&sh->stripe_lock); - sh->batch_head =NULL ; -spin_unlock_irq (&sh->stripe_lock);for (i =0 ; i < sh->disks; i++) {if (test_and_clear_bit (R5_Overlap, &sh->dev[i].flags))wake_up_bit (&sh->dev[i].flags, R5_Overlap); - sh->dev[i].flags = head_sh->dev[i].flags & + sh->dev[i].flags =READ_ONCE (head_sh->dev[i].flags) & (~((1 << R5_WriteError) | (1 << R5_Overlap))); } + sh->batch_head =NULL ; +spin_unlock_irq (&sh->stripe_lock); state =READ_ONCE (sh->state);if (handle_flags ==0 || (state & handle_flags))
@@ -4885,11 +4885,11 @@ static void break_stripe_batch_list(struct stripe_head *head_sh,raid5_release_stripe (sh); }spin_lock_irq (&head_sh->stripe_lock); - head_sh->batch_head =NULL ; -spin_unlock_irq (&head_sh->stripe_lock);for (i =0 ; i < head_sh->disks; i++)if (test_and_clear_bit (R5_Overlap, &head_sh->dev[i].flags))wake_up_bit (&head_sh->dev[i].flags, R5_Overlap); + head_sh->batch_head =NULL ; +spin_unlock_irq (&head_sh->stripe_lock); state =READ_ONCE (head_sh->state);if (state & handle_flags)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1225/2077 bpf: Disable xfrm_decode_session hook attachment
In reply to Greg Kroah-Hartman7.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bradley Morgan <[email protected]>
[ Upstream commit 12091470c6b4c1c14b2de12dcbae2ada6cb6d20b ]
BPF LSM programs can currently attach to xfrm_decode_session(). That hook may return an error, but security_skb_classify_flow() calls it from a void path and triggers BUG_ON() if an error is returned.
Disable BPF attachment to the hook to prevent a BPF LSM program from turning packet classification into a full panic.
--- kernel/bpf/bpf_lsm.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/bpf/bpf_lsm.c +3 -0
@@ -51,6 +51,9 @@ BTF_ID(func, bpf_lsm_key_getsecurity)#ifdef CONFIG_AUDIT BTF_ID(func, bpf_lsm_audit_rule_match)#endif +#ifdef CONFIG_SECURITY_NETWORK_XFRM +BTF_ID(func, bpf_lsm_xfrm_decode_session) +#endif BTF_ID(func, bpf_lsm_ismaclabel) BTF_ID(func, bpf_lsm_file_alloc_security)BTF_SET_END (bpf_lsm_disabled_hooks)
Signature · 1 line
2.53.0