6.1.169-rc1 review
Subsystems (3)
Greg Kroah-Hartman
maintainercover 6.1.169-rc1 review
This is the start of the stable review cycle for the 6.1.169 release. There are 55 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Wed, 15 Apr 2026 15:57:08 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
https://www.kernel.org/pub/linux/kernel/v6.x/stable-review/patch-6.1.169-rc1.gz
or in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git linux-6.1.y
and the diffstat can be found below.
thanks,
greg k-h
-------------
Pseudo-Shortlog of commits:
Greg Kroah-Hartman <[email protected]>
Linux 6.1.169-rc1
Manivannan Sadhasivam <[email protected]>
Revert "PCI: Enable ACS after configuring IOMMU for OF platforms"
David Howells <[email protected]>
rxrpc: Fix key/keyring checks in setsockopt(RXRPC_SECURITY_KEY/KEYRING)
Luxiao Xu <[email protected]>
rxrpc: fix reference count leak in rxrpc_server_keyring()
Tyllis Xu <[email protected]>
net: stmmac: fix integer underflow in chain mode
Pengpeng Hou <[email protected]>
net: qualcomm: qca_uart: report the consumed byte on RX skb allocation failure
Johan Hovold <[email protected]>
mmc: vub300: fix NULL-deref on disconnect
Michael Guralnik <[email protected]>
net/mlx5: Update the list of the PCI supported devices
Sebastian Brzezinka <[email protected]>
drm/i915/gt: fix refcount underflow in intel_engine_park_heartbeat
Haoze Xie <[email protected]>
batman-adv: hold claim backbone gateways by reference
David Carlier <[email protected]>
net: altera-tse: fix skb leak on DMA mapping error in tse_start_xmit()
Muhammad Alifa Ramdhan <[email protected]>
net/tls: fix use-after-free in -EBUSY error path of tls_do_encryption
Borislav Petkov (AMD) <[email protected]>
EDAC/mc: Fix error path ordering in edac_mc_alloc()
Ruide Cao <[email protected]>
batman-adv: reject oversized global TT response buffers
Pengpeng Hou <[email protected]>
nfc: pn533: allocate rx skb before consuming bytes
Shawn Guo <[email protected]>
arm64: dts: hisilicon: hi3798cv200: Add missing dma-ranges
Shawn Guo <[email protected]>
arm64: dts: hisilicon: poplar: Correct PCIe reset GPIO polarity
Thomas Fourier <[email protected]>
wifi: brcmsmac: Fix dma_free_coherent() size
Oleh Konko <[email protected]>
tipc: fix bc_ackers underflow on duplicate GRP_ACK_MSG
Yasuaki Torimaru <[email protected]>
xfrm: clear trailing padding in build_polexpire()
Tuan Do <[email protected]>
netfilter: nft_ct: fix use-after-free in timeout object destroy
Florian Westphal <[email protected]>
netfilter: nft_set_pipapo: do not rely on ZERO_SIZE_PTR
Lin.Cao <[email protected]>
drm/scheduler: signal scheduled fence when kill job
Matthieu Baerts (NGI0) <[email protected]>
Revert "mptcp: add needs_id for netlink appending addr"
Andrea Mayer <[email protected]>
seg6: separate dst_cache for input and output paths in seg6 lwtunnel
Greg Kroah-Hartman <[email protected]>
net: rfkill: prevent unlimited numbers of rfkill events from being created
Johannes Berg <[email protected]>
net: rfkill: reduce data->mtx scope in rfkill_fop_open
Johannes Berg <[email protected]>
rfkill: sync before userspace visibility/changes
Bo Liu <[email protected]>
rfkill: Use sysfs_emit() to instead of sprintf()
Michael Zimmermann <[email protected]>
usb: gadget: f_hid: move list and spinlock inits from bind to alloc
Rafael J. Wysocki <[email protected]>
ACPI: EC: Evaluate _REG outside the EC scope more carefully
Rafael J. Wysocki <[email protected]>
ACPICA: Add a depth argument to acpi_execute_reg_methods()
Rafael J. Wysocki <[email protected]>
Revert "ACPI: EC: Evaluate orphan _REG under EC device"
Kuen-Han Tsai <[email protected]>
usb: gadget: u_ether: Fix race between gether_disconnect and eth_stop
John Johansen <[email protected]>
apparmor: fix race between freeing data and fs accessing it
John Johansen <[email protected]>
apparmor: fix race on rawdata dereference
John Johansen <[email protected]>
apparmor: fix differential encoding verification
John Johansen <[email protected]>
apparmor: fix unprivileged local user can do privileged policy management
John Johansen <[email protected]>
apparmor: Fix double free of ns_name in aa_replace_profiles()
Massimiliano Pellizzer <[email protected]>
apparmor: fix missing bounds check on DEFAULT table in verify_dfa()
Massimiliano Pellizzer <[email protected]>
apparmor: fix side-effect bug in match_char() macro usage
John Johansen <[email protected]>
apparmor: fix: limit the number of levels of policy namespaces
Massimiliano Pellizzer <[email protected]>
apparmor: replace recursive profile removal with iterative approach
Massimiliano Pellizzer <[email protected]>
apparmor: fix memory leak in verify_header
Massimiliano Pellizzer <[email protected]>
apparmor: validate DFA start states are in bounds in unpack_pdb
Ricardo Ribalda <[email protected]>
media: uvcvideo: Use heuristic to find stream entity
Thadeu Lima de Souza Cascardo <[email protected]>
media: uvcvideo: Mark invalid entities with id UVC_INVALID_ENTITY_ID
Maciej W. Rozycki <[email protected]>
MIPS: mm: Rewrite TLB uniquification for the hidden bit feature
Maciej W. Rozycki <[email protected]>
MIPS: mm: Suppress TLB uniquification on EHINV hardware
Maciej W. Rozycki <[email protected]>
MIPS: Always record SEGBITS in cpu_data.vmbits
Dmitry Torokhov <[email protected]>
Input: uinput - take event lock when submitting FF request "event"
Mikhail Gavrilov <[email protected]>
Input: uinput - fix circular locking dependency with ff-core
Jiayuan Chen <[email protected]>
mptcp: fix slab-use-after-free in __inet_lookup_established
Greg Kroah-Hartman <[email protected]>
xfrm_user: fix info leak in build_report()
Johan Hovold <[email protected]>
wifi: rt2x00usb: fix devres lifetime
Eric Biggers <[email protected]>
lib/crypto: chacha: Zeroize permuted_state before it leaves scope
-------------
Diffstat:
Makefile | 4 +- .../boot/dts/hisilicon/hi3798cv200-poplar.dts | 2 +- arch/arm64/boot/dts/hisilicon/hi3798cv200.dtsi | 1 + arch/mips/include/asm/cpu-features.h | 1 - arch/mips/include/asm/cpu-info.h | 2 - arch/mips/include/asm/mipsregs.h | 2 + arch/mips/kernel/cpu-probe.c | 13 +- arch/mips/kernel/cpu-r3k-probe.c | 2 + arch/mips/mm/tlb-r4k.c | 285 +++++++++++++++++---- drivers/acpi/acpica/acevents.h | 6 +- drivers/acpi/acpica/evregion.c | 12 +- drivers/acpi/acpica/evxfregn.c | 64 +---- drivers/acpi/ec.c | 14 +- drivers/acpi/internal.h | 1 + drivers/acpi/scan.c | 2 + drivers/edac/edac_mc.c | 6 +- drivers/gpu/drm/i915/gt/intel_engine_heartbeat.c | 26 +- drivers/gpu/drm/scheduler/sched_entity.c | 1 + drivers/input/misc/uinput.c | 35 ++- drivers/media/usb/uvc/uvc_driver.c | 88 +++++-- drivers/media/usb/uvc/uvcvideo.h | 2 + drivers/mmc/host/vub300.c | 2 +- drivers/net/ethernet/altera/altera_tse_main.c | 1 + drivers/net/ethernet/mellanox/mlx5/core/main.c | 1 + drivers/net/ethernet/qualcomm/qca_uart.c | 2 +- drivers/net/ethernet/stmicro/stmmac/chain_mode.c | 11 +- .../net/wireless/broadcom/brcm80211/brcmsmac/dma.c | 2 +- drivers/net/wireless/ralink/rt2x00/rt2x00usb.c | 2 +- drivers/nfc/pn533/uart.c | 11 +- drivers/pci/pci-driver.c | 8 - drivers/pci/pci.c | 10 +- drivers/pci/pci.h | 1 - drivers/usb/gadget/function/f_hid.c | 11 +- drivers/usb/gadget/function/u_ether.c | 8 +- include/acpi/acpixf.h | 5 +- include/net/netfilter/nf_conntrack_timeout.h | 1 + lib/crypto/chacha.c | 4 + net/batman-adv/bridge_loop_avoidance.c | 27 +- net/batman-adv/translation-table.c | 9 +- net/ipv6/seg6_iptunnel.c | 41 ++- net/mptcp/pm_netlink.c | 24 +- net/mptcp/protocol.c | 2 + net/mptcp/protocol.h | 1 + net/mptcp/subflow.c | 15 +- net/netfilter/nft_ct.c | 2 +- net/netfilter/nft_set_pipapo.c | 20 +- net/rfkill/core.c | 84 ++++-- net/rxrpc/af_rxrpc.c | 6 - net/rxrpc/key.c | 2 +- net/rxrpc/server_key.c | 3 + net/tipc/group.c | 6 +- net/tls/tls_sw.c | 10 + net/xfrm/xfrm_user.c | 3 + security/apparmor/apparmorfs.c | 228 ++++++++++------- security/apparmor/include/label.h | 16 +- security/apparmor/include/lib.h | 12 + security/apparmor/include/match.h | 1 + security/apparmor/include/policy.h | 13 +- security/apparmor/include/policy_ns.h | 2 + security/apparmor/include/policy_unpack.h | 83 +++--- security/apparmor/label.c | 12 +- security/apparmor/match.c | 58 +++-- security/apparmor/policy.c | 82 +++++- security/apparmor/policy_ns.c | 2 + security/apparmor/policy_unpack.c | 74 ++++-- 65 files changed, 989 insertions(+), 498 deletions(-)
Greg Kroah-Hartman
maintainerPATCH 1/55 lib/crypto: chacha: Zeroize permuted_state before it leaves scope
6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit e5046823f8fa3677341b541a25af2fcb99a5b1e0 upstream.
Since the ChaCha permutation is invertible, the local variable 'permuted_state' is sufficient to compute the original 'state', and thus the key, even after the permutation has been done.
While the kernel is quite inconsistent about zeroizing secrets on the stack (and some prominent userspace crypto libraries don't bother at all since it's not guaranteed to work anyway), the kernel does try to do it as a best practice, especially in cases involving the RNG.
Thus, explicitly zeroize 'permuted_state' before it goes out of scope.
--- lib/crypto/chacha.c | 4 ++++ 1 file changed, 4 insertions(+)
lib/crypto/chacha.c +4 -0
@@ -86,6 +86,8 @@ void chacha_block_generic(u32 *state, u8put_unaligned_le32 (x[i] + state[i], &stream[i *sizeof (u32)]); state[12 ]++; + +memzero_explicit (x,sizeof (x)); }EXPORT_SYMBOL (chacha_block_generic);
@@ -110,5 +112,7 @@ void hchacha_block_generic(const u32 *stmemcpy (&stream[0 ], &x[0 ],16 );memcpy (&stream[4 ], &x[12 ],16 ); + +memzero_explicit (x,sizeof (x)); }EXPORT_SYMBOL (hchacha_block_generic);
Greg Kroah-Hartman
maintainerPATCH 2/55 wifi: rt2x00usb: fix devres lifetime
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 25369b22223d1c56e42a0cd4ac9137349d5a898e upstream.
USB drivers bind to USB interfaces and any device managed resources should have their lifetime tied to the interface rather than parent USB device. This avoids issues like memory leaks when drivers are unbound without their devices being physically disconnected (e.g. on probe deferral or configuration changes).
Fix the USB anchor lifetime so that it is released on driver unbind.
--- drivers/net/wireless/ralink/rt2x00/rt2x00usb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ralink/rt2x00/rt2x00usb.c +1 -1
@@ -830,7 +830,7 @@ int rt2x00usb_probe(struct usb_interfaceif (retval) goto exit_free_device; - rt2x00dev->anchor =devm_kmalloc (&usb_dev->dev, + rt2x00dev->anchor =devm_kmalloc (&usb_intf->dev,sizeof (struct usb_anchor ),GFP_KERNEL );if (!rt2x00dev->anchor) {
Greg Kroah-Hartman
maintainerPATCH 3/55 xfrm_user: fix info leak in build_report()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
commit d10119968d0e1f2b669604baf2a8b5fdb72fa6b4 upstream.
struct xfrm_user_report is a __u8 proto field followed by a struct xfrm_selector which means there is three "empty" bytes of padding, but the padding is never zeroed before copying to userspace. Fix that up by zeroing the structure before setting individual member variables.
--- net/xfrm/xfrm_user.c | 1 + 1 file changed, 1 insertion(+)
net/xfrm/xfrm_user.c +1 -0
@@ -3679,6 +3679,7 @@ static int build_report(struct sk_buff *return -EMSGSIZE ; ur =nlmsg_data (nlh); +memset (ur,0 ,sizeof (*ur)); ur->proto = proto;memcpy (&ur->sel, sel,sizeof (ur->sel));
Greg Kroah-Hartman
maintainerPATCH 4/55 mptcp: fix slab-use-after-free in __inet_lookup_established
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiayuan Chen <[email protected]>
commit 9b55b253907e7431210483519c5ad711a37dafa1 upstream.
The ehash table lookups are lockless and rely on SLAB_TYPESAFE_BY_RCU to guarantee socket memory stability during RCU read-side critical sections. Both tcp_prot and tcpv6_prot have their slab caches created with this flag via proto_register().
However, MPTCP's mptcp_subflow_init() copies tcpv6_prot into tcpv6_prot_override during inet_init() (fs_initcall, level 5), before inet6_init() (module_init/device_initcall, level 6) has called proto_register(&tcpv6_prot). At that point, tcpv6_prot.slab is still NULL, so tcpv6_prot_override.slab remains NULL permanently.
This causes MPTCP v6 subflow child sockets to be allocated via kmalloc (falling into kmalloc-4k) instead of the TCPv6 slab cache. The kmalloc-4k cache lacks SLAB_TYPESAFE_BY_RCU, so when these sockets are freed without SOCK_RCU_FREE (which is cleared for child sockets by design), the memory can be immediately reused. Concurrent ehash lookups under rcu_read_lock can then access freed memory, triggering a slab-use-after-free in __inet_lookup_established.
Fix this by splitting the IPv6-specific initialization out of mptcp_subflow_init() into a new mptcp_subflow_v6_init(), called from mptcp_proto_v6_init() before protocol registration. This ensures tcpv6_prot_override.slab correctly inherits the SLAB_TYPESAFE_BY_RCU slab cache.
--- net/mptcp/protocol.c | 2 ++ net/mptcp/protocol.h | 1 + net/mptcp/subflow.c | 15 +++++++++------ 3 files changed, 12 insertions(+), 6 deletions(-)
net/mptcp/protocol.c +2 -0
@@ -4264,6 +4264,8 @@ int __init mptcp_proto_v6_init(void) {int err; +mptcp_subflow_v6_init (); + mptcp_v6_prot = mptcp_prot;strcpy (mptcp_v6_prot.name,"MPTCPv6" ); mptcp_v6_prot.slab =NULL ;
net/mptcp/protocol.h +1 -0
@@ -677,6 +677,7 @@ static inline void mptcp_subflow_tcp_falvoid __init mptcp_proto_init (void );#if IS_ENABLED (CONFIG_MPTCP_IPV6 )int __init mptcp_proto_v6_init (void ); +void __init mptcp_subflow_v6_init (void );#endif struct sock *mptcp_sk_clone_init(const struct sock *sk,
net/mptcp/subflow.c +9 -6
@@ -1993,7 +1993,15 @@ void __init mptcp_subflow_init(void) tcp_prot_override.psock_update_sk_prot =NULL ;#endif +mptcp_diag_subflow_init (&subflow_ulp_ops); + +if (tcp_register_ulp (&subflow_ulp_ops) !=0 ) +panic ("MPTCP: failed to register subflows to ULP\n" ); +} +#if IS_ENABLED (CONFIG_MPTCP_IPV6 ) +void __init mptcp_subflow_v6_init (void ) +{/* In struct mptcp_subflow_request_sock, we assume the TCP request sock * structures for v4 and v6 have the same size. It should not changed in * the future but better to make sure to be warned if it is no longer
@@ -2032,10 +2040,5 @@ void __init mptcp_subflow_init(void)/* Disable sockmap processing for subflows */ tcpv6_prot_override.psock_update_sk_prot =NULL ; #endif -#endif - -mptcp_diag_subflow_init (&subflow_ulp_ops); - -if (tcp_register_ulp (&subflow_ulp_ops) !=0 ) -panic ("MPTCP: failed to register subflows to ULP\n" ); } +#endif
Greg Kroah-Hartman
maintainerPATCH 5/55 Input: uinput - fix circular locking dependency with ff-core
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikhail Gavrilov <[email protected]>
commit 4cda78d6f8bf2b700529f2fbccb994c3e826d7c2 upstream.
A lockdep circular locking dependency warning can be triggered reproducibly when using a force-feedback gamepad with uinput (for example, playing ELDEN RING under Wine with a Flydigi Vader 5 controller):
ff->mutex -> udev->mutex -> input_mutex -> dev->mutex -> ff->mutex
The cycle is caused by four lock acquisition paths:
1. ff upload: input_ff_upload() holds ff->mutex and calls uinput_dev_upload_effect() -> uinput_request_submit() -> uinput_request_send(), which acquires udev->mutex.
2. device create: uinput_ioctl_handler() holds udev->mutex and calls uinput_create_device() -> input_register_device(), which acquires input_mutex.
3. device register: input_register_device() holds input_mutex and calls kbd_connect() -> input_register_handle(), which acquires dev->mutex.
4. evdev release: evdev_release() calls input_flush_device() under dev->mutex, which calls input_ff_flush() acquiring ff->mutex.
Fix this by introducing a new state_lock spinlock to protect udev->state and udev->dev access in uinput_request_send() instead of acquiring udev->mutex. The function only needs to atomically check device state and queue an input event into the ring buffer via uinput_dev_event() -- both operations are safe under a spinlock (ktime_get_ts64() and wake_up_interruptible() do not sleep). This breaks the ff->mutex -> udev->mutex link since a spinlock is a leaf in the lock ordering and cannot form cycles with mutexes.
To keep state transitions visible to uinput_request_send(), protect writes to udev->state in uinput_create_device() and uinput_destroy_device() with the same state_lock spinlock.
Additionally, move init_completion(&request->done) from uinput_request_send() to uinput_request_submit() before uinput_request_reserve_slot(). Once the slot is allocated, uinput_flush_requests() may call complete() on it at any time from the destroy path, so the completion must be initialised before the request becomes visible.
Lock ordering after the fix:
ff->mutex -> state_lock (spinlock, leaf)
udev->mutex -> state_lock (spinlock, leaf)
udev->mutex -> input_mutex -> dev->mutex -> ff->mutex (no back-edge)
--- drivers/input/misc/uinput.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-)
drivers/input/misc/uinput.c +21 -7
@@ -56,6 +56,7 @@ struct uinput_device {struct input_dev *dev;struct mutex mutex;enum uinput_state state; +spinlock_t state_lock;wait_queue_head_t waitq;unsigned char ready;unsigned char head;
@@ -145,19 +146,15 @@ static void uinput_request_release_slot(static int uinput_request_send (struct uinput_device *udev,struct uinput_request *request) { -int retval; +int retval =0 ; - retval =mutex_lock_interruptible (&udev->mutex); -if (retval) -return retval; +spin_lock (&udev->state_lock);if (udev->state !=UIST_CREATED ) { retval = -ENODEV ; goto out; } -init_completion (&request->done); -/* * Tell our userspace application about this new request * by queueing an input event.
@@ -165,7 +162,7 @@ static int uinput_request_send(struct uiuinput_dev_event (udev->dev,EV_UINPUT , request->code, request->id); out: -mutex_unlock (&udev->mutex); +spin_unlock (&udev->state_lock);return retval; }
@@ -174,6 +171,13 @@ static int uinput_request_submit(struct {int retval; +/* +* Initialize completion before allocating the request slot. +* Once the slot is allocated, uinput_flush_requests() may +* complete it at any time, so it must be initialized first. +*/ +init_completion (&request->done); + retval =uinput_request_reserve_slot (udev, request);if (retval)return retval;
@@ -288,7 +292,14 @@ static void uinput_destroy_device(structstruct input_dev *dev = udev->dev;enum uinput_state old_state = udev->state; +/* +* Update state under state_lock so that concurrent +* uinput_request_send() sees the state change before we +* flush pending requests and tear down the device. +*/ +spin_lock (&udev->state_lock); udev->state =UIST_NEW_DEVICE ; +spin_unlock (&udev->state_lock);if (dev) { name = dev->name;
@@ -365,7 +376,9 @@ static int uinput_create_device(struct uif (error) goto fail2; +spin_lock (&udev->state_lock); udev->state =UIST_CREATED ; +spin_unlock (&udev->state_lock);return 0 ;
@@ -383,6 +396,7 @@ static int uinput_open(struct inode *inoreturn -ENOMEM ;mutex_init (&newdev->mutex); +spin_lock_init (&newdev->state_lock);spin_lock_init (&newdev->requests_lock);init_waitqueue_head (&newdev->requests_waitq);init_waitqueue_head (&newdev->waitq);
Greg Kroah-Hartman
maintainerPATCH 6/55 Input: uinput - take event lock when submitting FF request "event"
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
commit ff14dafde15c11403fac61367a34fea08926e9ee upstream.
To avoid racing with FF playback events and corrupting device's event queue take event_lock spinlock when calling uinput_dev_event() when submitting a FF upload or erase "event".
--- drivers/input/misc/uinput.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/input/misc/uinput.c +7 -0
@@ -25,8 +25,10 @@#include <linux/module.h> #include <linux/init.h> #include <linux/fs.h> +#include <linux/lockdep.h> #include <linux/miscdevice.h> #include <linux/overflow.h> +#include <linux/spinlock.h> #include <linux/input/mt.h> #include "../input-compat.h"
@@ -75,6 +77,8 @@ static int uinput_dev_event(struct inputstruct uinput_device *udev =input_get_drvdata (dev);struct timespec64 ts; +lockdep_assert_held (&dev->event_lock); +ktime_get_ts64 (&ts); udev->buff[udev->head] = (struct input_event ) {
@@ -146,6 +150,7 @@ static void uinput_request_release_slot(static int uinput_request_send (struct uinput_device *udev,struct uinput_request *request) { +unsigned long flags;int retval =0 ;spin_lock (&udev->state_lock);
@@ -159,7 +164,9 @@ static int uinput_request_send(struct ui* Tell our userspace application about this new request * by queueing an input event. */ +spin_lock_irqsave (&udev->dev->event_lock, flags);uinput_dev_event (udev->dev,EV_UINPUT , request->code, request->id); +spin_unlock_irqrestore (&udev->dev->event_lock, flags); out:spin_unlock (&udev->state_lock);
Greg Kroah-Hartman
maintainerPATCH 7/55 MIPS: Always record SEGBITS in cpu_data.vmbits
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maciej W. Rozycki <[email protected]>
commit 8374c2cb83b95b3c92f129fd56527225c20a058c upstream.
With a 32-bit kernel running on 64-bit MIPS hardware the hardcoded value of `cpu_vmbits' only records the size of compatibility useg and does not reflect the size of native xuseg or the complete range of values allowed in the VPN2 field of TLB entries.
An upcoming change will need the actual VPN2 value range permitted even in 32-bit kernel configurations, so always include the vmbits' member in struct cpuinfo_mips' and probe for SEGBITS when running on 64-bit hardware and resorting to the currently hardcoded value of 31 on 32-bit processors. No functional change for users of `cpu_vmbits'.
--- arch/mips/include/asm/cpu-features.h | 1 - arch/mips/include/asm/cpu-info.h | 2 -- arch/mips/include/asm/mipsregs.h | 2 ++ arch/mips/kernel/cpu-probe.c | 13 ++++++++----- arch/mips/kernel/cpu-r3k-probe.c | 2 ++ 5 files changed, 12 insertions(+), 8 deletions(-)
arch/mips/include/asm/cpu-features.h +0 -1
@@ -484,7 +484,6 @@# endif # ifndef cpu_vmbits# define cpu_vmbits cpu_data[0].vmbits -# define __NEED_VMBITS_PROBE# endif #endif
arch/mips/include/asm/cpu-info.h +0 -2
@@ -80,9 +80,7 @@ struct cpuinfo_mips {int srsets;/* Shadow register sets */ int package;/* physical package number */ unsigned int globalnumber; -#ifdef CONFIG_64BIT int vmbits;/* Virtual memory size in bits */ -#endif void *data;/* Additional data */ unsigned int watch_reg_count;/* Number that exist */ unsigned int watch_reg_use_cnt;/* Usable by ptrace */
arch/mips/include/asm/mipsregs.h +2 -0
@@ -1714,6 +1714,8 @@ do { \#define read_c0_entryhi () __read_ulong_c0_register($10, 0)#define write_c0_entryhi (val) __write_ulong_c0_register($10, 0, val) +#define read_c0_entryhi_64 () __read_64bit_c0_register($10, 0) +#define write_c0_entryhi_64 (val) __write_64bit_c0_register($10, 0, val)#define read_c0_guestctl1 () __read_32bit_c0_register($10, 4)#define write_c0_guestctl1 (val) __write_32bit_c0_register($10, 4, val)
arch/mips/kernel/cpu-probe.c +8 -5
@@ -208,11 +208,14 @@ static inline void set_elf_base_platform(const char *plat)static inline void cpu_probe_vmbits (struct cpuinfo_mips *c) { -#ifdef __NEED_VMBITS_PROBE -write_c0_entryhi (0x3fffffffffffe000ULL ); -back_to_back_c0_hazard (); - c->vmbits =fls64 (read_c0_entryhi () &0x3fffffffffffe000ULL ); -#endif +int vmbits =31 ; + +if (cpu_has_64bits) { +write_c0_entryhi_64 (0x3fffffffffffe000ULL ); +back_to_back_c0_hazard (); + vmbits =fls64 (read_c0_entryhi_64 () &0x3fffffffffffe000ULL ); + } + c->vmbits = vmbits; }static void set_isa (struct cpuinfo_mips *c,unsigned int isa)
arch/mips/kernel/cpu-r3k-probe.c +2 -0
@@ -138,6 +138,8 @@ void cpu_probe(void)else cpu_set_nofpu_opts (c); + c->vmbits =31 ; +reserve_exception_space (0 ,0x400 ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 8/55 MIPS: mm: Suppress TLB uniquification on EHINV hardware
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maciej W. Rozycki <[email protected]>
commit 74283cfe216392c7b776ebf6045b5b15ed9dffcd upstream.
Hardware that supports the EHINV feature, mandatory for R6 ISA and FTLB implementation, lets software mark TLB entries invalid, which eliminates the need to ensure no duplicate matching entries are ever created. This feature is already used by local_flush_tlb_all(), via the UNIQUE_ENTRYHI macro, making the preceding call to r4k_tlb_uniquify() superfluous.
The next change will also modify uniquification code such that it'll become incompatible with the FTLB and MMID features, as well as MIPSr6 CPUs that do not implement 4KiB pages.
Therefore prevent r4k_tlb_uniquify() from being used on EHINV hardware, as denoted by `cpu_has_tlbinv'.
--- arch/mips/mm/tlb-r4k.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/mips/mm/tlb-r4k.c +2 -1
@@ -630,7 +630,8 @@ static void r4k_tlb_configure(void) temp_tlb_entry = current_cpu_data.tlbsize -1 ;/* From this point on the ARC firmware is dead. */ -r4k_tlb_uniquify (); +if (!cpu_has_tlbinv) +r4k_tlb_uniquify ();local_flush_tlb_all ();/* Did I tell you that ARC SUCKS? */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 9/55 MIPS: mm: Rewrite TLB uniquification for the hidden bit feature
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maciej W. Rozycki <[email protected]>
commit 540760b77b8fc49d39d1b2b76196e5ec57711a32 upstream.
Before the introduction of the EHINV feature, which lets software mark TLB entries invalid, certain older implementations of the MIPS ISA were equipped with an analogous bit, as a vendor extension, which however is hidden from software and only ever set at reset, and then any software write clears it, making the intended TLB entry valid.
This feature makes it unsafe to read a TLB entry with TLBR, modify the page mask, and write the entry back with TLBWI, because this operation will implicitly clear the hidden bit and this may create a duplicate entry, as with the presence of the hidden bit there is no guarantee all the entries across the TLB are unique each.
Usually the firmware has already uniquified TLB entries before handing control over, in which case we only need to guarantee at bootstrap no clash will happen with the VPN2 values chosen in local_flush_tlb_all().
However with systems such as Mikrotik RB532 we get handed the TLB as at reset, with the hidden bit set across the entries and possibly duplicate entries present. This then causes a machine check exception when page sizes are reset in r4k_tlb_uniquify() and prevents the system from booting.
Rewrite the algorithm used in r4k_tlb_uniquify() then such as to avoid the reuse of ASID/VPN values across the TLB. Get rid of global entries first as they may be blocking the entire address space, e.g. 16 256MiB pages will exhaust the whole address space of a 32-bit CPU and a single big page can exhaust the 32-bit compatibility space on a 64-bit CPU.
Details of the algorithm chosen are given across the code itself.
--- arch/mips/mm/tlb-r4k.c | 282 +++++++++++++++++++++++++++++++++-------- 1 file changed, 228 insertions(+), 54 deletions(-)
arch/mips/mm/tlb-r4k.c +228 -54
@@ -13,6 +13,7 @@#include <linux/sched.h> #include <linux/smp.h> #include <linux/memblock.h> +#include <linux/minmax.h> #include <linux/mm.h> #include <linux/hugetlb.h> #include <linux/export.h>
@@ -24,6 +25,7 @@#include <asm/hazards.h> #include <asm/mmu_context.h> #include <asm/tlb.h> +#include <asm/tlbdebug.h> #include <asm/tlbmisc.h> extern void build_tlb_refill_handler (void );
@@ -501,87 +503,259 @@ static int __init set_ntlb(char *str)__setup ("ntlb=" , set_ntlb); -/* Comparison function for EntryHi VPN fields. */ -static int r4k_vpn_cmp (const void *a,const void *b) +/* The start bit position of VPN2 and Mask in EntryHi/PageMask registers. */ +#define VPN2_SHIFT 13 + +/* Read full EntryHi even with CONFIG_32BIT. */ +static inline unsigned long long read_c0_entryhi_native (void ) +{ +return cpu_has_64bits ?read_c0_entryhi_64 () :read_c0_entryhi (); +} + +/* Write full EntryHi even with CONFIG_32BIT. */ +static inline void write_c0_entryhi_native (unsigned long long v) { -long v = *(unsigned long *)a - *(unsigned long *)b; -int s =sizeof (long ) >sizeof (int ) ?sizeof (long ) *8 -1 :0 ; -return s ? (v !=0 ) | v >> s : v; +if (cpu_has_64bits) +write_c0_entryhi_64 (v); +else +write_c0_entryhi (v); } +/* TLB entry state for uniquification. */ +struct tlbent { +unsigned long long wired:1 ; +unsigned long long global:1 ; +unsigned long long asid:10 ; +unsigned long long vpn:51 ; +unsigned long long pagesz:5 ; +unsigned long long index:14 ; +}; +/* -* Initialise all TLB entries with unique values that do not clash with -* what we have been handed over and what we'll be using ourselves. +* Comparison function for TLB entry sorting. Place wired entries first, +* then global entries, then order by the increasing VPN/ASID and the +* decreasing page size. This lets us avoid clashes with wired entries +* easily and get entries for larger pages out of the way first. +* +* We could group bits so as to reduce the number of comparisons, but this +* is seldom executed and not performance-critical, so prefer legibility. */ -static void __ref r4k_tlb_uniquify (void ) +static int r4k_entry_cmp (const void *a,const void *b) { -int tlbsize = current_cpu_data.tlbsize; -bool use_slab =slab_is_available (); -int start =num_wired_entries (); -phys_addr_t tlb_vpn_size; -unsigned long *tlb_vpns; -unsigned long vpn_mask; -int cnt, ent, idx, i; - - vpn_mask =GENMASK (cpu_vmbits -1 ,13 ); - vpn_mask |=IS_ENABLED (CONFIG_64BIT ) ?3ULL <<62 :1 <<31 ; +struct tlbent ea = *(struct tlbent *)a, eb = *(struct tlbent *)b; + +if (ea.wired > eb.wired) +return -1 ; +else if (ea.wired < eb.wired) +return 1 ; +else if (ea.global > eb.global) +return -1 ; +else if (ea.global < eb.global) +return 1 ; +else if (ea.vpn < eb.vpn) +return -1 ; +else if (ea.vpn > eb.vpn) +return 1 ; +else if (ea.asid < eb.asid) +return -1 ; +else if (ea.asid > eb.asid) +return 1 ; +else if (ea.pagesz > eb.pagesz) +return -1 ; +else if (ea.pagesz < eb.pagesz) +return 1 ; +else +return 0 ; +} - tlb_vpn_size = tlbsize *sizeof (*tlb_vpns); - tlb_vpns = (use_slab ? -kmalloc (tlb_vpn_size,GFP_ATOMIC ) : -memblock_alloc_raw (tlb_vpn_size,sizeof (*tlb_vpns))); -if (WARN_ON (!tlb_vpns)) -return ;/* Pray local_flush_tlb_all() is good enough. */ +/* +* Fetch all the TLB entries. Mask individual VPN values retrieved with +* the corresponding page mask and ignoring any 1KiB extension as we'll +* be using 4KiB pages for uniquification. +*/ +static void __ref r4k_tlb_uniquify_read (struct tlbent *tlb_vpns,int tlbsize) +{ +int start =num_wired_entries (); +unsigned long long vpn_mask; +bool global; +int i; -htw_stop (); + vpn_mask =GENMASK (current_cpu_data.vmbits -1 ,VPN2_SHIFT ); + vpn_mask |= cpu_has_64bits ?3ULL <<62 :1 <<31 ; -for (i = start, cnt =0 ; i < tlbsize; i++, cnt++) { -unsigned long vpn; +for (i =0 ; i < tlbsize; i++) { +unsigned long long entryhi, vpn, mask, asid; +unsigned int pagesz;write_c0_index (i);mtc0_tlbr_hazard ();tlb_read ();tlb_read_hazard (); - vpn =read_c0_entryhi (); - vpn &= vpn_mask &PAGE_MASK ; - tlb_vpns[cnt] = vpn; -/* Prevent any large pages from overlapping regular ones. */ -write_c0_pagemask (read_c0_pagemask () &PM_DEFAULT_MASK ); -mtc0_tlbw_hazard (); -tlb_write_indexed (); -tlbw_use_hazard (); + global = !!(read_c0_entrylo0 () &ENTRYLO_G ); + entryhi =read_c0_entryhi_native (); + mask =read_c0_pagemask (); + + asid = entryhi &cpu_asid_mask (¤t_cpu_data); + vpn = (entryhi & vpn_mask & ~mask) >>VPN2_SHIFT ; + pagesz =ilog2 ((mask >>VPN2_SHIFT ) +1 ); + + tlb_vpns[i].global = global; + tlb_vpns[i].asid = global ?0 : asid; + tlb_vpns[i].vpn = vpn; + tlb_vpns[i].pagesz = pagesz; + tlb_vpns[i].wired = i < start; + tlb_vpns[i].index = i; } +} -sort (tlb_vpns, cnt,sizeof (tlb_vpns[0 ]), r4k_vpn_cmp,NULL ); +/* +* Write unique values to all but the wired TLB entries each, using +* the 4KiB page size. This size might not be supported with R6, but +* EHINV is mandatory for R6, so we won't ever be called in that case. +* +* A sorted table is supplied with any wired entries at the beginning, +* followed by any global entries, and then finally regular entries. +* We start at the VPN and ASID values of zero and only assign user +* addresses, therefore guaranteeing no clash with addresses produced +* by UNIQUE_ENTRYHI. We avoid any VPN values used by wired or global +* entries, by increasing the VPN value beyond the span of such entry. +* +* When a VPN/ASID clash is found with a regular entry we increment the +* ASID instead until no VPN/ASID clash has been found or the ASID space +* has been exhausted, in which case we increase the VPN value beyond +* the span of the largest clashing entry. +* +* We do not need to be concerned about FTLB or MMID configurations as +* those are required to implement the EHINV feature. +*/ +static void __ref r4k_tlb_uniquify_write (struct tlbent *tlb_vpns,int tlbsize) +{ +unsigned long long asid, vpn, vpn_size, pagesz; +int widx, gidx, idx, sidx, lidx, i; -write_c0_pagemask (PM_DEFAULT_MASK ); + vpn_size =1ULL << (current_cpu_data.vmbits -VPN2_SHIFT ); + pagesz =ilog2 ((PM_4K >>VPN2_SHIFT ) +1 ); + +write_c0_pagemask (PM_4K );write_c0_entrylo0 (0 );write_c0_entrylo1 (0 ); - idx =0 ; - ent = tlbsize; -for (i = start; i < tlbsize; i++) -while (1 ) { -unsigned long entryhi, vpn; + asid =0 ; + vpn =0 ; + widx =0 ; + gidx =0 ; +for (sidx =0 ; sidx < tlbsize && tlb_vpns[sidx].wired; sidx++) + ; +for (lidx = sidx; lidx < tlbsize && tlb_vpns[lidx].global; lidx++) + ; + idx = gidx = sidx +1 ; +for (i = sidx; i < tlbsize; i++) { +unsigned long long entryhi, vpn_pagesz =0 ; - entryhi =UNIQUE_ENTRYHI (ent); - vpn = entryhi & vpn_mask &PAGE_MASK ; +while (1 ) { +if (WARN_ON (vpn >= vpn_size)) { +dump_tlb_all (); +/* Pray local_flush_tlb_all() will cope. */ +return ; + } -if (idx >= cnt || vpn < tlb_vpns[idx]) { -write_c0_entryhi (entryhi); -write_c0_index (i); -mtc0_tlbw_hazard (); -tlb_write_indexed (); - ent++; -break ; - }else if (vpn == tlb_vpns[idx]) { - ent++; - }else { +/* VPN must be below the next wired entry. */ +if (widx < sidx && vpn >= tlb_vpns[widx].vpn) { + vpn =max (vpn, + (tlb_vpns[widx].vpn + + (1ULL << tlb_vpns[widx].pagesz))); + asid =0 ; + widx++; +continue ; + } +/* VPN must be below the next global entry. */ +if (gidx < lidx && vpn >= tlb_vpns[gidx].vpn) { + vpn =max (vpn, + (tlb_vpns[gidx].vpn + + (1ULL << tlb_vpns[gidx].pagesz))); + asid =0 ; + gidx++; +continue ; + } +/* Try to find a free ASID so as to conserve VPNs. */ +if (idx < tlbsize && vpn == tlb_vpns[idx].vpn && + asid == tlb_vpns[idx].asid) { +unsigned long long idx_pagesz; + + idx_pagesz = tlb_vpns[idx].pagesz; + vpn_pagesz =max (vpn_pagesz, idx_pagesz); +do + idx++; +while (idx < tlbsize && + vpn == tlb_vpns[idx].vpn && + asid == tlb_vpns[idx].asid); + asid++; +if (asid >cpu_asid_mask (¤t_cpu_data)) { + vpn += vpn_pagesz; + asid =0 ; + vpn_pagesz =0 ; + } +continue ; + } +/* VPN mustn't be above the next regular entry. */ +if (idx < tlbsize && vpn > tlb_vpns[idx].vpn) { + vpn =max (vpn, + (tlb_vpns[idx].vpn + + (1ULL << tlb_vpns[idx].pagesz))); + asid =0 ; idx++; +continue ; } +break ; } + entryhi = (vpn <<VPN2_SHIFT ) | asid; +write_c0_entryhi_native (entryhi); +write_c0_index (tlb_vpns[i].index); +mtc0_tlbw_hazard (); +tlb_write_indexed (); + + tlb_vpns[i].asid = asid; + tlb_vpns[i].vpn = vpn; + tlb_vpns[i].pagesz = pagesz; + + asid++; +if (asid >cpu_asid_mask (¤t_cpu_data)) { + vpn +=1ULL << pagesz; + asid =0 ; + } + } +} + +/* +* Initialise all TLB entries with unique values that do not clash with +* what we have been handed over and what we'll be using ourselves. +*/ +static void __ref r4k_tlb_uniquify (void ) +{ +int tlbsize = current_cpu_data.tlbsize; +bool use_slab =slab_is_available (); +phys_addr_t tlb_vpn_size; +struct tlbent *tlb_vpns; + + tlb_vpn_size = tlbsize *sizeof (*tlb_vpns); + tlb_vpns = (use_slab ? +kmalloc (tlb_vpn_size,GFP_ATOMIC ) : +memblock_alloc_raw (tlb_vpn_size,sizeof (*tlb_vpns))); +if (WARN_ON (!tlb_vpns)) +return ;/* Pray local_flush_tlb_all() is good enough. */ + +htw_stop (); + +r4k_tlb_uniquify_read (tlb_vpns, tlbsize); + +sort (tlb_vpns, tlbsize,sizeof (*tlb_vpns), r4k_entry_cmp,NULL ); + +r4k_tlb_uniquify_write (tlb_vpns, tlbsize); + +write_c0_pagemask (PM_DEFAULT_MASK ); +tlbw_use_hazard ();htw_start ();flush_micro_tlb ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 10/55 media: uvcvideo: Mark invalid entities with id UVC_INVALID_ENTITY_ID
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thadeu Lima de Souza Cascardo <[email protected]>
[ Upstream commit 0e2ee70291e64a30fe36960c85294726d34a103e ]
Per UVC 1.1+ specification 3.7.2, units and terminals must have a non-zero unique ID.
``` Each Unit and Terminal within the video function is assigned a unique identification number, the Unit ID (UID) or Terminal ID (TID), contained in the bUnitID or bTerminalID field of the descriptor. The value 0x00 is reserved for undefined ID, ```
If we add a new entity with id 0 or a duplicated ID, it will be marked as UVC_INVALID_ENTITY_ID.
In a previous attempt commit 3dd075fe8ebb ("media: uvcvideo: Require entities to have a non-zero unique ID"), we ignored all the invalid units, this broke a lot of non-compatible cameras. Hopefully we are more lucky this time.
This also prevents some syzkaller reproducers from triggering warnings due to a chain of entities referring to themselves. In one particular case, an Output Unit is connected to an Input Unit, both with the same ID of 1. But when looking up for the source ID of the Output Unit, that same entity is found instead of the input entity, which leads to such warnings.
In another case, a backward chain was considered finished as the source ID was 0. Later on, that entity was found, but its pads were not valid.
Here is a sample stack trace for one of those cases.
[ 20.650953] usb 1-1: new high-speed USB device number 2 using dummy_hcd [ 20.830206] usb 1-1: Using ep0 maxpacket: 8 [ 20.833501] usb 1-1: config 0 descriptor?? [ 21.038518] usb 1-1: string descriptor 0 read error: -71 [ 21.038893] usb 1-1: Found UVC 0.00 device <unnamed> (2833:0201) [ 21.039299] uvcvideo 1-1:0.0: Entity type for entity Output 1 was not initialized! [ 21.041583] uvcvideo 1-1:0.0: Entity type for entity Input 1 was not initialized! [ 21.042218] ------------[ cut here ]------------ [ 21.042536] WARNING: CPU: 0 PID: 9 at drivers/media/mc/mc-entity.c:1147 media_create_pad_link+0x2c4/0x2e0 [ 21.043195] Modules linked in: [ 21.043535] CPU: 0 UID: 0 PID: 9 Comm: kworker/0:1 Not tainted 6.11.0-rc7-00030-g3480e43aeccf #444 [ 21.044101] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.15.0-1 04/01/2014 [ 21.044639] Workqueue: usb_hub_wq hub_event [ 21.045100] RIP: 0010:media_create_pad_link+0x2c4/0x2e0 [ 21.045508] Code: fe e8 20 01 00 00 b8 f4 ff ff ff 48 83 c4 30 5b 41 5c 41 5d 41 5e 41 5f 5d c3 cc cc cc cc 0f 0b eb e9 0f 0b eb 0a 0f 0b eb 06 <0f> 0b eb 02 0f 0b b8 ea ff ff ff eb d4 66 2e 0f 1f 84 00 00 00 00 [ 21.046801] RSP: 0018:ffffc9000004b318 EFLAGS: 00010246 [ 21.047227] RAX: ffff888004e5d458 RBX: 0000000000000000 RCX: ffffffff818fccf1 [ 21.047719] RDX: 000000000000007b RSI: 0000000000000000 RDI: ffff888004313290 [ 21.048241] RBP: ffff888004313290 R08: 0001ffffffffffff R09: 0000000000000000 [ 21.048701] R10: 0000000000000013 R11: 0001888004313290 R12: 0000000000000003 [ 21.049138] R13: ffff888004313080 R14: ffff888004313080 R15: 0000000000000000 [ 21.049648] FS: 0000000000000000(0000) GS:ffff88803ec00000(0000) knlGS:0000000000000000 [ 21.050271] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 21.050688] CR2: 0000592cc27635b0 CR3: 000000000431c000 CR4: 0000000000750ef0 [ 21.051136] PKRU: 55555554 [ 21.051331] Call Trace: [ 21.051480] <TASK> [ 21.051611] ? __warn+0xc4/0x210 [ 21.051861] ? media_create_pad_link+0x2c4/0x2e0 [ 21.052252] ? report_bug+0x11b/0x1a0 [ 21.052540] ? trace_hardirqs_on+0x31/0x40 [ 21.052901] ? handle_bug+0x3d/0x70 [ 21.053197] ? exc_invalid_op+0x1a/0x50 [ 21.053511] ? asm_exc_invalid_op+0x1a/0x20 [ 21.053924] ? media_create_pad_link+0x91/0x2e0 [ 21.054364] ? media_create_pad_link+0x2c4/0x2e0 [ 21.054834] ? media_create_pad_link+0x91/0x2e0 [ 21.055131] ? _raw_spin_unlock+0x1e/0x40 [ 21.055441] ? __v4l2_device_register_subdev+0x202/0x210 [ 21.055837] uvc_mc_register_entities+0x358/0x400 [ 21.056144] uvc_register_chains+0x1fd/0x290 [ 21.056413] uvc_probe+0x380e/0x3dc0 [ 21.056676] ? __lock_acquire+0x5aa/0x26e0 [ 21.056946] ? find_held_lock+0x33/0xa0 [ 21.057196] ? kernfs_activate+0x70/0x80 [ 21.057533] ? usb_match_dynamic_id+0x1b/0x70 [ 21.057811] ? find_held_lock+0x33/0xa0 [ 21.058047] ? usb_match_dynamic_id+0x55/0x70 [ 21.058330] ? lock_release+0x124/0x260 [ 21.058657] ? usb_match_one_id_intf+0xa2/0x100 [ 21.058997] usb_probe_interface+0x1ba/0x330 [ 21.059399] really_probe+0x1ba/0x4c0 [ 21.059662] __driver_probe_device+0xb2/0x180 [ 21.059944] driver_probe_device+0x5a/0x100 [ 21.060170] __device_attach_driver+0xe9/0x160 [ 21.060427] ? __pfx___device_attach_driver+0x10/0x10 [ 21.060872] bus_for_each_drv+0xa9/0x100 [ 21.061312] __device_attach+0xed/0x190 [ 21.061812] device_initial_probe+0xe/0x20 [ 21.062229] bus_probe_device+0x4d/0xd0 [ 21.062590] device_add+0x308/0x590 [ 21.062912] usb_set_configuration+0x7b6/0xaf0 [ 21.063403] usb_generic_driver_probe+0x36/0x80 [ 21.063714] usb_probe_device+0x7b/0x130 [ 21.063936] really_probe+0x1ba/0x4c0 [ 21.064111] __driver_probe_device+0xb2/0x180 [ 21.064577] driver_probe_device+0x5a/0x100 [ 21.065019] __device_attach_driver+0xe9/0x160 [ 21.065403] ? __pfx___device_attach_driver+0x10/0x10 [ 21.065820] bus_for_each_drv+0xa9/0x100 [ 21.066094] __device_attach+0xed/0x190 [ 21.066535] device_initial_probe+0xe/0x20 [ 21.066992] bus_probe_device+0x4d/0xd0 [ 21.067250] device_add+0x308/0x590 [ 21.067501] usb_new_device+0x347/0x610 [ 21.067817] hub_event+0x156b/0x1e30 [ 21.068060] ? process_scheduled_works+0x48b/0xaf0 [ 21.068337] process_scheduled_works+0x5a3/0xaf0 [ 21.068668] worker_thread+0x3cf/0x560 [ 21.068932] ? kthread+0x109/0x1b0 [ 21.069133] kthread+0x197/0x1b0 [ 21.069343] ? __pfx_worker_thread+0x10/0x10 [ 21.069598] ? __pfx_kthread+0x10/0x10 [ 21.069908] ret_from_fork+0x32/0x40 [ 21.070169] ? __pfx_kthread+0x10/0x10 [ 21.070424] ret_from_fork_asm+0x1a/0x30 [ 21.070737] </TASK>
--- drivers/media/usb/uvc/uvc_driver.c | 73 +++++++++++++++++++----------- drivers/media/usb/uvc/uvcvideo.h | 2 + 2 files changed, 48 insertions(+), 27 deletions(-)
drivers/media/usb/uvc/uvc_driver.c +46 -27
@@ -134,6 +134,9 @@ struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id) {struct uvc_entity *entity; +if (id ==UVC_INVALID_ENTITY_ID ) +return NULL ; +list_for_each_entry (entity, &dev->entities, list) {if (entity->id == id)return entity;
@@ -757,14 +760,27 @@ static const u8 uvc_media_transport_input_guid[16] =UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT ;static const u8 uvc_processing_guid[16 ] =UVC_GUID_UVC_PROCESSING ; -static struct uvc_entity *uvc_alloc_entity (u16 type,u16 id, -unsigned int num_pads,unsigned int extra_size) +static struct uvc_entity *uvc_alloc_new_entity (struct uvc_device *dev,u16 type, +u16 id,unsigned int num_pads, +unsigned int extra_size) {struct uvc_entity *entity;unsigned int num_inputs;unsigned int size;unsigned int i; +/* Per UVC 1.1+ spec 3.7.2, the ID should be non-zero. */ +if (id ==0 ) { +dev_err (&dev->intf->dev,"Found Unit with invalid ID 0\n" ); + id =UVC_INVALID_ENTITY_ID ; + } + +/* Per UVC 1.1+ spec 3.7.2, the ID is unique. */ +if (uvc_entity_by_id (dev, id)) { +dev_err (&dev->intf->dev,"Found multiple Units with ID %u\n" , id); + id =UVC_INVALID_ENTITY_ID ; + } + extra_size =roundup (extra_size,sizeof (*entity->pads));if (num_pads) num_inputs = type &UVC_TERM_OUTPUT ? num_pads : num_pads -1 ;
@@ -774,7 +790,7 @@ static struct uvc_entity *uvc_alloc_entity(u16 type, u16 id, + num_inputs; entity =kzalloc (size,GFP_KERNEL );if (entity ==NULL ) -return NULL ; +return ERR_PTR (-ENOMEM ); entity->id = id; entity->type = type;
@@ -865,10 +881,10 @@ static int uvc_parse_vendor_control(struct uvc_device *dev,break ; } - unit =uvc_alloc_entity (UVC_VC_EXTENSION_UNIT , buffer[3 ], - p +1 ,2 *n); -if (unit ==NULL ) -return -ENOMEM ; + unit =uvc_alloc_new_entity (dev,UVC_VC_EXTENSION_UNIT , + buffer[3 ], p +1 ,2 * n); +if (IS_ERR (unit)) +return PTR_ERR (unit);memcpy (unit->guid, &buffer[4 ],16 ); unit->extension.bNumControls = buffer[20 ];
@@ -978,10 +994,10 @@ static int uvc_parse_standard_control(struct uvc_device *dev,return -EINVAL ; } - term =uvc_alloc_entity (type |UVC_TERM_INPUT , buffer[3 ], -1 , n + p); -if (term ==NULL ) -return -ENOMEM ; + term =uvc_alloc_new_entity (dev, type |UVC_TERM_INPUT , + buffer[3 ],1 , n + p); +if (IS_ERR (term)) +return PTR_ERR (term);if (UVC_ENTITY_TYPE (term) ==UVC_ITT_CAMERA ) { term->camera.bControlSize = n;
@@ -1038,10 +1054,10 @@ static int uvc_parse_standard_control(struct uvc_device *dev,return 0 ; } - term =uvc_alloc_entity (type |UVC_TERM_OUTPUT , buffer[3 ], -1 ,0 ); -if (term ==NULL ) -return -ENOMEM ; + term =uvc_alloc_new_entity (dev, type |UVC_TERM_OUTPUT , + buffer[3 ],1 ,0 ); +if (IS_ERR (term)) +return PTR_ERR (term);memcpy (term->baSourceID, &buffer[7 ],1 );
@@ -1062,9 +1078,10 @@ static int uvc_parse_standard_control(struct uvc_device *dev,return -EINVAL ; } - unit =uvc_alloc_entity (buffer[2 ], buffer[3 ], p +1 ,0 ); -if (unit ==NULL ) -return -ENOMEM ; + unit =uvc_alloc_new_entity (dev, buffer[2 ], buffer[3 ], + p +1 ,0 ); +if (IS_ERR (unit)) +return PTR_ERR (unit);memcpy (unit->baSourceID, &buffer[5 ], p);
@@ -1086,9 +1103,9 @@ static int uvc_parse_standard_control(struct uvc_device *dev,return -EINVAL ; } - unit =uvc_alloc_entity (buffer[2 ], buffer[3 ],2 , n); -if (unit ==NULL ) -return -ENOMEM ; + unit =uvc_alloc_new_entity (dev, buffer[2 ], buffer[3 ],2 , n); +if (IS_ERR (unit)) +return PTR_ERR (unit);memcpy (unit->baSourceID, &buffer[4 ],1 ); unit->processing.wMaxMultiplier =
@@ -1117,9 +1134,10 @@ static int uvc_parse_standard_control(struct uvc_device *dev,return -EINVAL ; } - unit =uvc_alloc_entity (buffer[2 ], buffer[3 ], p +1 , n); -if (unit ==NULL ) -return -ENOMEM ; + unit =uvc_alloc_new_entity (dev, buffer[2 ], buffer[3 ], + p +1 , n); +if (IS_ERR (unit)) +return PTR_ERR (unit);memcpy (unit->guid, &buffer[4 ],16 ); unit->extension.bNumControls = buffer[20 ];
@@ -1260,9 +1278,10 @@ static int uvc_gpio_parse(struct uvc_device *dev)return dev_err_probe (&dev->intf->dev, irq,"No IRQ for privacy GPIO\n" ); - unit =uvc_alloc_entity (UVC_EXT_GPIO_UNIT ,UVC_EXT_GPIO_UNIT_ID ,0 ,1 ); -if (!unit) -return -ENOMEM ; + unit =uvc_alloc_new_entity (dev,UVC_EXT_GPIO_UNIT , +UVC_EXT_GPIO_UNIT_ID ,0 ,1 ); +if (IS_ERR (unit)) +return PTR_ERR (unit); unit->gpio.gpio_privacy = gpio_privacy; unit->gpio.irq = irq;
drivers/media/usb/uvc/uvcvideo.h +2 -0
@@ -41,6 +41,8 @@#define UVC_EXT_GPIO_UNIT 0x7ffe#define UVC_EXT_GPIO_UNIT_ID 0x100 +#define UVC_INVALID_ENTITY_ID 0xffff +/* ------------------------------------------------------------------------ * Driver specific constants. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 11/55 media: uvcvideo: Use heuristic to find stream entity
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ricardo Ribalda <[email protected]>
[ Upstream commit 758dbc756aad429da11c569c0d067f7fd032bcf7 ]
Some devices, like the Grandstream GUV3100 webcam, have an invalid UVC descriptor where multiple entities share the same ID, this is invalid and makes it impossible to make a proper entity tree without heuristics.
We have recently introduced a change in the way that we handle invalid entities that has caused a regression on broken devices.
Implement a new heuristic to handle these devices properly.
--- drivers/media/usb/uvc/uvc_driver.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/media/usb/uvc/uvc_driver.c +14 -1
@@ -164,13 +164,26 @@ static struct uvc_entity *uvc_entity_by_reference(struct uvc_device *dev,static struct uvc_streaming *uvc_stream_by_id (struct uvc_device *dev,int id) { -struct uvc_streaming *stream; +struct uvc_streaming *stream, *last_stream; +unsigned int count =0 ;list_for_each_entry (stream, &dev->streams, list) { + count +=1 ; + last_stream = stream;if (stream->header.bTerminalLink == id)return stream; } +/* +* If the streaming entity is referenced by an invalid ID, notify the +* user and use heuristics to guess the correct entity. +*/ +if (count ==1 && id ==UVC_INVALID_ENTITY_ID ) { +dev_warn (&dev->intf->dev, +"UVC non compliance: Invalid USB header. The streaming entity has an invalid ID, guessing the correct one." ); +return last_stream; + } +return NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 12/55 apparmor: validate DFA start states are in bounds in unpack_pdb
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Massimiliano Pellizzer <[email protected]>
commit 9063d7e2615f4a7ab321de6b520e23d370e58816 upstream.
Backport for conflicts caused byad596ea74e74 ("apparmor: group dfa policydb unpacking") which rearrange and consolidated the unpack.
Start states are read from untrusted data and used as indexes into the DFA state tables. The aa_dfa_next() function call in unpack_pdb() will access dfa->tables[YYTD_ID_BASE][start], and if the start state exceeds the number of states in the DFA, this results in an out-of-bound read.
==================================================================
BUG: KASAN: slab-out-of-bounds in aa_dfa_next+0x2a1/0x360 Read of size 4 at addr ffff88811956fb90 by task su/1097 ...
Reject policies with out-of-bounds start states during unpacking to prevent the issue.
--- security/apparmor/policy_unpack.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)
security/apparmor/policy_unpack.c +19 -2
@@ -824,9 +824,18 @@ static struct aa_profile *unpack_profile error = -EPROTO ; goto fail; } -if (!aa_unpack_u32 (e, &profile->policy.start[0 ],"start" )) +if (!aa_unpack_u32 (e, &profile->policy.start[0 ],"start" )) {/* default start state */ profile->policy.start[0 ] =DFA_START ; + }else { +size_t state_count = profile->policy.dfa->tables[YYTD_ID_BASE ]->td_lolen; + +if (profile->policy.start[0 ] >= state_count) { + info ="invalid dfa start state" ; + goto fail; + } + } +/* setup class index */ for (i =AA_CLASS_FILE ; i <=AA_CLASS_LAST ; i++) { profile->policy.start[i] =
@@ -847,9 +856,17 @@ static struct aa_profile *unpack_profile info ="failed to unpack profile file rules" ; goto fail; }else if (profile->file.dfa) { -if (!aa_unpack_u32 (e, &profile->file.start,"dfa_start" )) +if (!aa_unpack_u32 (e, &profile->file.start,"dfa_start" )) {/* default start state */ profile->file.start =DFA_START ; + }else { +size_t state_count = profile->file.dfa->tables[YYTD_ID_BASE ]->td_lolen; + +if (profile->file.start >= state_count) { + info ="invalid dfa start state" ; + goto fail; + } + } }else if (profile->policy.dfa && profile->policy.start[AA_CLASS_FILE ]) { profile->file.dfa =aa_get_dfa (profile->policy.dfa);
Greg Kroah-Hartman
maintainerPATCH 13/55 apparmor: fix memory leak in verify_header
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Massimiliano Pellizzer <[email protected]>
commit e38c55d9f834e5b848bfed0f5c586aaf45acb825 upstream.
The function sets *ns = NULL on every call, leaking the namespace string allocated in previous iterations when multiple profiles are unpacked. This also breaks namespace consistency checking since *ns is always NULL when the comparison is made.
Remove the incorrect assignment.
The caller (aa_unpack) initializes *ns to NULL once before the loop, which is sufficient.
--- security/apparmor/policy_unpack.c | 1 - 1 file changed, 1 deletion(-)
security/apparmor/policy_unpack.c +0 -1
@@ -959,7 +959,6 @@ static int verify_header(struct aa_ext * {int error = -EPROTONOSUPPORT ;const char *name =NULL ; - *ns =NULL ;/* get the interface version */ if (!aa_unpack_u32 (e, &e->version,"version" )) {
Greg Kroah-Hartman
maintainerPATCH 14/55 apparmor: replace recursive profile removal with iterative approach
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Massimiliano Pellizzer <[email protected]>
commit ab09264660f9de5d05d1ef4e225aa447c63a8747 upstream.
The profile removal code uses recursion when removing nested profiles, which can lead to kernel stack exhaustion and system crashes.
Reproducer:
$ pf='a'; for ((i=0; i<1024; i++)); do
echo -e "profile $pf { \n }" | apparmor_parser -K -a;
pf="$pf//x";
done
$ echo -n a > /sys/kernel/security/apparmor/.removeReplace the recursive __aa_profile_list_release() approach with an iterative approach in __remove_profile(). The function repeatedly finds and removes leaf profiles until the entire subtree is removed, maintaining the same removal semantic without recursion.
--- security/apparmor/policy.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-)
security/apparmor/policy.c +27 -3
@@ -146,19 +146,43 @@ static void __list_remove_profile(struct }/** -* __remove_profile - remove old profile, and children -* @profile: profile to be replaced (NOT NULL) +* __remove_profile - remove profile, and children +* @profile: profile to be removed (NOT NULL) * * Requires: namespace list lock be held, or list not be shared */ static void __remove_profile (struct aa_profile *profile) { +struct aa_profile *curr, *to_remove; +AA_BUG (!profile);AA_BUG (!profile->ns);AA_BUG (!mutex_is_locked (&profile->ns->lock));/* release any children lists first */ -__aa_profile_list_release (&profile->base.profiles); +if (!list_empty (&profile->base.profiles)) { + curr = list_first_entry(&profile->base.profiles, struct aa_profile, base.list); + +while (curr != profile) { + +while (!list_empty (&curr->base.profiles)) + curr =list_first_entry (&curr->base.profiles, + struct aa_profile, base.list); + + to_remove = curr; +if (!list_is_last (&to_remove->base.list, + &aa_deref_parent (curr)->base.profiles)) + curr =list_next_entry (to_remove, base.list); +else + curr =aa_deref_parent (curr); + +/* released by free_profile */ +aa_label_remove (&to_remove->label); +__aafs_profile_rmdir (to_remove); +__list_remove_profile (to_remove); + } + } +/* released by free_profile */ aa_label_remove (&profile->label);__aafs_profile_rmdir (profile);
Greg Kroah-Hartman
maintainerPATCH 15/55 apparmor: fix: limit the number of levels of policy namespaces
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Johansen <[email protected]>
commit 306039414932c80f8420695a24d4fe10c84ccfb2 upstream.
Currently the number of policy namespaces is not bounded relying on the user namespace limit. However policy namespaces aren't strictly tied to user namespaces and it is possible to create them and nest them arbitrarily deep which can be used to exhaust system resource.
Hard cap policy namespaces to the same depth as user namespaces.
--- security/apparmor/include/policy_ns.h | 2 ++ security/apparmor/policy_ns.c | 2 ++ 2 files changed, 4 insertions(+)
security/apparmor/include/policy_ns.h +2 -0
@@ -18,6 +18,8 @@#include "label.h" #include "policy.h" +/* Match max depth of user namespaces */ +#define MAX_NS_DEPTH 32/* struct aa_ns_acct - accounting of profiles in namespace * @max_size: maximum space allowed for all profiles in namespace
security/apparmor/policy_ns.c +2 -0
@@ -262,6 +262,8 @@ static struct aa_ns *__aa_create_ns(struAA_BUG (!name);AA_BUG (!mutex_is_locked (&parent->lock)); +if (parent->level >MAX_NS_DEPTH ) +return ERR_PTR (-ENOSPC ); ns =alloc_ns (parent->base.hname, name);if (!ns)return ERR_PTR (-ENOMEM );
Greg Kroah-Hartman
maintainerPATCH 16/55 apparmor: fix side-effect bug in match_char() macro usage
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Massimiliano Pellizzer <[email protected]>
commit 8756b68edae37ff546c02091989a4ceab3f20abd upstream.
The match_char() macro evaluates its character parameter multiple times when traversing differential encoding chains. When invoked with *str++, the string pointer advances on each iteration of the inner do-while loop, causing the DFA to check different characters at each iteration and therefore skip input characters. This results in out-of-bounds reads when the pointer advances past the input buffer boundary.
[ 94.984676] ================================================================== [ 94.985301] BUG: KASAN: slab-out-of-bounds in aa_dfa_match+0x5ae/0x760 [ 94.985655] Read of size 1 at addr ffff888100342000 by task file/976
[ 94.986319] CPU: 7 UID: 1000 PID: 976 Comm: file Not tainted 6.19.0-rc7-next-20260127 #1 PREEMPT(lazy) [ 94.986322] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 [ 94.986329] Call Trace: [ 94.986341] <TASK> [ 94.986347] dump_stack_lvl+0x5e/0x80 [ 94.986374] print_report+0xc8/0x270 [ 94.986384] ? aa_dfa_match+0x5ae/0x760 [ 94.986388] kasan_report+0x118/0x150 [ 94.986401] ? aa_dfa_match+0x5ae/0x760 [ 94.986405] aa_dfa_match+0x5ae/0x760 [ 94.986408] __aa_path_perm+0x131/0x400 [ 94.986418] aa_path_perm+0x219/0x2f0 [ 94.986424] apparmor_file_open+0x345/0x570 [ 94.986431] security_file_open+0x5c/0x140 [ 94.986442] do_dentry_open+0x2f6/0x1120 [ 94.986450] vfs_open+0x38/0x2b0 [ 94.986453] ? may_open+0x1e2/0x2b0 [ 94.986466] path_openat+0x231b/0x2b30 [ 94.986469] ? __x64_sys_openat+0xf8/0x130 [ 94.986477] do_file_open+0x19d/0x360 [ 94.986487] do_sys_openat2+0x98/0x100 [ 94.986491] __x64_sys_openat+0xf8/0x130 [ 94.986499] do_syscall_64+0x8e/0x660 [ 94.986515] ? count_memcg_events+0x15f/0x3c0 [ 94.986526] ? srso_alias_return_thunk+0x5/0xfbef5 [ 94.986540] ? handle_mm_fault+0x1639/0x1ef0 [ 94.986551] ? vma_start_read+0xf0/0x320 [ 94.986558] ? srso_alias_return_thunk+0x5/0xfbef5 [ 94.986561] ? srso_alias_return_thunk+0x5/0xfbef5 [ 94.986563] ? fpregs_assert_state_consistent+0x50/0xe0 [ 94.986572] ? srso_alias_return_thunk+0x5/0xfbef5 [ 94.986574] ? arch_exit_to_user_mode_prepare+0x9/0xb0 [ 94.986587] ? srso_alias_return_thunk+0x5/0xfbef5 [ 94.986588] ? irqentry_exit+0x3c/0x590 [ 94.986595] entry_SYSCALL_64_after_hwframe+0x76/0x7e [ 94.986597] RIP: 0033:0x7fda4a79c3ea
Fix by extracting the character value before invoking match_char, ensuring single evaluation per outer loop.
--- security/apparmor/match.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-)
security/apparmor/match.c +20 -10
@@ -452,13 +452,18 @@ unsigned int aa_dfa_match_len(struct aa_if (dfa->tables[YYTD_ID_EC ]) {/* Equivalence class table defined */ u8 *equiv =EQUIV_TABLE (dfa); -for (; len; len--) -match_char (state, def, base, next, check, - equiv[(u8) *str++]); +for (; len; len--) { +u8 c = equiv[(u8) *str]; + +match_char (state, def, base, next, check, c); + str++; + } }else {/* default is direct to next state */ -for (; len; len--) -match_char (state, def, base, next, check, (u8) *str++); +for (; len; len--) { +match_char (state, def, base, next, check, (u8) *str); + str++; + } }return state;
@@ -493,13 +498,18 @@ unsigned int aa_dfa_match(struct aa_dfa/* Equivalence class table defined */ u8 *equiv =EQUIV_TABLE (dfa);/* default is direct to next state */ -while (*str) -match_char (state, def, base, next, check, - equiv[(u8) *str++]); +while (*str) { +u8 c = equiv[(u8) *str]; + +match_char (state, def, base, next, check, c); + str++; + } }else {/* default is direct to next state */ -while (*str) -match_char (state, def, base, next, check, (u8) *str++); +while (*str) { +match_char (state, def, base, next, check, (u8) *str); + str++; + } }return state;
Greg Kroah-Hartman
maintainerPATCH 17/55 apparmor: fix missing bounds check on DEFAULT table in verify_dfa()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Massimiliano Pellizzer <[email protected]>
commit d352873bbefa7eb39995239d0b44ccdf8aaa79a4 upstream.
The verify_dfa() function only checks DEFAULT_TABLE bounds when the state is not differentially encoded.
When the verification loop traverses the differential encoding chain, it reads k = DEFAULT_TABLE[j] and uses k as an array index without validation. A malformed DFA with DEFAULT_TABLE[j] >= state_count, therefore, causes both out-of-bounds reads and writes.
[ 57.179855] ================================================================== [ 57.180549] BUG: KASAN: slab-out-of-bounds in verify_dfa+0x59a/0x660 [ 57.180904] Read of size 4 at addr ffff888100eadec4 by task su/993
[ 57.181554] CPU: 1 UID: 0 PID: 993 Comm: su Not tainted 6.19.0-rc7-next-20260127 #1 PREEMPT(lazy) [ 57.181558] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 [ 57.181563] Call Trace: [ 57.181572] <TASK> [ 57.181577] dump_stack_lvl+0x5e/0x80 [ 57.181596] print_report+0xc8/0x270 [ 57.181605] ? verify_dfa+0x59a/0x660 [ 57.181608] kasan_report+0x118/0x150 [ 57.181620] ? verify_dfa+0x59a/0x660 [ 57.181623] verify_dfa+0x59a/0x660 [ 57.181627] aa_dfa_unpack+0x1610/0x1740 [ 57.181629] ? __kmalloc_cache_noprof+0x1d0/0x470 [ 57.181640] unpack_pdb+0x86d/0x46b0 [ 57.181647] ? srso_alias_return_thunk+0x5/0xfbef5 [ 57.181653] ? srso_alias_return_thunk+0x5/0xfbef5 [ 57.181656] ? aa_unpack_nameX+0x1a8/0x300 [ 57.181659] aa_unpack+0x20b0/0x4c30 [ 57.181662] ? srso_alias_return_thunk+0x5/0xfbef5 [ 57.181664] ? stack_depot_save_flags+0x33/0x700 [ 57.181681] ? kasan_save_track+0x4f/0x80 [ 57.181683] ? kasan_save_track+0x3e/0x80 [ 57.181686] ? __kasan_kmalloc+0x93/0xb0 [ 57.181688] ? __kvmalloc_node_noprof+0x44a/0x780 [ 57.181693] ? aa_simple_write_to_buffer+0x54/0x130 [ 57.181697] ? policy_update+0x154/0x330 [ 57.181704] aa_replace_profiles+0x15a/0x1dd0 [ 57.181707] ? srso_alias_return_thunk+0x5/0xfbef5 [ 57.181710] ? __kvmalloc_node_noprof+0x44a/0x780 [ 57.181712] ? aa_loaddata_alloc+0x77/0x140 [ 57.181715] ? srso_alias_return_thunk+0x5/0xfbef5 [ 57.181717] ? _copy_from_user+0x2a/0x70 [ 57.181730] policy_update+0x17a/0x330 [ 57.181733] profile_replace+0x153/0x1a0 [ 57.181735] ? rw_verify_area+0x93/0x2d0 [ 57.181740] vfs_write+0x235/0xab0 [ 57.181745] ksys_write+0xb0/0x170 [ 57.181748] do_syscall_64+0x8e/0x660 [ 57.181762] entry_SYSCALL_64_after_hwframe+0x76/0x7e [ 57.181765] RIP: 0033:0x7f6192792eb2
Remove the MATCH_FLAG_DIFF_ENCODE condition to validate all DEFAULT_TABLE entries unconditionally.
--- security/apparmor/match.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
security/apparmor/match.c +3 -2
@@ -204,9 +204,10 @@ static int verify_dfa(struct aa_dfa *dfaif (state_count ==0 ) goto out;for (i =0 ; i < state_count; i++) { -if (!(BASE_TABLE (dfa)[i] &MATCH_FLAG_DIFF_ENCODE ) && - (DEFAULT_TABLE (dfa)[i] >= state_count)) +if (DEFAULT_TABLE (dfa)[i] >= state_count) { +pr_err ("AppArmor DFA default state out of bounds" ); goto out; + }if (BASE_TABLE (dfa)[i] &MATCH_FLAGS_INVALID ) {pr_err ("AppArmor DFA state with invalid match flags" ); goto out;
Greg Kroah-Hartman
maintainerPATCH 18/55 apparmor: Fix double free of ns_name in aa_replace_profiles()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Johansen <[email protected]>
commit 5df0c44e8f5f619d3beb871207aded7c78414502 upstream.
if ns_name is NULL after
1071 error = aa_unpack(udata, &lh, &ns_name);
and if ent->ns_name contains an ns_name in
1089 } else if (ent->ns_name) {
then ns_name is assigned the ent->ns_name
1095 ns_name = ent->ns_name;
however ent->ns_name is freed at
1262 aa_load_ent_free(ent);
and then again when freeing ns_name at
1270 kfree(ns_name);
Fix this by NULLing out ent->ns_name after it is transferred to ns_name
")
--- security/apparmor/policy.c | 1 + 1 file changed, 1 insertion(+)
security/apparmor/policy.c +1 -0
@@ -958,6 +958,7 @@ ssize_t aa_replace_profiles(struct aa_ns goto fail; } ns_name = ent->ns_name; + ent->ns_name =NULL ; }else count++; }
Greg Kroah-Hartman
maintainerPATCH 19/55 apparmor: fix unprivileged local user can do privileged policy management
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Johansen <[email protected]>
commit 6601e13e82841879406bf9f369032656f441a425 upstream.
Backport for api changes introduced in 90c436a64a6e ("apparmor: pass cred through to audit info.")
An unprivileged local user can load, replace, and remove profiles by opening the apparmorfs interfaces, via a confused deputy attack, by passing the opened fd to a privileged process, and getting the privileged process to write to the interface.
This does require a privileged target that can be manipulated to do the write for the unprivileged process, but once such access is achieved full policy management is possible and all the possible implications that implies: removing confinement, DoS of system or target applications by denying all execution, by-passing the unprivileged user namespace restriction, to exploiting kernel bugs for a local privilege escalation.
The policy management interface can not have its permissions simply changed from 0666 to 0600 because non-root processes need to be able to load policy to different policy namespaces.
Instead ensure the task writing the interface has privileges that are a subset of the task that opened the interface. This is already done via policy for confined processes, but unconfined can delegate access to the opened fd, by-passing the usual policy check.
--- security/apparmor/apparmorfs.c | 19 +++++++++++------- security/apparmor/include/policy.h | 5 ++-- security/apparmor/policy.c | 39 +++++++++++++++++++++++++++++++++++-- 3 files changed, 52 insertions(+), 11 deletions(-)
security/apparmor/apparmorfs.c +12 -7
@@ -412,7 +412,8 @@ static struct aa_loaddata *aa_simple_wri }static ssize_t policy_update (u32 mask,const char __user *buf,size_t size, -loff_t *pos,struct aa_ns *ns) +loff_t *pos,struct aa_ns *ns, +const struct cred *ocred) {struct aa_loaddata *data;struct aa_label *label;
@@ -423,7 +424,7 @@ static ssize_t policy_update(u32 mask, c/* high level check about policy management - fine grained in * below after unpack */ - error =aa_may_manage_policy (label, ns, mask); + error =aa_may_manage_policy (current_cred (), label, ns, ocred, mask);if (error) goto end_section;
@@ -444,7 +445,8 @@ static ssize_t profile_load(struct file loff_t *pos) {struct aa_ns *ns =aa_get_ns (f->f_inode->i_private); -int error =policy_update (AA_MAY_LOAD_POLICY , buf, size, pos, ns); +int error =policy_update (AA_MAY_LOAD_POLICY , buf, size, pos, ns, + f->f_cred);aa_put_ns (ns);
@@ -462,7 +464,7 @@ static ssize_t profile_replace(struct fi {struct aa_ns *ns =aa_get_ns (f->f_inode->i_private);int error =policy_update (AA_MAY_LOAD_POLICY |AA_MAY_REPLACE_POLICY , - buf, size, pos, ns); + buf, size, pos, ns, f->f_cred);aa_put_ns (ns);return error;
@@ -486,7 +488,8 @@ static ssize_t profile_remove(struct fil/* high level check about policy management - fine grained in * below after unpack */ - error =aa_may_manage_policy (label, ns,AA_MAY_REMOVE_POLICY ); + error =aa_may_manage_policy (current_cred (), label, ns, + f->f_cred,AA_MAY_REMOVE_POLICY );if (error) goto out;
@@ -1808,7 +1811,8 @@ static int ns_mkdir_op(struct user_namesint error; label =begin_current_label_crit_section (); - error =aa_may_manage_policy (label,NULL ,AA_MAY_LOAD_POLICY ); + error =aa_may_manage_policy (current_cred (), label,NULL ,NULL , +AA_MAY_LOAD_POLICY );end_current_label_crit_section (label);if (error)return error;
@@ -1857,7 +1861,8 @@ static int ns_rmdir_op(struct inode *dirint error; label =begin_current_label_crit_section (); - error =aa_may_manage_policy (label,NULL ,AA_MAY_LOAD_POLICY ); + error =aa_may_manage_policy (current_cred (), label,NULL ,NULL , +AA_MAY_LOAD_POLICY );end_current_label_crit_section (label);if (error)return error;
security/apparmor/include/policy.h +3 -2
@@ -307,8 +307,9 @@ static inline int AUDIT_MODE(struct aa_pbool aa_policy_view_capable (struct aa_label *label,struct aa_ns *ns);bool aa_policy_admin_capable (struct aa_label *label,struct aa_ns *ns); -int aa_may_manage_policy (struct aa_label *label,struct aa_ns *ns, -u32 mask); +int aa_may_manage_policy (const struct cred *subj_cred, +struct aa_label *label,struct aa_ns *ns, +const struct cred *ocred,u32 mask);bool aa_current_policy_view_capable (struct aa_ns *ns);bool aa_current_policy_admin_capable (struct aa_ns *ns);
security/apparmor/policy.c +37 -2
@@ -736,14 +736,44 @@ bool aa_current_policy_admin_capable(strreturn res; } +static bool is_subset_of_obj_privilege (const struct cred *cred, +struct aa_label *label, +const struct cred *ocred) +{ +if (cred == ocred) +return true; + +if (!aa_label_is_subset (label,cred_label (ocred))) +return false; +/* don't allow crossing userns for now */ +if (cred->user_ns != ocred->user_ns) +return false; +if (!cap_issubset (cred->cap_inheritable, ocred->cap_inheritable)) +return false; +if (!cap_issubset (cred->cap_permitted, ocred->cap_permitted)) +return false; +if (!cap_issubset (cred->cap_effective, ocred->cap_effective)) +return false; +if (!cap_issubset (cred->cap_bset, ocred->cap_bset)) +return false; +if (!cap_issubset (cred->cap_ambient, ocred->cap_ambient)) +return false; +return true; +} + +/** * aa_may_manage_policy - can the current task manage policy +* @subj_cred; subjects cred * @label: label to check if it can manage policy -* @op: the policy manipulation operation being done +* @ns: namespace being managed by @label (may be NULL if @label's ns) +* @ocred: object cred if request is coming from an open object +* @mask: contains the policy manipulation operation being done * * Returns: 0 if the task is allowed to manipulate policy else error */ -int aa_may_manage_policy (struct aa_label *label,struct aa_ns *ns,u32 mask) +int aa_may_manage_policy (const struct cred *subj_cred,struct aa_label *label, +struct aa_ns *ns,const struct cred *ocred,u32 mask) {const char *op;
@@ -759,6 +789,11 @@ int aa_may_manage_policy(struct aa_labelreturn audit_policy (label, op,NULL ,NULL ,"policy_locked" , -EACCES ); +if (ocred && !is_subset_of_obj_privilege (subj_cred, label, ocred)) +return audit_policy (label, op,NULL ,NULL , +"not privileged for target profile" , + -EACCES ); +if (!aa_policy_admin_capable (label, ns))return audit_policy (label, op,NULL ,NULL ,"not policy admin" , -EACCES );
Greg Kroah-Hartman
maintainerPATCH 20/55 apparmor: fix differential encoding verification
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Johansen <[email protected]>
commit 39440b137546a3aa383cfdabc605fb73811b6093 upstream.
Differential encoding allows loops to be created if it is abused. To prevent this the unpack should verify that a diff-encode chain terminates.
Unfortunately the differential encode verification had two bugs.
1. it conflated states that had gone through check and already been marked, with states that were currently being checked and marked. This means that loops in the current chain being verified are treated as a chain that has already been verified.
2. the order bailout on already checked states compared current chain check iterators j,k instead of using the outer loop iterator i. Meaning a step backwards in states in the current chain verification was being mistaken for moving to an already verified state.
Move to a double mark scheme where already verified states get a different mark, than the current chain being kept. This enables us to also drop the backwards verification check that was the cause of the second error as any already verified state is already marked.
--- security/apparmor/include/match.h | 1 + security/apparmor/match.c | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-)
security/apparmor/include/match.h +1 -0
@@ -190,6 +190,7 @@ static inline void aa_put_dfa(struct aa_#define MATCH_FLAG_DIFF_ENCODE 0x80000000#define MARK_DIFF_ENCODE 0x40000000#define MATCH_FLAG_OOB_TRANSITION 0x20000000 +#define MARK_DIFF_ENCODE_VERIFIED 0x10000000#define MATCH_FLAGS_MASK 0xff000000#define MATCH_FLAGS_VALID (MATCH_FLAG_DIFF_ENCODE | MATCH_FLAG_OOB_TRANSITION)#define MATCH_FLAGS_INVALID (MATCH_FLAGS_MASK & ~MATCH_FLAGS_VALID)
security/apparmor/match.c +19 -4
@@ -246,16 +246,31 @@ static int verify_dfa(struct aa_dfa *dfasize_t j, k;for (j = i; - (BASE_TABLE (dfa)[j] &MATCH_FLAG_DIFF_ENCODE ) && - !(BASE_TABLE (dfa)[j] &MARK_DIFF_ENCODE ); + ((BASE_TABLE (dfa)[j] &MATCH_FLAG_DIFF_ENCODE ) && + !(BASE_TABLE (dfa)[j] &MARK_DIFF_ENCODE_VERIFIED )); j = k) { +if (BASE_TABLE (dfa)[j] &MARK_DIFF_ENCODE ) +/* loop in current chain */ + goto out; k =DEFAULT_TABLE (dfa)[j];if (j == k) +/* self loop */ goto out; -if (k < j) -break ;/* already verified */ BASE_TABLE (dfa)[j] |=MARK_DIFF_ENCODE ; } +/* move mark to verified */ +for (j = i; + (BASE_TABLE (dfa)[j] &MATCH_FLAG_DIFF_ENCODE ); + j = k) { + k =DEFAULT_TABLE (dfa)[j]; +if (j < i) +/* jumps to state/chain that has been +* verified +*/ +break ; +BASE_TABLE (dfa)[j] &= ~MARK_DIFF_ENCODE ; +BASE_TABLE (dfa)[j] |=MARK_DIFF_ENCODE_VERIFIED ; + } } error =0 ;
Greg Kroah-Hartman
maintainerPATCH 21/55 apparmor: fix race on rawdata dereference
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Johansen <[email protected]>
commit a0b7091c4de45a7325c8780e6934a894f92ac86b upstream.
There is a race condition that leads to a use-after-free situation:
because the rawdata inodes are not refcounted, an attacker can start open()ing one of the rawdata files, and at the same time remove the last reference to this rawdata (by removing the corresponding profile, for example), which frees its struct aa_loaddata; as a result, when seq_rawdata_open() is reached, i_private is a dangling pointer and freed memory is accessed.
The rawdata inodes weren't refcounted to avoid a circular refcount and were supposed to be held by the profile rawdata reference. However during profile removal there is a window where the vfs and profile destruction race, resulting in the use after free.
Fix this by moving to a double refcount scheme. Where the profile refcount on rawdata is used to break the circular dependency. Allowing for freeing of the rawdata once all inode references to the rawdata are put.
--- security/apparmor/apparmorfs.c | 35 ++++++++------ security/apparmor/include/policy_unpack.h | 71 ++++++++++++++++++------------ security/apparmor/policy.c | 12 ++--- security/apparmor/policy_unpack.c | 32 +++++++++---- 4 files changed, 93 insertions(+), 57 deletions(-)
security/apparmor/apparmorfs.c +21 -14
@@ -79,7 +79,7 @@ static void rawdata_f_data_free(struct rif (!private)return ; -aa_put_loaddata (private->loaddata); +aa_put_i_loaddata (private->loaddata);kvfree (private); }
@@ -404,7 +404,8 @@ static struct aa_loaddata *aa_simple_wri data->size = copy_size;if (copy_from_user (data->data, userbuf, copy_size)) { -aa_put_loaddata (data); +/* trigger free - don't need to put pcount */ +aa_put_i_loaddata (data);return ERR_PTR (-EFAULT ); }
@@ -432,7 +433,10 @@ static ssize_t policy_update(u32 mask, c error =PTR_ERR (data);if (!IS_ERR (data)) { error =aa_replace_profiles (ns, label, mask, data); -aa_put_loaddata (data); +/* put pcount, which will put count and free if no +* profiles referencing it. +*/ +aa_put_profile_loaddata (data); } end_section:end_current_label_crit_section (label);
@@ -503,7 +507,7 @@ static ssize_t profile_remove(struct filif (!IS_ERR (data)) { data->data[size] =0 ; error =aa_remove_profiles (ns, label, data->data, size); -aa_put_loaddata (data); +aa_put_profile_loaddata (data); } out:end_current_label_crit_section (label);
@@ -1227,18 +1231,17 @@ static const struct file_operations seq_static int seq_rawdata_open (struct inode *inode,struct file *file,int (*show)(struct seq_file *,void *)) { -struct aa_loaddata *data =__aa_get_loaddata (inode->i_private); +struct aa_loaddata *data =aa_get_i_loaddata (inode->i_private);int error;if (!data) -/* lost race this ent is being reaped */ return -ENOENT ; error =single_open (file, show, data);if (error) {AA_BUG (file->private_data && ((struct seq_file *)file->private_data)->private); -aa_put_loaddata (data); +aa_put_i_loaddata (data); }return error;
@@ -1249,7 +1252,7 @@ static int seq_rawdata_release(struct instruct seq_file *seq = (struct seq_file *) file->private_data;if (seq) -aa_put_loaddata (seq->private); +aa_put_i_loaddata (seq->private);return single_release (inode, file); }
@@ -1371,9 +1374,8 @@ static int rawdata_open(struct inode *inif (!aa_current_policy_view_capable (NULL ))return -EACCES ; - loaddata =__aa_get_loaddata (inode->i_private); + loaddata =aa_get_i_loaddata (inode->i_private);if (!loaddata) -/* lost race: this entry is being reaped */ return -ENOENT ; private =rawdata_f_data_alloc (loaddata->size);
@@ -1398,7 +1400,7 @@ fail_decompress:return error; fail_private_alloc: -aa_put_loaddata (loaddata); +aa_put_i_loaddata (loaddata);return error; }
@@ -1415,9 +1417,9 @@ static void remove_rawdata_dents(structfor (i =0 ; i <AAFS_LOADDATA_NDENTS ; i++) {if (!IS_ERR_OR_NULL (rawdata->dents[i])) { -/* no refcounts on i_private */ aafs_remove (rawdata->dents[i]); rawdata->dents[i] =NULL ; +aa_put_i_loaddata (rawdata); } } }
@@ -1456,18 +1458,21 @@ int __aa_fs_create_rawdata(struct aa_nsif (IS_ERR (dir))/* ->name freed when rawdata freed */ return PTR_ERR (dir); +aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_DIR ] = dir; dent =aafs_create_file ("abi" ,S_IFREG |0444 , dir, rawdata, &seq_rawdata_abi_fops);if (IS_ERR (dent)) goto fail; +aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_ABI ] = dent; dent =aafs_create_file ("revision" ,S_IFREG |0444 , dir, rawdata, &seq_rawdata_revision_fops);if (IS_ERR (dent)) goto fail; +aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_REVISION ] = dent;if (aa_g_hash_policy) {
@@ -1475,6 +1480,7 @@ int __aa_fs_create_rawdata(struct aa_ns rawdata, &seq_rawdata_hash_fops);if (IS_ERR (dent)) goto fail; +aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_HASH ] = dent; }
@@ -1483,24 +1489,25 @@ int __aa_fs_create_rawdata(struct aa_ns &seq_rawdata_compressed_size_fops);if (IS_ERR (dent)) goto fail; +aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_COMPRESSED_SIZE ] = dent; dent =aafs_create_file ("raw_data" ,S_IFREG |0444 , dir, rawdata, &rawdata_fops);if (IS_ERR (dent)) goto fail; +aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_DATA ] = dent;d_inode (dent)->i_size = rawdata->size; rawdata->ns =aa_get_ns (ns);list_add (&rawdata->list, &ns->rawdata_list); -/* no refcount on inode rawdata */ return 0 ; fail:remove_rawdata_dents (rawdata); - +aa_put_i_loaddata (rawdata); return PTR_ERR(dent); }#endif /* CONFIG_SECURITY_APPARMOR_EXPORT_BINARY */
security/apparmor/include/policy_unpack.h +43 -28
112 lines not on this page · raw message
security/apparmor/policy.c +6 -6
@@ -266,7 +266,7 @@ void aa_free_profile(struct aa_profile * }kfree_sensitive (profile->hash); -aa_put_loaddata (profile->rawdata); +aa_put_profile_loaddata (profile->rawdata);aa_label_destroy (&profile->label);kfree_sensitive (profile);
@@ -966,7 +966,7 @@ ssize_t aa_replace_profiles(struct aa_nsLIST_HEAD (lh); op = mask &AA_MAY_REPLACE_POLICY ?OP_PROF_REPL :OP_PROF_LOAD ; -aa_get_loaddata (udata); +aa_get_profile_loaddata (udata);/* released below */ error =aa_unpack (udata, &lh, &ns_name);if (error)
@@ -1018,10 +1018,10 @@ ssize_t aa_replace_profiles(struct aa_nsif (aa_rawdata_eq (rawdata_ent, udata)) {struct aa_loaddata *tmp; - tmp =__aa_get_loaddata (rawdata_ent); + tmp =aa_get_profile_loaddata (rawdata_ent);/* check we didn't fail the race */ if (tmp) { -aa_put_loaddata (udata); +aa_put_profile_loaddata (udata); udata = tmp;break ; }
@@ -1033,7 +1033,7 @@ ssize_t aa_replace_profiles(struct aa_nsstruct aa_policy *policy;if (aa_g_export_binary) - ent->new->rawdata =aa_get_loaddata (udata); + ent->new->rawdata =aa_get_profile_loaddata (udata); error =__lookup_replace (ns, ent->new->base.hname, !(mask &AA_MAY_REPLACE_POLICY ), &ent->old, &info);
@@ -1149,7 +1149,7 @@ ssize_t aa_replace_profiles(struct aa_ns out:aa_put_ns (ns); -aa_put_loaddata (udata); +aa_put_profile_loaddata (udata);kfree (ns_name);if (error)
security/apparmor/policy_unpack.c +23 -9
@@ -112,34 +112,47 @@ bool aa_rawdata_eq(struct aa_loaddata *lreturn memcmp (l->data, r->data, r->compressed_size ?: r->size) ==0 ; } +static void do_loaddata_free (struct aa_loaddata *d) +{ +kfree_sensitive (d->hash); +kfree_sensitive (d->name); +kvfree (d->data); +kfree_sensitive (d); +} + +void aa_loaddata_kref (struct kref *kref) +{ + struct aa_loaddata *d = container_of(kref, struct aa_loaddata, count); + +do_loaddata_free (d); +} +/* * need to take the ns mutex lock which is NOT safe most places that * put_loaddata is called, so we have to delay freeing it */ -static void do_loaddata_free (struct work_struct *work) +static void do_ploaddata_rmfs (struct work_struct *work) { struct aa_loaddata *d = container_of(work, struct aa_loaddata, work);struct aa_ns *ns =aa_get_ns (d->ns);if (ns) {mutex_lock_nested (&ns->lock, ns->level); +/* remove fs ref to loaddata */ __aa_fs_remove_rawdata (d);mutex_unlock (&ns->lock);aa_put_ns (ns); } - -kfree_sensitive (d->hash); -kfree_sensitive (d->name); -kvfree (d->data); -kfree_sensitive (d); +/* called by dropping last pcount, so drop its associated icount */ +aa_put_i_loaddata (d); } -void aa_loaddata_kref (struct kref *kref) +void aa_ploaddata_kref (struct kref *kref) { - struct aa_loaddata *d = container_of(kref, struct aa_loaddata, count); + struct aa_loaddata *d = container_of(kref, struct aa_loaddata, pcount);if (d) { -INIT_WORK (&d->work, do_loaddata_free); +INIT_WORK (&d->work, do_ploaddata_rmfs);schedule_work (&d->work); } }
@@ -157,6 +170,7 @@ struct aa_loaddata *aa_loaddata_alloc(sireturn ERR_PTR (-ENOMEM ); }kref_init (&d->count); +kref_init (&d->pcount);INIT_LIST_HEAD (&d->list);return d;
Greg Kroah-Hartman
maintainerPATCH 22/55 apparmor: fix race between freeing data and fs accessing it
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Johansen <[email protected]>
commit 8e135b8aee5a06c52a4347a5a6d51223c6f36ba3 upstream.
Backport for conflicts introdued by conversion from sha1 to sha256 introduced in
e44a4dc4b36c ("apparmor: switch SECURITY_APPARMOR_HASH from sha1 to sha256")
AppArmor was putting the reference to i_private data on its end after removing the original entry from the file system. However the inode can and does live beyond that point and it is possible that some of the fs call back functions will be invoked after the reference has been put, which results in a race between freeing the data and accessing it through the fs.
While the rawdata/loaddata is the most likely candidate to fail the race, as it has the fewest references. If properly crafted it might be possible to trigger a race for the other types stored in i_private.
Fix this by moving the put of i_private referenced data to the correct place which is during inode eviction.
--- security/apparmor/apparmorfs.c | 194 +++++++++++++++++------------- security/apparmor/include/label.h | 16 +- security/apparmor/include/lib.h | 12 + security/apparmor/include/policy.h | 8 - security/apparmor/include/policy_unpack.h | 6 security/apparmor/label.c | 12 + security/apparmor/policy_unpack.c | 6 7 files changed, 153 insertions(+), 101 deletions(-)
security/apparmor/apparmorfs.c +114 -80
@@ -32,6 +32,7 @@#include "include/crypto.h" #include "include/ipc.h" #include "include/label.h" +#include "include/lib.h" #include "include/policy.h" #include "include/policy_ns.h" #include "include/resource.h"
@@ -62,6 +63,7 @@* securityfs and apparmorfs filesystems. */ +#define IREF_POISON 101/* * support fns
@@ -153,6 +155,71 @@ static int aafs_show_path(struct seq_filreturn 0 ; } +static struct aa_ns *get_ns_common_ref (struct aa_common_ref *ref) +{ +if (ref) { + struct aa_label *reflabel = container_of(ref, struct aa_label, + count); +return aa_get_ns (labels_ns (reflabel)); + } + +return NULL ; +} + +static struct aa_proxy *get_proxy_common_ref (struct aa_common_ref *ref) +{ +if (ref) + return aa_get_proxy(container_of(ref, struct aa_proxy, count)); + +return NULL ; +} + +static struct aa_loaddata *get_loaddata_common_ref (struct aa_common_ref *ref) +{ +if (ref) + return aa_get_i_loaddata(container_of(ref, struct aa_loaddata, + count)); +return NULL ; +} + +static void aa_put_common_ref (struct aa_common_ref *ref) +{ +if (!ref) +return ; + +switch (ref->reftype) { +case REF_RAWDATA : +aa_put_i_loaddata (container_of (ref ,struct aa_loaddata , +count )); +break ; +case REF_PROXY : +aa_put_proxy (container_of (ref ,struct aa_proxy , +count )); +break ; +case REF_NS : +/* ns count is held on its unconfined label */ +aa_put_ns (labels_ns (container_of (ref ,struct aa_label ,count ))); +break ; +default : +AA_BUG (true,"unknown refcount type" ); +break ; + } +} + +static void aa_get_common_ref (struct aa_common_ref *ref) +{ +kref_get (&ref->count); +} + +static void aafs_evict (struct inode *inode) +{ +struct aa_common_ref *ref = inode->i_private; + +clear_inode (inode); +aa_put_common_ref (ref); + inode->i_private = (void *)IREF_POISON ; +} +static void aafs_free_inode (struct inode *inode) {if (S_ISLNK (inode->i_mode))
@@ -162,6 +229,7 @@ static void aafs_free_inode(struct inodestatic const struct super_operations aafs_super_ops = { .statfs = simple_statfs, + .evict_inode = aafs_evict, .free_inode = aafs_free_inode, .show_path = aafs_show_path, };
@@ -262,7 +330,8 @@ static int __aafs_setup_d_inode(struct i* aafs_remove(). Will return ERR_PTR on failure. */ static struct dentry *aafs_create (const char *name,umode_t mode, -struct dentry *parent,void *data,void *link, +struct dentry *parent, +struct aa_common_ref *data,void *link,const struct file_operations *fops,const struct inode_operations *iops) {
@@ -299,6 +368,9 @@ static struct dentry *aafs_create(const goto fail_dentry;inode_unlock (dir); +if (data) +aa_get_common_ref (data); +return dentry; fail_dentry:
@@ -323,7 +395,8 @@ fail_lock:* see aafs_create */ static struct dentry *aafs_create_file (const char *name,umode_t mode, -struct dentry *parent,void *data, +struct dentry *parent, +struct aa_common_ref *data,const struct file_operations *fops) {return aafs_create (name, mode, parent, data,NULL , fops,NULL );
@@ -448,7 +521,7 @@ end_section:static ssize_t profile_load (struct file *f,const char __user *buf,size_t size,loff_t *pos) { -struct aa_ns *ns =aa_get_ns (f->f_inode->i_private); +struct aa_ns *ns =get_ns_common_ref (f->f_inode->i_private);int error =policy_update (AA_MAY_LOAD_POLICY , buf, size, pos, ns, f->f_cred);
@@ -466,7 +539,7 @@ static const struct file_operations aa_fstatic ssize_t profile_replace (struct file *f,const char __user *buf,size_t size,loff_t *pos) { -struct aa_ns *ns =aa_get_ns (f->f_inode->i_private); +struct aa_ns *ns =get_ns_common_ref (f->f_inode->i_private);int error =policy_update (AA_MAY_LOAD_POLICY |AA_MAY_REPLACE_POLICY , buf, size, pos, ns, f->f_cred);aa_put_ns (ns);
@@ -486,7 +559,7 @@ static ssize_t profile_remove(struct filstruct aa_loaddata *data;struct aa_label *label;ssize_t error; -struct aa_ns *ns =aa_get_ns (f->f_inode->i_private); +struct aa_ns *ns =get_ns_common_ref (f->f_inode->i_private); label =begin_current_label_crit_section ();/* high level check about policy management - fine grained in
@@ -576,7 +649,7 @@ static int ns_revision_open(struct inodeif (!rev)return -ENOMEM ; - rev->ns =aa_get_ns (inode->i_private); + rev->ns =get_ns_common_ref (inode->i_private);if (!rev->ns) rev->ns =aa_get_current_ns (); file->private_data = rev;
@@ -1053,7 +1126,7 @@ static const struct file_operations seq_static int seq_profile_open (struct inode *inode,struct file *file,int (*show)(struct seq_file *,void *)) { -struct aa_proxy *proxy =aa_get_proxy (inode->i_private); +struct aa_proxy *proxy =get_proxy_common_ref (inode->i_private);int error =single_open (file, show, proxy);if (error) {
@@ -1231,7 +1304,7 @@ static const struct file_operations seq_static int seq_rawdata_open (struct inode *inode,struct file *file,int (*show)(struct seq_file *,void *)) { -struct aa_loaddata *data =aa_get_i_loaddata (inode->i_private); +struct aa_loaddata *data =get_loaddata_common_ref (inode->i_private);int error;if (!data)
@@ -1374,7 +1447,7 @@ static int rawdata_open(struct inode *inif (!aa_current_policy_view_capable (NULL ))return -EACCES ; - loaddata =aa_get_i_loaddata (inode->i_private); + loaddata =get_loaddata_common_ref (inode->i_private);if (!loaddata)return -ENOENT ;
@@ -1419,7 +1492,6 @@ static void remove_rawdata_dents(structif (!IS_ERR_OR_NULL (rawdata->dents[i])) {aafs_remove (rawdata->dents[i]); rawdata->dents[i] =NULL ; -aa_put_i_loaddata (rawdata); } } }
@@ -1458,45 +1530,41 @@ int __aa_fs_create_rawdata(struct aa_nsif (IS_ERR (dir))/* ->name freed when rawdata freed */ return PTR_ERR (dir); -aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_DIR ] = dir; - dent =aafs_create_file ("abi" ,S_IFREG |0444 , dir, rawdata, + dent =aafs_create_file ("abi" ,S_IFREG |0444 , dir, &rawdata->count, &seq_rawdata_abi_fops);if (IS_ERR (dent)) goto fail; -aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_ABI ] = dent; - dent =aafs_create_file ("revision" ,S_IFREG |0444 , dir, rawdata, - &seq_rawdata_revision_fops); + dent =aafs_create_file ("revision" ,S_IFREG |0444 , dir, + &rawdata->count, + &seq_rawdata_revision_fops);if (IS_ERR (dent)) goto fail; -aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_REVISION ] = dent;if (aa_g_hash_policy) { dent =aafs_create_file ("sha1" ,S_IFREG |0444 , dir, - rawdata, &seq_rawdata_hash_fops); + &rawdata->count, + &seq_rawdata_hash_fops);if (IS_ERR (dent)) goto fail; -aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_HASH ] = dent; } dent =aafs_create_file ("compressed_size" ,S_IFREG |0444 , dir, - rawdata, + &rawdata->count, &seq_rawdata_compressed_size_fops);if (IS_ERR (dent)) goto fail; -aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_COMPRESSED_SIZE ] = dent; - dent =aafs_create_file ("raw_data" ,S_IFREG |0444 , - dir, rawdata, &rawdata_fops); + dent =aafs_create_file ("raw_data" ,S_IFREG |0444 , dir, + &rawdata->count, &rawdata_fops);if (IS_ERR (dent)) goto fail; -aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_DATA ] = dent;d_inode (dent)->i_size = rawdata->size;
@@ -1507,7 +1575,6 @@ int __aa_fs_create_rawdata(struct aa_ns fail:remove_rawdata_dents (rawdata); -aa_put_i_loaddata (rawdata); return PTR_ERR(dent); }#endif /* CONFIG_SECURITY_APPARMOR_EXPORT_BINARY */
@@ -1531,13 +1598,10 @@ void __aafs_profile_rmdir(struct aa_prof__aafs_profile_rmdir (child);for (i =AAFS_PROF_SIZEOF -1 ; i >=0 ; --i) { -struct aa_proxy *proxy;if (!profile->dents[i])continue ; - proxy =d_inode (profile->dents[i])->i_private;aafs_remove (profile->dents[i]); -aa_put_proxy (proxy); profile->dents[i] =NULL ; } }
@@ -1567,14 +1631,7 @@ static struct dentry *create_profile_filstruct aa_profile *profile, const struct file_operations *fops) { - struct aa_proxy *proxy = aa_get_proxy(profile->label.proxy); -struct dentry *dent; - - dent =aafs_create_file (name,S_IFREG |0444 , dir, proxy, fops); -if (IS_ERR (dent)) -aa_put_proxy (proxy); - -return dent; + return aafs_create_file(name, S_IFREG | 0444, dir, &profile->label.proxy->count, fops); }#ifdef CONFIG_SECURITY_APPARMOR_EXPORT_BINARY
@@ -1625,7 +1682,8 @@ static const char *rawdata_get_link_basestruct delayed_call *done, const char *name) { - struct aa_proxy *proxy = inode->i_private; + struct aa_common_ref *ref = inode->i_private; + struct aa_proxy *proxy = container_of(ref, struct aa_proxy, count);struct aa_label *label;struct aa_profile *profile;char *target;
@@ -1767,27 +1825,24 @@ int __aafs_profile_mkdir(struct aa_profiif (profile->rawdata) {if (aa_g_hash_policy) { dent =aafs_create ("raw_sha1" ,S_IFLNK |0444 , dir, - profile->label.proxy,NULL ,NULL , - &rawdata_link_sha1_iops); + &profile->label.proxy->count,NULL , +NULL , &rawdata_link_sha1_iops);if (IS_ERR (dent)) goto fail; -aa_get_proxy (profile->label.proxy); profile->dents[AAFS_PROF_RAW_HASH ] = dent; } dent =aafs_create ("raw_abi" ,S_IFLNK |0444 , dir, - profile->label.proxy,NULL ,NULL , + &profile->label.proxy->count,NULL ,NULL , &rawdata_link_abi_iops);if (IS_ERR (dent)) goto fail; -aa_get_proxy (profile->label.proxy); profile->dents[AAFS_PROF_RAW_ABI ] = dent; dent =aafs_create ("raw_data" ,S_IFLNK |0444 , dir, - profile->label.proxy,NULL ,NULL , + &profile->label.proxy->count,NULL ,NULL , &rawdata_link_data_iops);if (IS_ERR (dent)) goto fail; -aa_get_proxy (profile->label.proxy); profile->dents[AAFS_PROF_RAW_DATA ] = dent; }#endif /*CONFIG_SECURITY_APPARMOR_EXPORT_BINARY */
@@ -1824,7 +1879,7 @@ static int ns_mkdir_op(struct user_namesif (error)return error; - parent =aa_get_ns (dir->i_private); + parent =get_ns_common_ref (dir->i_private);AA_BUG (d_inode (ns_subns_dir (parent)) != dir);/* we have to unlock and then relock to get locking order right
@@ -1874,7 +1929,7 @@ static int ns_rmdir_op(struct inode *dirif (error)return error; - parent =aa_get_ns (dir->i_private); + parent =get_ns_common_ref (dir->i_private);/* rmdir calls the generic securityfs functions to remove files * from the apparmor dir. It is up to the apparmor ns locking * to avoid races.
@@ -1944,27 +1999,6 @@ void __aafs_ns_rmdir(struct aa_ns *ns)__aa_fs_list_remove_rawdata (ns); -if (ns_subns_dir (ns)) { - sub =d_inode (ns_subns_dir (ns))->i_private; -aa_put_ns (sub); - } -if (ns_subload (ns)) { - sub =d_inode (ns_subload (ns))->i_private; -aa_put_ns (sub); - } -if (ns_subreplace (ns)) { - sub =d_inode (ns_subreplace (ns))->i_private; -aa_put_ns (sub); - } -if (ns_subremove (ns)) { - sub =d_inode (ns_subremove (ns))->i_private; -aa_put_ns (sub); - } -if (ns_subrevision (ns)) { - sub =d_inode (ns_subrevision (ns))->i_private; -aa_put_ns (sub); - } -for (i =AAFS_NS_SIZEOF -1 ; i >=0 ; --i) {aafs_remove (ns->dents[i]); ns->dents[i] =NULL ;
@@ -1989,40 +2023,40 @@ static int __aafs_ns_mkdir_entries(strucreturn PTR_ERR (dent);ns_subdata_dir (ns) = dent; - dent =aafs_create_file ("revision" ,0444 , dir, ns, + dent =aafs_create_file ("revision" ,0444 , dir, + &ns->unconfined->label.count, &aa_fs_ns_revision_fops);if (IS_ERR (dent))return PTR_ERR (dent); -aa_get_ns (ns);ns_subrevision (ns) = dent; - dent =aafs_create_file (".load" ,0640 , dir, ns, - &aa_fs_profile_load); + dent =aafs_create_file (".load" ,0640 , dir, + &ns->unconfined->label.count, + &aa_fs_profile_load);if (IS_ERR (dent))return PTR_ERR (dent); -aa_get_ns (ns);ns_subload (ns) = dent; - dent =aafs_create_file (".replace" ,0640 , dir, ns, - &aa_fs_profile_replace); + dent =aafs_create_file (".replace" ,0640 , dir, + &ns->unconfined->label.count, + &aa_fs_profile_replace);if (IS_ERR (dent))return PTR_ERR (dent); -aa_get_ns (ns);ns_subreplace (ns) = dent; - dent =aafs_create_file (".remove" ,0640 , dir, ns, - &aa_fs_profile_remove); + dent =aafs_create_file (".remove" ,0640 , dir, + &ns->unconfined->label.count, + &aa_fs_profile_remove);if (IS_ERR (dent))return PTR_ERR (dent); -aa_get_ns (ns);ns_subremove (ns) = dent;/* use create_dentry so we can supply private data */ - dent =aafs_create ("namespaces" ,S_IFDIR |0755 , dir, ns,NULL ,NULL , - &ns_dir_inode_operations); + dent =aafs_create ("namespaces" ,S_IFDIR |0755 , dir, + &ns->unconfined->label.count, +NULL ,NULL , &ns_dir_inode_operations);if (IS_ERR (dent))return PTR_ERR (dent); -aa_get_ns (ns);ns_subns_dir (ns) = dent;return 0 ;
security/apparmor/include/label.h +8 -8
@@ -101,7 +101,7 @@ enum label_flags {struct aa_label ;struct aa_proxy { -struct kref count; +struct aa_common_ref count;struct aa_label __rcu *label; };
@@ -121,7 +121,7 @@ struct label_it {* @ent: set of profiles for label, actual size determined by @size */ struct aa_label { -struct kref count; +struct aa_common_ref count;struct rb_node node;struct rcu_head rcu;struct aa_proxy *proxy;
@@ -372,7 +372,7 @@ int aa_label_match(struct aa_profile *pr*/ static inline struct aa_label *__aa_get_label (struct aa_label *l) { -if (l &&kref_get_unless_zero (&l->count)) +if (l &&kref_get_unless_zero (&l->count.count))return l;return NULL ;
@@ -381,7 +381,7 @@ static inline struct aa_label *__aa_get_static inline struct aa_label *aa_get_label (struct aa_label *l) {if (l) -kref_get (&(l->count)); +kref_get (&(l->count.count));return l; }
@@ -401,7 +401,7 @@ static inline struct aa_label *aa_get_larcu_read_lock ();do { c =rcu_dereference (*l); - }while (c && !kref_get_unless_zero (&c->count)); + }while (c && !kref_get_unless_zero (&c->count.count));rcu_read_unlock ();return c;
@@ -441,7 +441,7 @@ static inline struct aa_label *aa_get_nestatic inline void aa_put_label (struct aa_label *l) {if (l) -kref_put (&l->count, aa_label_kref); +kref_put (&l->count.count, aa_label_kref); }
@@ -451,7 +451,7 @@ void aa_proxy_kref(struct kref *kref);static inline struct aa_proxy *aa_get_proxy (struct aa_proxy *proxy) {if (proxy) -kref_get (&(proxy->count)); +kref_get (&(proxy->count.count));return proxy; }
@@ -459,7 +459,7 @@ static inline struct aa_proxy *aa_get_prstatic inline void aa_put_proxy (struct aa_proxy *proxy) {if (proxy) -kref_put (&proxy->count, aa_proxy_kref); +kref_put (&proxy->count.count, aa_proxy_kref); }void __aa_proxy_redirect (struct aa_label *orig,struct aa_label *new);
security/apparmor/include/lib.h +12 -0
@@ -69,6 +69,18 @@ void aa_info_message(const char *str);/* Security blob offsets */ extern struct lsm_blob_sizes apparmor_blob_sizes; +enum reftype { +REF_NS , +REF_PROXY , +REF_RAWDATA , +}; + +/* common reference count used by data the shows up in aafs */ +struct aa_common_ref { +struct kref count; +enum reftype reftype; +}; +/** * aa_strneq - compare null terminated @str to a non null terminated substring * @str: a null terminated string
security/apparmor/include/policy.h +4 -4
@@ -247,7 +247,7 @@ static inline unsigned int PROFILE_MEDIAstatic inline struct aa_profile *aa_get_profile (struct aa_profile *p) {if (p) -kref_get (&(p->label.count)); +kref_get (&(p->label.count.count));return p; }
@@ -261,7 +261,7 @@ static inline struct aa_profile *aa_get_*/ static inline struct aa_profile *aa_get_profile_not0 (struct aa_profile *p) { -if (p &&kref_get_unless_zero (&p->label.count)) +if (p &&kref_get_unless_zero (&p->label.count.count))return p;return NULL ;
@@ -281,7 +281,7 @@ static inline struct aa_profile *aa_get_rcu_read_lock ();do { c =rcu_dereference (*p); - }while (c && !kref_get_unless_zero (&c->label.count)); + }while (c && !kref_get_unless_zero (&c->label.count.count));rcu_read_unlock ();return c;
@@ -294,7 +294,7 @@ static inline struct aa_profile *aa_get_static inline void aa_put_profile (struct aa_profile *p) {if (p) -kref_put (&p->label.count, aa_label_kref); +kref_put (&p->label.count.count, aa_label_kref); }static inline int AUDIT_MODE (struct aa_profile *profile)
security/apparmor/include/policy_unpack.h +3 -3
@@ -106,7 +106,7 @@ struct aa_ext {* fs entries and drops the associated @count ref. */ struct aa_loaddata { -struct kref count; +struct aa_common_ref count;struct kref pcount;struct list_head list;struct work_struct work;
@@ -141,7 +141,7 @@ aa_get_i_loaddata(struct aa_loaddata *da {if (data) -kref_get (&(data->count)); +kref_get (&(data->count.count));return data; }
@@ -169,7 +169,7 @@ struct aa_loaddata *aa_loaddata_alloc(sistatic inline void aa_put_i_loaddata (struct aa_loaddata *data) {if (data) -kref_put (&data->count, aa_loaddata_kref); +kref_put (&data->count.count, aa_loaddata_kref); }static inline void aa_put_profile_loaddata (struct aa_loaddata *data)
security/apparmor/label.c +8 -4
@@ -52,7 +52,8 @@ static void free_proxy(struct aa_proxy *void aa_proxy_kref (struct kref *kref) { - struct aa_proxy *proxy = container_of(kref, struct aa_proxy, count); + struct aa_proxy *proxy = container_of(kref, struct aa_proxy, + count.count);free_proxy (proxy); }
@@ -63,7 +64,8 @@ struct aa_proxy *aa_alloc_proxy(struct a new =kzalloc (sizeof (struct aa_proxy ), gfp);if (new) { -kref_init (&new->count); +kref_init (&new->count.count); + new->count.reftype =REF_PROXY ;rcu_assign_pointer (new->label,aa_get_label (label)); }return new;
@@ -369,7 +371,8 @@ static void label_free_rcu(struct rcu_hevoid aa_label_kref (struct kref *kref) { - struct aa_label *label = container_of(kref, struct aa_label, count); + struct aa_label *label = container_of(kref, struct aa_label, + count.count);struct aa_ns *ns =labels_ns (label);if (!ns) {
@@ -406,7 +409,8 @@ bool aa_label_init(struct aa_label *labe label->size = size;/* doesn't include null */ label->vec[size] =NULL ;/* null terminate */ -kref_init (&label->count); +kref_init (&label->count.count); + label->count.reftype =REF_NS ;/* for aafs purposes */ RB_CLEAR_NODE (&label->node);return true;
security/apparmor/policy_unpack.c +4 -2
@@ -122,7 +122,8 @@ static void do_loaddata_free(struct aa_lvoid aa_loaddata_kref (struct kref *kref) { - struct aa_loaddata *d = container_of(kref, struct aa_loaddata, count); + struct aa_loaddata *d = container_of(kref, struct aa_loaddata, + count.count);do_loaddata_free (d); }
@@ -169,7 +170,8 @@ struct aa_loaddata *aa_loaddata_alloc(sikfree (d);return ERR_PTR (-ENOMEM ); } -kref_init (&d->count); +kref_init (&d->count.count); + d->count.reftype =REF_RAWDATA ;kref_init (&d->pcount);INIT_LIST_HEAD (&d->list);
Greg Kroah-Hartman
maintainerPATCH 23/55 usb: gadget: u_ether: Fix race between gether_disconnect and eth_stop
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuen-Han Tsai <[email protected]>
[ Upstream commit e1eabb072c75681f78312c484ccfffb7430f206e ]
A race condition between gether_disconnect() and eth_stop() leads to a NULL pointer dereference. Specifically, if eth_stop() is triggered concurrently while gether_disconnect() is tearing down the endpoints, eth_stop() attempts to access the cleared endpoint descriptor, causing the following NPE:
Unable to handle kernel NULL pointer dereference Call trace: __dwc3_gadget_ep_enable+0x60/0x788 dwc3_gadget_ep_enable+0x70/0xe4 usb_ep_enable+0x60/0x15c eth_stop+0xb8/0x108
Because eth_stop() crashes while holding the dev->lock, the thread running gether_disconnect() fails to acquire the same lock and spins forever, resulting in a hardlockup:
Core - Debugging Information for Hardlockup core(7)
Call trace: queued_spin_lock_slowpath+0x94/0x488 _raw_spin_lock+0x64/0x6c gether_disconnect+0x19c/0x1e8 ncm_set_alt+0x68/0x1a0 composite_setup+0x6a0/0xc50
The root cause is that the clearing of dev->port_usb in gether_disconnect() is delayed until the end of the function.
Move the clearing of dev->port_usb to the very beginning of gether_disconnect() while holding dev->lock. This cuts off the link immediately, ensuring eth_stop() will see dev->port_usb as NULL and safely bail out.
--- drivers/usb/gadget/function/u_ether.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/usb/gadget/function/u_ether.c +4 -4
@@ -1175,6 +1175,10 @@ void gether_disconnect(struct gether *liDBG (dev,"%s\n" , __func__); +spin_lock (&dev->lock); + dev->port_usb =NULL ; +spin_unlock (&dev->lock); +netif_stop_queue (dev->net);netif_carrier_off (dev->net);
@@ -1212,10 +1216,6 @@ void gether_disconnect(struct gether *li dev->header_len =0 ; dev->unwrap =NULL ; dev->wrap =NULL ; - -spin_lock (&dev->lock); - dev->port_usb =NULL ; -spin_unlock (&dev->lock); }EXPORT_SYMBOL_GPL (gether_disconnect);
Greg Kroah-Hartman
maintainerPATCH 24/55 Revert "ACPI: EC: Evaluate orphan _REG under EC device"
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Rafael J. Wysocki" <[email protected]>
[ Upstream commit 779bac9994452f6a894524f70c00cfb0cd4b6364 ]
This reverts commit 0e6b6dedf168 ("Revert "ACPI: EC: Evaluate orphan _REG under EC device") because the problem addressed by it will be addressed differently in what follows.
Stable-dep-of: 71bf41b8e913 ("ACPI: EC: Evaluate _REG outside the EC scope more carefully")
--- drivers/acpi/acpica/acevents.h | 4 --- drivers/acpi/acpica/evregion.c | 6 +++- drivers/acpi/acpica/evxfregn.c | 54 ----------------------------------------- drivers/acpi/ec.c | 3 -- include/acpi/acpixf.h | 4 --- 5 files changed, 5 insertions(+), 66 deletions(-)
drivers/acpi/acpica/acevents.h +0 -4
@@ -191,10 +191,6 @@ void acpi_ev_execute_reg_methods(struct acpi_namespace_node *node, acpi_adr_space_type space_id, u32 function); -void -acpi_ev_execute_orphan_reg_method (struct acpi_namespace_node *node, -acpi_adr_space_type space_id); -acpi_status acpi_ev_execute_reg_method (union acpi_operand_object *region_obj,u32 function);
drivers/acpi/acpica/evregion.c +5 -1
@@ -20,6 +20,10 @@ extern u8 acpi_gbl_default_address_space/* Local prototypes */ +static void +acpi_ev_execute_orphan_reg_method (struct acpi_namespace_node *device_node, +acpi_adr_space_type space_id); +static acpi_status acpi_ev_reg_run (acpi_handle obj_handle,u32 level,void *context,void **return_value);
@@ -807,7 +811,7 @@ acpi_ev_reg_run(acpi_handle obj_handle,* ******************************************************************************/ -void +static void acpi_ev_execute_orphan_reg_method (struct acpi_namespace_node *device_node,acpi_adr_space_type space_id) {
drivers/acpi/acpica/evxfregn.c +0 -54
57 lines not on this page · raw message
drivers/acpi/ec.c +0 -3
@@ -1532,9 +1532,6 @@ static int ec_install_handlers(struct acif (call_reg && !test_bit (EC_FLAGS_EC_REG_CALLED , &ec->flags)) {acpi_execute_reg_methods (scope_handle,ACPI_ADR_SPACE_EC ); -if (scope_handle != ec->handle) -acpi_execute_orphan_reg_method (ec->handle,ACPI_ADR_SPACE_EC ); -set_bit (EC_FLAGS_EC_REG_CALLED , &ec->flags); }
include/acpi/acpixf.h +0 -4
@@ -669,10 +669,6 @@ ACPI_EXTERNAL_RETURN_STATUS(acpi_status acpi_adr_space_type space_id)) ACPI_EXTERNAL_RETURN_STATUS(acpi_status - acpi_execute_orphan_reg_method(acpi_handle device, - acpi_adr_space_type - space_id)) -ACPI_EXTERNAL_RETURN_STATUS(acpi_status acpi_remove_address_space_handler(acpi_handle device, acpi_adr_space_type
Greg Kroah-Hartman
maintainerPATCH 25/55 ACPICA: Add a depth argument to acpi_execute_reg_methods()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Rafael J. Wysocki" <[email protected]>
[ Upstream commit cdf65d73e001fde600b18d7e45afadf559425ce5 ]
A subsequent change will need to pass a depth argument to acpi_execute_reg_methods(), so prepare that function for it.
No intentional functional changes.
Stable-dep-of: 71bf41b8e913 ("ACPI: EC: Evaluate _REG outside the EC scope more carefully")
--- drivers/acpi/acpica/acevents.h | 2 +- drivers/acpi/acpica/evregion.c | 6 ++++-- drivers/acpi/acpica/evxfregn.c | 10 +++++++--- drivers/acpi/ec.c | 2 +- include/acpi/acpixf.h | 1 + 5 files changed, 14 insertions(+), 7 deletions(-)
drivers/acpi/acpica/acevents.h +1 -1
@@ -188,7 +188,7 @@ acpi_ev_detach_region(union acpi_operand u8 acpi_ns_is_locked);void -acpi_ev_execute_reg_methods (struct acpi_namespace_node *node, +acpi_ev_execute_reg_methods (struct acpi_namespace_node *node,u32 max_depth,acpi_adr_space_type space_id,u32 function); acpi_status
drivers/acpi/acpica/evregion.c +4 -2
@@ -65,6 +65,7 @@ acpi_status acpi_ev_initialize_op_region acpi_gbl_default_address_spaces [i])) {acpi_ev_execute_reg_methods (acpi_gbl_root_node, +ACPI_UINT32_MAX , acpi_gbl_default_address_spaces [i],ACPI_REG_CONNECT ); }
@@ -665,6 +666,7 @@ cleanup1:* FUNCTION: acpi_ev_execute_reg_methods * * PARAMETERS: node - Namespace node for the device +* max_depth - Depth to which search for _REG * space_id - The address space ID * function - Passed to _REG: On (1) or Off (0) *
@@ -676,7 +678,7 @@ cleanup1:******************************************************************************/ void -acpi_ev_execute_reg_methods (struct acpi_namespace_node *node, +acpi_ev_execute_reg_methods (struct acpi_namespace_node *node,u32 max_depth,acpi_adr_space_type space_id,u32 function) {struct acpi_reg_walk_info info;
@@ -710,7 +712,7 @@ acpi_ev_execute_reg_methods(struct acpi_* regions and _REG methods. (i.e. handlers must be installed for all * regions of this Space ID before we can run any _REG methods) */ - (void )acpi_ns_walk_namespace (ACPI_TYPE_ANY , node,ACPI_UINT32_MAX , + (void )acpi_ns_walk_namespace (ACPI_TYPE_ANY , node, max_depth,ACPI_NS_WALK_UNLOCK , acpi_ev_reg_run,NULL , &info,NULL );
drivers/acpi/acpica/evxfregn.c +7 -3
@@ -85,7 +85,8 @@ acpi_install_address_space_handler_inter/* Run all _REG methods for this address space */ if (run_reg) { -acpi_ev_execute_reg_methods (node, space_id,ACPI_REG_CONNECT ); +acpi_ev_execute_reg_methods (node,ACPI_UINT32_MAX , space_id, +ACPI_REG_CONNECT ); } unlock_and_exit:
@@ -261,6 +262,7 @@ ACPI_EXPORT_SYMBOL(acpi_remove_address_s* FUNCTION: acpi_execute_reg_methods * * PARAMETERS: device - Handle for the device +* max_depth - Depth to which search for _REG * space_id - The address space ID * * RETURN: Status
@@ -269,7 +271,8 @@ ACPI_EXPORT_SYMBOL(acpi_remove_address_s* ******************************************************************************/ acpi_status -acpi_execute_reg_methods (acpi_handle device,acpi_adr_space_type space_id) +acpi_execute_reg_methods (acpi_handle device,u32 max_depth, +acpi_adr_space_type space_id) {struct acpi_namespace_node *node;acpi_status status;
@@ -294,7 +297,8 @@ acpi_execute_reg_methods(acpi_handle dev/* Run all _REG methods for this address space */ -acpi_ev_execute_reg_methods (node, space_id,ACPI_REG_CONNECT ); +acpi_ev_execute_reg_methods (node, max_depth, space_id, +ACPI_REG_CONNECT ); }else { status =AE_BAD_PARAMETER ; }
drivers/acpi/ec.c +1 -1
@@ -1531,7 +1531,7 @@ static int ec_install_handlers(struct ac }if (call_reg && !test_bit (EC_FLAGS_EC_REG_CALLED , &ec->flags)) { -acpi_execute_reg_methods (scope_handle,ACPI_ADR_SPACE_EC ); +acpi_execute_reg_methods (scope_handle,ACPI_UINT32_MAX ,ACPI_ADR_SPACE_EC );set_bit (EC_FLAGS_EC_REG_CALLED , &ec->flags); }
include/acpi/acpixf.h +1 -0
@@ -666,6 +666,7 @@ ACPI_EXTERNAL_RETURN_STATUS(acpi_status void *context)) ACPI_EXTERNAL_RETURN_STATUS(acpi_status acpi_execute_reg_methods(acpi_handle device, + u32 nax_depth, acpi_adr_space_type space_id)) ACPI_EXTERNAL_RETURN_STATUS(acpi_status
Greg Kroah-Hartman
maintainerPATCH 26/55 ACPI: EC: Evaluate _REG outside the EC scope more carefully
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Rafael J. Wysocki" <[email protected]>
[ Upstream commit 71bf41b8e913ec9fc91f0d39ab8fb320229ec604 ]
Commit 60fa6ae6e6d0 ("ACPI: EC: Install address space handler at the namespace root") caused _REG methods for EC operation regions outside the EC device scope to be evaluated which on some systems leads to the evaluation of _REG methods in the scopes of device objects representing devices that are not present and not functional according to the _STA return values. Some of those device objects represent EC "alternatives" and if _REG is evaluated for their operation regions, the platform firmware may be confused and the platform may start to behave incorrectly.
To avoid this problem, only evaluate _REG for EC operation regions located in the scopes of device objects representing known-to-be-present devices.
For this purpose, partially revert commit 60fa6ae6e6d0 and trigger the evaluation of _REG for EC operation regions from acpi_bus_attach() for the known-valid devices.
--- drivers/acpi/ec.c | 11 +++++++++-- drivers/acpi/internal.h | 1 + drivers/acpi/scan.c | 2 ++ 3 files changed, 12 insertions(+), 2 deletions(-)
drivers/acpi/ec.c +9 -2
@@ -1512,12 +1512,13 @@ static bool install_gpio_irq_event_handlstatic int ec_install_handlers (struct acpi_ec *ec,struct acpi_device *device,bool call_reg) { -acpi_handle scope_handle = ec == first_ec ?ACPI_ROOT_OBJECT : ec->handle;acpi_status status;acpi_ec_start (ec, false);if (!test_bit (EC_FLAGS_EC_HANDLER_INSTALLED , &ec->flags)) { +acpi_handle scope_handle = ec == first_ec ?ACPI_ROOT_OBJECT : ec->handle; +acpi_ec_enter_noirq (ec); status = acpi_install_address_space_handler_no_reg(scope_handle, ACPI_ADR_SPACE_EC,
@@ -1531,7 +1532,7 @@ static int ec_install_handlers(struct ac }if (call_reg && !test_bit (EC_FLAGS_EC_REG_CALLED , &ec->flags)) { -acpi_execute_reg_methods (scope_handle,ACPI_UINT32_MAX ,ACPI_ADR_SPACE_EC ); +acpi_execute_reg_methods (ec->handle,ACPI_UINT32_MAX ,ACPI_ADR_SPACE_EC );set_bit (EC_FLAGS_EC_REG_CALLED , &ec->flags); }
@@ -1749,6 +1750,12 @@ static int acpi_ec_remove(struct acpi_dereturn 0 ; } +void acpi_ec_register_opregions (struct acpi_device *adev) +{ +if (first_ec && first_ec->handle != adev->handle) +acpi_execute_reg_methods (adev->handle,1 ,ACPI_ADR_SPACE_EC ); +} +static acpi_status ec_parse_io_ports (struct acpi_resource *resource,void *context) {
drivers/acpi/internal.h +1 -0
@@ -210,6 +210,7 @@ int acpi_ec_add_query_handler(struct acp acpi_handle handle, acpi_ec_query_func func, void *data);void acpi_ec_remove_query_handler (struct acpi_ec *ec,u8 query_bit); +void acpi_ec_register_opregions (struct acpi_device *adev);#ifdef CONFIG_PM_SLEEP void acpi_ec_flush_work (void );
drivers/acpi/scan.c +2 -0
@@ -2198,6 +2198,8 @@ static int acpi_bus_attach(struct acpi_dif (device->handler) goto ok; +acpi_ec_register_opregions (device); +if (!device->flags.initialized) { device->flags.power_manageable = device->power.states[ACPI_STATE_D0 ].flags.valid;
Greg Kroah-Hartman
maintainerPATCH 27/55 usb: gadget: f_hid: move list and spinlock inits from bind to alloc
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Zimmermann <[email protected]>
[ Upstream commit 4e0a88254ad59f6c53a34bf5fa241884ec09e8b2 ]
There was an issue when you did the following:
- setup and bind an hid gadget
- open /dev/hidg0
- use the resulting fd in EPOLL_CTL_ADD
- unbind the UDC
- bind the UDC
- use the fd in EPOLL_CTL_DEL
When CONFIG_DEBUG_LIST was enabled, a list_del corruption was reported within remove_wait_queue (via ep_remove_wait_queue). After some debugging I found out that the queues, which f_hid registers via poll_wait were the problem. These were initialized using init_waitqueue_head inside hidg_bind. So effectively, the bind function re-initialized the queues while there were still items in them.
The solution is to move the initialization from hidg_bind to hidg_alloc to extend their lifetimes to the lifetime of the function instance.
Additionally, I found many other possibly problematic init calls in the bind function, which I moved as well.
--- drivers/usb/gadget/function/f_hid.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/usb/gadget/function/f_hid.c +6 -5
@@ -996,13 +996,8 @@ static int hidg_bind(struct usb_configurif (status) goto fail; -spin_lock_init (&hidg->write_spinlock); hidg->write_pending =1 ; hidg->req =NULL ; -spin_lock_init (&hidg->read_spinlock); -init_waitqueue_head (&hidg->write_queue); -init_waitqueue_head (&hidg->read_queue); -INIT_LIST_HEAD (&hidg->completed_out_req);/* create char device */ cdev_init (&hidg->cdev, &f_hidg_fops);
@@ -1272,6 +1267,12 @@ static struct usb_function *hidg_alloc(smutex_lock (&opts->lock); ++opts->refcnt; +spin_lock_init (&hidg->write_spinlock); +spin_lock_init (&hidg->read_spinlock); +init_waitqueue_head (&hidg->write_queue); +init_waitqueue_head (&hidg->read_queue); +INIT_LIST_HEAD (&hidg->completed_out_req); +device_initialize (&hidg->dev); hidg->dev.release = hidg_release; hidg->dev.class = hidg_class;
Greg Kroah-Hartman
maintainerPATCH 28/55 rfkill: Use sysfs_emit() to instead of sprintf()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bo Liu <[email protected]>
[ Upstream commit 796703baead0c2862f7f2ebb9b177590af533035 ]
Follow the advice of the Documentation/filesystems/sysfs.rst and show() should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space.
Stable-dep-of: ea245d78dec5 ("net: rfkill: prevent unlimited numbers of rfkill events from being created")
--- net/rfkill/core.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
net/rfkill/core.c +8 -8
@@ -685,7 +685,7 @@ static ssize_t name_show(struct device * {struct rfkill *rfkill =to_rfkill (dev); -return sprintf (buf,"%s\n" , rfkill->name); +return sysfs_emit (buf,"%s\n" , rfkill->name); }static DEVICE_ATTR_RO (name);
@@ -694,7 +694,7 @@ static ssize_t type_show(struct device * {struct rfkill *rfkill =to_rfkill (dev); -return sprintf (buf,"%s\n" , rfkill_types[rfkill->type]); +return sysfs_emit (buf,"%s\n" , rfkill_types[rfkill->type]); }static DEVICE_ATTR_RO (type);
@@ -703,7 +703,7 @@ static ssize_t index_show(struct device {struct rfkill *rfkill =to_rfkill (dev); -return sprintf (buf,"%d\n" , rfkill->idx); +return sysfs_emit (buf,"%d\n" , rfkill->idx); }static DEVICE_ATTR_RO (index);
@@ -712,7 +712,7 @@ static ssize_t persistent_show(struct de {struct rfkill *rfkill =to_rfkill (dev); -return sprintf (buf,"%d\n" , rfkill->persistent); +return sysfs_emit (buf,"%d\n" , rfkill->persistent); }static DEVICE_ATTR_RO (persistent);
@@ -721,7 +721,7 @@ static ssize_t hard_show(struct device * {struct rfkill *rfkill =to_rfkill (dev); -return sprintf (buf,"%d\n" , (rfkill->state &RFKILL_BLOCK_HW ) ?1 :0 ); +return sysfs_emit (buf,"%d\n" , (rfkill->state &RFKILL_BLOCK_HW ) ?1 :0 ); }static DEVICE_ATTR_RO (hard);
@@ -730,7 +730,7 @@ static ssize_t soft_show(struct device * {struct rfkill *rfkill =to_rfkill (dev); -return sprintf (buf,"%d\n" , (rfkill->state &RFKILL_BLOCK_SW ) ?1 :0 ); +return sysfs_emit (buf,"%d\n" , (rfkill->state &RFKILL_BLOCK_SW ) ?1 :0 ); } static ssize_t soft_store(struct device *dev, struct device_attribute *attr,
@@ -764,7 +764,7 @@ static ssize_t hard_block_reasons_show(s {struct rfkill *rfkill =to_rfkill (dev); -return sprintf (buf,"0x%lx\n" , rfkill->hard_block_reasons); +return sysfs_emit (buf,"0x%lx\n" , rfkill->hard_block_reasons); }static DEVICE_ATTR_RO (hard_block_reasons);
@@ -783,7 +783,7 @@ static ssize_t state_show(struct device {struct rfkill *rfkill =to_rfkill (dev); -return sprintf (buf,"%d\n" ,user_state_from_blocked (rfkill->state)); +return sysfs_emit (buf,"%d\n" ,user_state_from_blocked (rfkill->state)); } static ssize_t state_store(struct device *dev, struct device_attribute *attr,
Greg Kroah-Hartman
maintainerPATCH 29/55 rfkill: sync before userspace visibility/changes
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Berg <[email protected]>
[ Upstream commit 2c3dfba4cf84ac4f306cc6653b37b6dd6859ae9d ]
If userspace quickly opens /dev/rfkill after a new instance was created, it might see the old state of the instance from before the sync work runs and may even _change_ the state, only to have the sync work change it again.
Fix this by doing the sync inline where needed, not just for /dev/rfkill but also for sysfs.
Stable-dep-of: ea245d78dec5 ("net: rfkill: prevent unlimited numbers of rfkill events from being created")
--- net/rfkill/core.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-)
net/rfkill/core.c +26 -6
@@ -48,6 +48,7 @@ struct rfkill {bool persistent;bool polling_paused;bool suspended; +bool need_sync;const struct rfkill_ops *ops;void *data;
@@ -368,6 +369,17 @@ static void rfkill_set_block(struct rfkirfkill_event (rfkill); } +static void rfkill_sync (struct rfkill *rfkill) +{ +lockdep_assert_held (&rfkill_global_mutex); + +if (!rfkill->need_sync) +return ; + +rfkill_set_block (rfkill, rfkill_global_states[rfkill->type].cur); + rfkill->need_sync = false; +} +static void rfkill_update_global_state (enum rfkill_type type,bool blocked) {int i;
@@ -730,6 +742,10 @@ static ssize_t soft_show(struct device * {struct rfkill *rfkill =to_rfkill (dev); +mutex_lock (&rfkill_global_mutex); +rfkill_sync (rfkill); +mutex_unlock (&rfkill_global_mutex); +return sysfs_emit (buf,"%d\n" , (rfkill->state &RFKILL_BLOCK_SW ) ?1 :0 ); }
@@ -751,6 +767,7 @@ static ssize_t soft_store(struct devicereturn -EINVAL ;mutex_lock (&rfkill_global_mutex); +rfkill_sync (rfkill);rfkill_set_block (rfkill, state);mutex_unlock (&rfkill_global_mutex);
@@ -783,6 +800,10 @@ static ssize_t state_show(struct device {struct rfkill *rfkill =to_rfkill (dev); +mutex_lock (&rfkill_global_mutex); +rfkill_sync (rfkill); +mutex_unlock (&rfkill_global_mutex); +return sysfs_emit (buf,"%d\n" ,user_state_from_blocked (rfkill->state)); }
@@ -805,6 +826,7 @@ static ssize_t state_store(struct devicereturn -EINVAL ;mutex_lock (&rfkill_global_mutex); +rfkill_sync (rfkill);rfkill_set_block (rfkill, state ==RFKILL_USER_STATE_SOFT_BLOCKED );mutex_unlock (&rfkill_global_mutex);
@@ -1032,14 +1054,10 @@ static void rfkill_uevent_work(struct wostatic void rfkill_sync_work (struct work_struct *work) { -struct rfkill *rfkill; -bool cur; - - rfkill = container_of(work, struct rfkill, sync_work); + struct rfkill *rfkill = container_of(work, struct rfkill, sync_work);mutex_lock (&rfkill_global_mutex); - cur = rfkill_global_states[rfkill->type].cur; -rfkill_set_block (rfkill, cur); +rfkill_sync (rfkill);mutex_unlock (&rfkill_global_mutex); }
@@ -1087,6 +1105,7 @@ int __must_check rfkill_register(struct round_jiffies_relative(POLL_INTERVAL));if (!rfkill->persistent || rfkill_epo_lock_active) { + rfkill->need_sync = true;schedule_work (&rfkill->sync_work); }else {#ifdef CONFIG_RFKILL_INPUT
@@ -1171,6 +1190,7 @@ static int rfkill_fop_open(struct inode ev =kzalloc (sizeof (*ev),GFP_KERNEL );if (!ev) goto free; +rfkill_sync (rfkill);rfkill_fill_event (&ev->ev, rfkill,RFKILL_OP_ADD );list_add_tail (&ev->list, &data->events); }
Greg Kroah-Hartman
maintainerPATCH 30/55 net: rfkill: reduce data->mtx scope in rfkill_fop_open
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Berg <[email protected]>
[ Upstream commit f2ac54ebf85615a6d78f5eb213a8bbeeb17ebe5d ]
In syzbot runs, lockdep reports that there's a (potential) deadlock here of data->mtx being locked recursively. This isn't really a deadlock since they are different instances, but lockdep cannot know, and teaching it would be far more difficult than other fixes.
At the same time we don't even really _need_ the mutex to be locked in rfkill_fop_open(), since we're modifying only a completely fresh instance of 'data' (struct rfkill_data) that's not yet added to the global list.
However, to avoid any reordering etc. within the globally locked section, and to make the code look more symmetric, we should still lock the data->events list manipulation, but also need to lock _only_ that. So do that.
Stable-dep-of: ea245d78dec5 ("net: rfkill: prevent unlimited numbers of rfkill events from being created")
--- net/rfkill/core.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
net/rfkill/core.c +2 -3
@@ -1180,7 +1180,6 @@ static int rfkill_fop_open(struct inodeinit_waitqueue_head (&data->read_wait);mutex_lock (&rfkill_global_mutex); -mutex_lock (&data->mtx);/* * start getting events from elsewhere but hold mtx to get * startup events added first
@@ -1192,10 +1191,11 @@ static int rfkill_fop_open(struct inode goto free;rfkill_sync (rfkill);rfkill_fill_event (&ev->ev, rfkill,RFKILL_OP_ADD ); +mutex_lock (&data->mtx);list_add_tail (&ev->list, &data->events); +mutex_unlock (&data->mtx); }list_add (&data->list, &rfkill_fds); -mutex_unlock (&data->mtx);mutex_unlock (&rfkill_global_mutex); file->private_data = data;
@@ -1203,7 +1203,6 @@ static int rfkill_fop_open(struct inodereturn stream_open (inode, file); free: -mutex_unlock (&data->mtx);mutex_unlock (&rfkill_global_mutex);mutex_destroy (&data->mtx);list_for_each_entry_safe (ev, tmp, &data->events, list)
Greg Kroah-Hartman
maintainerPATCH 31/55 net: rfkill: prevent unlimited numbers of rfkill events from being created
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
[ Upstream commit ea245d78dec594372e27d8c79616baf49e98a4a1 ]
Userspace can create an unlimited number of rfkill events if the system is so configured, while not consuming them from the rfkill file descriptor, causing a potential out of memory situation. Prevent this from bounding the number of pending rfkill events at a "large" number (i.e. 1000) to prevent abuses like this.
--- net/rfkill/core.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-)
net/rfkill/core.c +24 -11
@@ -73,11 +73,14 @@ struct rfkill_int_event {struct rfkill_event_ext ev; }; +/* Max rfkill events that can be "in-flight" for one data source */ +#define MAX_RFKILL_EVENT 1000struct rfkill_data {struct list_head list;struct list_head events;struct mutex mtx;wait_queue_head_t read_wait; +u32 event_count;bool input_handler;u8 max_size; };
@@ -255,10 +258,12 @@ static void rfkill_global_led_trigger_un }#endif /* CONFIG_RFKILL_LEDS */ -static void rfkill_fill_event (struct rfkill_event_ext *ev, -struct rfkill *rfkill, -enum rfkill_operation op) +static int rfkill_fill_event (struct rfkill_int_event *int_ev, +struct rfkill *rfkill, +struct rfkill_data *data, +enum rfkill_operation op) { +struct rfkill_event_ext *ev = &int_ev->ev;unsigned long flags; ev->idx = rfkill->idx;
@@ -271,6 +276,15 @@ static void rfkill_fill_event(struct rfk RFKILL_BLOCK_SW_PREV)); ev->hard_block_reasons = rfkill->hard_block_reasons;spin_unlock_irqrestore (&rfkill->lock, flags); + + scoped_guard(mutex, &data->mtx) { +if (data->event_count++ >MAX_RFKILL_EVENT ) { + data->event_count--; +return -ENOSPC ; + } +list_add_tail (&int_ev->list, &data->events); + } +return 0 ; }static void rfkill_send_events (struct rfkill *rfkill,enum rfkill_operation op)
@@ -282,10 +296,10 @@ static void rfkill_send_events(struct rf ev =kzalloc (sizeof (*ev),GFP_KERNEL );if (!ev)continue ; -rfkill_fill_event (&ev->ev, rfkill, op); -mutex_lock (&data->mtx); -list_add_tail (&ev->list, &data->events); -mutex_unlock (&data->mtx); +if (rfkill_fill_event (ev, rfkill, data, op)) { +kfree (ev); +continue ; + }wake_up_interruptible (&data->read_wait); } }
@@ -1190,10 +1204,8 @@ static int rfkill_fop_open(struct inodeif (!ev) goto free;rfkill_sync (rfkill); -rfkill_fill_event (&ev->ev, rfkill,RFKILL_OP_ADD ); -mutex_lock (&data->mtx); -list_add_tail (&ev->list, &data->events); -mutex_unlock (&data->mtx); +if (rfkill_fill_event (ev, rfkill, data,RFKILL_OP_ADD )) +kfree (ev); }list_add (&data->list, &rfkill_fds);mutex_unlock (&rfkill_global_mutex);
@@ -1263,6 +1275,7 @@ static ssize_t rfkill_fop_read(struct fi ret = -EFAULT ;list_del (&ev->list); + data->event_count--;kfree (ev); out:mutex_unlock (&data->mtx);
Greg Kroah-Hartman
maintainerPATCH 32/55 seg6: separate dst_cache for input and output paths in seg6 lwtunnel
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrea Mayer <[email protected]>
[ Upstream commit c3812651b522fe8437ebb7063b75ddb95b571643 ]
The seg6 lwtunnel uses a single dst_cache per encap route, shared between seg6_input_core() and seg6_output_core(). These two paths can perform the post-encap SID lookup in different routing contexts (e.g., ip rules matching on the ingress interface, or VRF table separation). Whichever path runs first populates the cache, and the other reuses it blindly, bypassing its own lookup.
Fix this by splitting the cache into cache_input and cache_output, so each path maintains its own cached dst independently.
--- net/ipv6/seg6_iptunnel.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-)
net/ipv6/seg6_iptunnel.c +28 -13
@@ -48,7 +48,8 @@ static size_t seg6_lwt_headroom(struct s }struct seg6_lwt { -struct dst_cache cache; +struct dst_cache cache_input; +struct dst_cache cache_output;struct seg6_iptunnel_encap tuninfo[]; };
@@ -486,7 +487,7 @@ static int seg6_input_core(struct net *n slwt =seg6_lwt_lwtunnel (lwtst);local_bh_disable (); - dst =dst_cache_get (&slwt->cache); + dst =dst_cache_get (&slwt->cache_input);local_bh_enable (); err =seg6_do_srh (skb, dst);
@@ -502,7 +503,7 @@ static int seg6_input_core(struct net *n/* cache only if we don't create a dst reference loop */ if (!dst->error && lwtst != dst->lwtstate) {local_bh_disable (); -dst_cache_set_ip6 (&slwt->cache, dst, +dst_cache_set_ip6 (&slwt->cache_input, dst, &ipv6_hdr (skb)->saddr);local_bh_enable (); }
@@ -561,7 +562,7 @@ static int seg6_output_core(struct net * slwt =seg6_lwt_lwtunnel (orig_dst->lwtstate);local_bh_disable (); - dst =dst_cache_get (&slwt->cache); + dst =dst_cache_get (&slwt->cache_output);local_bh_enable (); err =seg6_do_srh (skb, dst);
@@ -586,9 +587,12 @@ static int seg6_output_core(struct net * goto drop; } -local_bh_disable (); -dst_cache_set_ip6 (&slwt->cache, dst, &fl6.saddr); -local_bh_enable (); +/* cache only if we don't create a dst reference loop */ +if (orig_dst->lwtstate != dst->lwtstate) { +local_bh_disable (); +dst_cache_set_ip6 (&slwt->cache_output, dst, &fl6.saddr); +local_bh_enable (); + } err =skb_cow_head (skb,LL_RESERVED_SPACE (dst->dev));if (unlikely (err))
@@ -695,11 +699,13 @@ static int seg6_build_state(struct net * slwt =seg6_lwt_lwtunnel (newts); - err =dst_cache_init (&slwt->cache,GFP_ATOMIC ); -if (err) { -kfree (newts); -return err; - } + err =dst_cache_init (&slwt->cache_input,GFP_ATOMIC ); +if (err) + goto err_free_newts; + + err =dst_cache_init (&slwt->cache_output,GFP_ATOMIC ); +if (err) + goto err_destroy_input;memcpy (&slwt->tuninfo, tuninfo, tuninfo_len);
@@ -714,11 +720,20 @@ static int seg6_build_state(struct net * *ts = newts;return 0 ; + +err_destroy_input: +dst_cache_destroy (&slwt->cache_input); +err_free_newts: +kfree (newts); +return err; }static void seg6_destroy_state (struct lwtunnel_state *lwt) { -dst_cache_destroy (&seg6_lwt_lwtunnel (lwt)->cache); +struct seg6_lwt *slwt =seg6_lwt_lwtunnel (lwt); + +dst_cache_destroy (&slwt->cache_input); +dst_cache_destroy (&slwt->cache_output); } static int seg6_fill_encap_info(struct sk_buff *skb,
Greg Kroah-Hartman
maintainerPATCH 33/55 Revert "mptcp: add needs_id for netlink appending addr"
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Matthieu Baerts (NGI0)" <[email protected]>
[ Upstream commit 8e2760eaab778494fc1fa257031e0e1799647f46 ]
This commit was originally adding the ability to add MPTCP endpoints with ID 0 by accident. The in-kernel PM, handling MPTCP endpoints at the net namespace level, is not supposed to handle endpoints with such ID, because this ID 0 is reserved to the initial subflow, as mentioned in the MPTCPv1 protocol [1], a per-connection setting.
Note that 'ip mptcp endpoint add id 0' stops early with an error, but other tools might still request the in-kernel PM to create MPTCP endpoints with this restricted ID 0.
In other words, it was wrong to call the mptcp_pm_has_addr_attr_id helper to check whether the address ID attribute is set: if it was set to 0, a new MPTCP endpoint would be created with ID 0, which is not expected, and might cause various issues later.
--- net/mptcp/pm_netlink.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-)
net/mptcp/pm_netlink.c +5 -19
@@ -1080,7 +1080,7 @@ static void __mptcp_pm_release_addr_entrstatic int mptcp_pm_nl_append_new_local_addr (struct pm_nl_pernet *pernet,struct mptcp_pm_addr_entry *entry, -bool needs_id,bool replace) +bool replace) {struct mptcp_pm_addr_entry *cur, *del_entry =NULL ;unsigned int addr_max;
@@ -1133,7 +1133,7 @@ static int mptcp_pm_nl_append_new_local_ } } -if (!entry->addr.id && needs_id) { +if (!entry->addr.id) { find_next: entry->addr.id = find_next_zero_bit(pernet->id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1,
@@ -1144,7 +1144,7 @@ find_next: } } -if (!entry->addr.id && needs_id) +if (!entry->addr.id) goto out;__set_bit (entry->addr.id, pernet->id_bitmap);
@@ -1271,7 +1271,7 @@ int mptcp_pm_nl_get_local_id(struct mptc entry->ifindex =0 ; entry->flags =MPTCP_PM_ADDR_FLAG_IMPLICIT ; entry->lsk =NULL ; - ret =mptcp_pm_nl_append_new_local_addr (pernet, entry, true, false); + ret =mptcp_pm_nl_append_new_local_addr (pernet, entry, false);if (ret <0 )kfree (entry);
@@ -1513,18 +1513,6 @@ next:return 0 ; } -static bool mptcp_pm_has_addr_attr_id (const struct nlattr *attr, -struct genl_info *info) -{ -struct nlattr *tb[MPTCP_PM_ADDR_ATTR_MAX +1 ]; - -if (!nla_parse_nested_deprecated (tb,MPTCP_PM_ADDR_ATTR_MAX , attr, - mptcp_pm_addr_policy, info->extack) && - tb[MPTCP_PM_ADDR_ATTR_ID ]) -return true; -return false; -} -static int mptcp_nl_cmd_add_addr (struct sk_buff *skb,struct genl_info *info) {struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR ];
@@ -1566,9 +1554,7 @@ static int mptcp_nl_cmd_add_addr(struct goto out_free; } } - ret =mptcp_pm_nl_append_new_local_addr (pernet, entry, - !mptcp_pm_has_addr_attr_id (attr, info), - true); + ret =mptcp_pm_nl_append_new_local_addr (pernet, entry, true);if (ret <0 ) {GENL_SET_ERR_MSG (info,"too many addresses or duplicate one" ); goto out_free;
Greg Kroah-Hartman
maintainerPATCH 34/55 drm/scheduler: signal scheduled fence when kill job
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lin.Cao <[email protected]>
commit 471db2c2d4f80ee94225a1ef246e4f5011733e50 upstream.
When an entity from application B is killed, drm_sched_entity_kill() removes all jobs belonging to that entity through drm_sched_entity_kill_jobs_work(). If application A's job depends on a scheduled fence from application B's job, and that fence is not properly signaled during the killing process, application A's dependency cannot be cleared.
This leads to application A hanging indefinitely while waiting for a dependency that will never be resolved. Fix this issue by ensuring that scheduled fences are properly signaled when an entity is killed, allowing dependent applications to continue execution.
[ Modified drm_sched_fence_scheduled(job->s_fence, NULL) to
drm_sched_fence_scheduled(job->s_fence) for kernel 6.1.y ]
--- drivers/gpu/drm/scheduler/sched_entity.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/scheduler/sched_entity.c +1 -0
@@ -196,6 +196,7 @@ static void drm_sched_entity_kill_jobs_w {struct drm_sched_job *job =container_of (wrk,typeof (*job), work); +drm_sched_fence_scheduled (job->s_fence);drm_sched_fence_finished (job->s_fence);WARN_ON (job->s_fence->parent); job->sched->ops->free_job (job);
Greg Kroah-Hartman
maintainerPATCH 35/55 netfilter: nft_set_pipapo: do not rely on ZERO_SIZE_PTR
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
commit 07ace0bbe03b3d8e85869af1dec5e4087b1d57b8 upstream
pipapo relies on kmalloc(0) returning ZERO_SIZE_PTR (i.e., not NULL but pointer is invalid).
Rework this to not call slab allocator when we'd request a 0-byte allocation.
[Keerthana: In older stable branches (v6.6 and earlier), the allocation logic in pipapo_clone() still relies on src->rules rather than src->rules_alloc (introduced in v6.9 via 9f439bd6ef4f). Consequently, the previously backported INT_MAX clamping check uses src->rules. This patch correctly moves that src->rules > (INT_MAX / ...) check inside the newif (src->rules > 0) block]
--- net/netfilter/nft_set_pipapo.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
net/netfilter/nft_set_pipapo.c +14 -6
@@ -525,6 +525,8 @@ static struct nft_pipapo_elem *pipapo_geint i; m = priv->clone; +if (m->bsize_max ==0 ) +return ret; res_map =kmalloc_array (m->bsize_max,sizeof (*res_map),GFP_ATOMIC );if (!res_map) {
@@ -1395,14 +1397,20 @@ static struct nft_pipapo_match *pipapo_c src->bsize *sizeof (*dst->lt) * src->groups * NFT_PIPAPO_BUCKETS(src->bb)); -if (src->rules > (INT_MAX /sizeof (*src->mt))) - goto out_mt; +if (src->rules >0 ) { +if (src->rules > (INT_MAX /sizeof (*src->mt))) + goto out_mt; + + dst->mt =kvmalloc_array (src->rules,sizeof (*src->mt), +GFP_KERNEL ); +if (!dst->mt) + goto out_mt; - dst->mt =kvmalloc (src->rules *sizeof (*src->mt),GFP_KERNEL_ACCOUNT ); -if (!dst->mt) - goto out_mt; +memcpy (dst->mt, src->mt, src->rules *sizeof (*src->mt)); + }else { + dst->mt =NULL ; + } -memcpy (dst->mt, src->mt, src->rules *sizeof (*src->mt)); src++; dst++; }
Greg Kroah-Hartman
maintainerPATCH 36/55 netfilter: nft_ct: fix use-after-free in timeout object destroy
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tuan Do <[email protected]>
commit f8dca15a1b190787bbd03285304b569631160eda upstream.
nft_ct_timeout_obj_destroy() frees the timeout object with kfree() immediately after nf_ct_untimeout(), without waiting for an RCU grace period. Concurrent packet processing on other CPUs may still hold RCU-protected references to the timeout object obtained via rcu_dereference() in nf_ct_timeout_data().
Add an rcu_head to struct nf_ct_timeout and use kfree_rcu() to defer freeing until after an RCU grace period, matching the approach already used in nfnetlink_cttimeout.c.
KASAN report:
BUG: KASAN: slab-use-after-free in nf_conntrack_tcp_packet+0x1381/0x29d0 Read of size 4 at addr ffff8881035fe19c by task exploit/80 Call Trace: nf_conntrack_tcp_packet+0x1381/0x29d0 nf_conntrack_in+0x612/0x8b0 nf_hook_slow+0x70/0x100 __ip_local_out+0x1b2/0x210 tcp_sendmsg_locked+0x722/0x1580 __sys_sendto+0x2d8/0x320 Allocated by task 75: nft_ct_timeout_obj_init+0xf6/0x290 nft_obj_init+0x107/0x1b0 nf_tables_newobj+0x680/0x9c0 nfnetlink_rcv_batch+0xc29/0xe00 Freed by task 26: nft_obj_destroy+0x3f/0xa0 nf_tables_trans_destroy_work+0x51c/0x5c0 process_one_work+0x2c4/0x5a0
--- include/net/netfilter/nf_conntrack_timeout.h | 1 + net/netfilter/nft_ct.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
include/net/netfilter/nf_conntrack_timeout.h +1 -0
@@ -14,6 +14,7 @@struct nf_ct_timeout {__u16 l3num;const struct nf_conntrack_l4proto *l4proto; +struct rcu_head rcu;char data[]; };
net/netfilter/nft_ct.c +1 -1
@@ -985,7 +985,7 @@ static void nft_ct_timeout_obj_destroy(cnf_queue_nf_hook_drop (ctx->net);nf_ct_untimeout (ctx->net, timeout);nf_ct_netns_put (ctx->net, ctx->family); -kfree (priv->timeout); +kfree_rcu (priv->timeout, rcu); } static int nft_ct_timeout_obj_dump(struct sk_buff *skb,
Greg Kroah-Hartman
maintainerPATCH 37/55 xfrm: clear trailing padding in build_polexpire()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yasuaki Torimaru <[email protected]>
commit 71a98248c63c535eaa4d4c22f099b68d902006d0 upstream.
build_expire() clears the trailing padding bytes of struct xfrm_user_expire after setting the hard field via memset_after(), but the analogous function build_polexpire() does not do this for struct xfrm_user_polexpire.
The padding bytes after the __u8 hard field are left uninitialized from the heap allocation, and are then sent to userspace via netlink multicast to XFRMNLGRP_EXPIRE listeners, leaking kernel heap memory contents.
Add the missing memset_after() call, matching build_expire().
--- net/xfrm/xfrm_user.c | 2 ++ 1 file changed, 2 insertions(+)
net/xfrm/xfrm_user.c +2 -0
@@ -3524,6 +3524,8 @@ static int build_polexpire(struct sk_bufreturn err; } upe->hard = !!hard; +/* clear the padding bytes */ +memset_after (upe,0 , hard);nlmsg_end (skb, nlh);return 0 ;
Greg Kroah-Hartman
maintainerPATCH 38/55 tipc: fix bc_ackers underflow on duplicate GRP_ACK_MSG
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oleh Konko <[email protected]>
commit 48a5fe38772b6f039522469ee6131a67838221a8 upstream.
The GRP_ACK_MSG handler in tipc_group_proto_rcv() currently decrements bc_ackers on every inbound group ACK, even when the same member has already acknowledged the current broadcast round.
Because bc_ackers is a u16, a duplicate ACK received after the last legitimate ACK wraps the counter to 65535. Once wrapped, tipc_group_bc_cong() keeps reporting congestion and later group broadcasts on the affected socket stay blocked until the group is recreated.
Fix this by ignoring duplicate or stale ACKs before touching bc_acked or bc_ackers. This makes repeated GRP_ACK_MSG handling idempotent and prevents the underflow path.
--- net/tipc/group.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/tipc/group.c +5 -1
@@ -746,6 +746,7 @@ void tipc_group_proto_rcv(struct tipc_gru32 port =msg_origport (hdr);struct tipc_member *m, *pm;u16 remitted, in_flight; +u16 acked;if (!grp)return ;
@@ -798,7 +799,10 @@ void tipc_group_proto_rcv(struct tipc_grcase GRP_ACK_MSG :if (!m)return ; - m->bc_acked =msg_grp_bc_acked (hdr); + acked =msg_grp_bc_acked (hdr); +if (less_eq (acked, m->bc_acked)) +return ; + m->bc_acked = acked;if (--grp->bc_ackers)return ;list_del_init (&m->small_win);
Greg Kroah-Hartman
maintainerPATCH 39/55 wifi: brcmsmac: Fix dma_free_coherent() size
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Fourier <[email protected]>
commit 12cd7632757a54ce586e36040210b1a738a0fc53 upstream.
dma_alloc_consistent() may change the size to align it. The new size is saved in alloced.
Change the free size to match the allocation size.
--- drivers/net/wireless/broadcom/brcm80211/brcmsmac/dma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/broadcom/brcm80211/brcmsmac/dma.c +1 -1
@@ -483,7 +483,7 @@ static void *dma_ringalloc(struct dma_inif (((desc_strtaddr + size -1 ) & boundary) != (desc_strtaddr & boundary)) { *alignbits =dma_align_sizetobits (size); -dma_free_coherent (di->dmadev, size, va, *descpa); +dma_free_coherent (di->dmadev, *alloced, va, *descpa); va =dma_alloc_consistent (di, size, *alignbits, alloced, descpa); }
Greg Kroah-Hartman
maintainerPATCH 40/55 arm64: dts: hisilicon: poplar: Correct PCIe reset GPIO polarity
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shawn Guo <[email protected]>
commit c1f2b0f2b5e37b2c27540a175aea2755a3799433 upstream.
The PCIe reset GPIO on Poplar is actually active low. The active high worked before because kernel driver didn't respect the setting from DT. This is changed since commit 1d26a55fbeb9 ("PCI: histb: Switch to using gpiod API"), and thus PCIe on Poplar got brken since then.
Fix the problem by correcting the polarity.
--- arch/arm64/boot/dts/hisilicon/hi3798cv200-poplar.dts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/hisilicon/hi3798cv200-poplar.dts +1 -1
@@ -179,7 +179,7 @@ }; &pcie { - reset-gpios = <&gpio4 4 GPIO_ACTIVE_HIGH>; + reset-gpios = <&gpio4 4 GPIO_ACTIVE_LOW>; vpcie-supply = <®_pcie>; status = "okay"; };
Greg Kroah-Hartman
maintainerPATCH 41/55 arm64: dts: hisilicon: hi3798cv200: Add missing dma-ranges
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shawn Guo <[email protected]>
commit 1af997cad473d505248df6d9577183bb91f69670 upstream.
Reboot starts failing on Poplar since commit 8424ecdde7df ("arm64: mm:
Set ZONE_DMA size based on devicetree's dma-ranges"), which effectively changes zone_dma_bits from 30 to 32 for arm64 platforms that do not properly define dma-ranges in device tree. It's unclear how Poplar reboot gets broken by this change exactly, but a dma-ranges limiting zone_dma to the first 1 GB fixes the regression.
--- arch/arm64/boot/dts/hisilicon/hi3798cv200.dtsi | 1 + 1 file changed, 1 insertion(+)
arch/arm64/boot/dts/hisilicon/hi3798cv200.dtsi +1 -0
@@ -81,6 +81,7 @@ #address-cells = <1>; #size-cells = <1>; ranges = <0x0 0x0 0xf0000000 0x10000000>; + dma-ranges = <0x0 0x0 0x0 0x40000000>; crg: clock-reset-controller@8a22000 { compatible = "hisilicon,hi3798cv200-crg", "syscon", "simple-mfd";
Greg Kroah-Hartman
maintainerPATCH 42/55 nfc: pn533: allocate rx skb before consuming bytes
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
commit c71ba669b570c7b3f86ec875be222ea11dacb352 upstream.
pn532_receive_buf() reports the number of accepted bytes to the serdev core. The current code consumes bytes into recv_skb and may already hand a complete frame to pn533_recv_frame() before allocating a fresh receive buffer.
If that alloc_skb() fails, the callback returns 0 even though it has already consumed bytes, and it leaves recv_skb as NULL for the next receive callback. That breaks the receive_buf() accounting contract and can also lead to a NULL dereference on the next skb_put_u8().
Allocate the receive skb lazily before consuming the next byte instead. If allocation fails, return the number of bytes already accepted.
--- drivers/nfc/pn533/uart.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/nfc/pn533/uart.c +8 -3
@@ -211,6 +211,13 @@ static int pn532_receive_buf(struct serddel_timer (&dev->cmd_timeout);for (i =0 ; i < count; i++) { +if (!dev->recv_skb) { + dev->recv_skb =alloc_skb (PN532_UART_SKB_BUFF_LEN , +GFP_KERNEL ); +if (!dev->recv_skb) +return i; + } +if (unlikely (!skb_tailroom (dev->recv_skb)))skb_trim (dev->recv_skb,0 );
@@ -219,9 +226,7 @@ static int pn532_receive_buf(struct serdcontinue ;pn533_recv_frame (dev->priv, dev->recv_skb,0 ); - dev->recv_skb =alloc_skb (PN532_UART_SKB_BUFF_LEN ,GFP_KERNEL ); -if (!dev->recv_skb) -return 0 ; + dev->recv_skb =NULL ; }return i;
Greg Kroah-Hartman
maintainerPATCH 43/55 batman-adv: reject oversized global TT response buffers
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruide Cao <[email protected]>
commit 3a359bf5c61d52e7f09754108309d637532164a6 upstream.
batadv_tt_prepare_tvlv_global_data() builds the allocation length for a global TT response in 16-bit temporaries. When a remote originator advertises a large enough global TT, the TT payload length plus the VLAN header offset can exceed 65535 and wrap before kmalloc().
The full-table response path still uses the original TT payload length when it fills tt_change, so the wrapped allocation is too small and batadv_tt_prepare_tvlv_global_data() writes past the end of the heap object before the later packet-size check runs.
Fix this by rejecting TT responses whose TVLV value length cannot fit in the 16-bit TVLV payload length field.
--- net/batman-adv/translation-table.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
net/batman-adv/translation-table.c +7 -2
@@ -844,8 +844,8 @@ batadv_tt_prepare_tvlv_global_data(struc {u16 num_vlan =0 ;u16 num_entries =0 ; -u16 change_offset; -u16 tvlv_len; +u16 tvlv_len =0 ; +unsigned int change_offset;struct batadv_tvlv_tt_vlan_data *tt_vlan;struct batadv_orig_node_vlan *vlan;u8 *tt_change_ptr;
@@ -863,6 +863,11 @@ batadv_tt_prepare_tvlv_global_data(strucif (*tt_len <0 ) *tt_len =batadv_tt_len (num_entries); +if (change_offset >U16_MAX || *tt_len >U16_MAX - change_offset) { + *tt_len =0 ; + goto out; + } + tvlv_len = *tt_len; tvlv_len += change_offset;
Greg Kroah-Hartman
maintainerPATCH 44/55 EDAC/mc: Fix error path ordering in edac_mc_alloc()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Borislav Petkov (AMD) <[email protected]>
commit 51520e03e70d6c73e33ee7cbe0319767d05764fe upstream.
When the mci->pvt_info allocation in edac_mc_alloc() fails, the error path will call put_device() which will end up calling the device's release function.
However, the init ordering is wrong such that device_initialize() happens *after* the failed allocation and thus the device itself and the release function pointer are not initialized yet when they're called:
MCE: In-kernel MCE decoding enabled.
------------[ cut here ]------------ kobject: '(null)': is not initialized, yet kobject_put() is being called. WARNING: lib/kobject.c:734 at kobject_put, CPU#22: systemd-udevd CPU: 22 UID: 0 PID: 538 Comm: systemd-udevd Not tainted 7.0.0-rc1+ #2 PREEMPT(full) RIP: 0010:kobject_put Call Trace: <TASK> edac_mc_alloc+0xbe/0xe0 [edac_core] amd64_edac_init+0x7a4/0xff0 [amd64_edac] ? __pfx_amd64_edac_init+0x10/0x10 [amd64_edac] do_one_initcall ...
Reorder the calling sequence so that the device is initialized and thus the release function pointer is properly set before it can be used.
This was found by Claude while reviewing another EDAC patch.
--- drivers/edac/edac_mc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/edac/edac_mc.c +3 -3
@@ -369,13 +369,13 @@ struct mem_ctl_info *edac_mc_alloc(unsigif (!mci->layers) goto error; + mci->dev.release = mci_release; +device_initialize (&mci->dev); + mci->pvt_info =kzalloc (sz_pvt,GFP_KERNEL );if (!mci->pvt_info) goto error; - mci->dev.release = mci_release; -device_initialize (&mci->dev); -/* setup index and various internal pointers */ mci->mc_idx = mc_num; mci->tot_dimms = tot_dimms;
Greg Kroah-Hartman
maintainerPATCH 45/55 net/tls: fix use-after-free in -EBUSY error path of tls_do_encryption
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muhammad Alifa Ramdhan <[email protected]>
commit a9b8b18364fffce4c451e6f6fd218fa4ab646705 upstream.
The -EBUSY handling in tls_do_encryption(), introduced by commit 859054147318 ("net: tls: handle backlogging of crypto requests"), has a use-after-free due to double cleanup of encrypt_pending and the scatterlist entry.
When crypto_aead_encrypt() returns -EBUSY, the request is enqueued to the cryptd backlog and the async callback tls_encrypt_done() will be invoked upon completion. That callback unconditionally restores the scatterlist entry (sge->offset, sge->length) and decrements ctx->encrypt_pending. However, if tls_encrypt_async_wait() returns an error, the synchronous error path in tls_do_encryption() performs the same cleanup again, double-decrementing encrypt_pending and double-restoring the scatterlist.
The double-decrement corrupts the encrypt_pending sentinel (initialized to 1), making tls_encrypt_async_wait() permanently skip the wait for pending async callbacks. A subsequent sendmsg can then free the tls_rec via bpf_exec_tx_verdict() while a cryptd callback is still pending, resulting in a use-after-free when the callback fires on the freed record.
Fix this by skipping the synchronous cleanup when the -EBUSY async wait returns an error, since the callback has already handled encrypt_pending and sge restoration.
--- net/tls/tls_sw.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
net/tls/tls_sw.c +10 -0
@@ -585,6 +585,16 @@ static int tls_do_encryption(struct sockif (rc == -EBUSY ) { rc =tls_encrypt_async_wait (ctx); rc = rc ?: -EINPROGRESS ; +/* +* The async callback tls_encrypt_done() has already +* decremented encrypt_pending and restored the sge on +* both success and error. Skip the synchronous cleanup +* below on error, just remove the record and return. +*/ +if (rc != -EINPROGRESS ) { +list_del (&rec->list); +return rc; + } }if (!rc || rc != -EINPROGRESS ) {atomic_dec (&ctx->encrypt_pending);
Greg Kroah-Hartman
maintainerPATCH 46/55 net: altera-tse: fix skb leak on DMA mapping error in tse_start_xmit()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Carlier <[email protected]>
commit 6dede3967619b5944003227a5d09fdc21ed57d10 upstream.
When dma_map_single() fails in tse_start_xmit(), the function returns NETDEV_TX_OK without freeing the skb. Since NETDEV_TX_OK tells the stack the packet was consumed, the skb is never freed, leaking memory on every DMA mapping failure.
Add dev_kfree_skb_any() before returning to properly free the skb.
--- drivers/net/ethernet/altera/altera_tse_main.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/altera/altera_tse_main.c +1 -0
@@ -572,6 +572,7 @@ static netdev_tx_t tse_start_xmit(struct DMA_TO_DEVICE);if (dma_mapping_error (priv->device, dma_addr)) {netdev_err (priv->dev,"%s: DMA mapping error\n" , __func__); +dev_kfree_skb_any (skb); ret =NETDEV_TX_OK ; goto out; }
Greg Kroah-Hartman
maintainerPATCH 47/55 batman-adv: hold claim backbone gateways by reference
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haoze Xie <[email protected]>
commit 82d8701b2c930d0e96b0dbc9115a218d791cb0d2 upstream.
batadv_bla_add_claim() can replace claim->backbone_gw and drop the old gateway's last reference while readers still follow the pointer.
The netlink claim dump path dereferences claim->backbone_gw->orig and takes claim->backbone_gw->crc_lock without pinning the underlying backbone gateway. batadv_bla_check_claim() still has the same naked pointer access pattern.
Reuse batadv_bla_claim_get_backbone_gw() in both readers so they operate on a stable gateway reference until the read-side work is complete. This keeps the dump and claim-check paths aligned with the lifetime rules introduced for the other BLA claim readers.
--- net/batman-adv/bridge_loop_avoidance.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-)
net/batman-adv/bridge_loop_avoidance.c +18 -9
@@ -2132,6 +2132,7 @@ batadv_bla_claim_dump_entry(struct sk_bu struct batadv_bla_claim *claim) {const u8 *primary_addr = primary_if->net_dev->dev_addr; +struct batadv_bla_backbone_gw *backbone_gw;u16 backbone_crc;bool is_own;void *hdr;
@@ -2147,32 +2148,35 @@ batadv_bla_claim_dump_entry(struct sk_bugenl_dump_check_consistent (cb, hdr); - is_own =batadv_compare_eth (claim->backbone_gw->orig, - primary_addr); + backbone_gw =batadv_bla_claim_get_backbone_gw (claim); + + is_own =batadv_compare_eth (backbone_gw->orig, primary_addr); -spin_lock_bh (&claim->backbone_gw->crc_lock); - backbone_crc = claim->backbone_gw->crc; -spin_unlock_bh (&claim->backbone_gw->crc_lock); +spin_lock_bh (&backbone_gw->crc_lock); + backbone_crc = backbone_gw->crc; +spin_unlock_bh (&backbone_gw->crc_lock);if (is_own)if (nla_put_flag (msg,BATADV_ATTR_BLA_OWN )) {genlmsg_cancel (msg, hdr); - goto out; + goto put_backbone_gw; }if (nla_put (msg,BATADV_ATTR_BLA_ADDRESS ,ETH_ALEN , claim->addr) ||nla_put_u16 (msg,BATADV_ATTR_BLA_VID , claim->vid) ||nla_put (msg,BATADV_ATTR_BLA_BACKBONE ,ETH_ALEN , - claim->backbone_gw->orig) || + backbone_gw->orig) ||nla_put_u16 (msg,BATADV_ATTR_BLA_CRC , backbone_crc)) {genlmsg_cancel (msg, hdr); - goto out; + goto put_backbone_gw; }genlmsg_end (msg, hdr); ret =0 ; +put_backbone_gw: +batadv_backbone_gw_put (backbone_gw); out:return ret; }
@@ -2468,6 +2472,7 @@ out:bool batadv_bla_check_claim (struct batadv_priv *bat_priv,u8 *addr,unsigned short vid) { +struct batadv_bla_backbone_gw *backbone_gw;struct batadv_bla_claim search_claim;struct batadv_bla_claim *claim =NULL ;struct batadv_hard_iface *primary_if =NULL ;
@@ -2490,9 +2495,13 @@ bool batadv_bla_check_claim(struct batad* return false. */ if (claim) { -if (!batadv_compare_eth (claim->backbone_gw->orig, + backbone_gw =batadv_bla_claim_get_backbone_gw (claim); + +if (!batadv_compare_eth (backbone_gw->orig, primary_if->net_dev->dev_addr)) ret = false; + +batadv_backbone_gw_put (backbone_gw);batadv_claim_put (claim); }
Greg Kroah-Hartman
maintainerPATCH 48/55 drm/i915/gt: fix refcount underflow in intel_engine_park_heartbeat
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Brzezinka <[email protected]>
commit 4c71fd099513bfa8acab529b626e1f0097b76061 upstream.
A use-after-free / refcount underflow is possible when the heartbeat worker and intel_engine_park_heartbeat() race to release the same engine->heartbeat.systole request.
The heartbeat worker reads engine->heartbeat.systole and calls i915_request_put() on it when the request is complete, but clears the pointer in a separate, non-atomic step. Concurrently, a request retirement on another CPU can drop the engine wakeref to zero, triggering __engine_park() -> intel_engine_park_heartbeat(). If the heartbeat timer is pending at that point, cancel_delayed_work() returns true and intel_engine_park_heartbeat() reads the stale non-NULL systole pointer and calls i915_request_put() on it again, causing a refcount underflow:
``` <4> [487.221889] Workqueue: i915-unordered engine_retire [i915] <4> [487.222640] RIP: 0010:refcount_warn_saturate+0x68/0xb0 ... <4> [487.222707] Call Trace: <4> [487.222711] <TASK> <4> [487.222716] intel_engine_park_heartbeat.part.0+0x6f/0x80 [i915] <4> [487.223115] intel_engine_park_heartbeat+0x25/0x40 [i915] <4> [487.223566] __engine_park+0xb9/0x650 [i915] <4> [487.223973] ____intel_wakeref_put_last+0x2e/0xb0 [i915] <4> [487.224408] __intel_wakeref_put_last+0x72/0x90 [i915] <4> [487.224797] intel_context_exit_engine+0x7c/0x80 [i915] <4> [487.225238] intel_context_exit+0xf1/0x1b0 [i915] <4> [487.225695] i915_request_retire.part.0+0x1b9/0x530 [i915] <4> [487.226178] i915_request_retire+0x1c/0x40 [i915] <4> [487.226625] engine_retire+0x122/0x180 [i915] <4> [487.227037] process_one_work+0x239/0x760 <4> [487.227060] worker_thread+0x200/0x3f0 <4> [487.227068] ? __pfx_worker_thread+0x10/0x10 <4> [487.227075] kthread+0x10d/0x150 <4> [487.227083] ? __pfx_kthread+0x10/0x10 <4> [487.227092] ret_from_fork+0x3d4/0x480 <4> [487.227099] ? __pfx_kthread+0x10/0x10 <4> [487.227107] ret_from_fork_asm+0x1a/0x30 <4> [487.227141] </TASK> ```
Fix this by replacing the non-atomic pointer read + separate clear with xchg() in both racing paths. xchg() is a single indivisible hardware instruction that atomically reads the old pointer and writes NULL. This guarantees only one of the two concurrent callers obtains the non-NULL pointer and performs the put, the other gets NULL and skips it.
--- drivers/gpu/drm/i915/gt/intel_engine_heartbeat.c | 26 +++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-)
drivers/gpu/drm/i915/gt/intel_engine_heartbeat.c +18 -8
@@ -116,10 +116,12 @@ static void heartbeat(struct work_struct/* Just in case everything has gone horribly wrong, give it a kick */ intel_engine_flush_submission (engine); - rq = engine->heartbeat.systole; -if (rq &&i915_request_completed (rq)) { -i915_request_put (rq); - engine->heartbeat.systole =NULL ; + rq =xchg (&engine->heartbeat.systole,NULL ); +if (rq) { +if (i915_request_completed (rq)) +i915_request_put (rq); +else + engine->heartbeat.systole = rq; }if (!intel_engine_pm_get_if_awake (engine))
@@ -200,8 +202,11 @@ static void heartbeat(struct work_struct unlock:mutex_unlock (&ce->timeline->mutex); out: -if (!engine->i915->params.enable_hangcheck || !next_heartbeat (engine)) -i915_request_put (fetch_and_zero (&engine->heartbeat.systole)); +if (!engine->i915->params.enable_hangcheck || !next_heartbeat (engine)) { + rq =xchg (&engine->heartbeat.systole,NULL ); +if (rq) +i915_request_put (rq); + }intel_engine_pm_put (engine); }
@@ -215,8 +220,13 @@ void intel_engine_unpark_heartbeat(strucvoid intel_engine_park_heartbeat (struct intel_engine_cs *engine) { -if (cancel_delayed_work (&engine->heartbeat.work)) -i915_request_put (fetch_and_zero (&engine->heartbeat.systole)); +if (cancel_delayed_work (&engine->heartbeat.work)) { +struct i915_request *rq; + + rq =xchg (&engine->heartbeat.systole,NULL ); +if (rq) +i915_request_put (rq); + } }void intel_gt_unpark_heartbeats (struct intel_gt *gt)
Greg Kroah-Hartman
maintainerPATCH 49/55 net/mlx5: Update the list of the PCI supported devices
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Guralnik <[email protected]>
commit a9d4f4f6e65e0bf9bbddedecc84d67249991979c upstream.
Add the upcoming ConnectX-10 NVLink-C2C device ID to the table of supported PCI device IDs.
--- drivers/net/ethernet/mellanox/mlx5/core/main.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/mellanox/mlx5/core/main.c +1 -0
@@ -2043,6 +2043,7 @@ static const struct pci_device_id mlx5_c { PCI_VDEVICE(MELLANOX, 0x1023) }, /* ConnectX-8 */ { PCI_VDEVICE(MELLANOX, 0x1025) }, /* ConnectX-9 */ { PCI_VDEVICE(MELLANOX, 0x1027) }, /* ConnectX-10 */ + { PCI_VDEVICE(MELLANOX, 0x2101) }, /* ConnectX-10 NVLink-C2C */ { PCI_VDEVICE(MELLANOX, 0xa2d2) }, /* BlueField integrated ConnectX-5 network controller */ { PCI_VDEVICE(MELLANOX, 0xa2d3), MLX5_PCI_DEV_IS_VF}, /* BlueField integrated ConnectX-5 network controller VF */ { PCI_VDEVICE(MELLANOX, 0xa2d6) }, /* BlueField-2 integrated ConnectX-6 Dx network controller */
Greg Kroah-Hartman
maintainerPATCH 50/55 mmc: vub300: fix NULL-deref on disconnect
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit dff34ef879c5e73298443956a8b391311ba78d57 upstream.
Make sure to deregister the controller before dropping the reference to the driver data on disconnect to avoid NULL-pointer dereferences or use-after-free.
--- drivers/mmc/host/vub300.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/host/vub300.c +1 -1
@@ -2371,8 +2371,8 @@ static void vub300_disconnect(struct usbusb_set_intfdata (interface,NULL );/* prevent more I/O from starting */ vub300->interface =NULL ; -kref_put (&vub300->kref, vub300_delete);mmc_remove_host (mmc); +kref_put (&vub300->kref, vub300_delete);pr_info ("USB vub300 remote SDIO host controller[%d]" " now disconnected" , ifnum);return ;
Greg Kroah-Hartman
maintainerPATCH 51/55 net: qualcomm: qca_uart: report the consumed byte on RX skb allocation failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
commit b76254c55dc8f23edc089027dd3f8792554c69fb upstream.
qca_tty_receive() consumes each input byte before checking whether a completed frame needs a fresh receive skb. When the current byte completes a frame, the driver delivers that frame and then allocates a new skb for the next one.
If that allocation fails, the current code returns i even though data[i] has already been consumed and may already have completed the delivered frame. Since serdev interprets the return value as the number of accepted bytes, this under-reports progress by one byte and can replay the final byte of the completed frame into a fresh parser state on the next call.
Return i + 1 in that failure path so the accepted-byte count matches the actual receive-state progress.
--- drivers/net/ethernet/qualcomm/qca_uart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/qualcomm/qca_uart.c +1 -1
@@ -115,7 +115,7 @@ qca_tty_receive(struct serdev_device *seif (!qca->rx_skb) {netdev_dbg (netdev,"recv: out of RX resources\n" ); n_stats->rx_errors++; -return i; +return i +1 ; } } }
Greg Kroah-Hartman
maintainerPATCH 52/55 net: stmmac: fix integer underflow in chain mode
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tyllis Xu <[email protected]>
commit 51f4e090b9f87b40c21b6daadb5c06e6c0a07b67 upstream.
The jumbo_frm() chain-mode implementation unconditionally computes
len = nopaged_len - bmax;
where nopaged_len = skb_headlen(skb) (linear bytes only) and bmax is BUF_SIZE_8KiB or BUF_SIZE_2KiB. However, the caller stmmac_xmit() decides to invoke jumbo_frm() based on skb->len (total length including page fragments):
is_jumbo = stmmac_is_jumbo_frm(priv, skb->len, enh_desc);
When a packet has a small linear portion (nopaged_len <= bmax) but a large total length due to page fragments (skb->len > bmax), the subtraction wraps as an unsigned integer, producing a huge len value (~0xFFFFxxxx). This causes the while (len != 0) loop to execute hundreds of thousands of iterations, passing skb->data + bmax * i pointers far beyond the skb buffer to dma_map_single(). On IOMMU-less SoCs (the typical deployment for stmmac), this maps arbitrary kernel memory to the DMA engine, constituting a kernel memory disclosure and potential memory corruption from hardware.
Fix this by introducing a buf_len local variable clamped to min(nopaged_len, bmax). Computing len = nopaged_len - buf_len is then always safe: it is zero when the linear portion fits within a single descriptor, causing the while (len != 0) loop to be skipped naturally, and the fragment loop in stmmac_xmit() handles page fragments afterward.
--- drivers/net/ethernet/stmicro/stmmac/chain_mode.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/net/ethernet/stmicro/stmmac/chain_mode.c +6 -5
@@ -20,7 +20,7 @@ static int jumbo_frm(struct stmmac_tx_quunsigned int nopaged_len =skb_headlen (skb);struct stmmac_priv *priv = tx_q->priv_data;unsigned int entry = tx_q->cur_tx; -unsigned int bmax, des2; +unsigned int bmax, buf_len, des2;unsigned int i =1 , len;struct dma_desc *desc;
@@ -31,17 +31,18 @@ static int jumbo_frm(struct stmmac_tx_quelse bmax = BUF_SIZE_2KiB; - len = nopaged_len - bmax; + buf_len = min_t(unsigned int, nopaged_len, bmax); + len = nopaged_len - buf_len; des2 =dma_map_single (priv->device, skb->data, - bmax,DMA_TO_DEVICE ); + buf_len,DMA_TO_DEVICE ); desc->des2 =cpu_to_le32 (des2);if (dma_mapping_error (priv->device, des2))return -1 ; tx_q->tx_skbuff_dma[entry].buf = des2; - tx_q->tx_skbuff_dma[entry].len = bmax; + tx_q->tx_skbuff_dma[entry].len = buf_len;/* do not close the descriptor and do not set own bit */ -stmmac_prepare_tx_desc (priv, desc,1 , bmax, csum,STMMAC_CHAIN_MODE , +stmmac_prepare_tx_desc (priv, desc,1 , buf_len, csum,STMMAC_CHAIN_MODE ,0 , false, skb->len);while (len !=0 ) {
Greg Kroah-Hartman
maintainerPATCH 53/55 rxrpc: fix reference count leak in rxrpc_server_keyring()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luxiao Xu <[email protected]>
commit f125846ee79fcae537a964ce66494e96fa54a6de upstream.
This patch fixes a reference count leak in rxrpc_server_keyring() by checking if rx->securities is already set.
--- net/rxrpc/server_key.c | 3 +++ 1 file changed, 3 insertions(+)
net/rxrpc/server_key.c +3 -0
@@ -125,6 +125,9 @@ int rxrpc_server_keyring(struct rxrpc_so_enter ("" ); +if (rx->securities) +return -EINVAL ; +if (optlen <=0 || optlen >PAGE_SIZE -1 )return -EINVAL ;
Greg Kroah-Hartman
maintainerPATCH 54/55 rxrpc: Fix key/keyring checks in setsockopt(RXRPC_SECURITY_KEY/KEYRING)
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
commit 2afd86ccbb2082a3c4258aea8c07e5bb6267bc2f upstream.
An AF_RXRPC socket can be both client and server at the same time. When sending new calls (ie. it's acting as a client), it uses rx->key to set the security, and when accepting incoming calls (ie. it's acting as a server), it uses rx->securities.
setsockopt(RXRPC_SECURITY_KEY) sets rx->key to point to an rxrpc-type key and setsockopt(RXRPC_SECURITY_KEYRING) sets rx->securities to point to a keyring of rxrpc_s-type keys.
Now, it should be possible to use both rx->key and rx->securities on the same socket - but for userspace AF_RXRPC sockets rxrpc_setsockopt() prevents that.
Fix this by:
(1) Remove the incorrect check rxrpc_setsockopt(RXRPC_SECURITY_KEYRING)
makes on rx->key.
(2) Move the check that rxrpc_setsockopt(RXRPC_SECURITY_KEY) makes on
rx->key down into rxrpc_request_key().
(3) Remove rxrpc_request_key()'s check on rx->securities.
This (in combination with a previous patch) pushes the checks down into the functions that set those pointers and removes the cross-checks that prevent both key and keyring being set.
--- net/rxrpc/af_rxrpc.c | 6 ------ net/rxrpc/key.c | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-)
net/rxrpc/af_rxrpc.c +0 -6
@@ -615,9 +615,6 @@ static int rxrpc_setsockopt(struct socke goto success;case RXRPC_SECURITY_KEY : - ret = -EINVAL ; -if (rx->key) - goto error; ret = -EISCONN ;if (rx->sk.sk_state !=RXRPC_UNBOUND ) goto error;
@@ -625,9 +622,6 @@ static int rxrpc_setsockopt(struct socke goto error;case RXRPC_SECURITY_KEYRING : - ret = -EINVAL ; -if (rx->key) - goto error; ret = -EISCONN ;if (rx->sk.sk_state !=RXRPC_UNBOUND ) goto error;
net/rxrpc/key.c +1 -1
@@ -452,7 +452,7 @@ int rxrpc_request_key(struct rxrpc_sock_enter ("" ); -if (optlen <=0 || optlen >PAGE_SIZE -1 || rx->securities) +if (optlen <=0 || optlen >PAGE_SIZE -1 || rx->key)return -EINVAL ; description =memdup_sockptr_nul (optval, optlen);
Greg Kroah-Hartman
maintainerPATCH 55/55 Revert "PCI: Enable ACS after configuring IOMMU for OF platforms"
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manivannan Sadhasivam <[email protected]>
This reverts commit 5d57164c0ab0ac5c99eca49c577994bfbca70a2a which is commit c41e2fb67e26b04d919257875fa954aa5f6e392e upstream.
The original commit attempted to enable ACS in pci_dma_configure() prior to IOMMU group assignment in iommu_init_device() to fix the ACS enablement issue for OF platforms. But that assumption doesn't hold true for kernel versions prior to v6.15, because on these older kernels, pci_dma_configure() is called *after* iommu_init_device(). So the IOMMU groups are already created before the ACS gets enabled. This causes the devices that should have been split into separate groups by ACS, getting merged into one group, thereby breaking the IOMMU isolation as reported on the AMD machines.
So revert the offending commit to restore the IOMMU group assignment on those affected machines. It should be noted that ACS has never really worked on kernel versions prior to v6.15, so the revert doesn't make any difference for OF platforms.
--- drivers/pci/pci-driver.c | 8 -------- drivers/pci/pci.c | 10 +++++++++- drivers/pci/pci.h | 1 - 3 files changed, 9 insertions(+), 10 deletions(-)
drivers/pci/pci-driver.c +0 -8
@@ -1667,14 +1667,6 @@ static int pci_dma_configure(struct devi ret =acpi_dma_configure (dev,acpi_get_dma_attr (adev)); } -/* -* Attempt to enable ACS regardless of capability because some Root -* Ports (e.g. those quirked with *_intel_pch_acs_*) do not have -* the standard ACS capability but still support ACS via those -* quirks. -*/ -pci_enable_acs (to_pci_dev (dev)); -pci_put_host_bridge_device (bridge);if (!ret && !driver->driver_managed_dma) {
drivers/pci/pci.c +9 -1
@@ -1040,7 +1040,7 @@ static void pci_std_enable_acs(struct pc* pci_enable_acs - enable ACS if hardware support it * @dev: the PCI device */ -void pci_enable_acs (struct pci_dev *dev) +static void pci_enable_acs (struct pci_dev *dev) {if (!pci_acs_enable) goto disable_acs_redir;
@@ -3777,6 +3777,14 @@ bool pci_acs_path_enabled(struct pci_devvoid pci_acs_init (struct pci_dev *dev) { dev->acs_cap =pci_find_ext_capability (dev,PCI_EXT_CAP_ID_ACS ); + +/* +* Attempt to enable ACS regardless of capability because some Root +* Ports (e.g. those quirked with *_intel_pch_acs_*) do not have +* the standard ACS capability but still support ACS via those +* quirks. +*/ +pci_enable_acs (dev); }/**
drivers/pci/pci.h +0 -1
@@ -526,7 +526,6 @@ static inline resource_size_t pci_resour }void pci_acs_init (struct pci_dev *dev); -void pci_enable_acs (struct pci_dev *dev);#ifdef CONFIG_PCI_QUIRKS int pci_dev_specific_acs_enabled (struct pci_dev *dev,u16 acs_flags);int pci_dev_specific_enable_acs (struct pci_dev *dev);
The first time I booted this kernel I had an odd failure where it failed to mount most of the filesystems and the network came up incorrectly (different mac). Some sort of udev issue perhaps? Nothing useful in dmesg to report and I've been unable to reproduce the problem after several reboots. Just mentioning it in case anyone else has any weird issues with this one.
# Librecast Test Results
020/020 [ OK ] liblcrq
010/010 [ OK ] libmld
120/120 [ OK ] liblibrecast
CPU/kernel: Linux auntie 6.1.169-rc1-00369-g6dadbe7e9a85 #1 SMP PREEMPT_DYNAMIC Mon Apr 13 17:05:23 -00 2026 x86_64 AMD Ryzen 9 9950X 16-Core Processor AuthenticAMD GNU/Linux
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 6.1.169 release. There are 55 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Wed, 15 Apr 2026 15:57:08 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 8 lines
https://www.kernel.org/pub/linux/kernel/v6.x/stable-review/patch-6.1.169-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-6.1.y
and the diffstat can be found below.thanks,
greg k-h
On ARCH_BRCMSTB using 32-bit and 64-bit ARM kernels, build tested on BMIPS_GENERIC:
Signature · 1 line
Florian
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 6.1.169 release. There are 55 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Wed, 15 Apr 2026 15:57:08 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 8 lines
https://www.kernel.org/pub/linux/kernel/v6.x/stable-review/patch-6.1.169-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-6.1.y
and the diffstat can be found below.thanks,
greg k-h
All tests passing for Tegra ...
Test results for stable-v6.1:
10 builds: 10 pass, 0 fail
28 boots: 28 pass, 0 fail
132 tests: 132 pass, 0 failLinux version: 6.1.169-rc1-g6dadbe7e9a85
Boards tested: tegra124-jetson-tk1, tegra186-p2771-0000,
tegra186-p3509-0000+p3636-0001, tegra194-p2972-0000,
tegra194-p3509-0000+p3668-0000, tegra20-ventana,
tegra210-p2371-2180, tegra210-p3450-0000,
tegra30-cardhu-a04Jon
Hi!
Quoted 4 lines
This is the start of the stable review cycle for the 6.1.169 release. There are 55 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
CIP testing did not find any problems here:
https://gitlab.com/cip-project/cip-testing/linux-stable-rc-ci/-/tree/linux-6.1.y
Best regards,
Pavel
Hi!
Quoted 4 lines
This is the start of the stable review cycle for the 6.1.169 release. There are 55 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
CIP testing did not find any problems here:
https://gitlab.com/cip-project/cip-testing/linux-stable-rc-ci/-/tree/linux-6.19.y
Best regards,
Pavel
Am 13.04.2026 um 18:00 schrieb Greg Kroah-Hartman:
Quoted 4 lines
This is the start of the stable review cycle for the 6.1.169 release. There are 55 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Builds, boots and works on my 2-socket Ivy Bridge Xeon E5-2697 v2 server. No dmesg oddities or regressions found.
Beste Grüße,
Peter Schneider
Signature · 8 lines
Climb the mountain not to plant your flag, but to embrace the challenge, enjoy the air and behold the view. Climb it so you can see the world, not so the world can see you. -- David McCullough Jr. OpenPGP: 0xA3828BD796CCE11A8CADE8866E3A92C92C3FF244 Download: https://www.peters-netzplatz.de/download/pschneider1968_pub.asc https://keys.mailvelope.com/pks/lookup?op=get&[email protected] https://keys.mailvelope.com/pks/lookup?op=get&[email protected]
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 6.1.169 release. There are 55 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Wed, 15 Apr 2026 15:57:08 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 8 lines
https://www.kernel.org/pub/linux/kernel/v6.x/stable-review/patch-6.1.169-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-6.1.y
and the diffstat can be found below.thanks,
greg k-h
Built and booted successfully on RISC-V RV64 (HiFive Unmatched).
Quoted 4 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 6.1.169 release. There are 55 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 6.1.169 release. There are 55 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Wed, 15 Apr 2026 15:57:08 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 9 lines
https://www.kernel.org/pub/linux/kernel/v6.x/stable-review/patch-6.1.169-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-6.1.y
and the diffstat can be found below.thanks,
greg k-h
Compiled and booted on my test system. No dmesg regressions.
thanks,
-- Shuah
Quoted 8 lines · On Mon, 13 Apr 2026 18:00:34 +0200 Greg Kroah-Hartman…
This is the start of the stable review cycle for the 6.1.169 release. There are 55 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Wed, 15 Apr 2026 15:57:08 +0000. Anything received after that time might be too late.
Boot-tested under QEMU for Rust x86_64:
Thanks!
Cheers,
Miguel
Quoted 4 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 6.1.169 release. There are 55 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 6.1.169 release. There are 55 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Wed, 15 Apr 2026 15:57:08 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 8 lines
https://www.kernel.org/pub/linux/kernel/v6.x/stable-review/patch-6.1.169-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-6.1.y
and the diffstat can be found below.thanks,
greg k-h
Tested on an amd64 laptop (Lenovo ThinkPad T14 Gen 1). Working well, no regressions observed.
Signature · 1 line
-Barry K. Nathan <[email protected]>
Hi,
Quoted 8 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 6.1.169 release. There are 55 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Wed, 15 Apr 2026 15:57:08 +0000. Anything received after that time might be too late.
Looking through my test logs, I find that the following build error has been reported since v6.1.166.
Building arm:ixp4xx_defconfig ... failed
--------------
Error log:drivers/net/ethernet/xscale/ixp4xx_eth.c:390:39: warning: 'struct kernel_hwtstamp_config' declared inside parameter list will not be visible outside of this definition or declaration
390 | struct kernel_hwtstamp_config *cfg,
| ^~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/xscale/ixp4xx_eth.c: In function 'ixp4xx_hwtstamp_set':drivers/net/ethernet/xscale/ixp4xx_eth.c:408:16: error: invalid use of undefined type 'struct kernel_hwtstamp_config'
Backported patches in that driver are
5195b10c34b8 net: ethernet: xscale: Check for PTP support properly a94d5447f6bf net: ixp4xx_eth: convert to ndo_hwtstamp_get() and ndo_hwtstamp_set()
where a94d5447f6bf introduces the problem and presumably was applied to be able to apply 5195b10c34b8 without having to resolve conflicts.
Unfortunately, 'struct kernel_hwtstamp_config' is indeed not available in v6.1, causing the build failure.
a94d5447f6bf can not be reverted on its own, so both patches would have to be reverted to fix the problem.
The same problem is seen in v5.15.y since v5.15.202. The commits there are
144dde314698 net: ethernet: xscale: Check for PTP support properly 612c622ab8ef net: ixp4xx_eth: convert to ndo_hwtstamp_get() and ndo_hwtstamp_set()
I have copied the patch authors for advice.
Guenter
Quoted 2 lines · Guenter Roeck
Looking through my test logs, I find that the following build error has been reported since v6.1.166.
Ugh not good, but no disaster, OpenWrt is the only downstream using stable and it only used v6.12 and v6.18.
Quoted 1 line
I have copied the patch authors for advice.
I'd just pull them both out again. It's fixing a runtime crash that appear only when you use ethtool. Annoying, but fringe system and not appearing in normal use.
Yours,
Linus Walleij