6.6.154-rc1 review
Greg Kroah-Hartman
maintainercover 6.6.154-rc1 review
This is the start of the stable review cycle for the 6.6.154 release. There are 87 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 Thu, 27 Aug 2026 13:25:02 +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.6.154-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.6.y
and the diffstat can be found below.
thanks,
greg k-h
-------------
Pseudo-Shortlog of commits:
Greg Kroah-Hartman <[email protected]>
Linux 6.6.154-rc1
Laxman Acharya Padhya <[email protected]>
Bluetooth: hci_event: validate LE Set CIG Parameters response
Chengfeng Ye <[email protected]>
Bluetooth: hci_event: fix LE list UAF on reset
Michael Bommarito <[email protected]>
HID: hyperv: validate initial device info bounds
Haoxiang Li <[email protected]>
HID: sensor: custom: Fix use-after-free in enable_sensor
Jann Horn <[email protected]>
HID: core: fix number/pointer type confusion on long items
Ibrahim Hashimov <[email protected]>
HID: nintendo: fix out-of-bounds read in joycon_ctlr_read_handler()
Bryam Vargas <[email protected]>
selinux: require a class's permission values to cover its permission count
Bryam Vargas <[email protected]>
selinux: reject a permission value exceeding the class permission count
Christian Göttsche <[email protected]>
selinux: more strict policy parsing
Christian Göttsche <[email protected]>
selinux: use u16 for security classes
Christian Göttsche <[email protected]>
selinux: make more use of str_read() when loading the policy
Christian Göttsche <[email protected]>
selinux: avoid unnecessary indirection in struct level_datum
Christian Göttsche <[email protected]>
selinux: use known type instead of void pointer
Paul Moore <[email protected]>
selinux: fix style issues in security/selinux/ss/policydb.c
Paul Moore <[email protected]>
selinux: fix style issues in security/selinux/ss/policydb.h
Shardul Bankar <[email protected]>
mptcp: pm: fix memory leak from alloc-during-teardown race
Donglin Lyu <[email protected]>
Input: atkbd - skip deactivate for HONOR ZQC-P
Cryolitia PukNgae <[email protected]>
Input: atkbd - skip deactivate for HONOR FMB-P's internal keyboard
Chengfeng Ye <[email protected]>
Bluetooth: hci_sync: Fix advertising data UAFs
Xiang Mei (Microsoft) <[email protected]>
xfrm: fix sk_dst_cache double-free in xfrm_user_policy()
Baul Lee <[email protected]>
HID: core: fix OOB read of field->usage in hid_set_field()
Lee Jones <[email protected]>
HID: magicmouse: Prevent out-of-bounds (OOB) read during DOUBLE_REPORT_ID
Jose Villaseñor Montfort <[email protected]>
HID: magicmouse: do not keep a stale msc->input if no input is claimed
Andrei Fed <[email protected]>
HID: magicmouse: fix battery reporting for Bluetooth Magic Trackpad USB-C
Qing Luo <[email protected]>
mptcp: pm: fix data race in add_addr timer callback
Dawid Wróbel <[email protected]>
ASoC: codecs: lpass-tx-macro: Fix enum kcontrol accesses
Peter Ujfalusi <[email protected]>
ASoC: SOF: ipc4-pcm: Continue the pipeline trigger in case of IPC timeout
Peter Ujfalusi <[email protected]>
ASoC: SOF: pcm: Add snd_sof_pcm specific wrappers for dev_dbg() and dev_err()
Peter Ujfalusi <[email protected]>
ASoC: SOF: pcm: Move period/buffer configuration print after platform open
Peter Ujfalusi <[email protected]>
ASoC: SOF: Relocate and rework functionality for PCM stream freeing
Kuninori Morimoto <[email protected]>
ASoC: sof: pcm: use snd_pcm_direction_name()
Greg Kroah-Hartman <[email protected]>
nvmet-tcp: Do not WARN on remotely-controlled oversized SGL allocations
Jiang HongHui <[email protected]>
nvmet-fc: fix invalid free in LS IOD error path
Bryam Vargas <[email protected]>
nvmet-auth: zero the AUTH_RECEIVE response buffer
Luxiao Xu <[email protected]>
ipv6: fix use-after-free in ip6_finish_output2()
Yong Wang <[email protected]>
ipv4: reject undersized MTUs in ip_do_fragment()
Pavitra Jha <[email protected]>
libceph: fix OOB read in decode_watchers() via missing bounds check
Linmao Li <[email protected]>
Input: byd - synchronize timer deletion before freeing private data
Eric Dumazet <[email protected]>
ndisc: ndisc_send_redirect() cleanup
Linmao Li <[email protected]>
nfc: nci: free destination parameters when closing a connection
Samuel Page <[email protected]>
nfc: nci: fix uninit-value in the RF discover/activated NTF handlers
Samuel Page <[email protected]>
nfc: nci: fix out-of-bounds write in nci_target_auto_activated()
Doruk Tan Ozturk <[email protected]>
nfc: st21nfca: validate ATR_REQ length against the received frame
Xu Rao <[email protected]>
nfc: pn533: purge fragmented skbs during cleanup
Doruk Tan Ozturk <[email protected]>
nfc: llcp: reject PDUs shorter than the LLCP header
Muhammad Bilal <[email protected]>
nfc: llcp: fix OOB read and u8 offset wrap in TLV parsers
Doruk Tan Ozturk <[email protected]>
nfc: llcp: bound the connect_sn TLV walk to the skb
Pengpeng Hou <[email protected]>
nfc: microread: validate target discovery payload lengths
Bryam Vargas <[email protected]>
nfc: fdp: bound the device-reported read length and fix an skb leak
Doruk Tan Ozturk <[email protected]>
nfc: digital: clamp SENSF_RES length to the destination buffer
Yang Wang <[email protected]>
drm/amdgpu: check ASPM on the dGPU host link
Nathan Lucas <[email protected]>
drm/amd/display: fix BT.2020 YCbCr limited output CSC matrix
Ilya Bakoulin <[email protected]>
drm/amd/display: Fix BT2020 YCbCr limited/full range input
Kenneth Feng <[email protected]>
drm/amd/amdgpu: disable ASPM in some situations
Eric Farman <[email protected]>
s390/vfio_ccw: Implement a crw lock
Eric Farman <[email protected]>
s390/vfio_ccw: Calculate idal length based on idaw type
Eric Farman <[email protected]>
s390/vfio_ccw: Ensure first IDAW remains constant
Eric Farman <[email protected]>
s390/vfio_ccw: Free all memory if cp_init() fails
Junjie Cao <[email protected]>
gpio: ml-ioh: use raw_spinlock_t for the register lock
Hongling Zeng <[email protected]>
xfs: validate attr entry pointer before field access
Guanghui Yang <[email protected]>
ext4: clear error before retrying inode xattr space fallback
Matthias Goergens <[email protected]>
ext4: stop retrying saturated xattr cache entries
Tetsuo Handa <[email protected]>
kcov: fix data corruption and race conditions on PREEMPT_RT
Rik van Riel <[email protected]>
null_blk: fix UBSAN shift-out-of-bounds when zone_size is 0 or overflows
Ian Bridges <[email protected]>
ocfs2: fix missing metadata reservation for large xattrs
Takashi Iwai <[email protected]>
ALSA: dummy: Check card index validity at probe
Ibrahim Hashimov <[email protected]>
xfs: bounds-check buffer log item's dirty bitmap
Christoph Hellwig <[email protected]>
xfs: don't use a xfs_log_iovec for ri_buf in log recovery
Pei Xiao <[email protected]>
mmc: atmel-mci: Fix use-after-free in atmci_remove due to race condition
Zhiling Zou <[email protected]>
inet: frags: publish queues before arming timer
Eric Dumazet <[email protected]>
inet: frags: save a pair of atomic operations in reassembly
Eric Dumazet <[email protected]>
inet: frags: change inet_frag_kill() to defer refcount updates
Eric Dumazet <[email protected]>
ipv4: frags: remove ipq_put()
Eric Dumazet <[email protected]>
inet: frags: add inet_frag_putn() helper
Luca Fresi <[email protected]>
serial: sc16is7xx: enable THRI before filling TX FIFO
Hugo Villeneuve <[email protected]>
serial: sc16is7xx: use guards for simple mutex locks
Hugo Villeneuve <[email protected]>
serial: sc16is7xx: rename EFR mutex with generic name
Lech Perczak <[email protected]>
serial: sc16is7xx: convert bitmask definitions to use BIT() macro
Lech Perczak <[email protected]>
serial: sc16is7xx: fix copy-paste errors in EFR_SWFLOWx_BIT constants
Jan Sebastian Götte <[email protected]>
serial: qcom-geni: fix TX DMA buffer flush
Aditya Chillara <[email protected]>
perf/core: Fix group leader use-after-free after sibling detach
Peter Zijlstra <[email protected]>
perf: Unify perf_event_free_task() / perf_event_exit_task_context()
Fan Wu <[email protected]>
serial: amba-pl011: synchronize DMA teardown
Koichiro Den <[email protected]>
NTB: ntb_netdev: Preserve RX queue depth on allocation failure
Griffin Kroah-Hartman <[email protected]>
rndis_host: add overflow check in rndis_rx_fixup()
Ali Ahmet Memis <[email protected]>
Bluetooth: RFCOMM: take rfcomm_mutex for the deferred setup accept
Steffen Persvold <[email protected]>
PCI: host-generic: Fix NULL pointer dereference on 32-bit CAM systems
-------------
Diffstat:
Makefile | 4 +- drivers/block/null_blk/zoned.c | 10 +- drivers/gpio/gpio-ml-ioh.c | 36 +- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 100 ++- drivers/gpu/drm/amd/amdgpu/nv.c | 2 +- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 6 +- .../drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c | 2 +- drivers/gpu/drm/amd/display/dc/basics/dc_common.c | 3 +- .../gpu/drm/amd/display/dc/core/dc_hw_sequencer.c | 34 +- drivers/gpu/drm/amd/display/dc/core/dc_resource.c | 4 +- drivers/gpu/drm/amd/display/dc/dc_hw_types.h | 4 +- .../drm/amd/display/dc/dce/dce_stream_encoder.c | 3 +- .../amd/display/dc/dcn10/dcn10_stream_encoder.c | 3 +- .../display/dc/dcn31/dcn31_hpo_dp_stream_encoder.c | 3 +- drivers/gpu/drm/amd/display/dc/inc/hw/dpp.h | 6 +- .../amd/display/modules/info_packet/info_packet.c | 4 +- drivers/hid/hid-core.c | 11 +- drivers/hid/hid-hyperv.c | 27 +- drivers/hid/hid-input.c | 3 + drivers/hid/hid-magicmouse.c | 45 +- drivers/hid/hid-nintendo.c | 7 +- drivers/hid/hid-sensor-custom.c | 21 +- drivers/input/keyboard/atkbd.c | 23 +- drivers/input/mouse/byd.c | 2 +- drivers/mmc/host/atmel-mci.c | 2 + drivers/net/ntb_netdev.c | 15 +- drivers/net/usb/rndis_host.c | 6 +- drivers/nfc/fdp/i2c.c | 27 + drivers/nfc/microread/microread.c | 31 +- drivers/nfc/pn533/pn533.c | 1 + drivers/nfc/st21nfca/dep.c | 3 + drivers/nvme/target/fabrics-cmd-auth.c | 2 +- drivers/nvme/target/fc.c | 2 +- drivers/nvme/target/tcp.c | 5 +- drivers/pci/controller/pci-host-generic.c | 11 +- drivers/pci/ecam.c | 13 + drivers/s390/cio/vfio_ccw_chp.c | 26 +- drivers/s390/cio/vfio_ccw_cp.c | 43 +- drivers/s390/cio/vfio_ccw_cp.h | 2 + drivers/s390/cio/vfio_ccw_drv.c | 6 + drivers/s390/cio/vfio_ccw_ops.c | 4 + drivers/s390/cio/vfio_ccw_private.h | 4 + drivers/tty/serial/amba-pl011.c | 8 +- drivers/tty/serial/qcom_geni_serial.c | 51 +- drivers/tty/serial/sc16is7xx.c | 222 +++--- fs/ext4/xattr.c | 7 +- fs/ocfs2/xattr.c | 18 +- fs/xfs/libxfs/xfs_attr_leaf.c | 14 + fs/xfs/libxfs/xfs_log_recover.h | 4 +- fs/xfs/xfs_attr_item.c | 24 +- fs/xfs/xfs_bmap_item.c | 18 +- fs/xfs/xfs_buf_item.c | 8 +- fs/xfs/xfs_buf_item.h | 2 +- fs/xfs/xfs_buf_item_recover.c | 95 ++- fs/xfs/xfs_dquot_item_recover.c | 20 +- fs/xfs/xfs_extfree_item.c | 43 +- fs/xfs/xfs_icreate_item.c | 2 +- fs/xfs/xfs_inode_item.c | 6 +- fs/xfs/xfs_inode_item.h | 4 +- fs/xfs/xfs_inode_item_recover.c | 26 +- fs/xfs/xfs_log_recover.c | 16 +- fs/xfs/xfs_refcount_item.c | 16 +- fs/xfs/xfs_rmap_item.c | 16 +- fs/xfs/xfs_trans.h | 1 - include/linux/pci-ecam.h | 3 + include/linux/sched.h | 8 + include/net/inet_frag.h | 6 +- include/net/ipv6_frag.h | 5 +- kernel/events/core.c | 161 ++--- kernel/kcov.c | 90 +-- lib/Kconfig.debug | 5 +- net/bluetooth/hci_event.c | 8 +- net/bluetooth/hci_sync.c | 137 +++- net/bluetooth/rfcomm/core.c | 24 +- net/ceph/osd_client.c | 5 +- net/ieee802154/6lowpan/reassembly.c | 27 +- net/ipv4/inet_fragment.c | 33 +- net/ipv4/ip_fragment.c | 48 +- net/ipv4/ip_output.c | 4 + net/ipv6/ip6_output.c | 2 + net/ipv6/ndisc.c | 8 +- net/ipv6/netfilter/nf_conntrack_reasm.c | 27 +- net/ipv6/reassembly.c | 29 +- net/mptcp/pm_netlink.c | 9 +- net/mptcp/pm_userspace.c | 7 +- net/mptcp/protocol.c | 9 + net/mptcp/protocol.h | 7 +- net/nfc/digital_technology.c | 2 + net/nfc/llcp_commands.c | 18 +- net/nfc/llcp_core.c | 15 +- net/nfc/nci/ntf.c | 10 +- net/nfc/nci/rsp.c | 1 + net/xfrm/xfrm_state.c | 4 +- security/selinux/include/security.h | 1 + security/selinux/ss/avtab.c | 45 +- security/selinux/ss/avtab.h | 23 +- security/selinux/ss/conditional.c | 40 +- security/selinux/ss/conditional.h | 6 +- security/selinux/ss/constraint.h | 1 + security/selinux/ss/ebitmap.c | 4 +- security/selinux/ss/ebitmap.h | 5 +- security/selinux/ss/mls.c | 6 +- security/selinux/ss/policydb.c | 743 +++++++++++++-------- security/selinux/ss/policydb.h | 249 +++---- security/selinux/ss/services.c | 8 +- sound/drivers/dummy.c | 6 + sound/soc/codecs/lpass-tx-macro.c | 4 +- sound/soc/sof/ipc3-pcm.c | 13 +- sound/soc/sof/ipc3-topology.c | 20 +- sound/soc/sof/ipc4-pcm.c | 35 +- sound/soc/sof/ipc4-topology.c | 18 +- sound/soc/sof/pcm.c | 157 +++-- sound/soc/sof/sof-audio.c | 36 - sound/soc/sof/sof-audio.h | 17 +- 115 files changed, 2047 insertions(+), 1291 deletions(-)
Greg Kroah-Hartman
maintainerPATCH 1/87 PCI: host-generic: Fix NULL pointer dereference on 32-bit CAM systems
6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steffen Persvold <[email protected]>
commit 008cb88edb41f3c7c8e0ed763ff9f26719830984 upstream.
On 32-bit systems the config space is too large to ioremap in one go, so pci_ecam_create() maps each bus segment separately and relies on the ->add_bus callback (pci_ecam_add_bus) to populate the per-bus mapping in cfg->winp[]. pci_ecam_map_bus() then uses that mapping as the base for every config access.
The generic ECAM ops (pci_generic_ecam_ops) already provide the ->add_bus and ->remove_bus callbacks, but the CAM (legacy) ops in pci-host-generic.c do not. As a result, on a 32-bit host using "pci-host-cam-generic" the per-bus mapping is never set up and the first config read dereferences a NULL base, crashing during bus enumeration:
Unable to handle kernel NULL pointer dereference at virtual address 00000800 Oops [#1] CPU: 0 PID: 1 Comm: swapper Not tainted 6.9.7+ #43 Hardware name: Digilent Nexys-Video-A7 RV32 (DT) epc : pci_generic_config_read+0x40/0xb0 ra : pci_generic_config_read+0x2c/0xb0 [<c038db9c>] pci_generic_config_read+0x40/0xb0 [<c038da04>] pci_bus_read_config_dword+0x50/0xb0 [<c0391e94>] pci_bus_generic_read_dev_vendor_id+0x3c/0x1ec [<c039245c>] pci_scan_single_device+0xa4/0x11c [<c0392570>] pci_scan_slot+0x9c/0x23c [<c039388c>] pci_scan_child_bus_extend+0x58/0x2f4 [<c0393db0>] pci_scan_root_bus_bridge+0x64/0xe8 [<c0393e54>] pci_host_probe+0x20/0xc8 [<c03bc6f4>] pci_host_common_probe+0x144/0x1e4
Fix this by giving the CAM ops the same ->add_bus/->remove_bus callbacks. Since pci_ecam_add_bus() and pci_ecam_remove_bus() are static to ecam.c, move the CAM ops definition there as pci_generic_cam_ops (mirroring pci_generic_ecam_ops) and export it for pci-host-generic.c to reference.
--- drivers/pci/controller/pci-host-generic.c | 11 +---------- drivers/pci/ecam.c | 13 +++++++++++++ include/linux/pci-ecam.h | 3 +++ 3 files changed, 17 insertions(+), 10 deletions(-)
drivers/pci/controller/pci-host-generic.c +1 -10
@@ -14,15 +14,6 @@#include <linux/pci-ecam.h> #include <linux/platform_device.h> -static const struct pci_ecam_ops gen_pci_cfg_cam_bus_ops = { - .bus_shift =16 , - .pci_ops = { - .map_bus = pci_ecam_map_bus, - .read = pci_generic_config_read, - .write = pci_generic_config_write, - } -}; -static bool pci_dw_valid_device (struct pci_bus *bus,unsigned int devfn) {struct pci_config_window *cfg = bus->sysdata;
@@ -58,7 +49,7 @@ static const struct pci_ecam_ops pci_dw_static const struct of_device_id gen_pci_of_match[] = { { .compatible ="pci-host-cam-generic" , - .data = &gen_pci_cfg_cam_bus_ops }, + .data = &pci_generic_cam_ops }, { .compatible ="pci-host-ecam-generic" , .data = &pci_generic_ecam_ops },
drivers/pci/ecam.c +13 -0
@@ -208,6 +208,19 @@ const struct pci_ecam_ops pci_generic_ec };EXPORT_SYMBOL_GPL (pci_generic_ecam_ops); +/* CAM ops */ +const struct pci_ecam_ops pci_generic_cam_ops = { + .bus_shift =16 , + .pci_ops = { + .add_bus = pci_ecam_add_bus, + .remove_bus = pci_ecam_remove_bus, + .map_bus = pci_ecam_map_bus, + .read = pci_generic_config_read, + .write = pci_generic_config_write, + } +}; +EXPORT_SYMBOL_GPL (pci_generic_cam_ops); +#if defined(CONFIG_ACPI ) && defined(CONFIG_PCI_QUIRKS )/* ECAM ops for 32-bit access only (non-compliant) */ const struct pci_ecam_ops pci_32b_ops = {
include/linux/pci-ecam.h +3 -0
@@ -77,6 +77,9 @@ void __iomem *pci_ecam_map_bus(struct pc/* default ECAM ops */ extern const struct pci_ecam_ops pci_generic_ecam_ops; +/* default CAM ops */ +extern const struct pci_ecam_ops pci_generic_cam_ops; +#if defined(CONFIG_ACPI ) && defined(CONFIG_PCI_QUIRKS )extern const struct pci_ecam_ops pci_32b_ops;/* 32-bit accesses only */ extern const struct pci_ecam_ops pci_32b_read_ops;/* 32-bit read only */
Greg Kroah-Hartman
maintainerPATCH 2/87 Bluetooth: RFCOMM: take rfcomm_mutex for the deferred setup accept
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ali Ahmet Memis <[email protected]>
commit 43a556b2fd43f2df6dded59c2e26560a27874c24 upstream.
rfcomm_sock_recvmsg() completes a deferred setup by calling rfcomm_dlc_accept() without holding any RFCOMM lock:
if (test_and_clear_bit(RFCOMM_DEFER_SETUP, &d->flags)) {
rfcomm_dlc_accept(d);
return 0;
}and rfcomm_dlc_accept() dereferences the session on its first line:
struct sock *sk = d->session->sock->sk;
Every other path that touches d->session runs under rfcomm_mutex:rfcomm_dlc_open(), rfcomm_dlc_close(), rfcomm_dlc_exists(), rfcomm_dlc_send_rpn(), and the RFCOMM thread through rfcomm_process_sessions(). rfcomm_connect_ind() is even documented as "called under rfcomm_lock()". This call site is the only one that skips it.
The RFCOMM_DEFER_SETUP bit looks like it serialises the accept against teardown, since __rfcomm_dlc_close() returns early when it wins the test_and_clear. But rfcomm_recv_disc() forces the state first:
d->state = BT_CLOSED; __rfcomm_dlc_close(d, err);
and the early return only covers BT_CONNECT, BT_CONFIG, BT_OPEN and BT_CONNECT2. With the state already BT_CLOSED that switch does not match, the bit is never consulted, and __rfcomm_dlc_close() falls through to rfcomm_dlc_unlink(), which sets d->session = NULL.
So a remote DISC on a deferred dlc clears the session while leaving RFCOMM_DEFER_SETUP set. The next recvmsg() then passes the test_and_clear and dereferences a NULL session. No timing window is
needed: once the DISC has been processed, the dereference is unconditional.
Give rfcomm_dlc_accept() the same shape as rfcomm_dlc_open() and rfcomm_dlc_close(): an exported wrapper that takes rfcomm_mutex and re-checks the session, around a __rfcomm_dlc_accept() that the two in-core callers, which already hold the mutex, keep using.
Reproduced on a KASAN + PROVE_LOCKING kernel with a BR/EDR peer emulated over /dev/vhci: the peer brings up an ACL link, opens L2CAP on the RFCOMM PSM, starts a session, opens a dlc on a channel bound with BT_DEFER_SETUP, and sends DISC after the socket is accepted. recv() on the accepted socket then hits:
Oops: general protection fault
KASAN: null-ptr-deref in range [0x0000000000000010-0x0000000000000017]
RIP: 0010:rfcomm_dlc_accept+0x54/0x350
Call Trace:
rfcomm_sock_recvmsg+0x1cd/0x230
sock_recvmsg+0x166/0x1c0
__sys_recvfrom+0x20d/0x3000x10 is the offset of sock in struct rfcomm_session. With this patch the same run completes with recv() returning 0 and no report, and lockdep stays quiet, confirming rfcomm_mutex is still taken before lock_sock on this path as it is on the thread side.
--- net/bluetooth/rfcomm/core.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)
net/bluetooth/rfcomm/core.c +21 -3
@@ -1334,7 +1334,10 @@ static struct rfcomm_session *rfcomm_recreturn s; } -void rfcomm_dlc_accept (struct rfcomm_dlc *d) +/* Must be called with rfcomm_mutex held, so that the session cannot be +* unlinked from under us. +*/ +static void __rfcomm_dlc_accept (struct rfcomm_dlc *d) {struct sock *sk = d->session->sock->sk;struct l2cap_conn *conn =l2cap_pi (sk)->chan->conn;
@@ -1356,6 +1359,21 @@ void rfcomm_dlc_accept(struct rfcomm_dlcrfcomm_send_msc (d->session,1 , d->dlci, d->v24_sig); } +void rfcomm_dlc_accept (struct rfcomm_dlc *d) +{ +rfcomm_lock (); + +/* rfcomm_recv_disc() sets the dlc state to BT_CLOSED before calling +* __rfcomm_dlc_close(), so the RFCOMM_DEFER_SETUP handshake there is +* skipped and the session can already be unlinked by the time the +* deferred accept runs from rfcomm_sock_recvmsg(). +*/ +if (d->session) +__rfcomm_dlc_accept (d); + +rfcomm_unlock (); +} +static void rfcomm_check_accept (struct rfcomm_dlc *d) {if (rfcomm_check_security (d)) {
@@ -1368,7 +1386,7 @@ static void rfcomm_check_accept(struct r d->state_change (d,0 );rfcomm_dlc_unlock (d); }else -rfcomm_dlc_accept (d); +__rfcomm_dlc_accept (d); }else {set_bit (RFCOMM_AUTH_PENDING , &d->flags);rfcomm_dlc_set_timer (d,RFCOMM_AUTH_TIMEOUT );
@@ -1953,7 +1971,7 @@ static void rfcomm_process_dlcs(struct r d->state_change (d,0 );rfcomm_dlc_unlock (d); }else -rfcomm_dlc_accept (d); +__rfcomm_dlc_accept (d); }continue ; }else if (test_and_clear_bit (RFCOMM_AUTH_REJECT , &d->flags)) {
Greg Kroah-Hartman
maintainerPATCH 3/87 rndis_host: add overflow check in rndis_rx_fixup()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Griffin Kroah-Hartman <[email protected]>
commit 965a251f23ff69cfb4486974d4532e9bb551c7fc upstream.
Add an overflow check to ensure that data_offset + data_len + 8 does not wrap, which would enable an OOB read of the USB data buffer.
--- drivers/net/usb/rndis_host.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/usb/rndis_host.c +5 -1
@@ -14,6 +14,7 @@#include <linux/usb/cdc.h> #include <linux/usb/usbnet.h> #include <linux/usb/rndis_host.h> +#include <linux/overflow.h> /*
@@ -506,6 +507,7 @@ int rndis_rx_fixup(struct usbnet *dev, sstruct rndis_data_hdr *hdr = (void *)skb->data;struct sk_buff *skb2;u32 msg_type, msg_len, data_offset, data_len; +u32 overflow_check; msg_type =le32_to_cpu (hdr->msg_type); msg_len =le32_to_cpu (hdr->msg_len);
@@ -514,7 +516,9 @@ int rndis_rx_fixup(struct usbnet *dev, s/* don't choke if we see oob, per-packet data, etc */ if (unlikely (msg_type !=RNDIS_MSG_PACKET || skb->len < msg_len - || (data_offset + data_len +8 ) > msg_len)) { + || (data_offset + data_len +8 ) > msg_len + ||check_add_overflow (data_offset, data_len, &overflow_check) + ||check_add_overflow (overflow_check,8 , &overflow_check))) { dev->net->stats.rx_frame_errors++; netdev_dbg(dev->net, "bad rndis message %d/%d/%d/%d, len %d\n", le32_to_cpu(hdr->msg_type),
Greg Kroah-Hartman
maintainerPATCH 4/87 NTB: ntb_netdev: Preserve RX queue depth on allocation failure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Koichiro Den <[email protected]>
[ Upstream commit d2121faf133ac3bf9531b53a7e21273649a08517 ]
ntb_netdev_rx_handler() hands the received skb to the network stack before allocating its replacement. If the allocation fails, nothing is reposted. Every failure therefore takes one buffer out of the RX queue while the interface remains up, and enough failures eventually stall reception.
A retry path could refill the queue later, but ntb_netdev has none. Allocate the replacement first instead. If that fails, drop the packet and repost the same skb. This keeps the queue full and lets packet delivery resume as soon as memory is available again.
--- drivers/net/ntb_netdev.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/net/ntb_netdev.c +8 -7
@@ -100,7 +100,7 @@ static void ntb_netdev_rx_handler(struct void *data, int len) {struct net_device *ndev = qp_data; -struct sk_buff *skb; +struct sk_buff *skb, *new_skb;int rc; skb = data;
@@ -115,6 +115,12 @@ static void ntb_netdev_rx_handler(struct goto enqueue_again; } + new_skb =netdev_alloc_skb (ndev, ndev->mtu +ETH_HLEN ); +if (!new_skb) { + ndev->stats.rx_dropped++; + goto enqueue_again; + } +skb_put (skb, len); skb->protocol =eth_type_trans (skb, ndev); skb->ip_summed =CHECKSUM_NONE ;
@@ -127,12 +133,7 @@ static void ntb_netdev_rx_handler(struct ndev->stats.rx_bytes += len; } - skb =netdev_alloc_skb (ndev, ndev->mtu +ETH_HLEN ); -if (!skb) { - ndev->stats.rx_errors++; - ndev->stats.rx_frame_errors++; -return ; - } + skb = new_skb; enqueue_again: rc =ntb_transport_rx_enqueue (qp, skb, skb->data, ndev->mtu +ETH_HLEN );
Greg Kroah-Hartman
maintainerPATCH 5/87 serial: amba-pl011: synchronize DMA teardown
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
[ Upstream commit 440915499231e9db1c361aa45bb702e8fd3b4a32 ]
dmaengine_terminate_all() does not wait for a running callback, so the TX callback can still touch the TX buffer after it is freed. The RX poll timer reads the RX buffers without the port lock.
Switch to dmaengine_terminate_sync() and delete the RX timer before freeing the buffers.
--- drivers/tty/serial/amba-pl011.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/tty/serial/amba-pl011.c +4 -4
@@ -1193,7 +1193,7 @@ static void pl011_dma_shutdown(struct uaif (uap->using_tx_dma) {/* In theory, this should already be done by pl011_dma_flush_buffer */ -dmaengine_terminate_all (uap->dmatx.chan); +dmaengine_terminate_sync (uap->dmatx.chan);if (uap->dmatx.queued) { dma_unmap_single(uap->dmatx.chan->device->dev, uap->dmatx.dma, uap->dmatx.len,
@@ -1206,12 +1206,12 @@ static void pl011_dma_shutdown(struct ua }if (uap->using_rx_dma) { -dmaengine_terminate_all (uap->dmarx.chan); +if (uap->dmarx.poll_rate) +timer_delete_sync (&uap->dmarx.timer); +dmaengine_terminate_sync (uap->dmarx.chan);/* Clean up the RX DMA */ pl011_dmabuf_free (uap->dmarx.chan, &uap->dmarx.dbuf_a,DMA_FROM_DEVICE );pl011_dmabuf_free (uap->dmarx.chan, &uap->dmarx.dbuf_b,DMA_FROM_DEVICE ); -if (uap->dmarx.poll_rate) -del_timer_sync (&uap->dmarx.timer); uap->using_rx_dma = false; } }
Greg Kroah-Hartman
maintainerPATCH 6/87 perf: Unify perf_event_free_task() / perf_event_exit_task_context()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Zijlstra <[email protected]>
[ Upstream commit 90661365021a6d0d7f3a2c5046ebe33e4df53b92 ]
Both perf_event_free_task() and perf_event_exit_task_context() are very similar, except perf_event_exit_task_context() is a little more generic / makes less assumptions.
Stable-dep-of: 42c5ca1f0a28 ("perf/core: Fix group leader use-after-free after sibling detach")
--- kernel/events/core.c | 96 +++++++++++++-------------------------------------- 1 file changed, 26 insertions(+), 70 deletions(-)
kernel/events/core.c +26 -70
@@ -2393,6 +2393,7 @@ __perf_remove_from_context(struct perf_eperf_cgroup_event_disable (event, ctx);perf_event_set_state (event,min (event->state, state)); +if (flags &DETACH_GROUP )perf_group_detach (event);if (flags &DETACH_CHILD )
@@ -13276,13 +13277,11 @@ perf_event_exit_event(struct perf_eventperf_event_wakeup (event); } -static void perf_event_exit_task_context (struct task_struct *child) +static void perf_event_exit_task_context (struct task_struct *child,bool exit) {struct perf_event_context *child_ctx, *clone_ctx =NULL ;struct perf_event *child_event, *next; -WARN_ON_ONCE (child != current); - child_ctx =perf_pin_task_context (child);if (!child_ctx)return ;
@@ -13305,7 +13304,8 @@ static void perf_event_exit_task_context* in. */ raw_spin_lock_irq (&child_ctx->lock); -task_ctx_sched_out (child_ctx,EVENT_ALL ); +if (exit) +task_ctx_sched_out (child_ctx,EVENT_ALL );/* * Now that the context is inactive, destroy the task <-> ctx relation
@@ -13314,7 +13314,7 @@ static void perf_event_exit_task_contextRCU_INIT_POINTER (child->perf_event_ctxp,NULL );put_ctx (child_ctx);/* cannot be last */ WRITE_ONCE (child_ctx->task,TASK_TOMBSTONE ); -put_task_struct (current);/* cannot be last */ +put_task_struct (child);/* cannot be last */ clone_ctx =unclone_ctx (child_ctx);raw_spin_unlock_irq (&child_ctx->lock);
@@ -13327,13 +13327,31 @@ static void perf_event_exit_task_context* won't get any samples after PERF_RECORD_EXIT. We can however still * get a few PERF_RECORD_READ events. */ -perf_event_task (child, child_ctx,0 ); +if (exit) +perf_event_task (child, child_ctx,0 );list_for_each_entry_safe (child_event, next, &child_ctx->event_list, event_entry)perf_event_exit_event (child_event, child_ctx,0 );mutex_unlock (&child_ctx->mutex); +if (!exit) { +/* +* perf_event_release_kernel() could still have a reference on +* this context. In that case we must wait for these events to +* have been freed (in particular all their references to this +* task must've been dropped). +* +* Without this copy_process() will unconditionally free this +* task (irrespective of its reference count) and +* _free_event()'s put_task_struct(event->hw.target) will be a +* use-after-free. +* +* Wait for all events to drop their context reference. +*/ +wait_var_event (&child_ctx->refcount, +refcount_read (&child_ctx->refcount) ==1 ); + }put_ctx (child_ctx); }
@@ -13361,7 +13379,7 @@ void perf_event_exit_task(struct task_st }mutex_unlock (&child->perf_event_mutex); -perf_event_exit_task_context (child); +perf_event_exit_task_context (child, true);/* * The perf_event_exit_task_context calls perf_event_task
@@ -13372,27 +13390,6 @@ void perf_event_exit_task(struct task_stperf_event_task (child,NULL ,0 ); } -static void perf_free_event (struct perf_event *event, -struct perf_event_context *ctx) -{ -struct perf_event *parent = event->parent; - -if (WARN_ON_ONCE (!parent)) -return ; - -mutex_lock (&parent->child_mutex); -list_del_init (&event->child_list); -mutex_unlock (&parent->child_mutex); - -put_event (parent); - -raw_spin_lock_irq (&ctx->lock); -perf_group_detach (event); -list_del_event (event, ctx); -raw_spin_unlock_irq (&ctx->lock); -free_event (event); -} -/* * Free a context as created by inheritance by perf_event_init_task() below, * used by fork() in case of fail.
@@ -13402,48 +13399,7 @@ static void perf_free_event(struct perf_*/ void perf_event_free_task (struct task_struct *task) { -struct perf_event_context *ctx; -struct perf_event *event, *tmp; - - ctx =rcu_access_pointer (task->perf_event_ctxp); -if (!ctx) -return ; - -mutex_lock (&ctx->mutex); -raw_spin_lock_irq (&ctx->lock); -/* -* Destroy the task <-> ctx relation and mark the context dead. -* -* This is important because even though the task hasn't been -* exposed yet the context has been (through child_list). -*/ -RCU_INIT_POINTER (task->perf_event_ctxp,NULL ); -WRITE_ONCE (ctx->task,TASK_TOMBSTONE ); -put_task_struct (task);/* cannot be last */ -raw_spin_unlock_irq (&ctx->lock); - - -list_for_each_entry_safe (event, tmp, &ctx->event_list, event_entry) -perf_free_event (event, ctx); - -mutex_unlock (&ctx->mutex); - -/* -* perf_event_release_kernel() could've stolen some of our -* child events and still have them on its free_list. In that -* case we must wait for these events to have been freed (in -* particular all their references to this task must've been -* dropped). -* -* Without this copy_process() will unconditionally free this -* task (irrespective of its reference count) and -* _free_event()'s put_task_struct(event->hw.target) will be a -* use-after-free. -* -* Wait for all events to drop their context reference. -*/ -wait_var_event (&ctx->refcount,refcount_read (&ctx->refcount) ==1 ); -put_ctx (ctx);/* must be last */ +perf_event_exit_task_context (task, false); }void perf_event_delayed_put (struct task_struct *task)
Greg Kroah-Hartman
maintainerPATCH 7/87 perf/core: Fix group leader use-after-free after sibling detach
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aditya Chillara <[email protected]>
[ Upstream commit 42c5ca1f0a288a52878bd72a5595b08261057438 ]
perf_group_detach() handles leader and sibling detach differently. When the group leader is detached, all siblings are promoted to singleton events and their group_leader pointer is reset to themselves. When a sibling is detached, it is removed from the leader's sibling_list, but its group_leader pointer is left pointing at the old leader.
That is harmless when the sibling is being closed and freed immediately, as in the DETACH_DEAD path. It is not safe when the sibling is detached but kept alive, such as during CPU hotplug with DETACH_GROUP. In that case the sibling is removed from the context, while its file descriptor can still keep it alive.
A typical failing sequence is:
- A group contains leader L and sibling S.
- CPU hot-unplug detaches S with DETACH_GROUP, removing it from
L->sibling_list but leaving S->group_leader == L.
- L is later closed and freed.
- A PERF_IOC_FLAG_GROUP ioctl on S follows S->group_leader and dereferences the freed leader.
This was reproduced by running the perf event fuzzer, CPU hotplug, and a stress workload concurrently:
Unable to handle kernel paging request at virtual address 006b6b6b6b6b6cdb CPU: 2 PID: 12489 Comm: perf_fuzzer 6.18.7 PREEMPT pc : perf_ioctl+0x34c/0xc68 x20: ffffff89a3fa2c70 x8 : 6b6b6b6b6b6b6b6b Code: 943c4a0e 340047a0 f9404a94 f9411e88 (f940b908) Call trace: perf_ioctl+0x34c/0xc68 (P) __arm64_sys_ioctl+0xa0/0xf4 invoke_syscall+0x58/0xe4 el0_svc_common+0xa8/0xdc do_el0_svc+0x1c/0x28 el0_svc+0x40/0xc0 el0t_64_sync_handler+0x68/0xdc el0t_64_sync+0x1c4/0x1c8
The fault happened in perf_ioctl(), where perf_event_for_each() follows the stale group_leader pointer and perf_event_for_each_child() then dereferences the freed leader's context.
Fix the use-after-free by promoting the detached sibling to a singleton. Also fix __event_disable() cgroup accounting and event state change.
--- kernel/events/core.c | 67 ++++++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 30 deletions(-)
kernel/events/core.c +37 -30
@@ -2162,6 +2162,34 @@ static inline struct list_head *get_even &event->pmu_ctx->flexible_active; } +/* @sibling must already be unlinked from its old leader's sibling_list. */ +static void perf_promote_sibling_to_leader (struct perf_event *sibling, +struct perf_event_context *ctx, +int group_caps) +{ +/* +* Events that have PERF_EV_CAP_SIBLING require being part of +* a group and cannot exist on their own, schedule them out +* and move them into the ERROR state. Also see +* _perf_event_enable(), it will not be able to recover this +* ERROR state. +*/ +if (sibling->event_caps &PERF_EV_CAP_SIBLING ) +__event_disable (sibling, ctx,PERF_EVENT_STATE_ERROR ); + + sibling->group_leader = sibling; + sibling->group_caps = group_caps; + +if (sibling->attach_state &PERF_ATTACH_CONTEXT ) { +add_event_to_groups (sibling, ctx); + +if (sibling->state ==PERF_EVENT_STATE_ACTIVE ) +list_add_tail (&sibling->active_list,get_event_list (sibling)); + } + +perf_event__header_size (sibling); +} +static void perf_group_detach (struct perf_event *event) {struct perf_event *leader = event->group_leader;
@@ -2185,8 +2213,9 @@ static void perf_group_detach(struct per*/ if (leader != event) {list_del_init (&event->sibling_list); - event->group_leader->nr_siblings--; - event->group_leader->group_generation++; + leader->nr_siblings--; + leader->group_generation++; +perf_promote_sibling_to_leader (event, ctx, event->event_caps); goto out; }
@@ -2196,32 +2225,14 @@ static void perf_group_detach(struct per* to whatever list we are on. */ list_for_each_entry_safe (sibling, tmp, &event->sibling_list, sibling_list) { - -/* -* Events that have PERF_EV_CAP_SIBLING require being part of -* a group and cannot exist on their own, schedule them out -* and move them into the ERROR state. Also see -* _perf_event_enable(), it will not be able to recover this -* ERROR state. -*/ -if (sibling->event_caps &PERF_EV_CAP_SIBLING ) -__event_disable (sibling, ctx,PERF_EVENT_STATE_ERROR ); - - sibling->group_leader = sibling;list_del_init (&sibling->sibling_list);/* Inherit group flags from the previous leader */ - sibling->group_caps = event->group_caps; - -if (sibling->attach_state &PERF_ATTACH_CONTEXT ) { -add_event_to_groups (sibling, event->ctx); - -if (sibling->state ==PERF_EVENT_STATE_ACTIVE ) -list_add_tail (&sibling->active_list,get_event_list (sibling)); - } +perf_promote_sibling_to_leader (sibling, ctx, event->group_caps);WARN_ON_ONCE (sibling->ctx != event->ctx); } + event->nr_siblings =0 ; out:for_each_sibling_event (tmp, leader)
@@ -2387,12 +2398,7 @@ __perf_remove_from_context(struct perf_eif (flags &DETACH_DEAD ) state =PERF_EVENT_STATE_DEAD ; -event_sched_out (event, ctx); - -if (event->state >PERF_EVENT_STATE_OFF ) -perf_cgroup_event_disable (event, ctx); - -perf_event_set_state (event,min (event->state, state)); +__event_disable (event, ctx, state);if (flags &DETACH_GROUP )perf_group_detach (event);
@@ -2462,8 +2468,9 @@ static void __event_disable(struct perf_ enum perf_event_state state) {event_sched_out (event, ctx); -perf_cgroup_event_disable (event, ctx); -perf_event_set_state (event, state); +if (event->state >PERF_EVENT_STATE_OFF ) +perf_cgroup_event_disable (event, ctx); +perf_event_set_state (event,min (event->state, state)); }/*
Greg Kroah-Hartman
maintainerPATCH 8/87 serial: qcom-geni: fix TX DMA buffer flush
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jan Sebastian Götte <[email protected]>
[ Upstream commit e3c04834ae1ab5e9cfbe8ac54ec734aa4774249d ]
When transmit flushing a qcom-geni UART during an ongoing TX DMA, the UART gets stuck infinitely repeating corrupted TX DMA frames.
The DMA-mode uart_ops does not provide a flush_buffer callback, so an in-flight transfer can complete after serial core has reset the transmit kfifo, underflowing its length and resubmitting page-sized transfers indefinitely. Add one that stops the transfer and clears tx_remaining and tx_queued.
The stop path was also broken: it unmapped the buffer while the serial engine could still read it, and never reset the TX DMA state machine. Cancel the main sequencer command first, then reset the state machine and wait for it before unmapping. Drop the early return so a pending mapping is also cleaned up when the main command is inactive.
The bug can be triggered from userspace with a large write immediately followed by TCOFLUSH. A following tcdrain will hang forever. The bug was reproduced and this fix was validated on Arduino Uno Q (QRB2210) using /dev/ttyHS1.
--- drivers/tty/serial/qcom_geni_serial.c | 51 ++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 18 deletions(-)
drivers/tty/serial/qcom_geni_serial.c +33 -18
@@ -144,6 +144,7 @@ static const struct uart_ops qcom_geni_ustatic struct uart_driver qcom_geni_console_driver;static struct uart_driver qcom_geni_uart_driver; +static void qcom_geni_serial_stop_tx_dma (struct uart_port *uport);static int qcom_geni_serial_port_setup (struct uart_port *uport);static inline struct qcom_geni_serial_port *to_dev_port (struct uart_port *uport)
@@ -597,35 +598,48 @@ static unsigned int qcom_geni_serial_tx_return !readl (uport->membase +SE_GENI_TX_FIFO_STATUS ); } +static void qcom_geni_serial_flush_buffer_dma (struct uart_port *uport) +{ +struct qcom_geni_serial_port *port =to_dev_port (uport); + +qcom_geni_serial_stop_tx_dma (uport); + port->tx_remaining =0 ; +} +static void qcom_geni_serial_stop_tx_dma (struct uart_port *uport) {struct qcom_geni_serial_port *port =to_dev_port (uport);bool done; -if (!qcom_geni_serial_main_active (uport)) -return ; +if (qcom_geni_serial_main_active (uport)) { +geni_se_cancel_m_cmd (&port->se); + + done =qcom_geni_serial_poll_bit (uport,SE_GENI_M_IRQ_STATUS , +M_CMD_CANCEL_EN , true); +if (!done) { +geni_se_abort_m_cmd (&port->se); + done =qcom_geni_serial_poll_bit (uport,SE_GENI_M_IRQ_STATUS , +M_CMD_ABORT_EN , true); +if (!done) +dev_err_ratelimited (uport->dev,"M_CMD_ABORT_EN not set" ); +writel (M_CMD_ABORT_EN , uport->membase +SE_GENI_M_IRQ_CLEAR ); + } + +writel (M_CMD_CANCEL_EN , uport->membase +SE_GENI_M_IRQ_CLEAR ); + }if (port->tx_dma_addr) { +writel (1 , uport->membase +SE_DMA_TX_FSM_RST ); +if (!qcom_geni_serial_poll_bit (uport,SE_DMA_TX_IRQ_STAT , +TX_RESET_DONE , true)) +dev_err_ratelimited (uport->dev,"TX DMA reset failed" ); +writel (TX_RESET_DONE |TX_DMA_DONE , + uport->membase +SE_DMA_TX_IRQ_CLR ); +geni_se_tx_dma_unprep (&port->se, port->tx_dma_addr, port->tx_remaining); port->tx_dma_addr =0 ; - port->tx_remaining =0 ; - } - -geni_se_cancel_m_cmd (&port->se); - - done =qcom_geni_serial_poll_bit (uport,SE_GENI_M_IRQ_STATUS , -M_CMD_CANCEL_EN , true); -if (!done) { -geni_se_abort_m_cmd (&port->se); - done =qcom_geni_serial_poll_bit (uport,SE_GENI_M_IRQ_STATUS , -M_CMD_ABORT_EN , true); -if (!done) -dev_err_ratelimited (uport->dev,"M_CMD_ABORT_EN not set" ); -writel (M_CMD_ABORT_EN , uport->membase +SE_GENI_M_IRQ_CLEAR ); } - -writel (M_CMD_CANCEL_EN , uport->membase +SE_GENI_M_IRQ_CLEAR ); }static void qcom_geni_serial_start_tx_dma (struct uart_port *uport)
@@ -1600,6 +1614,7 @@ static const struct uart_ops qcom_geni_u .request_port = qcom_geni_serial_request_port, .config_port = qcom_geni_serial_config_port, .shutdown = qcom_geni_serial_shutdown, + .flush_buffer = qcom_geni_serial_flush_buffer_dma, .type = qcom_geni_serial_get_type, .set_mctrl = qcom_geni_serial_set_mctrl, .get_mctrl = qcom_geni_serial_get_mctrl,
Greg Kroah-Hartman
maintainerPATCH 9/87 serial: sc16is7xx: fix copy-paste errors in EFR_SWFLOWx_BIT constants
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lech Perczak <[email protected]>
[ Upstream commit eccdb0fd1c340155666533f5c60c5229d370baab ]
Comments attached to bits 0 and 1 incorrectly referenced bits 2 and 3, which don't match the datasheet - fix them.
At the same time remove comments for individual constants, as they add nothing to the definitions themselves.
Stable-dep-of: 246ac114f485 ("serial: sc16is7xx: enable THRI before filling TX FIFO")
--- drivers/tty/serial/sc16is7xx.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/tty/serial/sc16is7xx.c +7 -7
@@ -263,9 +263,9 @@* and writing to IER[7:4], * FCR[5:4], MCR[7:5] */ -#define SC16IS7XX_EFR_SWFLOW3_BIT (1 << 3)/* SWFLOW bit 3 */ -#define SC16IS7XX_EFR_SWFLOW2_BIT (1 << 2)/* SWFLOW bit 2 -* +#define SC16IS7XX_EFR_SWFLOW3_BIT (1 << 3) +#define SC16IS7XX_EFR_SWFLOW2_BIT (1 << 2) +/* * SWFLOW bits 3 & 2 table: * 00 -> no transmitter flow * control
@@ -277,10 +277,10 @@* XON1, XON2, XOFF1 and * XOFF2 */ -#define SC16IS7XX_EFR_SWFLOW1_BIT (1 << 1)/* SWFLOW bit 2 */ -#define SC16IS7XX_EFR_SWFLOW0_BIT (1 << 0)/* SWFLOW bit 3 -* -* SWFLOW bits 3 & 2 table: +#define SC16IS7XX_EFR_SWFLOW1_BIT (1 << 1) +#define SC16IS7XX_EFR_SWFLOW0_BIT (1 << 0) +/* +* SWFLOW bits 1 & 0 table: * 00 -> no received flow * control * 01 -> receiver compares
Greg Kroah-Hartman
maintainerPATCH 10/87 serial: sc16is7xx: convert bitmask definitions to use BIT() macro
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lech Perczak <[email protected]>
[ Upstream commit d2e8590fd1048c5c0dba160edc6a48ee8305a1f0 ]
Now that bit definition comments were cleaned up, convert bitmask definitions to use BIT() macro for clarity.
Convert SC16IS7XX_IIR_ID_MASK to use GENMASK() macro -
- while at that, realign comments.
Compose SC16IS7XX_LSR_BRK_ERROR_MASK using aforementioned constants, instead of open-coding it, and remove now unneeded comments.
Stable-dep-of: 246ac114f485 ("serial: sc16is7xx: enable THRI before filling TX FIFO")
--- drivers/tty/serial/sc16is7xx.c | 176 +++++++++++++++++++++-------------------- 1 file changed, 91 insertions(+), 85 deletions(-)
drivers/tty/serial/sc16is7xx.c +91 -85
@@ -9,6 +9,7 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt#include <linux/bitops.h> +#include <linux/bits.h> #include <linux/clk.h> #include <linux/delay.h> #include <linux/device.h>
@@ -73,52 +74,52 @@#define SC16IS7XX_XOFF2_REG (0x07)/* Xoff2 word */ /* IER register bits */ -#define SC16IS7XX_IER_RDI_BIT (1 << 0)/* Enable RX data interrupt */ -#define SC16IS7XX_IER_THRI_BIT (1 << 1)/* Enable TX holding register +#define SC16IS7XX_IER_RDI_BIT BIT(0)/* Enable RX data interrupt */ +#define SC16IS7XX_IER_THRI_BIT BIT(1)/* Enable TX holding register * interrupt */ -#define SC16IS7XX_IER_RLSI_BIT (1 << 2)/* Enable RX line status +#define SC16IS7XX_IER_RLSI_BIT BIT(2)/* Enable RX line status * interrupt */ -#define SC16IS7XX_IER_MSI_BIT (1 << 3)/* Enable Modem status +#define SC16IS7XX_IER_MSI_BIT BIT(3)/* Enable Modem status * interrupt */ /* IER register bits - write only if (EFR[4] == 1) */ -#define SC16IS7XX_IER_SLEEP_BIT (1 << 4)/* Enable Sleep mode */ -#define SC16IS7XX_IER_XOFFI_BIT (1 << 5)/* Enable Xoff interrupt */ -#define SC16IS7XX_IER_RTSI_BIT (1 << 6)/* Enable nRTS interrupt */ -#define SC16IS7XX_IER_CTSI_BIT (1 << 7)/* Enable nCTS interrupt */ +#define SC16IS7XX_IER_SLEEP_BIT BIT(4)/* Enable Sleep mode */ +#define SC16IS7XX_IER_XOFFI_BIT BIT(5)/* Enable Xoff interrupt */ +#define SC16IS7XX_IER_RTSI_BIT BIT(6)/* Enable nRTS interrupt */ +#define SC16IS7XX_IER_CTSI_BIT BIT(7)/* Enable nCTS interrupt */ /* FCR register bits */ -#define SC16IS7XX_FCR_FIFO_BIT (1 << 0)/* Enable FIFO */ -#define SC16IS7XX_FCR_RXRESET_BIT (1 << 1)/* Reset RX FIFO */ -#define SC16IS7XX_FCR_TXRESET_BIT (1 << 2)/* Reset TX FIFO */ -#define SC16IS7XX_FCR_RXLVLL_BIT (1 << 6)/* RX Trigger level LSB */ -#define SC16IS7XX_FCR_RXLVLH_BIT (1 << 7)/* RX Trigger level MSB */ +#define SC16IS7XX_FCR_FIFO_BIT BIT(0)/* Enable FIFO */ +#define SC16IS7XX_FCR_RXRESET_BIT BIT(1)/* Reset RX FIFO */ +#define SC16IS7XX_FCR_TXRESET_BIT BIT(2)/* Reset TX FIFO */ +#define SC16IS7XX_FCR_RXLVLL_BIT BIT(6)/* RX Trigger level LSB */ +#define SC16IS7XX_FCR_RXLVLH_BIT BIT(7)/* RX Trigger level MSB */ /* FCR register bits - write only if (EFR[4] == 1) */ -#define SC16IS7XX_FCR_TXLVLL_BIT (1 << 4)/* TX Trigger level LSB */ -#define SC16IS7XX_FCR_TXLVLH_BIT (1 << 5)/* TX Trigger level MSB */ +#define SC16IS7XX_FCR_TXLVLL_BIT BIT(4)/* TX Trigger level LSB */ +#define SC16IS7XX_FCR_TXLVLH_BIT BIT(5)/* TX Trigger level MSB */ /* IIR register bits */ -#define SC16IS7XX_IIR_NO_INT_BIT (1 << 0)/* No interrupts pending */ -#define SC16IS7XX_IIR_ID_MASK 0x3e/* Mask for the interrupt ID */ -#define SC16IS7XX_IIR_THRI_SRC 0x02/* TX holding register empty */ -#define SC16IS7XX_IIR_RDI_SRC 0x04/* RX data interrupt */ -#define SC16IS7XX_IIR_RLSE_SRC 0x06/* RX line status error */ -#define SC16IS7XX_IIR_RTOI_SRC 0x0c/* RX time-out interrupt */ -#define SC16IS7XX_IIR_MSI_SRC 0x00/* Modem status interrupt -* - only on 75x/76x -*/ -#define SC16IS7XX_IIR_INPIN_SRC 0x30/* Input pin change of state -* - only on 75x/76x -*/ -#define SC16IS7XX_IIR_XOFFI_SRC 0x10/* Received Xoff */ -#define SC16IS7XX_IIR_CTSRTS_SRC 0x20/* nCTS,nRTS change of state -* from active (LOW) -* to inactive (HIGH) -*/ +#define SC16IS7XX_IIR_NO_INT_BIT 0x01/* No interrupts pending */ +#define SC16IS7XX_IIR_ID_MASK GENMASK(5, 1)/* Mask for the interrupt ID */ +#define SC16IS7XX_IIR_THRI_SRC 0x02/* TX holding register empty */ +#define SC16IS7XX_IIR_RDI_SRC 0x04/* RX data interrupt */ +#define SC16IS7XX_IIR_RLSE_SRC 0x06/* RX line status error */ +#define SC16IS7XX_IIR_RTOI_SRC 0x0c/* RX time-out interrupt */ +#define SC16IS7XX_IIR_MSI_SRC 0x00/* Modem status interrupt +* - only on 75x/76x +*/ +#define SC16IS7XX_IIR_INPIN_SRC 0x30/* Input pin change of state +* - only on 75x/76x +*/ +#define SC16IS7XX_IIR_XOFFI_SRC 0x10/* Received Xoff */ +#define SC16IS7XX_IIR_CTSRTS_SRC 0x20/* nCTS,nRTS change of state +* from active (LOW) +* to inactive (HIGH) +*/ /* LCR register bits */ -#define SC16IS7XX_LCR_LENGTH0_BIT (1 << 0)/* Word length bit 0 */ -#define SC16IS7XX_LCR_LENGTH1_BIT (1 << 1)/* Word length bit 1 +#define SC16IS7XX_LCR_LENGTH0_BIT BIT(0)/* Word length bit 0 */ +#define SC16IS7XX_LCR_LENGTH1_BIT BIT(1)/* Word length bit 1 * * Word length bits table: * 00 -> 5 bit words
@@ -126,7 +127,7 @@* 10 -> 7 bit words * 11 -> 8 bit words */ -#define SC16IS7XX_LCR_STOPLEN_BIT (1 << 2)/* STOP length bit +#define SC16IS7XX_LCR_STOPLEN_BIT BIT(2)/* STOP length bit * * STOP length bit table: * 0 -> 1 stop bit
@@ -134,11 +135,11 @@* word length is 5, * 2 stop bits otherwise */ -#define SC16IS7XX_LCR_PARITY_BIT (1 << 3)/* Parity bit enable */ -#define SC16IS7XX_LCR_EVENPARITY_BIT (1 << 4)/* Even parity bit enable */ -#define SC16IS7XX_LCR_FORCEPARITY_BIT (1 << 5)/* 9-bit multidrop parity */ -#define SC16IS7XX_LCR_TXBREAK_BIT (1 << 6)/* TX break enable */ -#define SC16IS7XX_LCR_DLAB_BIT (1 << 7)/* Divisor Latch enable */ +#define SC16IS7XX_LCR_PARITY_BIT BIT(3)/* Parity bit enable */ +#define SC16IS7XX_LCR_EVENPARITY_BIT BIT(4)/* Even parity bit enable */ +#define SC16IS7XX_LCR_FORCEPARITY_BIT BIT(5)/* 9-bit multidrop parity */ +#define SC16IS7XX_LCR_TXBREAK_BIT BIT(6)/* TX break enable */ +#define SC16IS7XX_LCR_DLAB_BIT BIT(7)/* Divisor Latch enable */ #define SC16IS7XX_LCR_WORD_LEN_5 (0x00)#define SC16IS7XX_LCR_WORD_LEN_6 (0x01)#define SC16IS7XX_LCR_WORD_LEN_7 (0x02)
@@ -149,58 +150,63 @@* reg set */ /* MCR register bits */ -#define SC16IS7XX_MCR_DTR_BIT (1 << 0)/* DTR complement +#define SC16IS7XX_MCR_DTR_BIT BIT(0)/* DTR complement * - only on 75x/76x */ -#define SC16IS7XX_MCR_RTS_BIT (1 << 1)/* RTS complement */ -#define SC16IS7XX_MCR_TCRTLR_BIT (1 << 2)/* TCR/TLR register enable */ -#define SC16IS7XX_MCR_LOOP_BIT (1 << 4)/* Enable loopback test mode */ -#define SC16IS7XX_MCR_XONANY_BIT (1 << 5)/* Enable Xon Any +#define SC16IS7XX_MCR_RTS_BIT BIT(1)/* RTS complement */ +#define SC16IS7XX_MCR_TCRTLR_BIT BIT(2)/* TCR/TLR register enable */ +#define SC16IS7XX_MCR_LOOP_BIT BIT(4)/* Enable loopback test mode */ +#define SC16IS7XX_MCR_XONANY_BIT BIT(5)/* Enable Xon Any * - write enabled * if (EFR[4] == 1) */ -#define SC16IS7XX_MCR_IRDA_BIT (1 << 6)/* Enable IrDA mode +#define SC16IS7XX_MCR_IRDA_BIT BIT(6)/* Enable IrDA mode * - write enabled * if (EFR[4] == 1) */ -#define SC16IS7XX_MCR_CLKSEL_BIT (1 << 7)/* Divide clock by 4 +#define SC16IS7XX_MCR_CLKSEL_BIT BIT(7)/* Divide clock by 4 * - write enabled * if (EFR[4] == 1) */ /* LSR register bits */ -#define SC16IS7XX_LSR_DR_BIT (1 << 0)/* Receiver data ready */ -#define SC16IS7XX_LSR_OE_BIT (1 << 1)/* Overrun Error */ -#define SC16IS7XX_LSR_PE_BIT (1 << 2)/* Parity Error */ -#define SC16IS7XX_LSR_FE_BIT (1 << 3)/* Frame Error */ -#define SC16IS7XX_LSR_BI_BIT (1 << 4)/* Break Interrupt */ -#define SC16IS7XX_LSR_BRK_ERROR_MASK 0x1E/* BI, FE, PE, OE bits */ -#define SC16IS7XX_LSR_THRE_BIT (1 << 5)/* TX holding register empty */ -#define SC16IS7XX_LSR_TEMT_BIT (1 << 6)/* Transmitter empty */ -#define SC16IS7XX_LSR_FIFOE_BIT (1 << 7)/* Fifo Error */ +#define SC16IS7XX_LSR_DR_BIT BIT(0)/* Receiver data ready */ +#define SC16IS7XX_LSR_OE_BIT BIT(1)/* Overrun Error */ +#define SC16IS7XX_LSR_PE_BIT BIT(2)/* Parity Error */ +#define SC16IS7XX_LSR_FE_BIT BIT(3)/* Frame Error */ +#define SC16IS7XX_LSR_BI_BIT BIT(4)/* Break Interrupt */ +#define SC16IS7XX_LSR_BRK_ERROR_MASK \ + (SC16IS7XX_LSR_OE_BIT | \ + SC16IS7XX_LSR_PE_BIT | \ + SC16IS7XX_LSR_FE_BIT | \ + SC16IS7XX_LSR_BI_BIT) + +#define SC16IS7XX_LSR_THRE_BIT BIT(5)/* TX holding register empty */ +#define SC16IS7XX_LSR_TEMT_BIT BIT(6)/* Transmitter empty */ +#define SC16IS7XX_LSR_FIFOE_BIT BIT(7)/* Fifo Error */ /* MSR register bits */ -#define SC16IS7XX_MSR_DCTS_BIT (1 << 0)/* Delta CTS Clear To Send */ -#define SC16IS7XX_MSR_DDSR_BIT (1 << 1)/* Delta DSR Data Set Ready +#define SC16IS7XX_MSR_DCTS_BIT BIT(0)/* Delta CTS Clear To Send */ +#define SC16IS7XX_MSR_DDSR_BIT BIT(1)/* Delta DSR Data Set Ready * or (IO4) * - only on 75x/76x */ -#define SC16IS7XX_MSR_DRI_BIT (1 << 2)/* Delta RI Ring Indicator +#define SC16IS7XX_MSR_DRI_BIT BIT(2)/* Delta RI Ring Indicator * or (IO7) * - only on 75x/76x */ -#define SC16IS7XX_MSR_DCD_BIT (1 << 3)/* Delta CD Carrier Detect +#define SC16IS7XX_MSR_DCD_BIT BIT(3)/* Delta CD Carrier Detect * or (IO6) * - only on 75x/76x */ -#define SC16IS7XX_MSR_CTS_BIT (1 << 4)/* CTS */ -#define SC16IS7XX_MSR_DSR_BIT (1 << 5)/* DSR (IO4) +#define SC16IS7XX_MSR_CTS_BIT BIT(4)/* CTS */ +#define SC16IS7XX_MSR_DSR_BIT BIT(5)/* DSR (IO4) * - only on 75x/76x */ -#define SC16IS7XX_MSR_RI_BIT (1 << 6)/* RI (IO7) +#define SC16IS7XX_MSR_RI_BIT BIT(6)/* RI (IO7) * - only on 75x/76x */ -#define SC16IS7XX_MSR_CD_BIT (1 << 7)/* CD (IO6) +#define SC16IS7XX_MSR_CD_BIT BIT(7)/* CD (IO6) * - only on 75x/76x */ #define SC16IS7XX_MSR_DELTA_MASK 0x0F/* Any of the delta bits! */
@@ -236,19 +242,19 @@#define SC16IS7XX_TLR_RX_TRIGGER (words) ((((words) / 4) & 0x0f) << 4)/* IOControl register bits (Only 750/760) */ -#define SC16IS7XX_IOCONTROL_LATCH_BIT (1 << 0)/* Enable input latching */ -#define SC16IS7XX_IOCONTROL_MODEM_A_BIT (1 << 1)/* Enable GPIO[7:4] as modem A pins */ -#define SC16IS7XX_IOCONTROL_MODEM_B_BIT (1 << 2)/* Enable GPIO[3:0] as modem B pins */ -#define SC16IS7XX_IOCONTROL_SRESET_BIT (1 << 3)/* Software Reset */ +#define SC16IS7XX_IOCONTROL_LATCH_BIT BIT(0)/* Enable input latching */ +#define SC16IS7XX_IOCONTROL_MODEM_A_BIT BIT(1)/* Enable GPIO[7:4] as modem A pins */ +#define SC16IS7XX_IOCONTROL_MODEM_B_BIT BIT(2)/* Enable GPIO[3:0] as modem B pins */ +#define SC16IS7XX_IOCONTROL_SRESET_BIT BIT(3)/* Software Reset */ /* EFCR register bits */ -#define SC16IS7XX_EFCR_9BIT_MODE_BIT (1 << 0)/* Enable 9-bit or Multidrop +#define SC16IS7XX_EFCR_9BIT_MODE_BIT BIT(0)/* Enable 9-bit or Multidrop * mode (RS485) */ -#define SC16IS7XX_EFCR_RXDISABLE_BIT (1 << 1)/* Disable receiver */ -#define SC16IS7XX_EFCR_TXDISABLE_BIT (1 << 2)/* Disable transmitter */ -#define SC16IS7XX_EFCR_AUTO_RS485_BIT (1 << 4)/* Auto RS485 RTS direction */ -#define SC16IS7XX_EFCR_RTS_INVERT_BIT (1 << 5)/* RTS output inversion */ -#define SC16IS7XX_EFCR_IRDA_MODE_BIT (1 << 7)/* IrDA mode +#define SC16IS7XX_EFCR_RXDISABLE_BIT BIT(1)/* Disable receiver */ +#define SC16IS7XX_EFCR_TXDISABLE_BIT BIT(2)/* Disable transmitter */ +#define SC16IS7XX_EFCR_AUTO_RS485_BIT BIT(4)/* Auto RS485 RTS direction */ +#define SC16IS7XX_EFCR_RTS_INVERT_BIT BIT(5)/* RTS output inversion */ +#define SC16IS7XX_EFCR_IRDA_MODE_BIT BIT(7)/* IrDA mode * 0 = rate upto 115.2 kbit/s * - Only 750/760 * 1 = rate upto 1.152 Mbit/s
@@ -256,15 +262,15 @@*/ /* EFR register bits */ -#define SC16IS7XX_EFR_AUTORTS_BIT (1 << 6)/* Auto RTS flow ctrl enable */ -#define SC16IS7XX_EFR_AUTOCTS_BIT (1 << 7)/* Auto CTS flow ctrl enable */ -#define SC16IS7XX_EFR_XOFF2_DETECT_BIT (1 << 5)/* Enable Xoff2 detection */ -#define SC16IS7XX_EFR_ENABLE_BIT (1 << 4)/* Enable enhanced functions +#define SC16IS7XX_EFR_AUTORTS_BIT BIT(6)/* Auto RTS flow ctrl enable */ +#define SC16IS7XX_EFR_AUTOCTS_BIT BIT(7)/* Auto CTS flow ctrl enable */ +#define SC16IS7XX_EFR_XOFF2_DETECT_BIT BIT(5)/* Enable Xoff2 detection */ +#define SC16IS7XX_EFR_ENABLE_BIT BIT(4)/* Enable enhanced functions * and writing to IER[7:4], * FCR[5:4], MCR[7:5] */ -#define SC16IS7XX_EFR_SWFLOW3_BIT (1 << 3) -#define SC16IS7XX_EFR_SWFLOW2_BIT (1 << 2) +#define SC16IS7XX_EFR_SWFLOW3_BIT BIT(3) +#define SC16IS7XX_EFR_SWFLOW2_BIT BIT(2)/* * SWFLOW bits 3 & 2 table: * 00 -> no transmitter flow
@@ -277,8 +283,8 @@* XON1, XON2, XOFF1 and * XOFF2 */ -#define SC16IS7XX_EFR_SWFLOW1_BIT (1 << 1) -#define SC16IS7XX_EFR_SWFLOW0_BIT (1 << 0) +#define SC16IS7XX_EFR_SWFLOW1_BIT BIT(1) +#define SC16IS7XX_EFR_SWFLOW0_BIT BIT(0)/* * SWFLOW bits 1 & 0 table: * 00 -> no received flow
@@ -311,9 +317,9 @@ struct sc16is7xx_devtype {int nr_uart; }; -#define SC16IS7XX_RECONF_MD (1 << 0) -#define SC16IS7XX_RECONF_IER (1 << 1) -#define SC16IS7XX_RECONF_RS485 (1 << 2) +#define SC16IS7XX_RECONF_MD BIT(0) +#define SC16IS7XX_RECONF_IER BIT(1) +#define SC16IS7XX_RECONF_RS485 BIT(2)struct sc16is7xx_one_config {unsigned int flags;
Greg Kroah-Hartman
maintainerPATCH 11/87 serial: sc16is7xx: rename EFR mutex with generic name
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hugo Villeneuve <[email protected]>
[ Upstream commit d9b2d7ddbb973b981c20b21e9228581bb156f66f ]
This mutex is used as a lock when accessing registers that share the same address space, not necessarily EFR registers.
For example, address 0x06 is shared by MSR, TCR and XOFF1 registers, independently of EFR.
Rename the mutex with a more generic name to avoid misinterpreting its usage.
Stable-dep-of: 246ac114f485 ("serial: sc16is7xx: enable THRI before filling TX FIFO")
--- drivers/tty/serial/sc16is7xx.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
drivers/tty/serial/sc16is7xx.c +13 -13
@@ -330,7 +330,7 @@ struct sc16is7xx_one_config {struct sc16is7xx_one {struct uart_port port;struct regmap *regmap; -struct mutex efr_lock;/* EFR registers access */ +struct mutex lock;/* For registers sharing same address space. */ struct kthread_work tx_work;struct kthread_work reg_work;struct kthread_delayed_work ms_work;
@@ -437,7 +437,7 @@ static void sc16is7xx_efr_lock(struct ua {struct sc16is7xx_one *one =to_sc16is7xx_one (port, port); -mutex_lock (&one->efr_lock); +mutex_lock (&one->lock);/* Backup content of LCR. */ one->old_lcr =sc16is7xx_port_read (port,SC16IS7XX_LCR_REG );
@@ -459,7 +459,7 @@ static void sc16is7xx_efr_unlock(struct/* Restore original content of LCR */ sc16is7xx_port_write (port,SC16IS7XX_LCR_REG , one->old_lcr); -mutex_unlock (&one->efr_lock); +mutex_unlock (&one->lock); }static void sc16is7xx_ier_clear (struct uart_port *port,u8 bit)
@@ -593,7 +593,7 @@ static int sc16is7xx_set_baud(struct uarSC16IS7XX_MCR_CLKSEL_BIT , prescaler == 1 ? 0 : SC16IS7XX_MCR_CLKSEL_BIT); -mutex_lock (&one->efr_lock); +mutex_lock (&one->lock);/* Backup LCR and access special register set (DLL/DLH) */ lcr =sc16is7xx_port_read (port,SC16IS7XX_LCR_REG );
@@ -609,7 +609,7 @@ static int sc16is7xx_set_baud(struct uar/* Restore LCR and access to general register set */ sc16is7xx_port_write (port,SC16IS7XX_LCR_REG , lcr); -mutex_unlock (&one->efr_lock); +mutex_unlock (&one->lock);return DIV_ROUND_CLOSEST ((clk / prescaler) /16 , div); }
@@ -765,7 +765,7 @@ static void sc16is7xx_update_mlines(struunsigned long flags;unsigned int status, changed; -lockdep_assert_held_once (&one->efr_lock); +lockdep_assert_held_once (&one->lock); status =sc16is7xx_get_hwmctrl (port); changed = status ^ one->old_mctrl;
@@ -796,7 +796,7 @@ static bool sc16is7xx_port_irq(struct scstruct uart_port *port = &s->p[portno].port;struct sc16is7xx_one *one =to_sc16is7xx_one (port, port); -mutex_lock (&one->efr_lock); +mutex_lock (&one->lock); iir =sc16is7xx_port_read (port,SC16IS7XX_IIR_REG );if (iir &SC16IS7XX_IIR_NO_INT_BIT ) {
@@ -843,7 +843,7 @@ static bool sc16is7xx_port_irq(struct sc } out_port_irq: -mutex_unlock (&one->efr_lock); +mutex_unlock (&one->lock);return rc; }
@@ -875,9 +875,9 @@ static void sc16is7xx_tx_proc(struct kth (port->rs485.delay_rts_before_send > 0))msleep (port->rs485.delay_rts_before_send); -mutex_lock (&one->efr_lock); +mutex_lock (&one->lock);sc16is7xx_handle_tx (port); -mutex_unlock (&one->efr_lock); +mutex_unlock (&one->lock); }static void sc16is7xx_reconf_rs485 (struct uart_port *port)
@@ -944,9 +944,9 @@ static void sc16is7xx_ms_proc(struct kthstruct sc16is7xx_port *s =dev_get_drvdata (one->port.dev);if (one->port.state) { -mutex_lock (&one->efr_lock); +mutex_lock (&one->lock);sc16is7xx_update_mlines (one); -mutex_unlock (&one->efr_lock); +mutex_unlock (&one->lock);kthread_queue_delayed_work (&s->kworker, &one->ms_work,HZ ); }
@@ -1587,7 +1587,7 @@ static int sc16is7xx_probe(struct device s->p[i].old_mctrl =0 ; s->p[i].regmap = regmaps[i]; -mutex_init (&s->p[i].efr_lock); +mutex_init (&s->p[i].lock); ret =uart_get_rs485_mode (&s->p[i].port);if (ret)
Greg Kroah-Hartman
maintainerPATCH 12/87 serial: sc16is7xx: use guards for simple mutex locks
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hugo Villeneuve <[email protected]>
[ Upstream commit 0f4f88bfd7e7bf3f3293045fffdc63586b0a889f ]
Guards can help to make the code more readable, so use them wherever they do so.
In sc16is7xx_port_irq(), labels and 'rc' locals are eliminated completely.
Stable-dep-of: 246ac114f485 ("serial: sc16is7xx: enable THRI before filling TX FIFO")
--- drivers/tty/serial/sc16is7xx.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-)
drivers/tty/serial/sc16is7xx.c +8 -15
@@ -10,6 +10,7 @@#include <linux/bitops.h> #include <linux/bits.h> +#include <linux/cleanup.h> #include <linux/clk.h> #include <linux/delay.h> #include <linux/device.h>
@@ -791,18 +792,15 @@ static void sc16is7xx_update_mlines(strustatic bool sc16is7xx_port_irq (struct sc16is7xx_port *s,int portno) { -bool rc = true;unsigned int iir, rxlen;struct uart_port *port = &s->p[portno].port;struct sc16is7xx_one *one =to_sc16is7xx_one (port, port); -mutex_lock (&one->lock); +guard (mutex)(&one->lock); iir =sc16is7xx_port_read (port,SC16IS7XX_IIR_REG ); -if (iir &SC16IS7XX_IIR_NO_INT_BIT ) { - rc = false; - goto out_port_irq; - } +if (iir &SC16IS7XX_IIR_NO_INT_BIT ) +return false; iir &=SC16IS7XX_IIR_ID_MASK ;
@@ -842,10 +840,7 @@ static bool sc16is7xx_port_irq(struct scbreak ; } -out_port_irq: -mutex_unlock (&one->lock); - -return rc; +return true; }static irqreturn_t sc16is7xx_irq (int irq,void *dev_id)
@@ -875,9 +870,8 @@ static void sc16is7xx_tx_proc(struct kth (port->rs485.delay_rts_before_send > 0))msleep (port->rs485.delay_rts_before_send); -mutex_lock (&one->lock); +guard (mutex)(&one->lock);sc16is7xx_handle_tx (port); -mutex_unlock (&one->lock); }static void sc16is7xx_reconf_rs485 (struct uart_port *port)
@@ -944,9 +938,8 @@ static void sc16is7xx_ms_proc(struct kthstruct sc16is7xx_port *s =dev_get_drvdata (one->port.dev);if (one->port.state) { -mutex_lock (&one->lock); -sc16is7xx_update_mlines (one); -mutex_unlock (&one->lock); + scoped_guard(mutex, &one->lock) +sc16is7xx_update_mlines (one);kthread_queue_delayed_work (&s->kworker, &one->ms_work,HZ ); }
Greg Kroah-Hartman
maintainerPATCH 13/87 serial: sc16is7xx: enable THRI before filling TX FIFO
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luca Fresi <[email protected]>
[ Upstream commit 246ac114f485c2affb454240f3ea4fabfce22456 ]
sc16is7xx_handle_tx() currently requests the THRI enable only after it has filled the TX FIFO. The request is asynchronous because the IER update is performed later by reg_work.
The SC16IS7xx generates a THRI interrupt when the TX FIFO crosses its trigger level. If the FIFO drains past that level before reg_work enables THRI, the chip does not generate a new interrupt. Characters remain queued indefinitely even though the hardware FIFO is empty.
This was observed on an SC16IS752 while both UART channels were active. During the stall the software TX buffer remained non-empty while TXLVL reported 64 bytes free, LSR reported THR and transmitter empty, IER had THRI enabled, and IIR reported no interrupt pending.
Enable THRI synchronously before filling the FIFO so the threshold crossing cannot be missed.
--- drivers/tty/serial/sc16is7xx.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/tty/serial/sc16is7xx.c +3 -0
@@ -871,6 +871,9 @@ static void sc16is7xx_tx_proc(struct kthmsleep (port->rs485.delay_rts_before_send);guard (mutex)(&one->lock); +sc16is7xx_port_update (port,SC16IS7XX_IER_REG , +SC16IS7XX_IER_THRI_BIT , +SC16IS7XX_IER_THRI_BIT );sc16is7xx_handle_tx (port); }
Greg Kroah-Hartman
maintainerPATCH 14/87 inet: frags: add inet_frag_putn() helper
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit ae2d90355aa5592b0e99c8bbb4c3fa1d8e205f1b ]
inet_frag_putn() can release multiple references
in one step.
Use it in inet_frags_free_cb().
Replace inet_frag_put(X) with inet_frag_putn(X, 1)
Stable-dep-of: 653d7ddf6cba ("inet: frags: publish queues before arming timer")
--- include/net/inet_frag.h | 4 ++-- include/net/ipv6_frag.h | 3 ++- net/ieee802154/6lowpan/reassembly.c | 7 ++++--- net/ipv4/inet_fragment.c | 3 +-- net/ipv4/ip_fragment.c | 2 +- net/ipv6/netfilter/nf_conntrack_reasm.c | 3 ++- net/ipv6/reassembly.c | 4 ++-- 7 files changed, 14 insertions(+), 12 deletions(-)
include/net/inet_frag.h +2 -2
@@ -133,9 +133,9 @@ struct inet_frag_queue *inet_frag_find(svoid inet_frag_queue_flush (struct inet_frag_queue *q,enum skb_drop_reason reason); -static inline void inet_frag_put (struct inet_frag_queue *q) +static inline void inet_frag_putn (struct inet_frag_queue *q,int refs) { -if (refcount_dec_and_test (&q->refcnt)) +if (refs &&refcount_sub_and_test (refs, &q->refcnt))inet_frag_destroy (q); }
include/net/ipv6_frag.h +2 -1
@@ -66,6 +66,7 @@ ip6frag_expire_frag_queue(struct net *ne {struct net_device *dev =NULL ;struct sk_buff *head; +int refs =1 ;rcu_read_lock ();spin_lock (&fq->q.lock);
@@ -112,7 +113,7 @@ out:spin_unlock (&fq->q.lock); out_rcu_unlock:rcu_read_unlock (); -inet_frag_put (&fq->q); +inet_frag_putn (&fq->q, refs); }/* Check if the upper layer header is truncated in the first fragment. */
net/ieee802154/6lowpan/reassembly.c +4 -3
@@ -45,6 +45,7 @@ static void lowpan_frag_expire(struct ti {struct inet_frag_queue *frag =from_timer (frag, t, timer);struct frag_queue *fq; +int refs =1 ; fq = container_of(frag, struct frag_queue, q);
@@ -56,7 +57,7 @@ static void lowpan_frag_expire(struct tiinet_frag_kill (&fq->q); out:spin_unlock (&fq->q.lock); -inet_frag_put (&fq->q); +inet_frag_putn (&fq->q, refs); } static inline struct lowpan_frag_queue *
@@ -302,13 +303,13 @@ int lowpan_frag_rcv(struct sk_buff *skb, fq =fq_find (net, cb, &hdr.source, &hdr.dest);if (fq !=NULL ) { -int ret; +int ret, refs =1 ;spin_lock (&fq->q.lock); ret =lowpan_frag_queue (fq, skb, frag_type);spin_unlock (&fq->q.lock); -inet_frag_put (&fq->q); +inet_frag_putn (&fq->q, refs);return ret; }
net/ipv4/inet_fragment.c +1 -2
@@ -145,8 +145,7 @@ static void inet_frags_free_cb(void *ptr }spin_unlock_bh (&fq->lock); -if (refcount_sub_and_test (count, &fq->refcnt)) -inet_frag_destroy (fq); +inet_frag_putn (fq, count); }static LLIST_HEAD (fqdir_free_list);
net/ipv4/ip_fragment.c +1 -1
@@ -112,7 +112,7 @@ static void ip4_frag_free(struct inet_frstatic void ipq_put (struct ipq *ipq) { -inet_frag_put (&ipq->q); +inet_frag_putn (&ipq->q,1 ); }/* Kill ipq entry. It is not destroyed immediately,
net/ipv6/netfilter/nf_conntrack_reasm.c +2 -1
@@ -449,6 +449,7 @@ int nf_ct_frag6_gather(struct net *net,struct frag_hdr *fhdr;struct frag_queue *fq;struct ipv6hdr *hdr; +int refs =1 ;u8 prevhdr;/* Jumbo payload inhibits frag. header */
@@ -491,7 +492,7 @@ int nf_ct_frag6_gather(struct net *net, }spin_unlock_bh (&fq->q.lock); -inet_frag_put (&fq->q); +inet_frag_putn (&fq->q, refs);return ret; }EXPORT_SYMBOL_GPL (nf_ct_frag6_gather);
net/ipv6/reassembly.c +2 -2
@@ -380,7 +380,7 @@ static int ipv6_frag_rcv(struct sk_buff fq =fq_find (net, fhdr->identification, hdr, iif);if (fq) {u32 prob_offset =0 ; -int ret; +int ret, refs =1 ;spin_lock (&fq->q.lock);
@@ -389,7 +389,7 @@ static int ipv6_frag_rcv(struct sk_buff &prob_offset);spin_unlock (&fq->q.lock); -inet_frag_put (&fq->q); +inet_frag_putn (&fq->q, refs);if (prob_offset) {__IP6_INC_STATS (net,__in6_dev_get_safely (skb->dev),IPSTATS_MIB_INHDRERRORS );
Greg Kroah-Hartman
maintainerPATCH 15/87 ipv4: frags: remove ipq_put()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit a2fb987c0ecf0498cc17056339cb11d128c46ab7 ]
Replace ipq_put() with inet_frag_putn()
Stable-dep-of: 653d7ddf6cba ("inet: frags: publish queues before arming timer")
--- net/ipv4/ip_fragment.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)
net/ipv4/ip_fragment.c +4 -11
@@ -107,14 +107,6 @@ static void ip4_frag_free(struct inet_frinet_putpeer (qp->peer); } - -/* Destruction primitives. */ - -static void ipq_put (struct ipq *ipq) -{ -inet_frag_putn (&ipq->q,1 ); -} -/* Kill ipq entry. It is not destroyed immediately, * because caller (and someone more) holds reference count. */
@@ -142,6 +134,7 @@ static void ip_expire(struct timer_liststruct sk_buff *head =NULL ;struct net *net;struct ipq *qp; +int refs =1 ;int err; qp = container_of(frag, struct ipq, q);
@@ -203,7 +196,7 @@ out: out_rcu_unlock:rcu_read_unlock ();kfree_skb_reason (head,SKB_DROP_REASON_FRAG_REASM_TIMEOUT ); -ipq_put (qp); +inet_frag_putn (&qp->q, refs); }/* Find the correct entry in the "incomplete datagrams" queue for
@@ -492,14 +485,14 @@ int ip_defrag(struct net *net, struct sk/* Lookup (or create) queue header */ qp =ip_find (net,ip_hdr (skb), user, vif);if (qp) { -int ret; +int ret, refs =1 ;spin_lock (&qp->q.lock); ret =ip_frag_queue (qp, skb);spin_unlock (&qp->q.lock); -ipq_put (qp); +inet_frag_putn (&qp->q, refs);return ret; }
Greg Kroah-Hartman
maintainerPATCH 16/87 inet: frags: change inet_frag_kill() to defer refcount updates
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit eb0dfc0ef195a04e519b15d73cf25d8c25ee8df7 ]
In the following patch, we no longer assume inet_frag_kill() callers own a reference.
Consuming two refcounts from inet_frag_kill() would lead in UAF.
Propagate the pointer to the refs that will be consumed later by the final inet_frag_putn() call.
Stable-dep-of: 653d7ddf6cba ("inet: frags: publish queues before arming timer")
--- include/net/inet_frag.h | 2 +- include/net/ipv6_frag.h | 2 +- net/ieee802154/6lowpan/reassembly.c | 17 ++++++++++------- net/ipv4/inet_fragment.c | 12 +++++++----- net/ipv4/ip_fragment.c | 30 ++++++++++++------------------ net/ipv6/netfilter/nf_conntrack_reasm.c | 21 ++++++++++++--------- net/ipv6/reassembly.c | 18 ++++++++++-------- 7 files changed, 53 insertions(+), 49 deletions(-)
include/net/inet_frag.h +1 -1
@@ -126,7 +126,7 @@ int fqdir_init(struct fqdir **fqdirp, stvoid fqdir_pre_exit (struct fqdir *fqdir);void fqdir_exit (struct fqdir *fqdir); -void inet_frag_kill (struct inet_frag_queue *q); +void inet_frag_kill (struct inet_frag_queue *q,int *refs);void inet_frag_destroy (struct inet_frag_queue *q);struct inet_frag_queue *inet_frag_find (struct fqdir *fqdir,void *key);
include/net/ipv6_frag.h +1 -1
@@ -75,7 +75,7 @@ ip6frag_expire_frag_queue(struct net *ne goto out; fq->q.flags |=INET_FRAG_DROP ; -inet_frag_kill (&fq->q); +inet_frag_kill (&fq->q, &refs);/* Paired with the WRITE_ONCE() in fqdir_pre_exit(). */ if (READ_ONCE (fq->q.fqdir->dead)) {
net/ieee802154/6lowpan/reassembly.c +10 -7
@@ -31,7 +31,8 @@ static const char lowpan_frags_cache_namstatic struct inet_frags lowpan_frags;static int lowpan_frag_reasm (struct lowpan_frag_queue *fq,struct sk_buff *skb, -struct sk_buff *prev,struct net_device *ldev); +struct sk_buff *prev,struct net_device *ldev, +int *refs);static void lowpan_frag_init (struct inet_frag_queue *q,const void *a) {
@@ -54,7 +55,7 @@ static void lowpan_frag_expire(struct tiif (fq->q.flags &INET_FRAG_COMPLETE ) goto out; -inet_frag_kill (&fq->q); +inet_frag_kill (&fq->q, &refs); out:spin_unlock (&fq->q.lock);inet_frag_putn (&fq->q, refs);
@@ -83,7 +84,8 @@ fq_find(struct net *net, const struct lo }static int lowpan_frag_queue (struct lowpan_frag_queue *fq, -struct sk_buff *skb,u8 frag_type) +struct sk_buff *skb,u8 frag_type, +int *refs) {struct sk_buff *prev_tail;struct net_device *ldev;
@@ -144,7 +146,7 @@ static int lowpan_frag_queue(struct lowpunsigned long orefdst = skb->_skb_refdst; skb->_skb_refdst =0UL ; - res =lowpan_frag_reasm (fq, skb, prev_tail, ldev); + res =lowpan_frag_reasm (fq, skb, prev_tail, ldev, refs); skb->_skb_refdst = orefdst;return res; }
@@ -163,11 +165,12 @@ err:* the last and the first frames arrived and all the bits are here. */ static int lowpan_frag_reasm (struct lowpan_frag_queue *fq,struct sk_buff *skb, -struct sk_buff *prev_tail,struct net_device *ldev) +struct sk_buff *prev_tail,struct net_device *ldev, +int *refs) {void *reasm_data; -inet_frag_kill (&fq->q); +inet_frag_kill (&fq->q, refs); reasm_data =inet_frag_reasm_prepare (&fq->q, skb, prev_tail);if (!reasm_data)
@@ -306,7 +309,7 @@ int lowpan_frag_rcv(struct sk_buff *skb,int ret, refs =1 ;spin_lock (&fq->q.lock); - ret =lowpan_frag_queue (fq, skb, frag_type); + ret =lowpan_frag_queue (fq, skb, frag_type, &refs);spin_unlock (&fq->q.lock);inet_frag_putn (&fq->q, refs);
net/ipv4/inet_fragment.c +7 -5
@@ -260,10 +260,10 @@ void fqdir_exit(struct fqdir *fqdir) }EXPORT_SYMBOL (fqdir_exit); -void inet_frag_kill (struct inet_frag_queue *fq) +void inet_frag_kill (struct inet_frag_queue *fq,int *refs) {if (del_timer (&fq->timer)) -refcount_dec (&fq->refcnt); + (*refs)++;if (!(fq->flags &INET_FRAG_COMPLETE )) {struct fqdir *fqdir = fq->fqdir;
@@ -278,7 +278,7 @@ void inet_frag_kill(struct inet_frag_queif (!READ_ONCE (fqdir->dead)) {rhashtable_remove_fast (&fqdir->rhashtable, &fq->node, fqdir->f->rhash_params); -refcount_dec (&fq->refcnt); + (*refs)++; }else { fq->flags |=INET_FRAG_HASH_DEAD ; }
@@ -397,9 +397,11 @@ static struct inet_frag_queue *inet_frag *prev =rhashtable_lookup_get_insert_key (&fqdir->rhashtable, &q->key, &q->node, f->rhash_params);if (*prev) { +int refs =2 ; + q->flags |=INET_FRAG_COMPLETE ; -inet_frag_kill (q); -inet_frag_destroy (q); +inet_frag_kill (q, &refs); +inet_frag_putn (q, refs);return NULL ; }return q;
net/ipv4/ip_fragment.c +12 -18
@@ -76,7 +76,8 @@ static u8 ip4_frag_ecn(u8 tos)static struct inet_frags ip4_frags;static int ip_frag_reasm (struct ipq *qp,struct sk_buff *skb, -struct sk_buff *prev_tail,struct net_device *dev); +struct sk_buff *prev_tail,struct net_device *dev, +int *refs);static void ip4_frag_init (struct inet_frag_queue *q,const void *a)
@@ -107,14 +108,6 @@ static void ip4_frag_free(struct inet_frinet_putpeer (qp->peer); } -/* Kill ipq entry. It is not destroyed immediately, -* because caller (and someone more) holds reference count. -*/ -static void ipq_kill (struct ipq *ipq) -{ -inet_frag_kill (&ipq->q); -} -static bool frag_expire_skip_icmp (u32 user) { return user == IP_DEFRAG_AF_PACKET ||
@@ -147,7 +140,7 @@ static void ip_expire(struct timer_list goto out; qp->q.flags |=INET_FRAG_DROP ; -ipq_kill (qp); +inet_frag_kill (&qp->q, &refs);/* Paired with WRITE_ONCE() in fqdir_pre_exit(). */ if (READ_ONCE (qp->q.fqdir->dead)) {
@@ -265,7 +258,7 @@ static int ip_frag_reinit(struct ipq *qp }/* Add new segment to existing queue. */ -static int ip_frag_queue (struct ipq *qp,struct sk_buff *skb) +static int ip_frag_queue (struct ipq *qp,struct sk_buff *skb,int *refs) {struct net *net = qp->q.fqdir->net;int ihl, end, flags, offset;
@@ -285,7 +278,7 @@ static int ip_frag_queue(struct ipq *qp,if (!(IPCB (skb)->flags &IPSKB_FRAG_COMPLETE ) &&unlikely (ip_frag_too_far (qp)) &&unlikely (err =ip_frag_reinit (qp))) { -ipq_kill (qp); +inet_frag_kill (&qp->q, refs); goto err; }
@@ -369,10 +362,10 @@ static int ip_frag_queue(struct ipq *qp,unsigned long orefdst = skb->_skb_refdst; skb->_skb_refdst =0UL ; - err =ip_frag_reasm (qp, skb, prev_tail, dev); + err =ip_frag_reasm (qp, skb, prev_tail, dev, refs); skb->_skb_refdst = orefdst;if (err) -inet_frag_kill (&qp->q); +inet_frag_kill (&qp->q, refs);return err; }
@@ -389,7 +382,7 @@ insert_error: err = -EINVAL ;__IP_INC_STATS (net,IPSTATS_MIB_REASM_OVERLAPS ); discard_qp: -inet_frag_kill (&qp->q); +inet_frag_kill (&qp->q, refs);__IP_INC_STATS (net,IPSTATS_MIB_REASMFAILS ); err:kfree_skb_reason (skb, reason);
@@ -403,7 +396,8 @@ static bool ip_frag_coalesce_ok(const st/* Build a new IP datagram from all its fragments. */ static int ip_frag_reasm (struct ipq *qp,struct sk_buff *skb, -struct sk_buff *prev_tail,struct net_device *dev) +struct sk_buff *prev_tail,struct net_device *dev, +int *refs) {struct net *net = qp->q.fqdir->net;struct iphdr *iph;
@@ -411,7 +405,7 @@ static int ip_frag_reasm(struct ipq *qp,int len, err;u8 ecn; -ipq_kill (qp); +inet_frag_kill (&qp->q, refs); ecn = ip_frag_ecn_table[qp->ecn];if (unlikely (ecn ==0xff )) {
@@ -489,7 +483,7 @@ int ip_defrag(struct net *net, struct skspin_lock (&qp->q.lock); - ret =ip_frag_queue (qp, skb); + ret =ip_frag_queue (qp, skb, &refs);spin_unlock (&qp->q.lock);inet_frag_putn (&qp->q, refs);
net/ipv6/netfilter/nf_conntrack_reasm.c +12 -9
@@ -124,7 +124,8 @@ static void __net_exit nf_ct_frags6_sysc#endif static int nf_ct_frag6_reasm (struct frag_queue *fq,struct sk_buff *skb, -struct sk_buff *prev_tail,struct net_device *dev); +struct sk_buff *prev_tail,struct net_device *dev, +int *refs);static inline u8 ip6_frag_ecn (const struct ipv6hdr *ipv6h) {
@@ -168,7 +169,8 @@ static struct frag_queue *fq_find(structstatic int nf_ct_frag6_queue (struct frag_queue *fq,struct sk_buff *skb, -const struct frag_hdr *fhdr,int nhoff) +const struct frag_hdr *fhdr,int nhoff, +int *refs) {unsigned int payload_len;struct net_device *dev;
@@ -222,7 +224,7 @@ static int nf_ct_frag6_queue(struct frag* this case. -DaveM */ pr_debug ("end of fragment not rounded to 8 bytes.\n" ); -inet_frag_kill (&fq->q); +inet_frag_kill (&fq->q, refs);return -EPROTO ; }if (end > fq->q.len) {
@@ -288,7 +290,7 @@ static int nf_ct_frag6_queue(struct fragunsigned long orefdst = skb->_skb_refdst; skb->_skb_refdst =0UL ; - err =nf_ct_frag6_reasm (fq, skb, prev, dev); + err =nf_ct_frag6_reasm (fq, skb, prev, dev, refs); skb->_skb_refdst = orefdst;/* After queue has assumed skb ownership, only 0 or
@@ -302,7 +304,7 @@ static int nf_ct_frag6_queue(struct fragreturn -EINPROGRESS ; insert_error: -inet_frag_kill (&fq->q); +inet_frag_kill (&fq->q, refs); err:skb_dst_drop (skb);return -EINVAL ;
@@ -316,13 +318,14 @@ err:* the last and the first frames arrived and all the bits are here. */ static int nf_ct_frag6_reasm (struct frag_queue *fq,struct sk_buff *skb, -struct sk_buff *prev_tail,struct net_device *dev) +struct sk_buff *prev_tail,struct net_device *dev, +int *refs) {void *reasm_data;int payload_len;u8 ecn; -inet_frag_kill (&fq->q); +inet_frag_kill (&fq->q, refs); ecn = ip_frag_ecn_table[fq->ecn];if (unlikely (ecn ==0xff ))
@@ -374,7 +377,7 @@ static int nf_ct_frag6_reasm(struct fragreturn 0 ; err: -inet_frag_kill (&fq->q); +inet_frag_kill (&fq->q, refs);return -EINVAL ; }
@@ -485,7 +488,7 @@ int nf_ct_frag6_gather(struct net *net,spin_lock_bh (&fq->q.lock); - ret =nf_ct_frag6_queue (fq, skb, fhdr, nhoff); + ret =nf_ct_frag6_queue (fq, skb, fhdr, nhoff, &refs);if (ret == -EPROTO ) { skb->transport_header = savethdr; ret =0 ;
net/ipv6/reassembly.c +10 -8
@@ -68,7 +68,8 @@ static u8 ip6_frag_ecn(const struct ipv6static struct inet_frags ip6_frags;static int ip6_frag_reasm (struct frag_queue *fq,struct sk_buff *skb, -struct sk_buff *prev_tail,struct net_device *dev); +struct sk_buff *prev_tail,struct net_device *dev, +int *refs);static void ip6_frag_expire (struct timer_list *t) {
@@ -105,7 +106,7 @@ fq_find(struct net *net, __be32 id, consstatic int ip6_frag_queue (struct frag_queue *fq,struct sk_buff *skb,struct frag_hdr *fhdr,int nhoff, -u32 *prob_offset) +u32 *prob_offset,int *refs) {struct net *net =dev_net (skb_dst (skb)->dev);int offset, end, fragsize;
@@ -220,7 +221,7 @@ static int ip6_frag_queue(struct frag_quunsigned long orefdst = skb->_skb_refdst; skb->_skb_refdst =0UL ; - err =ip6_frag_reasm (fq, skb, prev_tail, dev); + err =ip6_frag_reasm (fq, skb, prev_tail, dev, refs); skb->_skb_refdst = orefdst;return err; }
@@ -238,7 +239,7 @@ insert_error:__IP6_INC_STATS (net,ip6_dst_idev (skb_dst (skb)),IPSTATS_MIB_REASM_OVERLAPS ); discard_fq: -inet_frag_kill (&fq->q); +inet_frag_kill (&fq->q, refs);__IP6_INC_STATS (net,ip6_dst_idev (skb_dst (skb)),IPSTATS_MIB_REASMFAILS ); err:
@@ -254,7 +255,8 @@ err:* the last and the first frames arrived and all the bits are here. */ static int ip6_frag_reasm (struct frag_queue *fq,struct sk_buff *skb, -struct sk_buff *prev_tail,struct net_device *dev) +struct sk_buff *prev_tail,struct net_device *dev, +int *refs) {struct net *net = fq->q.fqdir->net;unsigned int nhoff;
@@ -262,7 +264,7 @@ static int ip6_frag_reasm(struct frag_quint payload_len;u8 ecn; -inet_frag_kill (&fq->q); +inet_frag_kill (&fq->q, refs); ecn = ip_frag_ecn_table[fq->ecn];if (unlikely (ecn ==0xff ))
@@ -320,7 +322,7 @@ out_fail:rcu_read_lock ();__IP6_INC_STATS (net,__in6_dev_stats_get (dev, skb),IPSTATS_MIB_REASMFAILS );rcu_read_unlock (); -inet_frag_kill (&fq->q); +inet_frag_kill (&fq->q, refs);return -1 ; }
@@ -386,7 +388,7 @@ static int ipv6_frag_rcv(struct sk_buff fq->iif = iif; ret =ip6_frag_queue (fq, skb, fhdr,IP6CB (skb)->nhoff, - &prob_offset); + &prob_offset, &refs);spin_unlock (&fq->q.lock);inet_frag_putn (&fq->q, refs);
Greg Kroah-Hartman
maintainerPATCH 17/87 inet: frags: save a pair of atomic operations in reassembly
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit ca0359df45a55a9eb4d6dc09a481064abf78320f ]
As mentioned in commit 648700f76b03 ("inet: frags:
use rhashtables for reassembly units"):
A followup patch will even remove the refcount hold/release left from prior implementation and save a couple of atomic operations.
This patch implements this idea, seven years later.
Stable-dep-of: 653d7ddf6cba ("inet: frags: publish queues before arming timer")
--- net/ieee802154/6lowpan/reassembly.c | 5 ++++- net/ipv4/inet_fragment.c | 18 ++++++++---------- net/ipv4/ip_fragment.c | 5 ++++- net/ipv6/netfilter/nf_conntrack_reasm.c | 5 ++++- net/ipv6/reassembly.c | 9 ++++----- 5 files changed, 24 insertions(+), 18 deletions(-)
net/ieee802154/6lowpan/reassembly.c +4 -1
@@ -304,17 +304,20 @@ int lowpan_frag_rcv(struct sk_buff *skb, goto err; } +rcu_read_lock (); fq =fq_find (net, cb, &hdr.source, &hdr.dest);if (fq !=NULL ) { -int ret, refs =1 ; +int ret, refs =0 ;spin_lock (&fq->q.lock); ret =lowpan_frag_queue (fq, skb, frag_type, &refs);spin_unlock (&fq->q.lock); +rcu_read_unlock ();inet_frag_putn (&fq->q, refs);return ret; } +rcu_read_unlock (); err:kfree_skb (skb);
net/ipv4/inet_fragment.c +8 -10
@@ -375,7 +375,8 @@ static struct inet_frag_queue *inet_fragtimer_setup (&q->timer, f->frag_expire,0 );spin_lock_init (&q->lock); -refcount_set (&q->refcnt,3 ); +/* One reference for the timer, one for the hash table. */ +refcount_set (&q->refcnt,2 );return q; }
@@ -397,7 +398,11 @@ static struct inet_frag_queue *inet_frag *prev =rhashtable_lookup_get_insert_key (&fqdir->rhashtable, &q->key, &q->node, f->rhash_params);if (*prev) { -int refs =2 ; +/* We could not insert in the hash table, +* we need to cancel what inet_frag_alloc() +* anticipated. +*/ +int refs =1 ; q->flags |=INET_FRAG_COMPLETE ;inet_frag_kill (q, &refs);
@@ -407,7 +412,6 @@ static struct inet_frag_queue *inet_fragreturn q; } -/* TODO : call from rcu_read_lock() and no longer use refcount_inc_not_zero() */ struct inet_frag_queue *inet_frag_find (struct fqdir *fqdir,void *key) {/* This pairs with WRITE_ONCE() in fqdir_pre_exit(). */
@@ -417,17 +421,11 @@ struct inet_frag_queue *inet_frag_find(sif (!high_thresh ||frag_mem_limit (fqdir) > high_thresh)return NULL ; -rcu_read_lock (); - prev =rhashtable_lookup (&fqdir->rhashtable, key, fqdir->f->rhash_params);if (!prev) fq =inet_frag_create (fqdir, key, &prev); -if (!IS_ERR_OR_NULL (prev)) { +if (!IS_ERR_OR_NULL (prev)) fq = prev; -if (!refcount_inc_not_zero (&fq->refcnt)) - fq =NULL ; - } -rcu_read_unlock ();return fq; }EXPORT_SYMBOL (inet_frag_find);
net/ipv4/ip_fragment.c +4 -1
@@ -477,18 +477,21 @@ int ip_defrag(struct net *net, struct sk__IP_INC_STATS (net,IPSTATS_MIB_REASMREQDS );/* Lookup (or create) queue header */ +rcu_read_lock (); qp =ip_find (net,ip_hdr (skb), user, vif);if (qp) { -int ret, refs =1 ; +int ret, refs =0 ;spin_lock (&qp->q.lock); ret =ip_frag_queue (qp, skb, &refs);spin_unlock (&qp->q.lock); +rcu_read_unlock ();inet_frag_putn (&qp->q, refs);return ret; } +rcu_read_unlock ();__IP_INC_STATS (net,IPSTATS_MIB_REASMFAILS );kfree_skb (skb);
net/ipv6/netfilter/nf_conntrack_reasm.c +4 -1
@@ -452,7 +452,7 @@ int nf_ct_frag6_gather(struct net *net,struct frag_hdr *fhdr;struct frag_queue *fq;struct ipv6hdr *hdr; -int refs =1 ; +int refs =0 ;u8 prevhdr;/* Jumbo payload inhibits frag. header */
@@ -479,9 +479,11 @@ int nf_ct_frag6_gather(struct net *net, hdr =ipv6_hdr (skb); fhdr = (struct frag_hdr *)skb_transport_header (skb); +rcu_read_lock (); fq =fq_find (net, fhdr->identification, user, hdr, skb->dev ? skb->dev->ifindex :0 );if (fq ==NULL ) { +rcu_read_unlock ();pr_debug ("Can't find and can't create new queue\n" );return -ENOMEM ; }
@@ -495,6 +497,7 @@ int nf_ct_frag6_gather(struct net *net, }spin_unlock_bh (&fq->q.lock); +rcu_read_unlock ();inet_frag_putn (&fq->q, refs);return ret; }
net/ipv6/reassembly.c +4 -5
@@ -305,9 +305,7 @@ static int ip6_frag_reasm(struct frag_quskb_postpush_rcsum (skb,skb_network_header (skb),skb_network_header_len (skb)); -rcu_read_lock ();__IP6_INC_STATS (net,__in6_dev_stats_get (dev, skb),IPSTATS_MIB_REASMOKS ); -rcu_read_unlock (); fq->q.rb_fragments =RB_ROOT ; fq->q.fragments_tail =NULL ; fq->q.last_run_head =NULL ;
@@ -319,9 +317,7 @@ out_oversize: out_oom:net_dbg_ratelimited ("ip6_frag_reasm: no memory for reassembly\n" ); out_fail: -rcu_read_lock ();__IP6_INC_STATS (net,__in6_dev_stats_get (dev, skb),IPSTATS_MIB_REASMFAILS ); -rcu_read_unlock ();inet_frag_kill (&fq->q, refs);return -1 ; }
@@ -379,10 +375,11 @@ static int ipv6_frag_rcv(struct sk_buff } iif = skb->dev ? skb->dev->ifindex :0 ; +rcu_read_lock (); fq =fq_find (net, fhdr->identification, hdr, iif);if (fq) {u32 prob_offset =0 ; -int ret, refs =1 ; +int ret, refs =0 ;spin_lock (&fq->q.lock);
@@ -391,6 +388,7 @@ static int ipv6_frag_rcv(struct sk_buff &prob_offset, &refs);spin_unlock (&fq->q.lock); +rcu_read_unlock ();inet_frag_putn (&fq->q, refs);if (prob_offset) { __IP6_INC_STATS(net, __in6_dev_get_safely(skb->dev),
@@ -400,6 +398,7 @@ static int ipv6_frag_rcv(struct sk_buff }return ret; } +rcu_read_unlock ();__IP6_INC_STATS (net,ip6_dst_idev (skb_dst (skb)),IPSTATS_MIB_REASMFAILS );kfree_skb (skb);
Greg Kroah-Hartman
maintainerPATCH 18/87 inet: frags: publish queues before arming timer
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhiling Zou <[email protected]>
[ Upstream commit 653d7ddf6cba867777a3d14c4f83ace008c5ad13 ]
inet_frag_create() arms the fragment queue timer before inserting the queue into the fqdir rhashtable. If the namespace fragment timeout is zero or negative, the timer can run before the queue is published.
The timer callback then marks the queue complete, tries to remove a node that is not in the hash table yet, and drops the anticipated hash reference. Creation can subsequently publish the completed queue without restoring that reference, leaving a stale hash node after the caller drops the remaining reference.
Publish the queue first and arm the timer while holding the queue lock. This makes timer expiry wait until the queue is visible in the hash table, so inet_frag_kill() can remove the node and balance the hash reference.
--- net/ipv4/inet_fragment.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
net/ipv4/inet_fragment.c +5 -5
@@ -393,8 +393,8 @@ static struct inet_frag_queue *inet_frag *prev =ERR_PTR (-ENOMEM );return NULL ; } -mod_timer (&q->timer, jiffies + fqdir->timeout); +spin_lock_bh (&q->lock); *prev =rhashtable_lookup_get_insert_key (&fqdir->rhashtable, &q->key, &q->node, f->rhash_params);if (*prev) {
@@ -402,13 +402,13 @@ static struct inet_frag_queue *inet_frag* we need to cancel what inet_frag_alloc() * anticipated. */ -int refs =1 ; - q->flags |=INET_FRAG_COMPLETE ; -inet_frag_kill (q, &refs); -inet_frag_putn (q, refs); +spin_unlock_bh (&q->lock); +inet_frag_putn (q,2 );return NULL ; } +mod_timer (&q->timer, jiffies + fqdir->timeout); +spin_unlock_bh (&q->lock);return q; }
Greg Kroah-Hartman
maintainerPATCH 19/87 mmc: atmel-mci: Fix use-after-free in atmci_remove due to race condition
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pei Xiao <[email protected]>
[ Upstream commit c125ee35a49a0518521b52b27631eef061b8719a ]
In atmci_probe, &host->bh_work is bound with atmci_work_func, and atmci_interrupt, atmci_timeout_timer and atmci_dma_complete can all queue this work on system_bh_wq.
If we remove the module, atmci_remove makes cleanup and the memory allocated for host with devm_kzalloc() is released after the remove callback returns, while the work mentioned above may still be pending or running. The sequence of operations that may lead to a UAF bug is as follows:
CPU0 CPU1
| atmci_interrupt
| queue_work(system_bh_wq,
| &host->bh_work)
atmci_remove |
atmci_cleanup_slot(...) |
atmci_writel(host, ATMCI_IDR, ~0UL) |
timer_delete_sync(&host->timer) |
dma_release_channel(host->dma.chan) |
free_irq(platform_get_irq(pdev, 0), host) |
| atmci_work_func
| // use host
// devm resources released after |
// remove returns, host is freed |
| // use host (use-after-free)Fix it by canceling the work after all the sources that can schedule it (IRQ handler, timeout timer and DMA completion callback) have been stopped, and before proceeding with the remaining cleanup in atmci_remove.
--- drivers/mmc/host/atmel-mci.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/mmc/host/atmel-mci.c +2 -0
@@ -2658,6 +2658,8 @@ static void atmci_remove(struct platformfree_irq (platform_get_irq (pdev,0 ), host); +cancel_work_sync (&host->bh_work); +clk_disable_unprepare (host->mck);pm_runtime_disable (&pdev->dev);
Greg Kroah-Hartman
maintainerPATCH 20/87 xfs: dont use a xfs_log_iovec for ri_buf in log recovery
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christoph Hellwig <[email protected]>
[ Upstream commit ded74fddcaf685a9440c5612f7831d0c4c1473ca ]
ri_buf just holds a pointer/len pair and is not a log iovec used for writing to the log. Switch to use a kvec instead.
Stable-dep-of: 813f8136a2ce ("xfs: bounds-check buffer log item's dirty bitmap")
--- fs/xfs/libxfs/xfs_log_recover.h | 4 +-- fs/xfs/xfs_attr_item.c | 24 ++++++++++----------- fs/xfs/xfs_bmap_item.c | 18 ++++++++-------- fs/xfs/xfs_buf_item.c | 8 +++---- fs/xfs/xfs_buf_item.h | 2 - fs/xfs/xfs_buf_item_recover.c | 38 ++++++++++++++++----------------- fs/xfs/xfs_dquot_item_recover.c | 20 ++++++++--------- fs/xfs/xfs_extfree_item.c | 45 +++++++++++++++++++++------------------- fs/xfs/xfs_icreate_item.c | 2 - fs/xfs/xfs_inode_item.c | 6 ++--- fs/xfs/xfs_inode_item.h | 4 +-- fs/xfs/xfs_inode_item_recover.c | 26 +++++++++++------------ fs/xfs/xfs_log_recover.c | 16 +++++++------- fs/xfs/xfs_refcount_item.c | 16 +++++++------- fs/xfs/xfs_rmap_item.c | 16 +++++++------- fs/xfs/xfs_trans.h | 1 16 files changed, 124 insertions(+), 122 deletions(-)
fs/xfs/libxfs/xfs_log_recover.h +2 -2
@@ -95,7 +95,7 @@ struct xlog_recover_item {struct list_head ri_list;int ri_cnt;/* count of regions found */ int ri_total;/* total regions */ -struct xfs_log_iovec *ri_buf;/* ptr to regions buffer */ +struct kvec *ri_buf;/* ptr to regions buffer */ const struct xlog_recover_item_ops *ri_ops; };
@@ -108,7 +108,7 @@ struct xlog_recover {struct list_head r_itemq;/* q for items */ }; -#define ITEM_TYPE (i) (*(unsigned short *)(i)->ri_buf[0].i_addr) +#define ITEM_TYPE (i) (*(unsigned short *)(i)->ri_buf[0].iov_base)#define XLOG_RECOVER_CRCPASS 0#define XLOG_RECOVER_PASS1 1
fs/xfs/xfs_attr_item.c +12 -12
@@ -729,13 +729,13 @@ xlog_recover_attri_commit_pass2(/* Validate xfs_attri_log_format before the large memory allocation */ len =sizeof (struct xfs_attri_log_format ); -if (item->ri_buf[i].i_len != len) { +if (item->ri_buf[i].iov_len != len) {XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , mp, - item->ri_buf[0 ].i_addr, item->ri_buf[0 ].i_len); + item->ri_buf[0 ].iov_base, item->ri_buf[0 ].iov_len);return -EFSCORRUPTED ; } - attri_formatp = item->ri_buf[i].i_addr; + attri_formatp = item->ri_buf[i].iov_base;if (!xfs_attri_validate (mp, attri_formatp)) {XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , mp, attri_formatp, len);
@@ -770,14 +770,14 @@ xlog_recover_attri_commit_pass2( i++;/* Validate the attr name */ -if (item->ri_buf[i].i_len != +if (item->ri_buf[i].iov_len !=xlog_calc_iovec_len (attri_formatp->alfi_name_len)) {XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , mp, attri_formatp, len);return -EFSCORRUPTED ; } - attr_name = item->ri_buf[i].i_addr; + attr_name = item->ri_buf[i].iov_base;if (!xfs_attr_namecheck (attri_formatp->alfi_attr_filter, attr_name, attri_formatp->alfi_name_len)) { XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
@@ -788,14 +788,14 @@ xlog_recover_attri_commit_pass2(/* Validate the attr value, if present */ if (attri_formatp->alfi_value_len !=0 ) { -if (item->ri_buf[i].i_len !=xlog_calc_iovec_len (attri_formatp->alfi_value_len)) { +if (item->ri_buf[i].iov_len !=xlog_calc_iovec_len (attri_formatp->alfi_value_len)) {XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , mp, - item->ri_buf[0 ].i_addr, - item->ri_buf[0 ].i_len); + item->ri_buf[0 ].iov_base, + item->ri_buf[0 ].iov_len);return -EFSCORRUPTED ; } - attr_value = item->ri_buf[i].i_addr; + attr_value = item->ri_buf[i].iov_base; i++; }
@@ -912,10 +912,10 @@ xlog_recover_attrd_commit_pass2( {struct xfs_attrd_log_format *attrd_formatp; - attrd_formatp = item->ri_buf[0 ].i_addr; -if (item->ri_buf[0 ].i_len !=sizeof (struct xfs_attrd_log_format )) { + attrd_formatp = item->ri_buf[0 ].iov_base; +if (item->ri_buf[0 ].iov_len !=sizeof (struct xfs_attrd_log_format )) {XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , log->l_mp, - item->ri_buf[0 ].i_addr, item->ri_buf[0 ].i_len); + item->ri_buf[0 ].iov_base, item->ri_buf[0 ].iov_len);return -EFSCORRUPTED ; }
fs/xfs/xfs_bmap_item.c +9 -9
@@ -669,24 +669,24 @@ xlog_recover_bui_commit_pass2(struct xfs_bui_log_format *bui_formatp;size_t len; - bui_formatp = item->ri_buf[0 ].i_addr; + bui_formatp = item->ri_buf[0 ].iov_base; -if (item->ri_buf[0 ].i_len <xfs_bui_log_format_sizeof (0 )) { +if (item->ri_buf[0 ].iov_len <xfs_bui_log_format_sizeof (0 )) {XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , mp, - item->ri_buf[0 ].i_addr, item->ri_buf[0 ].i_len); + item->ri_buf[0 ].iov_base, item->ri_buf[0 ].iov_len);return -EFSCORRUPTED ; }if (bui_formatp->bui_nextents !=XFS_BUI_MAX_FAST_EXTENTS ) {XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , mp, - item->ri_buf[0 ].i_addr, item->ri_buf[0 ].i_len); + item->ri_buf[0 ].iov_base, item->ri_buf[0 ].iov_len);return -EFSCORRUPTED ; } len =xfs_bui_log_format_sizeof (bui_formatp->bui_nextents); -if (item->ri_buf[0 ].i_len != len) { +if (item->ri_buf[0 ].iov_len != len) {XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , mp, - item->ri_buf[0 ].i_addr, item->ri_buf[0 ].i_len); + item->ri_buf[0 ].iov_base, item->ri_buf[0 ].iov_len);return -EFSCORRUPTED ; }
@@ -720,10 +720,10 @@ xlog_recover_bud_commit_pass2( {struct xfs_bud_log_format *bud_formatp; - bud_formatp = item->ri_buf[0 ].i_addr; -if (item->ri_buf[0 ].i_len !=sizeof (struct xfs_bud_log_format )) { + bud_formatp = item->ri_buf[0 ].iov_base; +if (item->ri_buf[0 ].iov_len !=sizeof (struct xfs_bud_log_format )) {XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , log->l_mp, - item->ri_buf[0 ].i_addr, item->ri_buf[0 ].i_len); + item->ri_buf[0 ].iov_base, item->ri_buf[0 ].iov_len);return -EFSCORRUPTED ; }
fs/xfs/xfs_buf_item.c +4 -4
@@ -35,16 +35,16 @@ static inline struct xfs_buf_log_item *B/* Is this log iovec plausibly large enough to contain the buffer log format? */ bool xfs_buf_log_check_iovec ( -struct xfs_log_iovec *iovec) +struct kvec *iovec) { -struct xfs_buf_log_format *blfp = iovec->i_addr; +struct xfs_buf_log_format *blfp = iovec->iov_base;char *bmp_end;char *item_end; -if (offsetof(struct xfs_buf_log_format , blf_data_map) > iovec->i_len) +if (offsetof(struct xfs_buf_log_format , blf_data_map) > iovec->iov_len)return false; - item_end = (char *)iovec->i_addr + iovec->i_len; + item_end = (char *)iovec->iov_base + iovec->iov_len; bmp_end = (char *)&blfp->blf_data_map[blfp->blf_map_size];return bmp_end <= item_end; }
fs/xfs/xfs_buf_item.h +1 -1
@@ -67,7 +67,7 @@ static inline void xfs_buf_dquot_io_fail }#endif /* CONFIG_XFS_QUOTA */ void xfs_buf_iodone (struct xfs_buf *); -bool xfs_buf_log_check_iovec (struct xfs_log_iovec *iovec); +bool xfs_buf_log_check_iovec (struct kvec *iovec);extern struct kmem_cache *xfs_buf_item_cache;
fs/xfs/xfs_buf_item_recover.c +19 -19
@@ -157,7 +157,7 @@ STATIC enum xlog_recover_reorderxlog_recover_buf_reorder ( struct xlog_recover_item *item) { -struct xfs_buf_log_format *buf_f = item->ri_buf[0 ].i_addr; +struct xfs_buf_log_format *buf_f = item->ri_buf[0 ].iov_base;if (buf_f->blf_flags &XFS_BLF_CANCEL )return XLOG_REORDER_CANCEL_LIST ;
@@ -171,7 +171,7 @@ xlog_recover_buf_ra_pass2(struct xlog *log, struct xlog_recover_item *item) { - struct xfs_buf_log_format *buf_f = item->ri_buf[0].i_addr; + struct xfs_buf_log_format *buf_f = item->ri_buf[0].iov_base;xlog_buf_readahead (log, buf_f->blf_blkno, buf_f->blf_len,NULL ); }
@@ -185,11 +185,11 @@ xlog_recover_buf_commit_pass1(struct xlog *log, struct xlog_recover_item *item) { - struct xfs_buf_log_format *bf = item->ri_buf[0].i_addr; + struct xfs_buf_log_format *bf = item->ri_buf[0].iov_base;if (!xfs_buf_log_check_iovec (&item->ri_buf[0 ])) { -xfs_err (log->l_mp,"bad buffer log item size (%d)" , - item->ri_buf[0 ].i_len); +xfs_err (log->l_mp,"bad buffer log item size (%zd)" , + item->ri_buf[0 ].iov_len);return -EFSCORRUPTED ; }
@@ -470,8 +470,8 @@ xlog_recover_do_reg_buffer( nbits =xfs_contig_bits (buf_f->blf_data_map, buf_f->blf_map_size, bit);ASSERT (nbits >0 ); -ASSERT (item->ri_buf[i].i_addr !=NULL ); -ASSERT (item->ri_buf[i].i_len %XFS_BLF_CHUNK ==0 ); +ASSERT (item->ri_buf[i].iov_base !=NULL ); +ASSERT (item->ri_buf[i].iov_len %XFS_BLF_CHUNK ==0 );ASSERT (BBTOB (bp->b_length) >= ((uint )bit <<XFS_BLF_SHIFT ) + (nbits <<XFS_BLF_SHIFT ));
@@ -483,8 +483,8 @@ xlog_recover_do_reg_buffer(* the log. Hence we need to trim nbits back to the length of * the current region being copied out of the log. */ -if (item->ri_buf[i].i_len < (nbits <<XFS_BLF_SHIFT )) - nbits = item->ri_buf[i].i_len >>XFS_BLF_SHIFT ; +if (item->ri_buf[i].iov_len < (nbits <<XFS_BLF_SHIFT )) + nbits = item->ri_buf[i].iov_len >>XFS_BLF_SHIFT ;/* * Do a sanity check if this is a dquot buffer. Just checking
@@ -494,18 +494,18 @@ xlog_recover_do_reg_buffer( fa =NULL ;if (buf_f->blf_flags & (XFS_BLF_UDQUOT_BUF |XFS_BLF_PDQUOT_BUF |XFS_BLF_GDQUOT_BUF )) { -if (item->ri_buf[i].i_addr ==NULL ) { +if (item->ri_buf[i].iov_base ==NULL ) {xfs_alert (mp,"XFS: NULL dquot in %s." , __func__); goto next; } -if (item->ri_buf[i].i_len < size_disk_dquot) { +if (item->ri_buf[i].iov_len < size_disk_dquot) {xfs_alert (mp, -"XFS: dquot too small (%d) in %s." , - item->ri_buf[i].i_len, __func__); +"XFS: dquot too small (%zd) in %s." , + item->ri_buf[i].iov_len, __func__); goto next; } - fa =xfs_dquot_verify (mp, item->ri_buf[i].i_addr,-1 ); + fa =xfs_dquot_verify (mp, item->ri_buf[i].iov_base,-1 );if (fa) { xfs_alert(mp, "dquot corrupt at %pS trying to replay into block 0x%llx",
@@ -516,7 +516,7 @@ xlog_recover_do_reg_buffer(memcpy (xfs_buf_offset (bp, (uint )bit <<XFS_BLF_SHIFT ),/* dest */ - item->ri_buf[i].i_addr,/* source */ + item->ri_buf[i].iov_base,/* source */ nbits<<XFS_BLF_SHIFT );/* length */ next: i++;
@@ -652,8 +652,8 @@ xlog_recover_do_inode_buffer(if (next_unlinked_offset < reg_buf_offset)continue ; -ASSERT (item->ri_buf[item_index].i_addr !=NULL ); -ASSERT ((item->ri_buf[item_index].i_len %XFS_BLF_CHUNK ) ==0 ); +ASSERT (item->ri_buf[item_index].iov_base !=NULL ); +ASSERT ((item->ri_buf[item_index].iov_len %XFS_BLF_CHUNK ) ==0 );ASSERT ((reg_buf_offset + reg_buf_bytes) <=BBTOB (bp->b_length));/*
@@ -661,7 +661,7 @@ xlog_recover_do_inode_buffer(* current di_next_unlinked field. Extract its value * and copy it to the buffer copy. */ - logged_nextp = item->ri_buf[item_index].i_addr + + logged_nextp = item->ri_buf[item_index].iov_base + next_unlinked_offset - reg_buf_offset;if (XFS_IS_CORRUPT (mp, *logged_nextp ==0 )) { xfs_alert(mp,
@@ -951,7 +951,7 @@ xlog_recover_buf_commit_pass2( struct xlog_recover_item *item, xfs_lsn_t current_lsn) { -struct xfs_buf_log_format *buf_f = item->ri_buf[0 ].i_addr; +struct xfs_buf_log_format *buf_f = item->ri_buf[0 ].iov_base;struct xfs_mount *mp = log->l_mp;struct xfs_buf *bp;int error;
fs/xfs/xfs_dquot_item_recover.c +10 -10
@@ -34,10 +34,10 @@ xlog_recover_dquot_ra_pass2(if (mp->m_qflags ==0 )return ; - recddq = item->ri_buf[1 ].i_addr; + recddq = item->ri_buf[1 ].iov_base;if (recddq ==NULL )return ; -if (item->ri_buf[1 ].i_len <sizeof (struct xfs_disk_dquot )) +if (item->ri_buf[1 ].iov_len <sizeof (struct xfs_disk_dquot ))return ; type = recddq->d_type &XFS_DQTYPE_REC_MASK ;
@@ -45,7 +45,7 @@ xlog_recover_dquot_ra_pass2(if (log->l_quotaoffs_flag & type)return ; - dq_f = item->ri_buf[0 ].i_addr; + dq_f = item->ri_buf[0 ].iov_base;ASSERT (dq_f);ASSERT (dq_f->qlf_len ==1 );
@@ -79,14 +79,14 @@ xlog_recover_dquot_commit_pass2(if (mp->m_qflags ==0 )return 0 ; - recddq = item->ri_buf[1 ].i_addr; + recddq = item->ri_buf[1 ].iov_base;if (recddq ==NULL ) {xfs_alert (log->l_mp,"NULL dquot in %s." , __func__);return -EFSCORRUPTED ; } -if (item->ri_buf[1 ].i_len <sizeof (struct xfs_disk_dquot )) { -xfs_alert (log->l_mp,"dquot too small (%d) in %s." , - item->ri_buf[1 ].i_len, __func__); +if (item->ri_buf[1 ].iov_len <sizeof (struct xfs_disk_dquot )) { +xfs_alert (log->l_mp,"dquot too small (%zd) in %s." , + item->ri_buf[1 ].iov_len, __func__);return -EFSCORRUPTED ; }
@@ -108,7 +108,7 @@ xlog_recover_dquot_commit_pass2(* The other possibility, of course, is that the quota subsystem was * removed since the last mount - ENOSYS. */ - dq_f = item->ri_buf[0 ].i_addr; + dq_f = item->ri_buf[0 ].iov_base;ASSERT (dq_f); fa =xfs_dquot_verify (mp, recddq, dq_f->qlf_id);if (fa) {
@@ -147,7 +147,7 @@ xlog_recover_dquot_commit_pass2( } } -memcpy (ddq, recddq, item->ri_buf[1 ].i_len); +memcpy (ddq, recddq, item->ri_buf[1 ].iov_len);if (xfs_has_crc (mp)) {xfs_update_cksum ((char *)dqb,sizeof (struct xfs_dqblk ),XFS_DQUOT_CRC_OFF );
@@ -192,7 +192,7 @@ xlog_recover_quotaoff_commit_pass1(struct xlog *log, struct xlog_recover_item *item) { - struct xfs_qoff_logformat *qoff_f = item->ri_buf[0].i_addr; + struct xfs_qoff_logformat *qoff_f = item->ri_buf[0].iov_base;ASSERT (qoff_f);/*
fs/xfs/xfs_extfree_item.c +24 -21
92 lines not on this page · raw message
fs/xfs/xfs_icreate_item.c +1 -1
@@ -158,7 +158,7 @@ xlog_recover_icreate_commit_pass2(int nbufs;int i; - icl = (struct xfs_icreate_log *)item->ri_buf[0 ].i_addr; + icl = (struct xfs_icreate_log *)item->ri_buf[0 ].iov_base;if (icl->icl_type !=XFS_LI_ICREATE ) {xfs_warn (log->l_mp,"xlog_recover_do_icreate_trans: bad type" );return -EINVAL ;
fs/xfs/xfs_inode_item.c +3 -3
@@ -1177,12 +1177,12 @@ xfs_iflush_shutdown_abort(*/ int xfs_inode_item_format_convert ( -struct xfs_log_iovec *buf, +struct kvec *buf,struct xfs_inode_log_format *in_f) { -struct xfs_inode_log_format_32 *in_f32 = buf->i_addr; +struct xfs_inode_log_format_32 *in_f32 = buf->iov_base; -if (buf->i_len !=sizeof (*in_f32)) { +if (buf->iov_len !=sizeof (*in_f32)) {XFS_ERROR_REPORT (__func__,XFS_ERRLEVEL_LOW ,NULL );return -EFSCORRUPTED ; }
fs/xfs/xfs_inode_item.h +2 -2
@@ -46,8 +46,8 @@ extern void xfs_inode_item_init(struct xextern void xfs_inode_item_destroy (struct xfs_inode *);extern void xfs_iflush_abort (struct xfs_inode *);extern void xfs_iflush_shutdown_abort (struct xfs_inode *); -extern int xfs_inode_item_format_convert (xfs_log_iovec_t *, -struct xfs_inode_log_format *); +int xfs_inode_item_format_convert (struct kvec *buf, +struct xfs_inode_log_format *in_f);extern struct kmem_cache *xfs_ili_cache;
fs/xfs/xfs_inode_item_recover.c +13 -13
@@ -28,13 +28,13 @@ xlog_recover_inode_ra_pass2( struct xlog *log, struct xlog_recover_item *item) { -if (item->ri_buf[0 ].i_len ==sizeof (struct xfs_inode_log_format )) { -struct xfs_inode_log_format *ilfp = item->ri_buf[0 ].i_addr; +if (item->ri_buf[0 ].iov_len ==sizeof (struct xfs_inode_log_format )) { +struct xfs_inode_log_format *ilfp = item->ri_buf[0 ].iov_base;xlog_buf_readahead (log, ilfp->ilf_blkno, ilfp->ilf_len, &xfs_inode_buf_ra_ops); }else { -struct xfs_inode_log_format_32 *ilfp = item->ri_buf[0 ].i_addr; +struct xfs_inode_log_format_32 *ilfp = item->ri_buf[0 ].iov_base;xlog_buf_readahead (log, ilfp->ilf_blkno, ilfp->ilf_len, &xfs_inode_buf_ra_ops);
@@ -288,8 +288,8 @@ xlog_recover_inode_commit_pass2(int need_free =0 ;xfs_failaddr_t fa; -if (item->ri_buf[0 ].i_len ==sizeof (struct xfs_inode_log_format )) { - in_f = item->ri_buf[0 ].i_addr; +if (item->ri_buf[0 ].iov_len ==sizeof (struct xfs_inode_log_format )) { + in_f = item->ri_buf[0 ].iov_base; }else { in_f =kmem_alloc (sizeof (struct xfs_inode_log_format ),0 ); need_free =1 ;
@@ -327,7 +327,7 @@ xlog_recover_inode_commit_pass2( error = -EFSCORRUPTED ; goto out_release; } - ldip = item->ri_buf[1 ].i_addr; + ldip = item->ri_buf[1 ].iov_base;if (XFS_IS_CORRUPT (mp, ldip->di_magic !=XFS_DINODE_MAGIC )) { xfs_alert(mp, "%s: Bad inode log record, rec ptr "PTR_FMT", ino %lld",
@@ -432,12 +432,12 @@ xlog_recover_inode_commit_pass2( goto out_release; } isize =xfs_log_dinode_size (mp); -if (unlikely (item->ri_buf[1 ].i_len > isize)) { +if (unlikely (item->ri_buf[1 ].iov_len > isize)) {XFS_CORRUPTION_ERROR ("Bad log dinode size" ,XFS_ERRLEVEL_LOW , mp, ldip,sizeof (*ldip));xfs_alert (mp, -"Bad inode 0x%llx log dinode size 0x%x" , - in_f->ilf_ino, item->ri_buf[1 ].i_len); +"Bad inode 0x%llx log dinode size 0x%zx" , + in_f->ilf_ino, item->ri_buf[1 ].iov_len); error = -EFSCORRUPTED ; goto out_release; }
@@ -460,8 +460,8 @@ xlog_recover_inode_commit_pass2(if (in_f->ilf_size ==2 ) goto out_owner_change; - len = item->ri_buf[2 ].i_len; - src = item->ri_buf[2 ].i_addr; + len = item->ri_buf[2 ].iov_len; + src = item->ri_buf[2 ].iov_base;ASSERT (in_f->ilf_size <=4 );ASSERT ((in_f->ilf_size ==3 ) || (fields &XFS_ILOG_AFORK )); ASSERT(!(fields & XFS_ILOG_DFORK) ||
@@ -498,8 +498,8 @@ xlog_recover_inode_commit_pass2( }else { attr_index =2 ; } - len = item->ri_buf[attr_index].i_len; - src = item->ri_buf[attr_index].i_addr; + len = item->ri_buf[attr_index].iov_len; + src = item->ri_buf[attr_index].iov_base;ASSERT (len ==xlog_calc_iovec_len (in_f->ilf_asize));switch (in_f->ilf_fields &XFS_ILOG_AFORK ) {
fs/xfs/xfs_log_recover.c +8 -8
@@ -2105,15 +2105,15 @@ xlog_recover_add_to_cont_trans( item = list_entry(trans->r_itemq.prev, struct xlog_recover_item, ri_list); - old_ptr = item->ri_buf[item->ri_cnt-1 ].i_addr; - old_len = item->ri_buf[item->ri_cnt-1 ].i_len; + old_ptr = item->ri_buf[item->ri_cnt-1 ].iov_base; + old_len = item->ri_buf[item->ri_cnt-1 ].iov_len; ptr =kvrealloc (old_ptr, old_len, len + old_len,GFP_KERNEL );if (!ptr)return -ENOMEM ;memcpy (&ptr[old_len], dp, len); - item->ri_buf[item->ri_cnt-1 ].i_len += len; - item->ri_buf[item->ri_cnt-1 ].i_addr = ptr; + item->ri_buf[item->ri_cnt-1 ].iov_len += len; + item->ri_buf[item->ri_cnt-1 ].iov_base = ptr;trace_xfs_log_recover_item_add_cont (log, trans, item,0 );return 0 ; }
@@ -2198,7 +2198,7 @@ xlog_recover_add_to_trans( item->ri_total = in_f->ilf_size; item->ri_buf = -kmem_zalloc (item->ri_total *sizeof (xfs_log_iovec_t), +kmem_zalloc (item->ri_total *sizeof (*item->ri_buf),0 ); }
@@ -2212,8 +2212,8 @@ xlog_recover_add_to_trans( }/* Description region is ri_buf[0] */ - item->ri_buf[item->ri_cnt].i_addr = ptr; - item->ri_buf[item->ri_cnt].i_len = len; + item->ri_buf[item->ri_cnt].iov_base = ptr; + item->ri_buf[item->ri_cnt].iov_len = len; item->ri_cnt++;trace_xfs_log_recover_item_add (log, trans, item,0 );return 0 ;
@@ -2237,7 +2237,7 @@ xlog_recover_free_trans(/* Free the regions in the item. */ list_del (&item->ri_list);for (i =0 ; i < item->ri_cnt; i++) -kmem_free (item->ri_buf[i].i_addr); +kmem_free (item->ri_buf[i].iov_base);/* Free the item itself */ kmem_free (item->ri_buf);kmem_free (item);
fs/xfs/xfs_refcount_item.c +8 -8
@@ -631,18 +631,18 @@ xlog_recover_cui_commit_pass2(struct xfs_cui_log_format *cui_formatp;size_t len; - cui_formatp = item->ri_buf[0 ].i_addr; + cui_formatp = item->ri_buf[0 ].iov_base; -if (item->ri_buf[0 ].i_len <xfs_cui_log_format_sizeof (0 )) { +if (item->ri_buf[0 ].iov_len <xfs_cui_log_format_sizeof (0 )) {XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , mp, - item->ri_buf[0 ].i_addr, item->ri_buf[0 ].i_len); + item->ri_buf[0 ].iov_base, item->ri_buf[0 ].iov_len);return -EFSCORRUPTED ; } len =xfs_cui_log_format_sizeof (cui_formatp->cui_nextents); -if (item->ri_buf[0 ].i_len != len) { +if (item->ri_buf[0 ].iov_len != len) {XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , mp, - item->ri_buf[0 ].i_addr, item->ri_buf[0 ].i_len); + item->ri_buf[0 ].iov_base, item->ri_buf[0 ].iov_len);return -EFSCORRUPTED ; }
@@ -676,10 +676,10 @@ xlog_recover_cud_commit_pass2( {struct xfs_cud_log_format *cud_formatp; - cud_formatp = item->ri_buf[0 ].i_addr; -if (item->ri_buf[0 ].i_len !=sizeof (struct xfs_cud_log_format )) { + cud_formatp = item->ri_buf[0 ].iov_base; +if (item->ri_buf[0 ].iov_len !=sizeof (struct xfs_cud_log_format )) {XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , log->l_mp, - item->ri_buf[0 ].i_addr, item->ri_buf[0 ].i_len); + item->ri_buf[0 ].iov_base, item->ri_buf[0 ].iov_len);return -EFSCORRUPTED ; }
fs/xfs/xfs_rmap_item.c +8 -8
@@ -684,18 +684,18 @@ xlog_recover_rui_commit_pass2(struct xfs_rui_log_format *rui_formatp;size_t len; - rui_formatp = item->ri_buf[0 ].i_addr; + rui_formatp = item->ri_buf[0 ].iov_base; -if (item->ri_buf[0 ].i_len <xfs_rui_log_format_sizeof (0 )) { +if (item->ri_buf[0 ].iov_len <xfs_rui_log_format_sizeof (0 )) {XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , mp, - item->ri_buf[0 ].i_addr, item->ri_buf[0 ].i_len); + item->ri_buf[0 ].iov_base, item->ri_buf[0 ].iov_len);return -EFSCORRUPTED ; } len =xfs_rui_log_format_sizeof (rui_formatp->rui_nextents); -if (item->ri_buf[0 ].i_len != len) { +if (item->ri_buf[0 ].iov_len != len) {XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , mp, - item->ri_buf[0 ].i_addr, item->ri_buf[0 ].i_len); + item->ri_buf[0 ].iov_base, item->ri_buf[0 ].iov_len);return -EFSCORRUPTED ; }
@@ -729,10 +729,10 @@ xlog_recover_rud_commit_pass2( {struct xfs_rud_log_format *rud_formatp; - rud_formatp = item->ri_buf[0 ].i_addr; -if (item->ri_buf[0 ].i_len !=sizeof (struct xfs_rud_log_format )) { + rud_formatp = item->ri_buf[0 ].iov_base; +if (item->ri_buf[0 ].iov_len !=sizeof (struct xfs_rud_log_format )) {XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , log->l_mp, - rud_formatp, item->ri_buf[0 ].i_len); + rud_formatp, item->ri_buf[0 ].iov_len);return -EFSCORRUPTED ; }
fs/xfs/xfs_trans.h +0 -1
@@ -15,7 +15,6 @@ struct xfs_efd_log_item;struct xfs_efi_log_item ;struct xfs_inode ;struct xfs_item_ops ; -struct xfs_log_iovec ;struct xfs_mount ;struct xfs_trans ;struct xfs_trans_res ;
Greg Kroah-Hartman
maintainerPATCH 21/87 xfs: bounds-check buffer log items dirty bitmap
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ibrahim Hashimov <[email protected]>
[ Upstream commit 813f8136a2ce1fee266d02a7df73db6e8a541604 ]
xlog_recover_do_reg_buffer() replays each dirty region described by a buffer log item's bitmap into the buffer read for that item:
memcpy(xfs_buf_offset(bp, (uint)bit << XFS_BLF_SHIFT), item->ri_buf[i].iov_base, nbits << XFS_BLF_SHIFT);
The destination offset (bit/nbits, from the logged dirty bitmap) and the buffer size (from the logged blf_len) are both attacker-controlled and otherwise unrelated, yet the only thing bounding the copy is an ASSERT(), which compiles away on production kernels. A crafted image logging a small blf_len together with a bitmap bit past the end of that buffer drives the memcpy() past the buffer's allocation, corrupting adjacent kernel heap during mount-time log recovery. This is reachable by anyone who can get a crafted image mounted -- the malicious-filesystem threat model XFS already guards against elsewhere.
Turn the ASSERT() into a real XFS_IS_CORRUPT() check that aborts recovery of the buffer with -EFSCORRUPTED, consistent with the validate-and-fail idiom already used in xlog_recover_do_inode_buffer() and xfs_dquot_item_recover.c. xlog_recover_do_reg_buffer() therefore becomes STATIC int and its three callers propagate the error.
Found and confirmed with KASAN on a CONFIG_XFS_DEBUG=n build: the crafted image trips a slab-out-of-bounds write before this change and fails recovery cleanly with -EFSCORRUPTED after it.
--- fs/xfs/xfs_buf_item_recover.c | 57 ++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 16 deletions(-)
fs/xfs/xfs_buf_item_recover.c +41 -16
@@ -444,7 +444,7 @@ xlog_recover_validate_buf_type(* given buffer. The bitmap in the buf log format structure indicates * where to place the logged data. */ -STATIC void +STATIC int xlog_recover_do_reg_buffer( struct xfs_mount *mp, struct xlog_recover_item *item,
@@ -472,8 +472,24 @@ xlog_recover_do_reg_buffer(ASSERT (nbits >0 );ASSERT (item->ri_buf[i].iov_base !=NULL );ASSERT (item->ri_buf[i].iov_len %XFS_BLF_CHUNK ==0 ); -ASSERT (BBTOB (bp->b_length) >= - ((uint )bit <<XFS_BLF_SHIFT ) + (nbits <<XFS_BLF_SHIFT )); +/* +* The bitmap is only trustworthy to the extent that it +* describes a region that actually fits inside the buffer we +* read in based on the (attacker-controlled) blf_len. Do not +* rely on an ASSERT() for this -- it compiles away entirely on +* non-DEBUG kernels, which is exactly where this matters, so +* validate it for real and abort recovery of this buffer rather +* than copying past the end of it. +*/ +if (XFS_IS_CORRUPT (mp,BBTOB (bp->b_length) < + ((uint )bit <<XFS_BLF_SHIFT ) + + (nbits <<XFS_BLF_SHIFT ))) { +xfs_alert (mp, +"Bad buffer log item dirty bitmap (bit %d, nbits %d) for %d-byte buffer at daddr 0x%llx." , + bit, nbits,BBTOB (bp->b_length), +xfs_buf_daddr (bp)); +return -EFSCORRUPTED ; + }/* * The dirty regions logged in the buffer, even though
@@ -527,6 +543,7 @@ xlog_recover_do_reg_buffer(ASSERT (i == item->ri_total);xlog_recover_validate_buf_type (mp, bp, buf_f, current_lsn); +return 0 ; }/*
@@ -535,10 +552,10 @@ xlog_recover_do_reg_buffer(* (ie. USR or GRP), then just toss this buffer away; don't recover it. * Else, treat it as a regular buffer and do recovery. * -* Return false if the buffer was tossed and true if we recovered the buffer to -* indicate to the caller if the buffer needs writing. +* Return 0 if the buffer was not recovered (tossed), 1 if it was recovered and +* needs writing, or a negative errno if recovery of the buffer failed. */ -STATIC bool +STATIC int xlog_recover_do_dquot_buffer( struct xfs_mount *mp, struct xlog *log,
@@ -547,6 +564,7 @@ xlog_recover_do_dquot_buffer( struct xfs_buf_log_format *buf_f) {uint type; +int error;trace_xfs_log_recover_buf_dquot_buf (log, buf_f);
@@ -554,7 +572,7 @@ xlog_recover_do_dquot_buffer(* Filesystems are required to send in quota flags at mount time. */ if (!mp->m_qflags) -return false; +return 0 ; type =0 ;if (buf_f->blf_flags &XFS_BLF_UDQUOT_BUF )
@@ -567,10 +585,12 @@ xlog_recover_do_dquot_buffer(* This type of quotas was turned off, so ignore this buffer */ if (log->l_quotaoffs_flag & type) -return false; +return 0 ; -xlog_recover_do_reg_buffer (mp, item, bp, buf_f,NULLCOMMITLSN ); -return true; + error =xlog_recover_do_reg_buffer (mp, item, bp, buf_f,NULLCOMMITLSN ); +if (error) +return error; +return 1 ; }/*
@@ -706,7 +726,9 @@ xlog_recover_do_primary_sb_buffer(xfs_agnumber_t orig_agcount = mp->m_sb.sb_agcount;int error; -xlog_recover_do_reg_buffer (mp, item, bp, buf_f, current_lsn); + error =xlog_recover_do_reg_buffer (mp, item, bp, buf_f, current_lsn); +if (error) +return error;if (orig_agcount ==0 ) {xfs_alert (mp,"Trying to grow file system without AGs" );
@@ -1026,11 +1048,11 @@ xlog_recover_buf_commit_pass2( goto out_release; }else if (buf_f->blf_flags & (XFS_BLF_UDQUOT_BUF |XFS_BLF_PDQUOT_BUF |XFS_BLF_GDQUOT_BUF )) { -bool dirty; - - dirty =xlog_recover_do_dquot_buffer (mp, log, item, bp, buf_f); -if (!dirty) + error =xlog_recover_do_dquot_buffer (mp, log, item, bp, buf_f); +if (error <=0 ) goto out_release; +/* write dirty buffer */ + error =0 ; }else if ((xfs_blft_from_flags (buf_f) &XFS_BLFT_SB_BUF ) &&xfs_buf_daddr (bp) ==0 ) { error = xlog_recover_do_primary_sb_buffer(mp, item, bp, buf_f,
@@ -1038,7 +1060,10 @@ xlog_recover_buf_commit_pass2(if (error) goto out_release; }else { -xlog_recover_do_reg_buffer (mp, item, bp, buf_f, current_lsn); + error =xlog_recover_do_reg_buffer (mp, item, bp, buf_f, + current_lsn); +if (error) + goto out_release; }/*
Greg Kroah-Hartman
maintainerPATCH 22/87 ALSA: dummy: Check card index validity at probe
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit 02442d5fe8ee365a084b055d4fa81a0c1abfc3fd upstream.
snd_dummy_probe() blindly trusts that the given devptr->id value is within the proper card index range. It's OK for the devices the driver itself creates at the module probe time, but if the device is bound manually via sysfs interface, this could be -1 as "none", and this leads to OOB access for index[] and other parameters.
Add a sanity check for the card index and warn/correct it if it's a value out of the range.
--- sound/drivers/dummy.c | 6 ++++++ 1 file changed, 6 insertions(+)
sound/drivers/dummy.c +6 -0
@@ -1025,6 +1025,12 @@ static int snd_dummy_probe(struct platfoint idx, err;int dev = devptr->id; +if (dev <0 || dev >=SNDRV_CARDS ) { +dev_warn (&devptr->dev, +"Invalid card index %d, using default 0\n" , dev); + dev =0 ; + } + err =snd_devm_card_new (&devptr->dev, index[dev], id[dev],THIS_MODULE ,sizeof (struct snd_dummy ), &card);if (err <0 )
Greg Kroah-Hartman
maintainerPATCH 23/87 ocfs2: fix missing metadata reservation for large xattrs
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Bridges <[email protected]>
commit 0cdc7dde00ec63ac714271fa8b2918d630b8da1a upstream.
[BUG]lsetxattr() panics the kernel when setting a large xattr value on a fragmented filesystem where the file already has an external xattr block.
[CAUSE]ocfs2_calc_xattr_set_need() never reserves metadata blocks for a new xattr value's extent tree when the file already has an external xattr block. The not_found path leaves meta_add at zero, so meta_ac is NULL when ocfs2_xattr_extend_allocation() runs.
A new value root has room for a single extent record. On a fragmented filesystem, the allocator cannot satisfy the xattr value in one contiguous run, so each non-contiguous run requires its own extent record. When the value root's extent list is full and meta_ac is NULL, ocfs2_add_clusters_in_btree() returns RESTART_META, and ocfs2_xattr_extend_allocation() hits BUG_ON(why == RESTART_META).
[FIX]
The case where no xattr block exists yet already calls ocfs2_extend_meta_needed(&def_xv.xv.xr_list) to reserve value tree metadata. Add the same reservation to the case where an xattr block already exists, making the two cases consistent.
Replace the BUG_ON with a -ENOSPC return so that if RESTART_META is returned despite the reservation, the error propagates to userspace instead of panicking the kernel.
--- fs/ocfs2/xattr.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
fs/ocfs2/xattr.c +12 -6
@@ -736,12 +736,10 @@ static int ocfs2_xattr_extend_allocation prev_clusters;if (why !=RESTART_NONE && clusters_to_add) { -/* -* We can only fail in case the alloc file doesn't give -* up enough clusters. -*/ -BUG_ON (why ==RESTART_META ); - +if (why ==RESTART_META ) { + status = -ENOSPC ; +break ; + } credits =ocfs2_calc_extend_credits (inode->i_sb, &vb->vb_xv->xr_list); status =ocfs2_extend_trans (handle, credits);
@@ -3211,6 +3209,14 @@ meta_guess: credits +=OCFS2_SUBALLOC_ALLOC +1 ;/* +* Reserve metadata for the new xattr's value extent tree. +* The not_found path above adds credits for this tree but +* omits meta_add, leaving meta_ac NULL for large values. +*/ +if (xi->xi_value_len >OCFS2_XATTR_INLINE_SIZE ) + meta_add +=ocfs2_extend_meta_needed (&def_xv.xv.xr_list); + +/* * This cluster will be used either for new bucket or for * new xattr block. * If the cluster size is the same as the bucket size, one
Greg Kroah-Hartman
maintainerPATCH 24/87 null_blk: fix UBSAN shift-out-of-bounds when zone_size is 0 or overflows
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rik van Riel <[email protected]>
commit 95491fb05105b61050cb623a5e0227eb26aa3525 upstream.
null_zone_no() does sect >> ilog2(dev->zone_size_sects). When zone_size_sects is 0, ilog2(0) returns -1, producing shift exponent -1 which UBSAN reports as shift-out-of-bounds.
UBSAN: shift-out-of-bounds in drivers/block/null_blk/zoned.c:21:14 shift exponent -1 is negative Call Trace: null_zone_no drivers/block/null_blk/zoned.c:21 [inline] null_process_zoned_cmd+0xf76/0xf80 drivers/block/null_blk/zoned.c:728 null_handle_cmd drivers/block/null_blk/main.c:1455 [inline] null_queue_rq+0x8bc/0xe70 drivers/block/null_blk/main.c:1703 __blk_mq_issue_directly block/blk-mq.c:2694 [inline] blk_mq_try_issue_directly+0x3f4/0x880 block/blk-mq.c:2754 blk_mq_submit_bio+0x20c0/0x2a40 block/blk-mq.c:3208 submit_bio_noacct_nocheck+0x2f4/0xa40 block/blk-core.c:790 block_read_full_folio+0x7a6/0x810 fs/buffer.c:2463 filemap_read_folio+0x12c/0x3a0 mm/filemap.c:2510 read_part_sector+0xb6/0x2b0 block/partitions/core.c:724 adfspart_check_ICS+0xb1/0x960 block/partitions/acorn.c:357 check_partition block/partitions/core.c:143 [inline] blk_add_partitions block/partitions/core.c:591 [inline] bdev_disk_changed+0x851/0x17a0 block/partitions/core.c:695 blkdev_get_whole+0x372/0x510 block/bdev.c:751 add_disk_final block/genhd.c:412 [inline] add_disk_fwnode+0x24b/0x3a0 block/genhd.c:606 null_add_dev+0x130b/0x1d70 drivers/block/null_blk/main.c:2052 nullb_device_power_store+0x240/0x380 drivers/block/null_blk/main.c:501 configfs_write_iter+0x337/0x430 fs/configfs/file.c:229
Syzkaller triggers this by creating a zoned null_blk device via configfs. The Call Trace shows configfs_write_iter in configfs/file.c handling a write to power file, which calls nullb_device_power_store in main.c, which calls null_add_dev in main.c, which calls add_disk in genhd.c, which triggers partition scan via bdev_disk_changed in partitions/core.c.
A zoned null_blk device with zone_size 0 should not be legal. Existing code tries to reject it via is_power_of_2() check in zoned.c and !zone_size check in main.c, but syzkaller can still reach null_zone_no() with zone_size_sects 0 via two paths:
1. Direct 0 via configfs: zone_size attribute store in main.c has NULLB_DEVICE_ATTR(zone_size, ulong, NULL) with no validation callback, so echo 0 > zone_size succeeds before power store. If zoned is false at power store time, the !zone_size check in main.c is skipped, and later zoned set true leaves zone_size 0.
2. Large value overflow: mb_to_sects() in zoned.c does (sector_t)mb * SZ_1M >> SECTOR_SHIFT which is mb * 2048. If mb is 1UL << 53 (9PB), mb * 2048 overflows 64-bit to 0. The value is power-of-two so is_power_of_2() passes, but mb_to_sects() returns 0.
Check for zero zone_size explicitly in null_init_zoned_dev() in zoned.c, returning -EINVAL with "must be non-zero power-of-two". Check for zero zone_size_sects after mb_to_sects() conversion, returning -EINVAL for overflow case. Keep defensive check in null_zone_no() returning 0 for zero sectors to avoid shift out-of-bounds even if zero slips through.
This change should be safe because zone_size is set once in null_init_zoned_dev() under device lock and never changes after, and 0 is never valid for a zoned device. Returning -EINVAL at init time fails device creation early with clear error, while defensive return 0 in null_zone_no() makes zoned command fail via offline zone check. No new locking is introduced.
--- drivers/block/null_blk/zoned.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/block/null_blk/zoned.c +8 -2
@@ -16,6 +16,8 @@ static inline sector_t mb_to_sects(unsigstatic inline unsigned int null_zone_no (struct nullb_device *dev,sector_t sect) { +if (WARN_ON_ONCE (!dev->zone_size_sects)) +return 0 ;return sect >>ilog2 (dev->zone_size_sects); }
@@ -65,8 +67,8 @@ int null_init_zoned_dev(struct nullb_devsector_t sector =0 ;unsigned int i; -if (!is_power_of_2 (dev->zone_size)) { -pr_err ("zone_size must be power-of-two\n" ); +if (!dev->zone_size || !is_power_of_2 (dev->zone_size)) { +pr_err ("zone_size must be non-zero power-of-two\n" );return -EINVAL ; }if (dev->zone_size > dev->size) {
@@ -97,6 +99,10 @@ int null_init_zoned_dev(struct nullb_dev zone_capacity_sects =mb_to_sects (dev->zone_capacity); dev_capacity_sects =mb_to_sects (dev->size); dev->zone_size_sects =mb_to_sects (dev->zone_size); +if (!dev->zone_size_sects) { +pr_err ("zone_size too large or too small, leads to zero sectors\n" ); +return -EINVAL ; + } dev->nr_zones =round_up (dev_capacity_sects, dev->zone_size_sects) >>ilog2 (dev->zone_size_sects);
Greg Kroah-Hartman
maintainerPATCH 25/87 kcov: fix data corruption and race conditions on PREEMPT_RT
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tetsuo Handa <[email protected]>
commit 2eed77fdcb0cc48e8eccb2bcd4b7f2c6d650e84c upstream.
syzbot is reporting KCOV state corruption on PREEMPT_RT kernels, for the temporary storage used for saving/restoring remote KCOV state is currently allocated as the per-CPU area.
On PREEMPT_RT kernels, softirq handlers run as preemptible task threads (e.g., ksoftirqd). If a softirq context preempts a task running a remote KCOV session, it safely saves the task's state into the per-CPU area. However, if that softirq thread is subsequently preempted by a higher- priority softirq thread on the same CPU, the second softirq will overwrite the same per-CPU area, permanently destroying the original task's KCOV state.
Fix this data corruption by moving the temporary storage from the per-CPU area to the per-thread area. Since each softirq thread now owns its own task context, nested softirq preemption no longer causes data overwrites.
Note that while the temporary storage is now on a per-thread basis, the per-CPU kcov_percpu_data.lock must be retained, for we need to ensure that kcov_remote_start() and kcov_remote_stop() operate atomically without racing against asynchronous interrupts that manipulate the current task's KCOV state.
It is likely that GFP_KERNEL allocation by vmalloc_node() in kcov_init() has already called panic() before returning NULL, for there will be no OOM-killable userspace processes when __init function of built-in module runs. But this patch also fixes crashing the kernel when vmalloc_node() in kcov_init() returned NULL, for kcov_init() left per-CPU irq_area == NULL but kcov_remote_start() depends on per-CPU irq_area != NULL, resulting in
(1) doing vmalloc() in kcov_remote_start() despite !in_task() context
(2) out-of-array-bounds access if (1) succeeded but
kcov->remote_size < CONFIG_KCOV_IRQ_AREA_SIZE
(3) always leak memory allocated by (1), eventually killing all OOM-killable userspace processes
problems.
--- include/linux/sched.h | 8 ++++ kernel/kcov.c | 90 ++++++++++++++++++++++++++------------------------ lib/Kconfig.debug | 5 +- 3 files changed, 58 insertions(+), 45 deletions(-)
include/linux/sched.h +8 -0
@@ -1437,6 +1437,14 @@ struct task_struct {/* Collect coverage from softirq context: */ unsigned int kcov_softirq; + +/* Temporary storage for preempting remote coverage collection: */ +unsigned int kcov_saved_mode; +unsigned int kcov_saved_size; +void *kcov_saved_area; +struct kcov *kcov_saved_kcov; +int kcov_saved_sequence; +#endif #ifdef CONFIG_MEMCG
kernel/kcov.c +47 -43
169 lines not on this page · raw message
lib/Kconfig.debug +3 -2
@@ -2083,10 +2083,11 @@ config KCOV_INSTRUMENT_ALL config KCOV_IRQ_AREA_SIZE hex "Size of interrupt coverage collection area in words" depends on KCOV + range 0x80 0x1000000 default 0x40000 help - KCOV uses preallocated per-cpu areas to collect coverage from - soft interrupts. This specifies the size of those areas in the + KCOV uses preallocated areas to collect coverage from soft + interrupts. This specifies the size of those areas in the number of unsigned long words. menuconfig RUNTIME_TESTING_MENU
Greg Kroah-Hartman
maintainerPATCH 26/87 ext4: stop retrying saturated xattr cache entries
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthias Goergens <[email protected]>
commit 54b6bd40898de7906acb2bccc9a96d1b8e6b4323 upstream.
ext4_xattr_block_set() retries when a cache entry selected for reuse has a saturated reference count after taking the buffer lock. The retry returns to the mbcache lookup without making that entry ineligible, so it can select the same unusable entry indefinitely. A task spinning there can hold the parent directory's i_rwsem and leave concurrent rmdir callers blocked.
Normally a reusable entry has a reference count below EXT4_XATTR_REFCOUNT_MAX because the count and MBE_REUSABLE_B are updated under the same buffer lock. A corrupted filesystem can violate that invariant. The syzbot reproducer reports allocator and xattr corruption before triggering this retry loop.
Check the untrusted on-disk count before incrementing it, avoiding overflow, and clear MBE_REUSABLE_B when it is already saturated. The next lookup then skips the entry that was just proven unusable. This mirrors the normal transition at EXT4_XATTR_REFCOUNT_MAX; the release path marks the entry reusable again on the exact 1024-to-1023 transition.
Using the same QEMU harness and guest parameters, current unpatched Linux hung in 6 of 8 420-second trials with the do_rmdir signature; representative NMI backtraces caught the owner spinning in ext4_xattr_block_set(). The patched kernel completed 28 of 28 trials without a hung-task report; the final twelve trials exercised the reviewed overflow-safe form of the change. syzbot's patch testing also completed without reproducing the hang.
--- fs/ext4/xattr.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
fs/ext4/xattr.c +4 -2
@@ -2070,12 +2070,13 @@ inserted:* stable so we can check the additional * reference fits. */ - ref =le32_to_cpu (BHDR (new_bh)->h_refcount) +1 ; -if (ref >EXT4_XATTR_REFCOUNT_MAX ) { + ref =le32_to_cpu (BHDR (new_bh)->h_refcount); +if (ref >=EXT4_XATTR_REFCOUNT_MAX ) {/* * Undo everything and check mbcache * again. */ +clear_bit (MBE_REUSABLE_B , &ce->e_flags);unlock_buffer (new_bh); dquot_free_block(inode, EXT4_C2B(EXT4_SB(sb),
@@ -2086,6 +2087,7 @@ inserted: new_bh =NULL ; goto inserted; } + ref++;BHDR (new_bh)->h_refcount =cpu_to_le32 (ref);if (ref ==EXT4_XATTR_REFCOUNT_MAX )clear_bit (MBE_REUSABLE_B , &ce->e_flags);
Greg Kroah-Hartman
maintainerPATCH 27/87 ext4: clear error before retrying inode xattr space fallback
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guanghui Yang <[email protected]>
commit 409a7f12a0933ff2c617fa814c76cef0bd1d457a upstream.
When ext4_xattr_make_inode_space() returns -ENOSPC, ext4_expand_extra_isize_ea() can retry the expansion with s_min_extra_isize. If that retry succeeds by finding enough ibody free space, control jumps directly to the shift label.
The previous -ENOSPC is still stored in error in that path, so the function can update i_extra_isize but still return -ENOSPC to the caller. Clear error before retrying so a successful fallback expansion returns success.
Reproduced with an ext4 image using 1 KiB blocks, project quota support, 256-byte inodes, and min_extra_isize/want_extra_isize set to 32. FS_IOC_FSSETXATTR failures dropped from 802 to 86 after the fix.
--- fs/ext4/xattr.c | 1 + 1 file changed, 1 insertion(+)
fs/ext4/xattr.c +1 -0
@@ -2836,6 +2836,7 @@ retry: s_min_extra_isize) { tried_min_extra_isize++; new_extra_isize = s_min_extra_isize; + error =0 ; goto retry; } goto cleanup;
Greg Kroah-Hartman
maintainerPATCH 28/87 xfs: validate attr entry pointer before field access
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hongling Zeng <[email protected]>
commit b7eea80be25f3334f131d52982b3131aba77b97d upstream.
xfs_attr3_leaf_verify_entry() accesses lentry/rentry fields (namelen, valuelen) before checking if the entry pointer itself is within bounds. If nameidx is crafted to point near the end of the buffer, these field accesses can read out-of-bounds before the bounds check at name_end > buf_end is performed.
Add explicit bounds checks for entry pointers before accessing their fields. Use offsetof() to check that the start of the flexible array member (nameval/name) is within bounds, which ensures all preceding fields are safe to access.
--- fs/xfs/libxfs/xfs_attr_leaf.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
fs/xfs/libxfs/xfs_attr_leaf.c +14 -0
@@ -267,6 +267,13 @@ xfs_attr3_leaf_verify_entry(*/ if (ent->flags &XFS_ATTR_LOCAL ) { lentry =xfs_attr3_leaf_name_local (leaf, idx); + +/* Validate lentry pointer is within bounds before field access */ +if ((char *)lentry >= buf_end) +return __this_address; +if ((char *)lentry + offsetof(struct xfs_attr_leaf_name_local , nameval) > buf_end) +return __this_address; + namesize =xfs_attr_leaf_entsize_local (lentry->namelen,be16_to_cpu (lentry->valuelen)); name_end = (char *)lentry + namesize;
@@ -274,6 +281,13 @@ xfs_attr3_leaf_verify_entry(return __this_address; }else { rentry =xfs_attr3_leaf_name_remote (leaf, idx); + +/* Validate rentry pointer is within bounds before field access */ +if ((char *)rentry >= buf_end) +return __this_address; +if ((char *)rentry + offsetof(struct xfs_attr_leaf_name_remote , name) > buf_end) +return __this_address; + namesize =xfs_attr_leaf_entsize_remote (rentry->namelen); name_end = (char *)rentry + namesize;if (rentry->namelen ==0 )
Greg Kroah-Hartman
maintainerPATCH 29/87 gpio: ml-ioh: use raw_spinlock_t for the register lock
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Junjie Cao <[email protected]>
commit 600411ea1f2443fdf5b1af9b6480f616d7aff9d0 upstream.
ioh_irq_type() is registered as the irq_chip .irq_set_type callback and takes chip->spinlock with spin_lock_irqsave(). This callback is reached from __setup_irq() -> __irq_set_trigger() -> chip->irq_set_type() while the caller holds desc->lock, a raw_spinlock_t, with hardirqs disabled. That context is not sleepable, but on PREEMPT_RT a regular spinlock_t is an rtmutex-backed sleeping lock, so acquiring it there is invalid. ioh_irq_enable() and ioh_irq_disable() take the same lock from the .irq_enable/.irq_disable callbacks, which are likewise invoked with desc->lock held.
Convert the register lock to raw_spinlock_t. The same lock also serializes the GPIO direction/value callbacks and the suspend/resume register save/restore, and those critical sections only perform short sequences of MMIO register accesses (ioread32()/iowrite32()); the .irq_set_type callback additionally emits a dev_warn() on an unsupported type. None of these are sleepable operations, so keeping this register lock non-sleeping is appropriate for the irqchip callbacks and does not change the GPIO-side locking contract.
This is the same fix as commit a02b8950d619 ("gpio: pch: use raw_spinlock_t for the register lock"); this driver shares the same structure as gpio-pch.
--- drivers/gpio/gpio-ml-ioh.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)
drivers/gpio/gpio-ml-ioh.c +18 -18
@@ -84,7 +84,7 @@ struct ioh_gpio {u32 gpio_use_sel;int ch;int irq_base; -spinlock_t spinlock; +raw_spinlock_t spinlock; };static const int num_ports[] = {6 ,12 ,16 ,16 ,15 ,16 ,16 ,12 };
@@ -95,7 +95,7 @@ static void ioh_gpio_set(struct gpio_chistruct ioh_gpio *chip =gpiochip_get_data (gpio);unsigned long flags; -spin_lock_irqsave (&chip->spinlock, flags); +raw_spin_lock_irqsave (&chip->spinlock, flags); reg_val =ioread32 (&chip->reg->regs[chip->ch].po);if (val) reg_val |=BIT (nr);
@@ -103,7 +103,7 @@ static void ioh_gpio_set(struct gpio_chi reg_val &= ~BIT (nr);iowrite32 (reg_val, &chip->reg->regs[chip->ch].po); -spin_unlock_irqrestore (&chip->spinlock, flags); +raw_spin_unlock_irqrestore (&chip->spinlock, flags); }static int ioh_gpio_get (struct gpio_chip *gpio,unsigned nr)
@@ -121,7 +121,7 @@ static int ioh_gpio_direction_output(stru32 reg_val;unsigned long flags; -spin_lock_irqsave (&chip->spinlock, flags); +raw_spin_lock_irqsave (&chip->spinlock, flags); pm =ioread32 (&chip->reg->regs[chip->ch].pm); pm &=BIT (num_ports[chip->ch]) -1 ; pm |=BIT (nr);
@@ -134,7 +134,7 @@ static int ioh_gpio_direction_output(str reg_val &= ~BIT (nr);iowrite32 (reg_val, &chip->reg->regs[chip->ch].po); -spin_unlock_irqrestore (&chip->spinlock, flags); +raw_spin_unlock_irqrestore (&chip->spinlock, flags);return 0 ; }
@@ -145,12 +145,12 @@ static int ioh_gpio_direction_input(struu32 pm;unsigned long flags; -spin_lock_irqsave (&chip->spinlock, flags); +raw_spin_lock_irqsave (&chip->spinlock, flags); pm =ioread32 (&chip->reg->regs[chip->ch].pm); pm &=BIT (num_ports[chip->ch]) -1 ; pm &= ~BIT (nr);iowrite32 (pm, &chip->reg->regs[chip->ch].pm); -spin_unlock_irqrestore (&chip->spinlock, flags); +raw_spin_unlock_irqrestore (&chip->spinlock, flags);return 0 ; }
@@ -254,7 +254,7 @@ static int ioh_irq_type(struct irq_datadev_dbg (chip->dev,"%s:irq=%d type=%d ch=%d pos=%d type=%d\n" , __func__, irq, type, ch, im_pos, type); -spin_lock_irqsave (&chip->spinlock, flags); +raw_spin_lock_irqsave (&chip->spinlock, flags);switch (type) {case IRQ_TYPE_EDGE_RISING :
@@ -294,7 +294,7 @@ static int ioh_irq_type(struct irq_data ien =ioread32 (&chip->reg->regs[chip->ch].ien);iowrite32 (ien |BIT (ch), &chip->reg->regs[chip->ch].ien); end: -spin_unlock_irqrestore (&chip->spinlock, flags); +raw_spin_unlock_irqrestore (&chip->spinlock, flags);return 0 ; }
@@ -324,11 +324,11 @@ static void ioh_irq_disable(struct irq_dunsigned long flags;u32 ien; -spin_lock_irqsave (&chip->spinlock, flags); +raw_spin_lock_irqsave (&chip->spinlock, flags); ien =ioread32 (&chip->reg->regs[chip->ch].ien); ien &= ~BIT (d->irq - chip->irq_base);iowrite32 (ien, &chip->reg->regs[chip->ch].ien); -spin_unlock_irqrestore (&chip->spinlock, flags); +raw_spin_unlock_irqrestore (&chip->spinlock, flags); }static void ioh_irq_enable (struct irq_data *d)
@@ -338,11 +338,11 @@ static void ioh_irq_enable(struct irq_daunsigned long flags;u32 ien; -spin_lock_irqsave (&chip->spinlock, flags); +raw_spin_lock_irqsave (&chip->spinlock, flags); ien =ioread32 (&chip->reg->regs[chip->ch].ien); ien |=BIT (d->irq - chip->irq_base);iowrite32 (ien, &chip->reg->regs[chip->ch].ien); -spin_unlock_irqrestore (&chip->spinlock, flags); +raw_spin_unlock_irqrestore (&chip->spinlock, flags); }static irqreturn_t ioh_gpio_handler (int irq,void *dev_id)
@@ -438,7 +438,7 @@ static int ioh_gpio_probe(struct pci_dev chip->base = base; chip->reg = chip->base; chip->ch = i; -spin_lock_init (&chip->spinlock); +raw_spin_lock_init (&chip->spinlock);ioh_gpio_setup (chip, num_ports[i]); ret =devm_gpiochip_add_data (dev, &chip->gpio, chip);if (ret) {
@@ -482,9 +482,9 @@ static int __maybe_unused ioh_gpio_suspestruct ioh_gpio *chip =dev_get_drvdata (dev);unsigned long flags; -spin_lock_irqsave (&chip->spinlock, flags); +raw_spin_lock_irqsave (&chip->spinlock, flags);ioh_gpio_save_reg_conf (chip); -spin_unlock_irqrestore (&chip->spinlock, flags); +raw_spin_unlock_irqrestore (&chip->spinlock, flags);return 0 ; }
@@ -494,11 +494,11 @@ static int __maybe_unused ioh_gpio_resumstruct ioh_gpio *chip =dev_get_drvdata (dev);unsigned long flags; -spin_lock_irqsave (&chip->spinlock, flags); +raw_spin_lock_irqsave (&chip->spinlock, flags);iowrite32 (0x01 , &chip->reg->srst);iowrite32 (0x00 , &chip->reg->srst);ioh_gpio_restore_reg_conf (chip); -spin_unlock_irqrestore (&chip->spinlock, flags); +raw_spin_unlock_irqrestore (&chip->spinlock, flags);return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 30/87 s390/vfio_ccw: Free all memory if cp_init() fails
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Farman <[email protected]>
commit 74186c2968f8f756ac3226b545b598457c910c75 upstream.
The routine cp_free() is called to unpin/free any memory once an I/O is completed successfully, or if cp_prefetch() fails. But if cp_init() fails, and cp->initialized is not enabled, the same routine cannot be used to free all the memory.
An attempt to address this exists in ccwchain_handle_ccw(), where a single call to ccwchain_free() is made for the currently-processed CCW segment. But this will leak other segments (created as a result of a Transfer in Channel) that had been allocated as part of the same channel program.
Address this by performing the cleanup outside of the recursive ccwchain_handle_ccw()/ccwchain_loop_tic() logic.
--- drivers/s390/cio/vfio_ccw_cp.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-)
drivers/s390/cio/vfio_ccw_cp.c +18 -4
@@ -450,9 +450,6 @@ static int ccwchain_handle_ccw(u32 cda,/* Loop for tics on this new chain. */ ret =ccwchain_loop_tic (chain, cp); -if (ret) -ccwchain_free (chain); -return ret; }
@@ -481,6 +478,23 @@ static int ccwchain_loop_tic(struct ccwcreturn 0 ; } +static int ccwchain_build_ccws (u32 cda,struct channel_program *cp) +{ +struct ccwchain *chain, *temp; +int ret; + + ret =ccwchain_handle_ccw (cda, cp); + +if (ret) { +/* Cleanup if an error occurred */ +list_for_each_entry_safe (chain, temp, &cp->ccwchain_list, next) { +ccwchain_free (chain); + } + } + +return ret; +} +static int ccwchain_fetch_tic (struct ccw1 *ccw,struct channel_program *cp) {
@@ -728,7 +742,7 @@ int cp_init(struct channel_program *cp,memcpy (&cp->orb, orb,sizeof (*orb));/* Build a ccwchain for the first CCW segment */ - ret =ccwchain_handle_ccw (orb->cmd.cpa, cp); + ret =ccwchain_build_ccws (orb->cmd.cpa, cp);if (!ret) cp->initialized = true;
Greg Kroah-Hartman
maintainerPATCH 31/87 s390/vfio_ccw: Ensure first IDAW remains constant
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Farman <[email protected]>
commit 565bef268d75bf7df665bce6923a88cd0eb74592 upstream.
The first IDAW in a list does not need to be on a 2K/4K boundary like all others, and so is read separately to accurately calculate the size of the buffer needed to read the full IDAL.
Verify that the address found in the first IDAW is unchanged between reads, to ensure a consistent set of IDAWs being worked with.
--- drivers/s390/cio/vfio_ccw_cp.c | 16 ++++++++++++++++ drivers/s390/cio/vfio_ccw_cp.h | 2 ++ 2 files changed, 18 insertions(+)
drivers/s390/cio/vfio_ccw_cp.c +16 -0
@@ -521,6 +521,7 @@ static unsigned long *get_guest_idal(str &container_of(cp, struct vfio_ccw_private, cp)->vdev;unsigned long *idaws;unsigned int *idaws_f1; +u64 first_idaw;int idal_len = idaw_nr *sizeof (*idaws);int idaw_size =idal_is_2k (cp) ?PAGE_SIZE /2 :PAGE_SIZE ;int idaw_mask = ~(idaw_size -1 );
@@ -537,6 +538,18 @@ static unsigned long *get_guest_idal(strkfree (idaws);return ERR_PTR (ret); } + + idaws_f1 = (unsigned int *)idaws; +if (cp->orb.cmd.c64) + first_idaw = idaws[0 ]; +else + first_idaw = (unsigned long )(idaws_f1[0 ]); + +/* Unexpected mismatch from earlier read */ +if (first_idaw != cp->guest_iova) { +kfree (idaws); +return ERR_PTR (-EINVAL ); + } }else {/* Fabricate an IDAL based off CCW data address */ if (cp->orb.cmd.c64) {
@@ -598,6 +611,9 @@ static int ccw_count_idaws(struct ccw1 * iova = ccw->cda; } +/* Save the read address for later */ + cp->guest_iova = iova; +/* Format-1 IDAWs operate on 2K each */ if (!cp->orb.cmd.c64)return idal_2k_nr_words ((void *)iova, bytes);
drivers/s390/cio/vfio_ccw_cp.h +2 -0
@@ -35,6 +35,7 @@* @initialized: whether this instance is actually initialized * @guest_cp: copy of guest channel program * @ccwchain_count: number of channel program segments (linked by TIC) +* @guest_iova: first data address of a guest channel program * * @ccwchain_list is the head of a ccwchain list, that contents the * translated result of the guest channel program that pointed out by
@@ -46,6 +47,7 @@ struct channel_program {bool initialized;struct ccw1 *guest_cp;unsigned int ccwchain_count; +u64 guest_iova; };int cp_init (struct channel_program *cp,union orb *orb);
Greg Kroah-Hartman
maintainerPATCH 32/87 s390/vfio_ccw: Calculate idal length based on idaw type
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Farman <[email protected]>
commit 4f6fdc6e1a7fbfa36b945af33c65a417948feac0 upstream.
Sashiko pointed out that get_guest_idal() unconditionally calculates the length of the IDAL presuming everything is a Format-2 IDAW.
The output of vfio-ccw is always Format-2, but the input can be either Format-1 (31-bit addresses) or Format-2 (64-bit addresses). As a result, the size of the guest IDAL may be incorrect and should be trimmed down.
--- drivers/s390/cio/vfio_ccw_cp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/s390/cio/vfio_ccw_cp.c +3 -2
@@ -233,6 +233,7 @@ static void convert_ccw0_to_ccw1(struct }#define idal_is_2k (_cp) (!(_cp)->orb.cmd.c64 || (_cp)->orb.cmd.i2k) +#define get_idaw_size (_cp) ((_cp)->orb.cmd.c64 ? sizeof(u64) : sizeof(u32))/* * Helpers to operate ccwchain.
@@ -522,7 +523,7 @@ static unsigned long *get_guest_idal(strunsigned long *idaws;unsigned int *idaws_f1;u64 first_idaw; -int idal_len = idaw_nr *sizeof (*idaws); +int idal_len = idaw_nr *get_idaw_size (cp);int idaw_size =idal_is_2k (cp) ?PAGE_SIZE /2 :PAGE_SIZE ;int idaw_mask = ~(idaw_size -1 );int i, ret;
@@ -587,7 +588,7 @@ static int ccw_count_idaws(struct ccw1 *struct vfio_device *vdev = &container_of(cp, struct vfio_ccw_private, cp)->vdev;u64 iova; -int size = cp->orb.cmd.c64 ?sizeof (u64) :sizeof (u32); +int size =get_idaw_size (cp);int ret;int bytes =1 ;
Greg Kroah-Hartman
maintainerPATCH 33/87 s390/vfio_ccw: Implement a crw lock
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Farman <[email protected]>
commit 16b0798024c0e9117e395829ddbbe70981c79d9c upstream.
Unlike the channel_program struct, which covers synchronous I/O submissions and asynchronous interrupts, the CRW region relies exclusively on asynchronous events coming from hardware.
Implement a lock to manage the list of those payloads, to ensure they are read cohesively.
--- drivers/s390/cio/vfio_ccw_chp.c | 26 ++++++++++++++++---------- drivers/s390/cio/vfio_ccw_drv.c | 6 ++++++ drivers/s390/cio/vfio_ccw_ops.c | 4 ++++ drivers/s390/cio/vfio_ccw_private.h | 4 ++++ 4 files changed, 30 insertions(+), 10 deletions(-)
drivers/s390/cio/vfio_ccw_chp.c +16 -10
@@ -93,18 +93,13 @@ static ssize_t vfio_ccw_crw_region_read(loff_t pos = *ppos &VFIO_CCW_OFFSET_MASK ;struct ccw_crw_region *region;struct vfio_ccw_crw *crw; +unsigned long flags;int ret;if (pos + count >sizeof (*region))return -EINVAL ;mutex_lock (&private->io_mutex); - crw =list_first_entry_or_null (&private->crw, - struct vfio_ccw_crw, next); - -if (crw) -list_del (&crw->next); -if (i >= private->num_regions) { ret = -EINVAL ; goto out;
@@ -113,6 +108,16 @@ static ssize_t vfio_ccw_crw_region_read( i =array_index_nospec (i, private->num_regions); region = private->region[i].data; +spin_lock_irqsave (&private->crw_lock, flags); + crw =list_first_entry_or_null (&private->crw, + struct vfio_ccw_crw, next); + +if (crw) +list_del (&crw->next); + +/* Drop CRW lock while copying to userspace */ +spin_unlock_irqrestore (&private->crw_lock, flags); +if (crw)memcpy (®ion->crw, &crw->crw,sizeof (region->crw));
@@ -122,15 +127,16 @@ static ssize_t vfio_ccw_crw_region_read( ret = count; region->crw =0 ; - -out: -mutex_unlock (&private->io_mutex); -kfree (crw);/* Notify the guest if more CRWs are on our queue */ +spin_lock_irqsave (&private->crw_lock, flags);if (!list_empty (&private->crw) && private->crw_trigger)eventfd_signal (private->crw_trigger,1 ); +spin_unlock_irqrestore (&private->crw_lock, flags); + +out: +mutex_unlock (&private->io_mutex);return ret; }
drivers/s390/cio/vfio_ccw_drv.c +6 -0
@@ -118,11 +118,14 @@ void vfio_ccw_sch_io_todo(struct work_stvoid vfio_ccw_crw_todo (struct work_struct *work) {struct vfio_ccw_private *private; +unsigned long flags; private = container_of(work, struct vfio_ccw_private, crw_work); +spin_lock_irqsave (&private->crw_lock, flags);if (!list_empty (&private->crw) && private->crw_trigger)eventfd_signal (private->crw_trigger,1 ); +spin_unlock_irqrestore (&private->crw_lock, flags); }void vfio_ccw_notoper_todo (struct work_struct *work)
@@ -286,6 +289,7 @@ static void vfio_ccw_queue_crw(struct vf unsigned int rsid) {struct vfio_ccw_crw *crw; +unsigned long flags;/* * If unable to allocate a CRW, just drop the event and
@@ -303,7 +307,9 @@ static void vfio_ccw_queue_crw(struct vf crw->crw.erc = erc; crw->crw.rsid = rsid; +spin_lock_irqsave (&private->crw_lock, flags);list_add_tail (&crw->next, &private->crw); +spin_unlock_irqrestore (&private->crw_lock, flags);queue_work (vfio_ccw_work_q, &private->crw_work); }
drivers/s390/cio/vfio_ccw_ops.c +4 -0
@@ -55,6 +55,7 @@ static int vfio_ccw_mdev_init_dev(structINIT_WORK (&private->io_work, vfio_ccw_sch_io_todo);INIT_WORK (&private->crw_work, vfio_ccw_crw_todo);INIT_WORK (&private->notoper_work, vfio_ccw_notoper_todo); +spin_lock_init (&private->crw_lock); private->cp.guest_cp =kcalloc (CCWCHAIN_LEN_MAX ,sizeof (struct ccw1 ),GFP_KERNEL );
@@ -132,6 +133,7 @@ static void vfio_ccw_mdev_release_dev(ststruct vfio_ccw_private *private = container_of(vdev, struct vfio_ccw_private, vdev);struct vfio_ccw_crw *crw, *temp; +unsigned long flags;/* * Ensure these work items are fully drained, so none can
@@ -147,10 +149,12 @@ static void vfio_ccw_mdev_release_dev(stcancel_work_sync (&private->crw_work);flush_work (&private->notoper_work); +spin_lock_irqsave (&private->crw_lock, flags);list_for_each_entry_safe (crw, temp, &private->crw, next) {list_del (&crw->next);kfree (crw); } +spin_unlock_irqrestore (&private->crw_lock, flags);kmem_cache_free (vfio_ccw_crw_region, private->crw_region);kmem_cache_free (vfio_ccw_schib_region, private->schib_region);
drivers/s390/cio/vfio_ccw_private.h +4 -0
@@ -98,6 +98,8 @@ struct vfio_ccw_parent {* @cp: channel program for the current I/O operation * @irb: irb info received from interrupt * @scsw: scsw info +* @crw_lock: serialization of CRW list information +* @crw: list of Channel Report Word elements * @io_trigger: eventfd ctx for signaling userspace I/O results * @crw_trigger: eventfd ctx for signaling userspace CRW information * @req_trigger: eventfd ctx for signaling userspace to return device
@@ -120,6 +122,8 @@ struct vfio_ccw_private {struct channel_program cp;struct irb irb;union scsw scsw; + +spinlock_t crw_lock;struct list_head crw;struct eventfd_ctx *io_trigger;
Greg Kroah-Hartman
maintainerPATCH 34/87 drm/amd/amdgpu: disable ASPM in some situations
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kenneth Feng <[email protected]>
[ Upstream commit c770ef19673fb1defcbde2ee2b91c3c89bfcf164 ]
disable ASPM with some ASICs on some specific platforms. required from PCIe controller owner.
Stable-dep-of: 2a9c5154a565 ("drm/amdgpu: check ASPM on the dGPU host link")
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 - drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 54 +++++++++++++++++++++++------ drivers/gpu/drm/amd/amdgpu/nv.c | 2 - 3 files changed, 45 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -1
@@ -1300,7 +1300,7 @@ int amdgpu_device_pci_reset(struct amdgpbool amdgpu_device_need_post (struct amdgpu_device *adev);bool amdgpu_device_pcie_dynamic_switching_supported (void );bool amdgpu_device_should_use_aspm (struct amdgpu_device *adev); -bool amdgpu_device_aspm_support_quirk (void ); +bool amdgpu_device_nv_aspm_support_quirk (void );void amdgpu_cs_report_moved_bytes (struct amdgpu_device *adev,u64 num_bytes,u64 num_vis_bytes);
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +43 -11
75 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/nv.c +1 -1
@@ -513,7 +513,7 @@ static int nv_set_vce_clocks(struct amdgstatic void nv_program_aspm (struct amdgpu_device *adev) { -if (!amdgpu_device_should_use_aspm (adev) || !amdgpu_device_aspm_support_quirk ()) +if (!amdgpu_device_should_use_aspm (adev) || !amdgpu_device_nv_aspm_support_quirk ())return ; if (!(adev->flags & AMD_IS_APU) &&
Greg Kroah-Hartman
maintainerPATCH 35/87 drm/amd/display: Fix BT2020 YCbCr limited/full range input
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ilya Bakoulin <[email protected]>
[ Upstream commit 07bc2dcbcf403d47d6f305ef7f0d3d489491c5fb ]
[Why]
BT2020 YCbCr input is not handled properly when full range quantization is used and limited range is not supported at all.
[How]
- Add enums for BT2020 YCbCr limited/full range
- Add limited range CSC matrix
Stable-dep-of: 2f9a5c0f018d ("drm/amd/display: fix BT.2020 YCbCr limited output CSC matrix")
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 6 +++--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c | 2 +- drivers/gpu/drm/amd/display/dc/basics/dc_common.c | 3 ++- drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c | 5 +++-- drivers/gpu/drm/amd/display/dc/core/dc_resource.c | 4 ++-- drivers/gpu/drm/amd/display/dc/dc_hw_types.h | 4 +++- drivers/gpu/drm/amd/display/dc/dce/dce_stream_encoder.c | 3 ++- drivers/gpu/drm/amd/display/dc/dcn10/dcn10_stream_encoder.c | 3 ++- drivers/gpu/drm/amd/display/dc/dcn31/dcn31_hpo_dp_stream_encoder.c | 3 ++- drivers/gpu/drm/amd/display/dc/inc/hw/dpp.h | 6 +++++- drivers/gpu/drm/amd/display/modules/info_packet/info_packet.c | 4 ++-- 11 files changed, 27 insertions(+), 16 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +3 -3
@@ -4937,9 +4937,9 @@ fill_plane_color_attributes(const structcase DRM_COLOR_YCBCR_BT2020 :if (full_range) - *color_space =COLOR_SPACE_2020_YCBCR ; + *color_space =COLOR_SPACE_2020_YCBCR_FULL ;else -return -EINVAL ; + *color_space =COLOR_SPACE_2020_YCBCR_LIMITED ;break ;default :
@@ -5430,7 +5430,7 @@ get_output_color_space(const struct dc_cif (dc_crtc_timing->pixel_encoding ==PIXEL_ENCODING_RGB ) color_space =COLOR_SPACE_2020_RGB_FULLRANGE ;else - color_space =COLOR_SPACE_2020_YCBCR ; + color_space =COLOR_SPACE_2020_YCBCR_LIMITED ;break ;case DRM_MODE_COLORIMETRY_DEFAULT :// ITU601 default :
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c +1 -1
@@ -1091,7 +1091,7 @@ static int amdgpu_current_colorspace_shocase COLOR_SPACE_2020_RGB_FULLRANGE :seq_puts (m,"BT2020_RGB" );break ; -case COLOR_SPACE_2020_YCBCR : +case COLOR_SPACE_2020_YCBCR_LIMITED :seq_puts (m,"BT2020_YCC" );break ;default :
drivers/gpu/drm/amd/display/dc/basics/dc_common.c +2 -1
@@ -40,7 +40,8 @@ bool is_rgb_cspace(enum dc_color_space ocase COLOR_SPACE_YCBCR709 :case COLOR_SPACE_YCBCR601_LIMITED :case COLOR_SPACE_YCBCR709_LIMITED : -case COLOR_SPACE_2020_YCBCR : +case COLOR_SPACE_2020_YCBCR_LIMITED : +case COLOR_SPACE_2020_YCBCR_FULL :return false;default :/* Add a case to switch */
drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c +3 -2
@@ -173,7 +173,7 @@ static bool is_ycbcr2020_type( {bool ret = false; -if (color_space ==COLOR_SPACE_2020_YCBCR ) +if (color_space ==COLOR_SPACE_2020_YCBCR_LIMITED || color_space ==COLOR_SPACE_2020_YCBCR_FULL ) ret = true;return ret; }
@@ -244,7 +244,8 @@ void color_space_to_black_color(case COLOR_SPACE_YCBCR709_BLACK :case COLOR_SPACE_YCBCR601_LIMITED :case COLOR_SPACE_YCBCR709_LIMITED : -case COLOR_SPACE_2020_YCBCR : +case COLOR_SPACE_2020_YCBCR_LIMITED : +case COLOR_SPACE_2020_YCBCR_FULL : *black_color = black_color_format[BLACK_COLOR_FORMAT_YUV_CV ];break ;
drivers/gpu/drm/amd/display/dc/core/dc_resource.c +2 -2
@@ -3296,7 +3296,7 @@ static void set_avi_info_frame(break ;case COLOR_SPACE_2020_RGB_FULLRANGE :case COLOR_SPACE_2020_RGB_LIMITEDRANGE : -case COLOR_SPACE_2020_YCBCR : +case COLOR_SPACE_2020_YCBCR_LIMITED : hdmi_info.bits.EC0_EC2 =COLORIMETRYEX_BT2020RGBYCBCR ; hdmi_info.bits.C0_C1 =COLORIMETRY_EXTENDED ;break ;
@@ -3310,7 +3310,7 @@ static void set_avi_info_frame(break ; } -if (pixel_encoding && color_space ==COLOR_SPACE_2020_YCBCR && +if (pixel_encoding && color_space ==COLOR_SPACE_2020_YCBCR_LIMITED && stream->out_transfer_func->tf ==TRANSFER_FUNCTION_GAMMA22 ) { hdmi_info.bits.EC0_EC2 =0 ; hdmi_info.bits.C0_C1 =COLORIMETRY_ITU709 ;
drivers/gpu/drm/amd/display/dc/dc_hw_types.h +3 -1
@@ -616,7 +616,8 @@ enum dc_color_space {COLOR_SPACE_YCBCR709_LIMITED ,COLOR_SPACE_2020_RGB_FULLRANGE ,COLOR_SPACE_2020_RGB_LIMITEDRANGE , -COLOR_SPACE_2020_YCBCR , +COLOR_SPACE_2020_YCBCR_LIMITED , +COLOR_SPACE_2020_YCBCR_FULL ,COLOR_SPACE_ADOBERGB ,COLOR_SPACE_DCIP3 , COLOR_SPACE_DISPLAYNATIVE,
@@ -624,6 +625,7 @@ enum dc_color_space {COLOR_SPACE_APPCTRL ,COLOR_SPACE_CUSTOMPOINTS ,COLOR_SPACE_YCBCR709_BLACK , + COLOR_SPACE_2020_YCBCR = COLOR_SPACE_2020_YCBCR_LIMITED, }; enum dc_dither_option {
drivers/gpu/drm/amd/display/dc/dce/dce_stream_encoder.c +2 -1
@@ -420,7 +420,7 @@ static void dce110_stream_encoder_dp_set dynamic_range_rgb =1 ;/*limited range*/ break ;case COLOR_SPACE_2020_RGB_FULLRANGE : -case COLOR_SPACE_2020_YCBCR : +case COLOR_SPACE_2020_YCBCR_LIMITED :case COLOR_SPACE_XR_RGB :case COLOR_SPACE_MSREF_SCRGB :case COLOR_SPACE_ADOBERGB :
@@ -432,6 +432,7 @@ static void dce110_stream_encoder_dp_setcase COLOR_SPACE_APPCTRL :case COLOR_SPACE_CUSTOMPOINTS :case COLOR_SPACE_UNKNOWN : +default :/* do nothing */ break ; }
drivers/gpu/drm/amd/display/dc/dcn10/dcn10_stream_encoder.c +2 -1
@@ -393,7 +393,7 @@ void enc1_stream_encoder_dp_set_stream_abreak ;case COLOR_SPACE_2020_RGB_LIMITEDRANGE :case COLOR_SPACE_2020_RGB_FULLRANGE : -case COLOR_SPACE_2020_YCBCR : +case COLOR_SPACE_2020_YCBCR_LIMITED :case COLOR_SPACE_XR_RGB :case COLOR_SPACE_MSREF_SCRGB :case COLOR_SPACE_ADOBERGB :
@@ -406,6 +406,7 @@ void enc1_stream_encoder_dp_set_stream_acase COLOR_SPACE_CUSTOMPOINTS :case COLOR_SPACE_UNKNOWN :case COLOR_SPACE_YCBCR709_BLACK : +default :/* do nothing */ break ; }
drivers/gpu/drm/amd/display/dc/dcn31/dcn31_hpo_dp_stream_encoder.c +2 -1
@@ -323,7 +323,7 @@ static void dcn31_hpo_dp_stream_enc_set_break ;case COLOR_SPACE_2020_RGB_LIMITEDRANGE :case COLOR_SPACE_2020_RGB_FULLRANGE : -case COLOR_SPACE_2020_YCBCR : +case COLOR_SPACE_2020_YCBCR_LIMITED :case COLOR_SPACE_XR_RGB :case COLOR_SPACE_MSREF_SCRGB :case COLOR_SPACE_ADOBERGB :
@@ -336,6 +336,7 @@ static void dcn31_hpo_dp_stream_enc_set_case COLOR_SPACE_CUSTOMPOINTS :case COLOR_SPACE_UNKNOWN :case COLOR_SPACE_YCBCR709_BLACK : +default :/* do nothing */ break ; }
drivers/gpu/drm/amd/display/dc/inc/hw/dpp.h +5 -1
@@ -94,10 +94,14 @@ static const struct dpp_input_csc_matrix {0x39a6 ,0x2568 ,0 ,0xe0d6 ,0xeedd ,0x2568 ,0xf925 ,0x9a8 , 0, 0x2568, 0x43ee, 0xdbb2 } }, - { COLOR_SPACE_2020_YCBCR, + { COLOR_SPACE_2020_YCBCR_FULL, { 0x2F30, 0x2000, 0, 0xE869,0xEDB7 ,0x2000 ,0xFABC ,0xBC6 , 0, 0x2000, 0x3C34, 0xE1E6 } }, + { COLOR_SPACE_2020_YCBCR_LIMITED, + { 0x35B9, 0x2543, 0, 0xE2B2, +0xEB2F ,0x2543 ,0xFA01 ,0x0B1F , + 0, 0x2543, 0x4489, 0xDB42 } }, { COLOR_SPACE_2020_RGB_LIMITEDRANGE, { 0x35E0, 0x255F, 0, 0xE2B3, 0xEB20, 0x255F, 0xF9FD, 0xB1E,
drivers/gpu/drm/amd/display/modules/info_packet/info_packet.c +2 -2
@@ -383,10 +383,10 @@ void mod_build_vsc_infopacket(const stru colorimetryFormat = ColorimetryYCC_DP_ITU709; else if (cs == COLOR_SPACE_ADOBERGB) colorimetryFormat = ColorimetryYCC_DP_AdobeYCC; - else if (cs == COLOR_SPACE_2020_YCBCR) + else if (cs == COLOR_SPACE_2020_YCBCR_LIMITED) colorimetryFormat = ColorimetryYCC_DP_ITU2020YCbCr; -if (cs ==COLOR_SPACE_2020_YCBCR && tf ==TRANSFER_FUNC_GAMMA_22 ) +if (cs ==COLOR_SPACE_2020_YCBCR_LIMITED && tf ==TRANSFER_FUNC_GAMMA_22 ) colorimetryFormat = ColorimetryYCC_DP_ITU709;break ;
Greg Kroah-Hartman
maintainerPATCH 36/87 drm/amd/display: fix BT.2020 YCbCr limited output CSC matrix
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nathan Lucas <[email protected]>
[ Upstream commit 2f9a5c0f018d4a1586ee892f81f1383219676415 ]
COLOR_SPACE_YCBCR2020_TYPE, which is selected for COLOR_SPACE_2020_YCBCR_LIMITED color_space, has coefficients that are incorrect for limited-range output. Its luma and chroma scaling is full-range so output is too bright and colors are incorrect.
COLOR_SPACE_YCBCR2020_TYPE is closer to a full-range conversion matrix with incorrect luma offset, so correct the luma offset for full-range and rename it to COLOR_SPACE_YCBCR2020_FULL_TYPE.
Add COLOR_SPACE_YCBCR2020_LIMITED_TYPE with correct scaling and range for limited-range output.
Fix related functions so COLOR_SPACE_YCBCR2020_LIMITED_TYPE and COLOR_SPACE_YCBCR2020_FULL_TYPE are correctly selected based on dc_color_space.
Derivation of both matrices follows ITU-T H.273:
Table 4, MatrixCoefficients 9, BT.2020-NCL weights:
KR = 0.2627, KB = 0.0593, KG = 1 - KR - KB = 0.6780.
Equations 45-47 in matrix form:
[ KR KG KB 0 ]
M2020_NCL = [ -KR/(2(1-KB)) -KG/(2(1-KB)) 1/2 0 ]
[ 1/2 -KG/(2(1-KR)) -KB/(2(1-KR)) 0 ]
[ 0 0 0 1 ]Limited and Full transforms based on equations 30-32 and 36-38 with bit depth 10, normalized by 1023:
[ 876/1023 0 0 64/1023 ]
MLimited = [ 0 896/1023 0 512/1023 ]
[ 0 0 896/1023 512/1023 ]
[ 0 0 0 1 ] [ 1023/1023 0 0 0 ]
MFull = [ 0 1023/1023 0 512/1023 ]
[ 0 0 1023/1023 512/1023 ]
[ 0 0 0 1 ]M2020_NCL_Limited = MLimited x M2020_NCLM2020_NCL_Full = MFull x M2020_NCL
The upper three rows of M2020_NCL_* are stored in CR, Y, CB order. Each M2020_NCL_* value is stored as Round(value * 8192) in its 16-bit two's-complement representation.
--- drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c | 31 +++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c +20 -11
@@ -47,7 +47,8 @@ enum dc_color_space_type {COLOR_SPACE_RGB_LIMITED_TYPE ,COLOR_SPACE_YCBCR601_TYPE ,COLOR_SPACE_YCBCR709_TYPE , -COLOR_SPACE_YCBCR2020_TYPE , +COLOR_SPACE_YCBCR2020_LIMITED_TYPE , +COLOR_SPACE_YCBCR2020_FULL_TYPE ,COLOR_SPACE_YCBCR601_LIMITED_TYPE ,COLOR_SPACE_YCBCR709_LIMITED_TYPE , COLOR_SPACE_YCBCR709_BLACK_TYPE,
@@ -99,9 +100,15 @@ static const struct out_csc_color_matrix {0xE00 ,0xF349 ,0xFEB7 ,0x1000 ,0x6CE ,0x16E3 ,0x24F ,0x200 , 0xFCCB, 0xF535, 0xE00, 0x1000} }, - { COLOR_SPACE_YCBCR2020_TYPE, +/* Corrected. Not included in the TODO above. */ + { COLOR_SPACE_YCBCR2020_LIMITED_TYPE, + { 0x0E04, 0xF31D, 0xFEDF, 0x1004, +0x0733 ,0x1294 ,0x01A0 ,0x0201 , + 0xFC16, 0xF5E6, 0x0E04, 0x1004} }, +/* Corrected. Not included in the TODO above. */ + { COLOR_SPACE_YCBCR2020_FULL_TYPE, { 0x1000, 0xF149, 0xFEB7, 0x1004, -0x0868 ,0x15B2 ,0x01E6 ,0x201 , +0x0868 ,0x15B2 ,0x01E6 ,0 , 0xFB88, 0xF478, 0x1000, 0x1004} }, { COLOR_SPACE_YCBCR709_BLACK_TYPE, { 0x0000, 0x0000, 0x0000, 0x1000,
@@ -168,14 +175,14 @@ static bool is_ycbcr709_type(return ret; } -static bool is_ycbcr2020_type ( -enum dc_color_space color_space) +static bool is_ycbcr2020_limited_type (enum dc_color_space color_space) { -bool ret = false; +return color_space ==COLOR_SPACE_2020_YCBCR_LIMITED ; +} -if (color_space ==COLOR_SPACE_2020_YCBCR_LIMITED || color_space ==COLOR_SPACE_2020_YCBCR_FULL ) - ret = true; -return ret; +static bool is_ycbcr2020_full_type (enum dc_color_space color_space) +{ +return color_space ==COLOR_SPACE_2020_YCBCR_FULL ; } static bool is_ycbcr709_limited_type(
@@ -204,8 +211,10 @@ static enum dc_color_space_type get_colo type =COLOR_SPACE_YCBCR601_LIMITED_TYPE ; else if (is_ycbcr709_limited_type(color_space)) type =COLOR_SPACE_YCBCR709_LIMITED_TYPE ; - else if (is_ycbcr2020_type(color_space)) - type =COLOR_SPACE_YCBCR2020_TYPE ; + else if (is_ycbcr2020_limited_type(color_space)) + type =COLOR_SPACE_YCBCR2020_LIMITED_TYPE ; + else if (is_ycbcr2020_full_type(color_space)) + type =COLOR_SPACE_YCBCR2020_FULL_TYPE ; else if (color_space == COLOR_SPACE_YCBCR709) type =COLOR_SPACE_YCBCR709_BLACK_TYPE ; else if (color_space == COLOR_SPACE_YCBCR709_BLACK)
Greg Kroah-Hartman
maintainerPATCH 37/87 drm/amdgpu: check ASPM on the dGPU host link
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yang Wang <[email protected]>
[ Upstream commit 2a9c5154a5650c09ad44ff5e1dff74754e15a3c6 ]
dGPUs with an internal PCIe switch expose graphics functions below the switch downstream port. The automatic ASPM check uses the display endpoint and evaluates the internal link instead of the host link.
Use the switch upstream port for the check and report the selected link.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 50 ++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +49 -1
@@ -1324,6 +1324,31 @@ static bool amdgpu_device_aspm_support_q#endif } +/* +* Some dGPUs expose their display endpoint below an internal PCIe switch. +* Use the switch upstream port to query the host-facing link. +*/ +static struct pci_dev *amdgpu_device_get_aspm_pdev (struct amdgpu_device *adev) +{ +struct pci_dev *swds, *swus; + + swds =pci_upstream_bridge (adev->pdev); +if (!swds || + (swds->vendor !=PCI_VENDOR_ID_ATI && + swds->vendor !=PCI_VENDOR_ID_AMD ) || +pci_pcie_type (swds) !=PCI_EXP_TYPE_DOWNSTREAM ) +return adev->pdev; + + swus =pci_upstream_bridge (swds); +if (!swus || + (swus->vendor !=PCI_VENDOR_ID_ATI && + swus->vendor !=PCI_VENDOR_ID_AMD ) || +pci_pcie_type (swus) !=PCI_EXP_TYPE_UPSTREAM ) +return adev->pdev; + +return swus; +} +/** * amdgpu_device_should_use_aspm - check if the device should program ASPM *
@@ -1336,6 +1361,9 @@ static bool amdgpu_device_aspm_support_q*/ bool amdgpu_device_should_use_aspm (struct amdgpu_device *adev) { +struct pci_dev *aspm_pdev, *parent; +bool enabled; +switch (amdgpu_aspm) {case -1 :break ;
@@ -1348,7 +1376,27 @@ bool amdgpu_device_should_use_aspm(struc }if (amdgpu_device_aspm_support_quirk (adev))return false; -return pcie_aspm_enabled (adev->pdev); + +/* +* pcie_aspm_enabled() checks the link between its argument and +* the immediate upstream bridge. Use SWUS for dGPUs with an +* internal switch so that this is the host-facing link. +*/ + aspm_pdev =amdgpu_device_get_aspm_pdev (adev); + parent =pci_upstream_bridge (aspm_pdev); +if (!parent) { +dev_dbg (adev->dev,"ASPM: no upstream PCIe link for %s\n" , +pci_name (aspm_pdev)); +return false; + } + + enabled =pcie_aspm_enabled (aspm_pdev); +/* Report the exact link used for the automatic ASPM decision. */ +dev_dbg (adev->dev,"ASPM: link %s <-> %s is %s\n" , +pci_name (parent),pci_name (aspm_pdev), + enabled ?"enabled" :"disabled" ); + +return enabled; }/* if we get transitioned to only one device, take VGA back */
Greg Kroah-Hartman
maintainerPATCH 38/87 nfc: digital: clamp SENSF_RES length to the destination buffer
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Doruk Tan Ozturk <[email protected]>
commit 344a56d7c8e0f3cbaff0bcb1bcd95a1a1db24b16 upstream.
digital_in_recv_sensf_res() memcpy()s resp->len bytes from a remote NFC-F device response into the NFC_SENSF_RES_MAXSIZE-byte target.sensf_res field without an upper-bound check. A nearby malicious NFC-F device can send an oversized SENSF_RES response to overflow the stack-local struct nfc_target.
Clamp resp->len to NFC_SENSF_RES_MAXSIZE before the copy.
Found by 0sec automated security-research tooling (https://0sec.ai).
--- net/nfc/digital_technology.c | 2 ++ 1 file changed, 2 insertions(+)
net/nfc/digital_technology.c +2 -0
@@ -778,6 +778,8 @@ static void digital_in_recv_sensf_res(st sensf_res = (struct digital_sensf_res *)resp->data; + resp->len = min_t(unsigned int, resp->len, NFC_SENSF_RES_MAXSIZE); +memcpy (target.sensf_res, sensf_res, resp->len); target.sensf_res_len = resp->len;
Greg Kroah-Hartman
maintainerPATCH 39/87 nfc: fdp: bound the device-reported read length and fix an skb leak
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
commit 7ad21dcfeb5181af0c3ee2608808c0c0a5283aa1 upstream.
fdp_nci_i2c_read() takes the next packet length from two device-supplied bytes and never validates it. The value is a u16 used as the i2c_master_recv() count into a 261-byte on-stack buffer: a malicious, counterfeit or malfunctioning controller (or an i2c bus interposer) can drive it far past the buffer for a stack out-of-bounds write that clobbers the canary and return address, or below the minimum frame size (directly, or by truncating the computed sum) so the header/LRC strip and the next length read run past a short receive. Reject a length outside [FDP_NCI_I2C_MIN_PAYLOAD, FDP_NCI_I2C_MAX_PAYLOAD], as a corrupted packet already is, and force resynchronization.
The same loop allocates one data skb per iteration and assumes a length packet followed by a data packet; a device that sends two data packets in one call leaks the first skb when the second allocation overwrites it. Free a previously allocated skb before allocating the next.
--- drivers/nfc/fdp/i2c.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
drivers/nfc/fdp/i2c.c +27 -0
@@ -166,9 +166,36 @@ static int fdp_nci_i2c_read(struct fdp_i/* Packet that contains a length */ if (tmp[0 ] ==0 && tmp[1 ] ==0 ) { phy->next_read_size = (tmp[2 ] <<8 ) + tmp[3 ] +3 ; + +/* +* next_read_size is taken from the device and is used +* as the i2c_master_recv() count for the next packet +* and as the data skb size. A value above the receive +* buffer overflows tmp[]; one below the minimum frame +* size runs the header/LRC strip and the length-field +* read past a short receive. Either way the packet is +* corrupt: drop it and force resynchronization. +*/ +if (phy->next_read_size <FDP_NCI_I2C_MIN_PAYLOAD || + phy->next_read_size >FDP_NCI_I2C_MAX_PAYLOAD ) { +dev_dbg (&client->dev,"%s: corrupted packet\n" , + __func__); + phy->next_read_size =FDP_NCI_I2C_MIN_PAYLOAD ; + goto flush; + } }else { phy->next_read_size =FDP_NCI_I2C_MIN_PAYLOAD ; +/* +* Only one data packet is delivered per call; if the +* device sends another, do not overwrite and leak the +* skb allocated for the previous one. +*/ +if (*skb) { +kfree_skb (*skb); + *skb =NULL ; + } + *skb =alloc_skb (len,GFP_KERNEL );if (*skb ==NULL ) { r = -ENOMEM ;
Greg Kroah-Hartman
maintainerPATCH 40/87 nfc: microread: validate target discovery payload lengths
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
commit 25519469972ef57c3edb1805dabd6c5612b90211 upstream.
microread_target_discovered() parses target discovery payloads from skb->data according to the HCI gate. The fixed field offsets and UID copies were checked only against the destination nfc_target buffers, not against the actual skb length.
Validate that each gate-specific payload contains the fixed fields and UID bytes before reading or copying them.
--- drivers/nfc/microread/microread.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-)
drivers/nfc/microread/microread.c +29 -2
@@ -483,13 +483,19 @@ static void microread_target_discovered(switch (gate) {case MICROREAD_GATE_ID_MREAD_ISO_A : +if (skb->len <=MICROREAD_EMCF_A_LEN ) { + r = -EINVAL ; + goto exit_free; + } + targets->supported_protocols =nfc_hci_sak_to_protocol (skb->data[MICROREAD_EMCF_A_SAK ]); targets->sens_res =be16_to_cpu (*(u16 *)&skb->data[MICROREAD_EMCF_A_ATQA ]); targets->sel_res = skb->data[MICROREAD_EMCF_A_SAK ]; targets->nfcid1_len = skb->data[MICROREAD_EMCF_A_LEN ]; -if (targets->nfcid1_len >sizeof (targets->nfcid1)) { +if (targets->nfcid1_len >sizeof (targets->nfcid1) || + targets->nfcid1_len > skb->len -MICROREAD_EMCF_A_UID ) { r = -EINVAL ; goto exit_free; }
@@ -497,13 +503,19 @@ static void microread_target_discovered( targets->nfcid1_len);break ;case MICROREAD_GATE_ID_MREAD_ISO_A_3 : +if (skb->len <=MICROREAD_EMCF_A3_LEN ) { + r = -EINVAL ; + goto exit_free; + } + targets->supported_protocols =nfc_hci_sak_to_protocol (skb->data[MICROREAD_EMCF_A3_SAK ]); targets->sens_res =be16_to_cpu (*(u16 *)&skb->data[MICROREAD_EMCF_A3_ATQA ]); targets->sel_res = skb->data[MICROREAD_EMCF_A3_SAK ]; targets->nfcid1_len = skb->data[MICROREAD_EMCF_A3_LEN ]; -if (targets->nfcid1_len >sizeof (targets->nfcid1)) { +if (targets->nfcid1_len >sizeof (targets->nfcid1) || + targets->nfcid1_len > skb->len -MICROREAD_EMCF_A3_UID ) { r = -EINVAL ; goto exit_free; }
@@ -511,11 +523,21 @@ static void microread_target_discovered( targets->nfcid1_len);break ;case MICROREAD_GATE_ID_MREAD_ISO_B : +if (skb->len <MICROREAD_EMCF_B_UID +4 ) { + r = -EINVAL ; + goto exit_free; + } + targets->supported_protocols =NFC_PROTO_ISO14443_B_MASK ;memcpy (targets->nfcid1, &skb->data[MICROREAD_EMCF_B_UID ],4 ); targets->nfcid1_len =4 ;break ;case MICROREAD_GATE_ID_MREAD_NFC_T1 : +if (skb->len <MICROREAD_EMCF_T1_UID +4 ) { + r = -EINVAL ; + goto exit_free; + } + targets->supported_protocols =NFC_PROTO_JEWEL_MASK ; targets->sens_res =le16_to_cpu (*(u16 *)&skb->data[MICROREAD_EMCF_T1_ATQA ]);
@@ -523,6 +545,11 @@ static void microread_target_discovered( targets->nfcid1_len =4 ;break ;case MICROREAD_GATE_ID_MREAD_NFC_T3 : +if (skb->len <MICROREAD_EMCF_T3_UID +8 ) { + r = -EINVAL ; + goto exit_free; + } + targets->supported_protocols =NFC_PROTO_FELICA_MASK ;memcpy (targets->nfcid1, &skb->data[MICROREAD_EMCF_T3_UID ],8 ); targets->nfcid1_len =8 ;
Greg Kroah-Hartman
maintainerPATCH 41/87 nfc: llcp: bound the connect_sn TLV walk to the skb
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Doruk Tan Ozturk <[email protected]>
commit 55c68ac93e7dacc0f5f608b9c39dd4ff48cf28e8 upstream.
Commit 27256cdb290e ("nfc: llcp: bound SNL TLV parsing to the skb and add length checks") fixed the unbounded TLV walk in nfc_llcp_recv_snl(), and commit d8bd2dedbde5 ("nfc: llcp: fix OOB read and u8 offset wrap in TLV parsers") subsequently bounded nfc_llcp_parse_gb_tlv() and nfc_llcp_parse_connection_tlv(). One sibling parser sharing the same pattern remains unbounded: nfc_llcp_connect_sn().
nfc_llcp_connect_sn() walks a TLV list, reading a two-byte header (type, length) followed by length bytes of value, without checking that the two header bytes or the declared length stay within the buffer. It returns a pointer to a service name of up to 255 bytes that may point past the end of the skb; it is subsequently consumed by memcmp() in nfc_llcp_sock_from_sn(). In addition tlv_array_len was computed as "skb->len - LLCP_HEADER_SIZE" in size_t, so a CONNECT/CC frame shorter than the LLCP header underflows to a huge length and the walk runs far past the buffer.
nfc_llcp_connect_sn() is reachable from nfc_llcp_recv_connect() and nfc_llcp_recv_cc(), i.e. from received CONNECT and CC PDUs. A nearby NFC device can reach this without authentication; LLCP link activation happens automatically after NFC-DEP, and the nfc_llcp_rx_skb() dispatcher applies no minimum-length guard.
Walk the TLV list by pointer, bounded by skb_tail_pointer(skb), and validate each declared length before use, matching the approach already used for nfc_llcp_recv_snl(). Starting the walk at &skb->data[LLCP_HEADER_SIZE] against the tail pointer also removes the size_t underflow for short frames.
Found by 0sec automated security-research tooling (https://0sec.ai).
--- net/nfc/llcp_core.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
net/nfc/llcp_core.c +6 -4
@@ -847,13 +847,16 @@ static struct nfc_llcp_sock *nfc_llcp_sostatic const u8 *nfc_llcp_connect_sn (const struct sk_buff *skb,size_t *sn_len) {u8 type, length; -const u8 *tlv = &skb->data[2 ]; -size_t tlv_array_len = skb->len -LLCP_HEADER_SIZE , offset =0 ; +const u8 *tlv = &skb->data[LLCP_HEADER_SIZE ]; +const u8 *tlv_end =skb_tail_pointer (skb); -while (offset < tlv_array_len) { +while (tlv +2 < tlv_end) { type = tlv[0 ]; length = tlv[1 ]; +if (tlv +2 + length > tlv_end) +break ; +pr_debug ("type 0x%x length %d\n" , type, length);if (type ==LLCP_TLV_SN ) {
@@ -861,7 +864,6 @@ static const u8 *nfc_llcp_connect_sn(conreturn &tlv[2 ]; } - offset += length +2 ; tlv += length +2 ; }
Greg Kroah-Hartman
maintainerPATCH 42/87 nfc: llcp: fix OOB read and u8 offset wrap in TLV parsers
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muhammad Bilal <[email protected]>
commit 78b20c8eeacd2e44a2d8a4cb5316d3c521d90911 upstream.
nfc_llcp_parse_gb_tlv() and nfc_llcp_parse_connection_tlv() contain three related bugs in their TLV parsing loops:
1. 'offset' is declared u8 but tlv_array_len is u16. When TLV data advances offset past 255 it silently wraps to zero, causing infinite loops or double-processing of buffer data.
2. Before reading tlv[0] (type) and tlv[1] (length) there is no check that offset+2 <= tlv_array_len. A truncated TLV causes an OOB read of one byte past the buffer end.
3. After reading the length field, the value bytes are accessed without checking offset+2+length <= tlv_array_len. A crafted length=0xFF on a short buffer causes up to 255 bytes of OOB read past the buffer end.
Both functions are reachable without authentication via nfc_llcp_set_remote_gb() which feeds remote LLCP general bytes directly into nfc_llcp_parse_gb_tlv() with no additional validation.
Fix all three issues by widening offset from u8 to u16 and adding bounds checks for both the TLV header and value field before each access.
--- net/nfc/llcp_commands.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
net/nfc/llcp_commands.c +16 -2
@@ -193,7 +193,8 @@ int nfc_llcp_parse_gb_tlv(struct nfc_llc const u8 *tlv_array, u16 tlv_array_len) { const u8 *tlv = tlv_array; -u8 type, length, offset =0 ; +u8 type, length; +u16 offset =0 ;pr_debug ("TLV array length %d\n" , tlv_array_len);
@@ -201,9 +202,15 @@ int nfc_llcp_parse_gb_tlv(struct nfc_llcreturn -ENODEV ;while (offset < tlv_array_len) { +if (offset +2 > tlv_array_len) +return -EINVAL ; + type = tlv[0 ]; length = tlv[1 ]; +if (offset +2 + length > tlv_array_len) +return -EINVAL ; +pr_debug ("type 0x%x length %d\n" , type, length);switch (type) {
@@ -243,7 +250,8 @@ int nfc_llcp_parse_connection_tlv(struct const u8 *tlv_array, u16 tlv_array_len) { const u8 *tlv = tlv_array; -u8 type, length, offset =0 ; +u8 type, length; +u16 offset =0 ;pr_debug ("TLV array length %d\n" , tlv_array_len);
@@ -251,9 +259,15 @@ int nfc_llcp_parse_connection_tlv(structreturn -ENOTCONN ;while (offset < tlv_array_len) { +if (offset +2 > tlv_array_len) +return -EINVAL ; + type = tlv[0 ]; length = tlv[1 ]; +if (offset +2 + length > tlv_array_len) +return -EINVAL ; +pr_debug ("type 0x%x length %d\n" , type, length);switch (type) {
Greg Kroah-Hartman
maintainerPATCH 43/87 nfc: llcp: reject PDUs shorter than the LLCP header
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Doruk Tan Ozturk <[email protected]>
commit 95674f506c6376d6722a23144c9acd26609771ed upstream.
Every LLCP PDU begins with a two-byte header (DSAP/SSAP + PTYPE), but the receive path never checked that a frame is at least LLCP_HEADER_SIZE bytes before parsing it.
nfc_llcp_rx_skb() reads the header via nfc_llcp_ptype()/nfc_llcp_dsap()/ nfc_llcp_ssap(), which dereference pdu->data[0] and pdu->data[1], and a CONNECT or CC PDU then computes
tlv_array_len = skb->len - LLCP_HEADER_SIZE;
as a size_t and hands it to the TLV walk. When the frame is shorter than the header the subtraction wraps to a huge value and the walk runs far past the buffer, an out-of-bounds read.
A nearby NFC device can reach this without authentication; LLCP link activation happens automatically after NFC-DEP.
Guard the common receive choke point __nfc_llcp_recv(), shared by both the target (nfc_llcp_data_received()) and initiator (nfc_llcp_recv()) paths, so a short skb is dropped before the rx_work worker parses it. Use pskb_may_pull() rather than a skb->len test so the two header bytes are guaranteed to sit in the skb linear area even for a non-linear skb, matching how the sibling NCI and HCI receive paths validate their headers.
Reproduced with a KFENCE out-of-bounds read via /dev/virtual_nci on linux-next.
Found by 0sec automated security-research tooling (https://0sec.ai).
--- net/nfc/llcp_core.c | 5 +++++ 1 file changed, 5 insertions(+)
net/nfc/llcp_core.c +5 -0
@@ -1552,6 +1552,11 @@ static void nfc_llcp_rx_work(struct workstatic void __nfc_llcp_recv (struct nfc_llcp_local *local,struct sk_buff *skb) { +if (!pskb_may_pull (skb,LLCP_HEADER_SIZE )) { +kfree_skb (skb); +return ; + } + local->rx_pending = skb;del_timer (&local->link_timer);schedule_work (&local->rx_work);
Greg Kroah-Hartman
maintainerPATCH 44/87 nfc: pn533: purge fragmented skbs during cleanup
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xu Rao <[email protected]>
commit 5718fc62198c38c2de5316020a90506f9e75e0bb upstream.
pn53x_common_clean() purges resp_q before freeing the common PN533 state, but it leaves fragment_skb untouched. The fragmentation helpers queue transmit fragments there while sending large initiator or target-mode frames, and those skbs remain owned by the driver until they are sent or discarded.
If the device is removed while fragments are still queued, the common cleanup path frees the PN533 state without releasing the queued fragment skbs, leaking them.
Purge fragment_skb during cleanup alongside resp_q.
--- drivers/nfc/pn533/pn533.c | 1 + 1 file changed, 1 insertion(+)
drivers/nfc/pn533/pn533.c +1 -0
@@ -2803,6 +2803,7 @@ void pn53x_common_clean(struct pn533 *prdestroy_workqueue (priv->wq);skb_queue_purge (&priv->resp_q); +skb_queue_purge (&priv->fragment_skb);list_for_each_entry_safe (cmd, n, &priv->cmd_queue, queue) {list_del (&cmd->queue);
Greg Kroah-Hartman
maintainerPATCH 45/87 nfc: st21nfca: validate ATR_REQ length against the received frame
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Doruk Tan Ozturk <[email protected]>
commit 5cdcca5d62a66eda6b774110a44cba67bc1a8d1d upstream.
st21nfca_tm_recv_atr_req() checks that the received ATR_REQ frame is at least ST21NFCA_ATR_REQ_MIN_SIZE and that the self-declared atr_req->length is at least sizeof(struct st21nfca_atr_req), but never checks that atr_req->length does not exceed the actual received length (skb->len).
st21nfca_tm_send_atr_res() then trusts the declared length:
gb_len = atr_req->length - sizeof(struct st21nfca_atr_req); ... memcpy(atr_res->gbi, atr_req->gbi, gb_len);
so an RF peer that sends a short frame but sets atr_req->length larger than the frame makes gb_len exceed the general bytes actually present, and the memcpy reads out of bounds past the received skb. Those bytes are placed in the ATR_RES and sent back to the peer (kernel-memory disclosure to a proximity attacker); a larger declared length is an out-of-bounds read (DoS).
Reject frames whose declared length exceeds the received length. The adjacent nfc_tm_activated() path in the same function already derives its general-bytes length from skb->len rather than the declared field.
Found by 0sec (https://0sec.ai) using automated source analysis; the missing bound is evident from source. Compile-tested.
--- drivers/nfc/st21nfca/dep.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/nfc/st21nfca/dep.c +3 -0
@@ -207,6 +207,9 @@ static int st21nfca_tm_recv_atr_req(struif (atr_req->length <sizeof (struct st21nfca_atr_req ))return -EPROTO ; +if (atr_req->length > skb->len) +return -EPROTO ; + r =st21nfca_tm_send_atr_res (hdev, atr_req);if (r)return r;
Greg Kroah-Hartman
maintainerPATCH 46/87 nfc: nci: fix out-of-bounds write in nci_target_auto_activated()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Samuel Page <[email protected]>
commit ac200079db50af81e6b04d058b33ec92901d8edd upstream.
nci_target_auto_activated() appends a target to the fixed-size array ndev->targets[NCI_MAX_DISCOVERED_TARGETS] and increments ndev->n_targets without first checking the array is full; unlike its sibling nci_add_new_target(), which bails out when n_targets already equals NCI_MAX_DISCOVERED_TARGETS.
ndev->n_targets is only cleared by nci_clear_target_list(), so an NFCC that repeatedly re-runs discovery (RF_DISCOVER_RSP, which re-enters NCI_DISCOVERY without clearing the target list) and reports an auto-activated target (RF_INTF_ACTIVATED_NTF) drives n_targets past the limit. The append then writes a struct nfc_target past the end of the array (a slab out-of-bounds write), and nfc_targets_found() goes on to walk the array with the inflated count:
BUG: KASAN: slab-out-of-bounds in nci_add_new_protocol+0x94/0x2ac [nci] Write of size 2 at addr ffff0000c7299a18 by task kworker/u8:0/12 Workqueue: nfc0_nci_rx_wq nci_rx_work [nci] Call trace: nci_add_new_protocol+0x94/0x2ac [nci] nci_ntf_packet+0xddc/0x11a0 [nci] nci_rx_work+0x15c/0x1e0 [nci] process_one_work+0x2dc/0x500 worker_thread+0x240/0x460 kthread+0x1c0/0x1d0 ret_from_fork+0x10/0x20 The buggy address belongs to the cache kmalloc-2k of size 2048 The buggy address is located 1024 bytes to the right of allocated 1560-byte region [ffff0000c7299000, ffff0000c7299618)
Guard nci_target_auto_activated() with the same check used by nci_add_new_target().
--- net/nfc/nci/ntf.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/nfc/nci/ntf.c +6 -0
@@ -603,6 +603,12 @@ static void nci_target_auto_activated(ststruct nfc_target *target;int rc; +/* This is a new target, check if we've enough room */ +if (ndev->n_targets ==NCI_MAX_DISCOVERED_TARGETS ) { +pr_debug ("not enough room, ignoring new target...\n" ); +return ; + } + target = &ndev->targets[ndev->n_targets]; rc = nci_add_new_protocol(ndev, target, ntf->rf_protocol,
Greg Kroah-Hartman
maintainerPATCH 47/87 nfc: nci: fix uninit-value in the RF discover/activated NTF handlers
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Samuel Page <[email protected]>
commit 8cbe06c1e699c0a165dae5093a2550e65f914818 upstream.
nci_rf_discover_ntf_packet() and nci_rf_intf_activated_ntf_packet() each parse a notification into an on-stack struct (nci_rf_discover_ntf / nci_rf_intf_activated_ntf) that is not initialised. The RF technology-specific parameters are only extracted when rf_tech_specific_params_len is non-zero, so a notification that reports a zero length leaves the rf_tech_specific_params union uninitialised - and both handlers then pass it to nci_add_new_protocol(), which reads it:
- discover: nci_add_new_target() -> nci_add_new_protocol();
- activated: nci_target_auto_activated() -> nci_add_new_protocol().
nci_add_new_protocol() uses nfca_poll->nfcid1_len as both a branch condition and a memcpy() length and copies nfcid1/sens_res/sel_res into ndev->targets, which is later exposed to user space via NFC_CMD_GET_TARGET.
BUG: KMSAN: uninit-value in nci_add_new_protocol+0x624/0x6c0 nci_add_new_protocol+0x624/0x6c0 nci_ntf_packet+0x25b2/0x3c30 nci_rx_work+0x318/0x5d0 process_scheduled_works+0x84b/0x17a0 worker_thread+0xc10/0x11b0 kthread+0x376/0x500 Local variable ntf.i created at: nci_ntf_packet+0xbc2/0x3c30
Zero-initialise both on-stack notifications so the union reads back as zero when no technology-specific parameters are present.
--- net/nfc/nci/ntf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/nfc/nci/ntf.c +2 -2
@@ -440,7 +440,7 @@ void nci_clear_target_list(struct nci_destatic int nci_rf_discover_ntf_packet (struct nci_dev *ndev,const struct sk_buff *skb) { -struct nci_rf_discover_ntf ntf; +struct nci_rf_discover_ntf ntf = {};const __u8 *data;bool add_target = true;
@@ -672,7 +672,7 @@ static int nci_rf_intf_activated_ntf_pac const struct sk_buff *skb) {struct nci_conn_info *conn_info; -struct nci_rf_intf_activated_ntf ntf; +struct nci_rf_intf_activated_ntf ntf = {};const __u8 *data;int err =NCI_STATUS_OK ;
Greg Kroah-Hartman
maintainerPATCH 48/87 nfc: nci: free destination parameters when closing a connection
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linmao Li <[email protected]>
commit 2e65bafdfd3a8bba972b3d17b6a57816557530fc upstream.
When a connection is closed, nci_core_conn_close_rsp_packet() frees conn_info but not conn_info->dest_params, which is a separate devm allocation. Each connect/close cycle leaks one dest_params until the NFC device is removed. Free dest_params along with conn_info.
--- net/nfc/nci/rsp.c | 1 + 1 file changed, 1 insertion(+)
net/nfc/nci/rsp.c +1 -0
@@ -336,6 +336,7 @@ static void nci_core_conn_close_rsp_packlist_del (&conn_info->list);if (conn_info == ndev->rf_conn_info) ndev->rf_conn_info =NULL ; +devm_kfree (&ndev->nfc_dev->dev, conn_info->dest_params);devm_kfree (&ndev->nfc_dev->dev, conn_info); } }
Greg Kroah-Hartman
maintainerPATCH 49/87 ndisc: ndisc_send_redirect() cleanup
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit 0784d83df3bfc977c13252a0599be924f0afa68d upstream.
ndisc_send_redirect() is always called under rcu_read_lock().
It can use dev_net_rcu() and avoid one redundant rcu_read_lock()/rcu_read_unlock() pair.
--- net/ipv6/ndisc.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
net/ipv6/ndisc.c +3 -5
@@ -1675,7 +1675,7 @@ static void ndisc_fill_redirect_hdr_optivoid ndisc_send_redirect (struct sk_buff *skb,const struct in6_addr *target) {struct net_device *dev = skb->dev; -struct net *net =dev_net (dev); +struct net *net =dev_net_rcu (dev);struct sock *sk = net->ipv6.ndisc_sk;int optlen =0 ;struct inet_peer *peer;
@@ -1690,8 +1690,8 @@ void ndisc_send_redirect(struct sk_buff ops_data_buf[NDISC_OPS_REDIRECT_DATA_SPACE ], *ops_data =NULL ;bool ret; -if (netif_is_l3_master (skb->dev)) { - dev =dev_get_by_index_rcu (dev_net (skb->dev),IPCB (skb)->iif); +if (netif_is_l3_master (dev)) { + dev =dev_get_by_index_rcu (net,IPCB (skb)->iif);if (!dev)return ; }
@@ -1729,12 +1729,10 @@ void ndisc_send_redirect(struct sk_buff goto release; } -rcu_read_lock (); peer =inet_getpeer_v6 (net->ipv6.peers, &ipv6_hdr (skb)->saddr);if (!peer) goto release; ret =inet_peer_xrlim_allow (peer,1 *HZ ); -rcu_read_unlock ();if (!ret) goto release;
Greg Kroah-Hartman
maintainerPATCH 50/87 Input: byd - synchronize timer deletion before freeing private data
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linmao Li <[email protected]>
commit c83e79c0842ed29860648bcce5022ef0ba5001c6 upstream.
byd_disconnect() uses timer_delete() before freeing the driver's private data. This does not wait for a running byd_clear_touch() callback, which dereferences the private data and its psmouse pointer. A callback racing with disconnect can therefore access the private data after it has been freed. The timer can also still be re-armed by byd_process_byte() while the disconnect is in progress.
Use timer_shutdown_sync() before freeing the private data: it waits for a running callback and turns any later re-arm attempt into a no-op.
--- drivers/input/mouse/byd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/mouse/byd.c +1 -1
@@ -426,7 +426,7 @@ static void byd_disconnect(struct psmousstruct byd_data *priv = psmouse->private;if (priv) { -del_timer (&priv->timer); +timer_shutdown_sync (&priv->timer);kfree (psmouse->private); psmouse->private =NULL ; }
Greg Kroah-Hartman
maintainerPATCH 51/87 libceph: fix OOB read in decode_watchers() via missing bounds check
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pavitra Jha <[email protected]>
commit 00ead17c7de137a692edee59f2772e6af687e8eb upstream.
ceph_start_decoding() validates that struct_len bytes remain in the buffer after the encoding header, but accepts struct_len=0 as valid:ceph_decode_need(p, end, 0, bad) always passes. When a malicious or compromised OSD sends an obj_list_watch_response_t reply with struct_len=0, ceph_start_decoding() returns success with p == end, leaving zero bytes guaranteed for subsequent reads.
The immediately following ceph_decode_32(p) in decode_watchers() has no preceding bounds check. With p == end this is a 4-byte read past the validated buffer boundary. The garbage value is then passed directly to kzalloc_objs() as the watcher count.
The sibling function decode_watcher() already uses the safe variants (ceph_decode_copy_safe, ceph_decode_64_safe, ceph_decode_skip_32) after its own ceph_start_decoding() call. decode_watchers() is the only site that uses the bare variant, confirming an oversight.
Fix by replacing ceph_decode_32(p) with ceph_decode_32_safe(p, end, *num_watchers, bad), consistent with the established pattern.
Attacker model: a malicious or compromised OSD in a multi-tenant Ceph deployment (e.g. cloud) can trigger this against any kernel client that calls CEPH_OSD_OP_LIST_WATCHERS, without any further privileges beyond OSD session establishment.
[ idryomov: trim changelog ]
--- net/ceph/osd_client.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/ceph/osd_client.c +4 -1
@@ -5090,7 +5090,7 @@ static int decode_watchers(void **p, voiif (ret)return ret; - *num_watchers =ceph_decode_32 (p); +ceph_decode_32_safe (p, end, *num_watchers, bad); *watchers =kcalloc (*num_watchers,sizeof (**watchers),GFP_NOIO );if (!*watchers)return -ENOMEM ;
@@ -5104,6 +5104,9 @@ static int decode_watchers(void **p, voi }return 0 ; + +bad: +return -EINVAL ; }/*
Greg Kroah-Hartman
maintainerPATCH 52/87 ipv4: reject undersized MTUs in ip_do_fragment()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yong Wang <[email protected]>
commit c0726f0caf8c6b3208552949e17d23634a2f3129 upstream.
ip_do_fragment() subtracts the IPv4 header length from the effective MTU and passes the resulting payload MTU to ip_frag_next().
If the effective MTU is smaller than hlen + 8, ip_frag_next() rounds the fragment payload length down to zero. The fragmentation state then never makes forward progress: state->left, state->ptr and state->offset stay unchanged while ip_do_fragment() keeps allocating and transmitting header-only fragments until the softlockup detector fires.
This is reproducible with a route installed using "mtu lock 20", but it is also reproducible without route MTU lock, for example by forwarding a packet to a device whose MTU is 20.
Fix it in ip_do_fragment() by rejecting mtu < hlen + 8 with -EMSGSIZE, matching the existing IPv6 fragmentation check.
--- net/ipv4/ip_output.c | 4 ++++ 1 file changed, 4 insertions(+)
net/ipv4/ip_output.c +4 -0
@@ -797,6 +797,10 @@ int ip_do_fragment(struct net *net, stru*/ hlen = iph->ihl *4 ; +if (mtu < hlen +8 ) { + err = -EMSGSIZE ; + goto fail; + } mtu = mtu - hlen;/* Size of data space */ IPCB (skb)->flags |=IPSKB_FRAG_COMPLETE ; ll_rs =LL_RESERVED_SPACE (rt->dst.dev);
Greg Kroah-Hartman
maintainerPATCH 53/87 ipv6: fix use-after-free in ip6_finish_output2()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luxiao Xu <[email protected]>
commit d0d48d999b0eee6bb176ef4e39d9be868fa80f7e upstream.
ip6_finish_output2() caches a pointer to the IPv6 destination address (daddr) before invoking lwtunnel_xmit(). The LWT-BPF transmit path or other encapsulation operations within lwtunnel_xmit() can reallocate the skb head, freeing the memory that daddr points to. When lwtunnel_xmit() returns LWTUNNEL_XMIT_CONTINUE, the function continues to use the stale daddr pointer to compute the nexthop and to look up or create the neighbour entry. This results in a use-after-free read, which can leak sensitive kernel data, pollute the neighbour table with arbitrary values, misdirect traffic, or crash the system.
Fix this by re-fetching the IPv6 header and the destination address pointer after lwtunnel_xmit() returns LWTUNNEL_XMIT_CONTINUE, ensuring that the subsequent nexthop computation and neighbour lookup operate on valid memory.
--- net/ipv6/ip6_output.c | 2 ++ 1 file changed, 2 insertions(+)
net/ipv6/ip6_output.c +2 -0
@@ -119,6 +119,8 @@ static int ip6_finish_output2(struct netif (res !=LWTUNNEL_XMIT_CONTINUE )return res; + hdr =ipv6_hdr (skb); + daddr = &hdr->daddr; }IP6_UPD_PO_STATS (net, idev,IPSTATS_MIB_OUT , skb->len);
Greg Kroah-Hartman
maintainerPATCH 54/87 nvmet-auth: zero the AUTH_RECEIVE response buffer
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
commit 3ddcfb013322aa37eaa7a0d344b73079c38dfa21 upstream.
nvmet_execute_auth_receive() allocates the response buffer with kmalloc() sized by the host-supplied AUTH_RECEIVE allocation length, but the DH-HMAC-CHAP builders write only a fixed-size message into it. The full allocation length is then copied to the wire by nvmet_copy_to_sgl(), so a remote initiator receives the bytes past the built message -- up to nearly a page of uninitialized slab -- during the pre-authentication handshake.
Allocate the buffer with kzalloc() so the unwritten tail is zeroed before it is sent; conforming responses are unaffected.
--- drivers/nvme/target/fabrics-cmd-auth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/target/fabrics-cmd-auth.c +1 -1
@@ -475,7 +475,7 @@ void nvmet_execute_auth_receive(struct nreturn ; } - d =kmalloc (al,GFP_KERNEL ); + d =kzalloc (al,GFP_KERNEL );if (!d) { status =NVME_SC_INTERNAL ; goto done;
Greg Kroah-Hartman
maintainerPATCH 55/87 nvmet-fc: fix invalid free in LS IOD error path
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiang HongHui <[email protected]>
commit ba98d6796d12258e837ece065d2ecb59d76ce4ff upstream.
nvmet_fc_alloc_ls_iodlist() advances iod while initializing the LS IOD array. If an rqstbuf allocation or response buffer DMA mapping fails, the unwind loop decrements iod past the start of the array. The final kfree(iod) therefore frees an address before the allocated object.
This can be reproduced with nvme-fcloop and failslab by setting fail-nth to 6 before creating a target port. KASAN reports:
BUG: KASAN: invalid-free in nvmet_fc_register_targetport Free of addr ffff88816cf8ff48 by task nvmet_fail_nth/9552
Free the original allocation base stored in tgtport->iod instead. With this fix applied, the same sysfs write with fail-nth=6 returns -ENOMEM without any KASAN report.
--- drivers/nvme/target/fc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/target/fc.c +1 -1
@@ -571,7 +571,7 @@ out_fail:list_del (&iod->ls_rcv_list); } -kfree (iod); +kfree (tgtport->iod);return -EFAULT ; }
Greg Kroah-Hartman
maintainerPATCH 56/87 nvmet-tcp: Do not WARN on remotely-controlled oversized SGL allocations
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
commit 737a3b535247226f6e1a7988fd9d6e63e7d6fc71 upstream.
When fuzzing the nvme target code, I tripped a kernel warning in nvmet_tcp_map_data() because the length passed into the allocator is controlled by the remote initiator.
A remote initiator that sends a command with an SGL claiming a huge number, can create a scatterlist and iovec allocation of over 1 million entries, which causes the backing kmalloc call to exceed MAX_PAGE_ORDER and then the page allocator will trip on a WARN_ON_ONCE_GFP() message:
WARNING: mm/page_alloc.c:5280 __alloc_frozen_pages_noprof Workqueue: nvmet_tcp_wq nvmet_tcp_io_work ... sgl_alloc_order nvmet_tcp_map_data nvmet_tcp_try_recv_pdu
As it's never good to trip a kernel warning remotely due to many systems having panic-on-warn enabled, let's silence it by just add GFP_NOWARN to the allocation flags.
--- drivers/nvme/target/tcp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/nvme/target/tcp.c +3 -2
@@ -428,14 +428,15 @@ static int nvmet_tcp_map_data(struct nvm } cmd->req.transfer_len += len; - cmd->req.sg =sgl_alloc (len,GFP_KERNEL , &cmd->req.sg_cnt); + cmd->req.sg =sgl_alloc (len,GFP_KERNEL | __GFP_NOWARN, + &cmd->req.sg_cnt);if (!cmd->req.sg)return NVME_SC_INTERNAL ; cmd->cur_sg = cmd->req.sg;if (nvmet_tcp_has_data_in (cmd)) { cmd->iov =kmalloc_array (cmd->req.sg_cnt, -sizeof (*cmd->iov),GFP_KERNEL ); +sizeof (*cmd->iov),GFP_KERNEL | __GFP_NOWARN);if (!cmd->iov) goto err; }
Greg Kroah-Hartman
maintainerPATCH 57/87 ASoC: sof: pcm: use snd_pcm_direction_name()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuninori Morimoto <[email protected]>
[ Upstream commit cda4aa0069b73e3404ee61864b4814ccc7b7a6ad ]
We already have snd_pcm_direction_name(). Let's use it.
Stable-dep-of: 17661c67b206 ("ASoC: SOF: ipc4-pcm: Continue the pipeline trigger in case of IPC timeout")
--- sound/soc/sof/pcm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/sof/pcm.c +1 -1
@@ -100,7 +100,7 @@ sof_pcm_setup_connected_widgets(struct s dpcm_end_walk_at_be);if (ret <0 ) {dev_err (sdev->dev,"error: dai %s has no valid %s path\n" , dai->name, - dir ==SNDRV_PCM_STREAM_PLAYBACK ?"playback" :"capture" ); +snd_pcm_direction_name (dir));return ret; }
Greg Kroah-Hartman
maintainerPATCH 58/87 ASoC: SOF: Relocate and rework functionality for PCM stream freeing
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
[ Upstream commit 169ec0a541aac8afb215ab591b0fd53276686014 ]
Move the sof_pcm_stream_free() from sof-audio.c to pcm.c as static function and add wrapper to free all active stream, which is going to be used in ipc3/4 topology code (removes duplicated code).
With this change most of the PCM stream related code is located in one source file for easier lookup and simplified flow.
Stable-dep-of: 17661c67b206 ("ASoC: SOF: ipc4-pcm: Continue the pipeline trigger in case of IPC timeout")
--- sound/soc/sof/ipc3-topology.c | 20 ++---------- sound/soc/sof/ipc4-topology.c | 18 ----------- sound/soc/sof/pcm.c | 65 ++++++++++++++++++++++++++++++++++++++++++ sound/soc/sof/sof-audio.c | 36 ----------------------- sound/soc/sof/sof-audio.h | 3 - 5 files changed, 71 insertions(+), 71 deletions(-)
sound/soc/sof/ipc3-topology.c +4 -16
@@ -2295,28 +2295,16 @@ static int sof_ipc3_set_up_all_pipelinesstatic int sof_tear_down_left_over_pipelines (struct snd_sof_dev *sdev) {struct snd_sof_widget *swidget; -struct snd_sof_pcm *spcm; -int dir, ret; +int ret;/* * free all PCMs and their associated DAPM widgets if their connected DAPM widget * list is not NULL. This should only be true for paused streams at this point. * This is equivalent to the handling of FE DAI suspend trigger for running streams. */ -list_for_each_entry (spcm, &sdev->pcm_list, list) { -for_each_pcm_streams (dir) { -struct snd_pcm_substream *substream = spcm->stream[dir].substream; - -if (!substream || !substream->runtime || spcm->stream[dir].suspend_ignored) -continue ; - -if (spcm->stream[dir].list) { - ret =sof_pcm_stream_free (sdev, substream, spcm, dir, true); -if (ret <0 ) -return ret; - } - } - } + ret =sof_pcm_free_all_streams (sdev); +if (ret) +return ret;/* * free any left over DAI widgets. This is equivalent to the handling of suspend trigger
sound/soc/sof/ipc4-topology.c +1 -17
@@ -2951,9 +2951,6 @@ static int sof_ipc4_dai_get_clk(struct sstatic int sof_ipc4_tear_down_all_pipelines (struct snd_sof_dev *sdev,bool verify) { -struct snd_sof_pcm *spcm; -int dir, ret; -/* * This function is called during system suspend, we need to make sure * that all streams have been freed up.
@@ -2965,21 +2962,8 @@ static int sof_ipc4_tear_down_all_pipeli* * This will also make sure that paused streams handled correctly. */ -list_for_each_entry (spcm, &sdev->pcm_list, list) { -for_each_pcm_streams (dir) { -struct snd_pcm_substream *substream = spcm->stream[dir].substream; - -if (!substream || !substream->runtime || spcm->stream[dir].suspend_ignored) -continue ; -if (spcm->stream[dir].list) { - ret =sof_pcm_stream_free (sdev, substream, spcm, dir, true); -if (ret <0 ) -return ret; - } - } - } -return 0 ; +return sof_pcm_free_all_streams (sdev); }static int sof_ipc4_link_setup (struct snd_sof_dev *sdev,struct snd_soc_dai_link *link)
sound/soc/sof/pcm.c +65 -0
71 lines not on this page · raw message
sound/soc/sof/sof-audio.c +0 -36
@@ -831,42 +831,6 @@ bool snd_sof_stream_suspend_ignored(strureturn false; } -int sof_pcm_stream_free (struct snd_sof_dev *sdev,struct snd_pcm_substream *substream, -struct snd_sof_pcm *spcm,int dir,bool free_widget_list) -{ -const struct sof_ipc_pcm_ops *pcm_ops =sof_ipc_get_ops (sdev, pcm); -int ret; - -if (spcm->prepared[substream->stream]) { -/* stop DMA first if needed */ -if (pcm_ops && pcm_ops->platform_stop_during_hw_free) -snd_sof_pcm_platform_trigger (sdev, substream,SNDRV_PCM_TRIGGER_STOP ); - -/* Send PCM_FREE IPC to reset pipeline */ -if (pcm_ops && pcm_ops->hw_free) { - ret = pcm_ops->hw_free (sdev->component, substream); -if (ret <0 ) -return ret; - } - - spcm->prepared[substream->stream] = false; - } - -/* reset the DMA */ - ret =snd_sof_pcm_platform_hw_free (sdev, substream); -if (ret <0 ) -return ret; - -/* free widget list */ -if (free_widget_list) { - ret =sof_widget_list_free (sdev, spcm, dir); -if (ret <0 ) -dev_err (sdev->dev,"failed to free widgets during suspend\n" ); - } - -return ret; -} -/* * Generic object lookup APIs. */
sound/soc/sof/sof-audio.h +1 -2
@@ -633,8 +633,7 @@ int sof_widget_list_setup(struct snd_sofint sof_widget_list_free (struct snd_sof_dev *sdev,struct snd_sof_pcm *spcm,int dir);int sof_pcm_dsp_pcm_free (struct snd_pcm_substream *substream,struct snd_sof_dev *sdev,struct snd_sof_pcm *spcm); -int sof_pcm_stream_free (struct snd_sof_dev *sdev,struct snd_pcm_substream *substream, -struct snd_sof_pcm *spcm,int dir,bool free_widget_list); +int sof_pcm_free_all_streams (struct snd_sof_dev *sdev);int get_token_u32 (void *elem,void *object,u32 offset);int get_token_u16 (void *elem,void *object,u32 offset);int get_token_comp_format (void *elem,void *object,u32 offset);
Greg Kroah-Hartman
maintainerPATCH 59/87 ASoC: SOF: pcm: Move period/buffer configuration print after platform open
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
[ Upstream commit 4d2ea16576c8aa1437048cf436bff85653f139fe ]
The platform specific pcm_open call via snd_sof_pcm_platform_open() can modify the initial buffer configuration via constraints.
Move the prints as last step in the sof_pcm_open() function to reflect the final setup.
Stable-dep-of: 17661c67b206 ("ASoC: SOF: ipc4-pcm: Continue the pipeline trigger in case of IPC timeout")
--- sound/soc/sof/pcm.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)
sound/soc/sof/pcm.c +13 -11
@@ -519,15 +519,6 @@ static int sof_pcm_open(struct snd_soc_c*/ runtime->hw.buffer_bytes_max =le32_to_cpu (caps->buffer_size_max); -dev_dbg (component->dev,"period min %zd max %zd bytes\n" , - runtime->hw.period_bytes_min, - runtime->hw.period_bytes_max); -dev_dbg (component->dev,"period count %d max %d\n" , - runtime->hw.periods_min, - runtime->hw.periods_max); -dev_dbg (component->dev,"buffer max %zd bytes\n" , - runtime->hw.buffer_bytes_max); -/* set wait time - TODO: come from topology */ substream->wait_time =500 ;
@@ -537,10 +528,21 @@ static int sof_pcm_open(struct snd_soc_c spcm->prepared[substream->stream] = false; ret =snd_sof_pcm_platform_open (sdev, substream); -if (ret <0 ) +if (ret <0 ) {dev_err (component->dev,"error: pcm open failed %d\n" , ret); +return ret; + } + +dev_dbg (component->dev,"period bytes min %zd, max %zd\n" , + runtime->hw.period_bytes_min, + runtime->hw.period_bytes_max); +dev_dbg (component->dev,"period count min %d, max %d\n" , + runtime->hw.periods_min, + runtime->hw.periods_max); +dev_dbg (component->dev,"buffer bytes max %zd\n" , + runtime->hw.buffer_bytes_max); -return ret; +return 0 ; } static int sof_pcm_close(struct snd_soc_component *component,
Greg Kroah-Hartman
maintainerPATCH 60/87 ASoC: SOF: pcm: Add snd_sof_pcm specific wrappers for dev_dbg() and dev_err()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
[ Upstream commit 860693187c597645b28a421d8acb26428b8afd3f ]
Introduce spcm_dbg() and spcm_err() macros to provide consistent printing for debug and error messages which includes usable information in the print's prefix.
Update the prints in pcm.c, ipc3-pcm.c and ipc4-pcm.c to take advantage of the features provided by the macros.
Stable-dep-of: 17661c67b206 ("ASoC: SOF: ipc4-pcm: Continue the pipeline trigger in case of IPC timeout")
--- sound/soc/sof/ipc3-pcm.c | 13 +++--- sound/soc/sof/ipc4-pcm.c | 10 +++-- sound/soc/sof/pcm.c | 86 ++++++++++++++++++++-------------------------- sound/soc/sof/sof-audio.h | 14 +++++++ 4 files changed, 65 insertions(+), 58 deletions(-)
sound/soc/sof/ipc3-pcm.c +7 -6
@@ -117,22 +117,23 @@ static int sof_ipc3_pcm_hw_params(structif (platform_params->cont_update_posn) pcm.params.cont_update_posn =1 ; -dev_dbg (component->dev,"stream_tag %d" , pcm.params.stream_tag); +spcm_dbg (spcm, substream->stream,"stream_tag %d\n" , + pcm.params.stream_tag);/* send hw_params IPC to the DSP */ ret =sof_ipc_tx_message (sdev->ipc, &pcm,sizeof (pcm), &ipc_params_reply,sizeof (ipc_params_reply));if (ret <0 ) { -dev_err (component->dev,"HW params ipc failed for stream %d\n" , - pcm.params.stream_tag); +spcm_err (spcm, substream->stream, +"STREAM_PCM_PARAMS ipc failed for stream_tag %d\n" , + pcm.params.stream_tag);return ret; } ret =snd_sof_set_stream_data_offset (sdev, &spcm->stream[substream->stream], ipc_params_reply.posn_offset);if (ret <0 ) { -dev_err (component->dev,"%s: invalid stream data offset for PCM %d\n" , - __func__, spcm->pcm.pcm_id); +spcm_err (spcm, substream->stream,"invalid stream data offset\n" );return ret; }
@@ -171,7 +172,7 @@ static int sof_ipc3_pcm_trigger(struct s stream.hdr.cmd |=SOF_IPC_STREAM_TRIG_STOP ;break ;default : -dev_err (component->dev,"Unhandled trigger cmd %d\n" , cmd); +spcm_err (spcm, substream->stream,"Unhandled trigger cmd %d\n" , cmd);return -EINVAL ; }
sound/soc/sof/ipc4-pcm.c +6 -4
@@ -291,12 +291,12 @@ static int sof_ipc4_trigger_pipelines(stint ret;int i; -dev_dbg (sdev->dev,"trigger cmd: %d state: %d\n" , cmd, state); - spcm =snd_sof_find_spcm_dai (component, rtd);if (!spcm)return -EINVAL ; +spcm_dbg (spcm, substream->stream,"cmd: %d, state: %d\n" , cmd, state); + pipeline_list = &spcm->stream[substream->stream].pipeline_list;/* nothing to trigger if the list is empty */
@@ -358,7 +358,7 @@ static int sof_ipc4_trigger_pipelines(st*/ ret =sof_ipc4_set_multi_pipeline_state (sdev,SOF_IPC4_PIPE_PAUSED , trigger_list);if (ret <0 ) { -dev_err (sdev->dev,"failed to pause all pipelines\n" ); +spcm_err (spcm, substream->stream,"failed to pause all pipelines\n" ); goto free; }
@@ -376,7 +376,9 @@ skip_pause_transition:/* else set the RUNNING/RESET state in the DSP */ ret =sof_ipc4_set_multi_pipeline_state (sdev, state, trigger_list);if (ret <0 ) { -dev_err (sdev->dev,"failed to set final state %d for all pipelines\n" , state); +spcm_err (spcm, substream->stream, +"failed to set final state %d for all pipelines\n" , + state);/* * workaround: if the firmware is crashed while setting the * pipelines to reset state we must ignore the error code and
sound/soc/sof/pcm.c +38 -48
199 lines not on this page · raw message
sound/soc/sof/sof-audio.h +14 -0
@@ -601,6 +601,20 @@ struct snd_sof_pcm *snd_sof_find_spcm_covoid snd_sof_pcm_period_elapsed (struct snd_pcm_substream *substream);void snd_sof_pcm_init_elapsed_work (struct work_struct *work); +/* +* snd_sof_pcm specific wrappers for dev_dbg() and dev_err() to provide +* consistent and useful prints. +*/ +#define spcm_dbg (__spcm, __dir, __fmt, ...) \ + dev_dbg((__spcm)->scomp->dev, "pcm%u (%s), dir %d: " __fmt, \ + (__spcm)->pcm.pcm_id, (__spcm)->pcm.pcm_name, __dir, \ + ##__VA_ARGS__) + +#define spcm_err (__spcm, __dir, __fmt, ...) \ + dev_err((__spcm)->scomp->dev, "%s: pcm%u (%s), dir %d: " __fmt, \ + __func__, (__spcm)->pcm.pcm_id, (__spcm)->pcm.pcm_name, __dir, \ + ##__VA_ARGS__) +#if IS_ENABLED (CONFIG_SND_SOC_SOF_COMPRESS )void snd_sof_compr_fragment_elapsed (struct snd_compr_stream *cstream);void snd_sof_compr_init_elapsed_work (struct work_struct *work);
Greg Kroah-Hartman
maintainerPATCH 61/87 ASoC: SOF: ipc4-pcm: Continue the pipeline trigger in case of IPC timeout
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
[ Upstream commit 17661c67b206612cb3ba65d5ae726cd2015d0a53 ]
Ignore IPC errors for pipeline state change if the firmware state is crashed or the IPC has timed out.
If the firmware has crashed the kernel still needs to go through the state changes to reset its internal to be able to correctly work the next time the DSP is booted up.
The case with IPC timeout is a bit more problematic, but it has been rootcaused to be the result of system scheduling blockage and the firmware did actually received and handled the message, but the reply handling got blocked by issues outside of the SOF stack.
So far the best way to handle this is to continue with setting the state.
--- sound/soc/sof/ipc4-pcm.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
sound/soc/sof/ipc4-pcm.c +19 -6
@@ -359,7 +359,19 @@ static int sof_ipc4_trigger_pipelines(st ret =sof_ipc4_set_multi_pipeline_state (sdev,SOF_IPC4_PIPE_PAUSED , trigger_list);if (ret <0 ) {spcm_err (spcm, substream->stream,"failed to pause all pipelines\n" ); - goto free; +/* +* workaround: if the firmware is crashed or the IPC timed out +* while setting the pipeline state we must ignore the error +* code and proceed to set adjust the local pipeline states. +* +* If the firmware is crashed we will not send IPC messages +* and we are going to see errors printed, but the state of the +* widgets will be correct for the next boot. +*/ +if (sdev->fw_state !=SOF_FW_CRASHED && ret != -ETIMEDOUT ) + goto free; + + ret =0 ; }/* update PAUSED state for all pipelines just triggered */
@@ -380,14 +392,15 @@ skip_pause_transition:"failed to set final state %d for all pipelines\n" , state);/* -* workaround: if the firmware is crashed while setting the -* pipelines to reset state we must ignore the error code and -* reset it to 0. -* Since the firmware is crashed we will not send IPC messages +* workaround: if the firmware is crashed or the IPC timed out +* while setting the pipeline state we must ignore the error +* code and proceed to set adjust the local pipeline states. +* +* If the firmware is crashed we will not send IPC messages * and we are going to see errors printed, but the state of the * widgets will be correct for the next boot. */ -if (sdev->fw_state !=SOF_FW_CRASHED || state !=SOF_IPC4_PIPE_RESET ) +if (sdev->fw_state !=SOF_FW_CRASHED && ret != -ETIMEDOUT ) goto free; ret =0 ;
Greg Kroah-Hartman
maintainerPATCH 62/87 ASoC: codecs: lpass-tx-macro: Fix enum kcontrol accesses
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dawid Wróbel <[email protected]>
[ Upstream commit 1ba381759e45d5d0442452cfa5c42e836191a568 ]
The "DEC0 MODE" to "DEC7 MODE" controls are enumerated, but tx_macro_dec_mode_get() and tx_macro_dec_mode_put() access their value through ucontrol->value.integer.value[0] (a long) instead of ucontrol->value.enumerated.item[0] (an unsigned int).
This same pattern was fixed in the sibling drivers by commit bcfe5f76cc40 ("ASoC: codecs: rx-macro: fix accessing array out of bounds for enum type") and
commit 0ea5eff7c606 ("ASoC: codecs: va-macro: fix accessing array out of bounds for enum type"), but tx-macro was missed.
On 64-bit kernels built with CONFIG_SND_CTL_DEBUG, the elem value sanity check catches the 4 bytes written past the enumerated item and every read of these controls fails with -EINVAL:
snd-sm8250 sound: control 2:0:0:DEC0 MODE:0: access overflow
--- sound/soc/codecs/lpass-tx-macro.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/soc/codecs/lpass-tx-macro.c +2 -2
@@ -1019,7 +1019,7 @@ static int tx_macro_dec_mode_get(structstruct soc_enum *e = (struct soc_enum *)kcontrol->private_value;int path = e->shift_l; - ucontrol->value.integer.value[0 ] = tx->dec_mode[path]; + ucontrol->value.enumerated.item[0 ] = tx->dec_mode[path];return 0 ; }
@@ -1028,7 +1028,7 @@ static int tx_macro_dec_mode_put(struct struct snd_ctl_elem_value *ucontrol) {struct snd_soc_component *component =snd_soc_kcontrol_component (kcontrol); -int value = ucontrol->value.integer.value[0 ]; +int value = ucontrol->value.enumerated.item[0 ];struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;int path = e->shift_l;struct tx_macro *tx =snd_soc_component_get_drvdata (component);
Greg Kroah-Hartman
maintainerPATCH 63/87 mptcp: pm: fix data race in add_addr timer callback
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qing Luo <[email protected]>
[ Upstream commit a7aad5b69d3bdaec20a3ed9284e184502450c0cd ]
The timer callback reads entry->retrans_times outside pm.lock to decide whether to call mptcp_pm_subflow_established(). Since mptcp_pm_announced_del_timer() can concurrently set retrans_times = ADD_ADDR_RETRANS_MAX under pm.lock, a race condition exists.
I discovered this issue while studying the code. AI tools helped me to verify the issue can potentially happen under race conditions.
Use a local 'retransmit' flag set inside pm.lock to capture whether retransmission is still possible when the lock is taken. This allows to call mptcp_pm_subflow_established() accordingly, and not depending on the situation that can be different when checked outside the pm.lock.
--- net/mptcp/pm_netlink.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/mptcp/pm_netlink.c +4 -2
@@ -297,6 +297,7 @@ static void mptcp_pm_add_timer(struct tistruct mptcp_sock *msk = entry->sock;struct sock *sk = (struct sock *)msk;unsigned int timeout =0 ; +bool retransmit;pr_debug ("msk=%p\n" , msk);
@@ -334,12 +335,13 @@ static void mptcp_pm_add_timer(struct ti entry->retrans_times++; } -if (entry->retrans_times >=ADD_ADDR_RETRANS_MAX ) + retransmit = entry->retrans_times <ADD_ADDR_RETRANS_MAX ; +if (!retransmit) timeout =0 ;spin_unlock_bh (&msk->pm.lock); -if (entry->retrans_times ==ADD_ADDR_RETRANS_MAX ) +if (!retransmit)mptcp_pm_subflow_established (msk); out:
Greg Kroah-Hartman
maintainerPATCH 64/87 HID: magicmouse: fix battery reporting for Bluetooth Magic Trackpad USB-C
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrei Fed <[email protected]>
commit a1556b48efc157fdda07b52ecc56c7bd1e1786f0 upstream.
The Apple Magic Trackpad 2 (USB-C) reports a wildly wrong battery capacity over Bluetooth, for example a constant 4% for a pack that is actually at 74%.
The device's battery input report (0x90) is laid out as [report-id][status][charge]. hid-input's synchronous capacity query, hidinput_query_battery_capacity(), assumes the common [report-id][capacity] layout and returns buf[1], which for this device is the status byte rather than the charge (buf[2]).
magicmouse_fetch_battery(), which requests the battery report through hid_hw_request() so the reply is decoded via the report descriptor at the correct field offset, is gated to the USB models and never runs over Bluetooth. The device does not push battery reports on its own either, except a single one at connect time, which is delivered while probe holds driver_input_lock and is silently dropped. All userspace reads therefore go through the misparsing query, and the device is stuck reporting its status byte as the capacity.
Enabling the fetch for Bluetooth is not sufficient on its own: user space reacts to the power_supply registration immediately, so a query is typically already in flight when the fetch reply is parsed. hidinput_get_battery_property() stores the query result and marks the battery as queried without rechecking whether a report arrived while it was waiting, clobbering the just-reported correct value with the misparsed one.
Fix this by adding HID_BATTERY_QUIRK_AVOID_QUERY for the Bluetooth Magic Trackpad USB-C so the misparsing query path is never used, and by fetching the battery at the end of probe for this device. hidp has no asynchronous request() callback, so the fetch is serviced synchronously via __hid_request() while probe still holds driver_input_lock; call hid_device_io_start() first so the reply is processed instead of being discarded.
Tested with a Magic Trackpad USB-C (004c:0324) over Bluetooth on 6.18.37: the reported capacity now matches the device (verified against a raw GET_REPORT of report 0x90) and updates on reconnect.
--- drivers/hid/hid-input.c | 3 +++ drivers/hid/hid-magicmouse.c | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-)
drivers/hid/hid-input.c +3 -0
@@ -361,6 +361,9 @@ static const struct hid_device_id hid_ba {HID_BLUETOOTH_DEVICE (USB_VENDOR_ID_APPLE ,USB_DEVICE_ID_APPLE_MAGICTRACKPAD ), HID_BATTERY_QUIRK_IGNORE }, + { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, +USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC ), + HID_BATTERY_QUIRK_AVOID_QUERY }, { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM,USB_DEVICE_ID_ELECOM_BM084 ), HID_BATTERY_QUIRK_IGNORE },
drivers/hid/hid-magicmouse.c +18 -1
@@ -792,6 +792,12 @@ static bool is_usb_magictrackpad2(__u32 product ==USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC ; } +static bool is_bt_magictrackpad2 (__u32 vendor,__u32 product) +{ +return vendor ==BT_VENDOR_ID_APPLE && + product ==USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC ; +} +static int magicmouse_fetch_battery (struct hid_device *hdev) {#ifdef CONFIG_HID_BATTERY_STRENGTH
@@ -800,7 +806,8 @@ static int magicmouse_fetch_battery(struif (!hdev->battery || (!is_usb_magicmouse2 (hdev->vendor, hdev->product) && - !is_usb_magictrackpad2 (hdev->vendor, hdev->product))) + !is_usb_magictrackpad2 (hdev->vendor, hdev->product) && + !is_bt_magictrackpad2 (hdev->vendor, hdev->product)))return -1 ; report_enum = &hdev->report_enum[hdev->battery_report_type];
@@ -926,6 +933,16 @@ static int magicmouse_probe(struct hid_dschedule_delayed_work (&msc->work,msecs_to_jiffies (500 )); } +/* +* Query the Bluetooth Magic Trackpad USB-C battery as done for USB. +* Start io first: probe holds driver_input_lock and the synchronous +* GET_REPORT reply would otherwise be dropped. +*/ +if (is_bt_magictrackpad2 (id->vendor, id->product)) { +hid_device_io_start (hdev); +magicmouse_fetch_battery (hdev); + } +return 0 ; err_stop_hw: if (is_usb_magicmouse2(id->vendor, id->product) ||
Greg Kroah-Hartman
maintainerPATCH 65/87 HID: magicmouse: do not keep a stale msc->input if no input is claimed
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jose Villaseñor Montfort <[email protected]>
commit 0af3b89705688af01aa06025b84fa7a1e06ba6cc upstream.
magicmouse_input_mapping() caches the first hid_input's input_dev in msc->input while the report descriptor is parsed, and the rest of the driver treats a non-NULL msc->input as proof that an input device was registered.
That does not hold on the hid-input error path. If hidinput_connect() fails -- for instance because input_register_device() returns an error -- it unwinds through hidinput_disconnect(), which frees every input_dev it created, including the one cached in msc->input.
The failure does not abort the probe. hid_connect() only skips the claim:
if ((connect_mask & HID_CONNECT_HIDINPUT) && !hidinput_connect(hdev, connect_mask & HID_CONNECT_HIDINPUT_FORCE)) hdev->claimed |= HID_CLAIMED_INPUT;
and the "device has no listeners" bailout below it does not fire for this driver, which sets ->raw_event; on the USB Magic Mouse 2 / Magic Trackpad 2 paths hidraw and hiddev are claimed as well. hid_hw_start() therefore returns 0 and magicmouse_probe() continues with msc->input pointing at freed memory. Being non-NULL, it passes the "input not registered" check in probe and the NULL checks in ->raw_event and ->event, so the next input report dereferences freed memory.
Clear msc->input when the HID core did not claim an input device, so the existing NULL checks cover this case as well.
--- drivers/hid/hid-magicmouse.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/hid/hid-magicmouse.c +10 -0
@@ -869,6 +869,16 @@ static int magicmouse_probe(struct hid_dreturn ret; } +/* +* When hidinput_connect() fails it frees every input device it +* created, but that does not fail hid_hw_start(): the core simply +* does not claim an input. msc->input, cached in ->input_mapping +* while the report descriptor was parsed, would then be a dangling +* pointer that passes every NULL check. Trust the core's claim. +*/ +if (!(hdev->claimed &HID_CLAIMED_INPUT )) + msc->input =NULL ; +if (is_usb_magicmouse2 (id->vendor, id->product) ||is_usb_magictrackpad2 (id->vendor, id->product)) {timer_setup (&msc->battery_timer, magicmouse_battery_timer_tick,0 );
Greg Kroah-Hartman
maintainerPATCH 66/87 HID: magicmouse: Prevent out-of-bounds (OOB) read during DOUBLE_REPORT_ID
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lee Jones <[email protected]>
commit d93ba918a185aca2594da63e92fdc5495b559c0f upstream.
It is currently possible for a malicious or misconfigured USB device to cause an out-of-bounds (OOB) read when submitting reports using DOUBLE_REPORT_ID by specifying a large report length and providing a smaller one.
Let's prevent that by comparing the specified report length with the actual size of the data read in from userspace. If the actual data length ends up being smaller than specified, we'll politely warn the user and prevent any further processing.
--- drivers/hid/hid-magicmouse.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/hid/hid-magicmouse.c +16 -0
@@ -384,6 +384,10 @@ static int magicmouse_raw_event(struct hstruct input_dev *input = msc->input;int x =0 , y =0 , ii, clicks =0 , npoints; +/* Protect against zero sized recursive calls from DOUBLE_REPORT_ID */ +if (size <1 ) +return 0 ; +switch (data[0 ]) {case TRACKPAD_REPORT_ID :case TRACKPAD2_BT_REPORT_ID :
@@ -484,6 +488,18 @@ static int magicmouse_raw_event(struct h/* Sometimes the trackpad sends two touch reports in one * packet. */ + +/* Ensure that we have at least 2 elements (report type and size) */ +if (size <2 ) +return 0 ; + +if (size < data[1 ] +2 ) { +hid_warn (hdev, +"received report length (%d) was smaller than specified (%d)" , + size, data[1 ] +2 ); +return 0 ; + } +magicmouse_raw_event (hdev, report, data +2 , data[1 ]);magicmouse_raw_event (hdev, report, data +2 + data[1 ], size -2 - data[1 ]);
Greg Kroah-Hartman
maintainerPATCH 67/87 HID: core: fix OOB read of field->usage in hid_set_field()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Baul Lee <[email protected]>
commit a13cdb19fcb223ed41bdab3bab42b98dba87e90b upstream.
hid_set_field() hands field->usage + offset to hid_dump_input() before the guard that bounds offset:
hid_dump_input(field->report->device, field->usage + offset, value);
if (offset >= field->report_count) {
hid_err(...);
return -1;
}Under CONFIG_DEBUG_FS hid_dump_input() dereferences that pointer, with buf = hid_resolv_usage(usage->hid, NULL). The usage[] array is allocated inline with the hid_field in hid_register_field() and holds field->maxusage entries, so an offset past it reads off the end of the kvzalloc()ed allocation and into a neighbouring object. Had the guard run first, offset < report_count <= maxusage would already have confined the pointer to the array.
A caller supplies such an offset today. picolcd_fb_send_tile() validates only report->maxfield before issuing hid_set_field(report->field[0], 11 + i, ...) for i = 0..31, so its offsets are fixed at 11..42 and are never checked against the bound field. When the device registers that field with fewer usages, the framebuffer deferred-io work drives the read on every tile. KASAN reports a 4-byte slab-out-of-bounds read in hid_dump_input() below hid_set_field(), and the same boot logs "offset (1) exceeds report_count (1)" from the guard that runs only afterwards.
Move the hid_dump_input() call below the guard. Because field->maxusage >= field->report_count, the guard then establishes that field->usage + offset lies inside the array before it is dereferenced, for every caller and without changing behaviour on the valid path.
Discovered by XBOW, triaged by Baul Lee <[email protected]>
--- drivers/hid/hid-core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/hid/hid-core.c +3 -2
@@ -1907,13 +1907,14 @@ int hid_set_field(struct hid_field *fiel size = field->report_size; -hid_dump_input (field->report->device, field->usage + offset, value); -if (offset >= field->report_count) {hid_err (field->report->device,"offset (%d) exceeds report_count (%d)\n" , offset, field->report_count);return -1 ; } + +hid_dump_input (field->report->device, field->usage + offset, value); +if (field->logical_minimum <0 ) {if (value !=snto32 (s32ton (value, size), size)) {hid_err (field->report->device,"value %d is out of range\n" , value);
Greg Kroah-Hartman
maintainerPATCH 68/87 xfrm: fix sk_dst_cache double-free in xfrm_user_policy()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiang Mei (Microsoft) <[email protected]>
[ Upstream commit c283e9ada7fcb7dd4b10592623086b2e6d2f9925 ]
xfrm_user_policy() clears the socket dst cache with __sk_dst_reset(), i.e. the non-atomic __sk_dst_set(sk, NULL): it reads sk_dst_cache with rcu_dereference_protected(), stores NULL and dst_release()s the old dst. That is only safe if no other thread modifies sk_dst_cache concurrently.
For a connected UDP socket that does not hold: the transmit fast path (udp_sendmsg -> sk_dst_check -> sk_dst_reset) resets the cache locklessly with an atomic xchg(). A per-socket policy change racing a send can make both sides observe the same old dst and each dst_release() it, dropping the socket's single reference twice and freeing the xfrm_dst bundle while it is still referenced:
BUG: KASAN: slab-use-after-free in dst_release Write of size 4 at addr ffff88801897b6c0 by task exploit/155 Call Trace: ... dst_release (... ./include/linux/rcuref.h:109) xfrm_user_policy (./include/net/sock.h:2239 ./include/net/sock.h:2256 net/xfrm/xfrm_state.c:3053) do_ip_setsockopt (net/ipv4/ip_sockglue.c:1347) ip_setsockopt (net/ipv4/ip_sockglue.c:1417) do_sock_setsockopt (net/socket.c:2368) __sys_setsockopt (net/socket.c:2393) __x64_sys_setsockopt (net/socket.c:2396) do_syscall_64 (arch/x86/entry/syscall_64.c:94) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121)
Reachable by an unprivileged user via a user+network namespace.
Use the atomic sk_dst_reset() so the cache is cleared and released with a single xchg(): whichever side wins releases the dst once, the other sees NULL and does nothing. Behaviour is otherwise unchanged.
--- net/xfrm/xfrm_state.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/xfrm/xfrm_state.c +2 -2
@@ -2711,7 +2711,7 @@ int xfrm_user_policy(struct sock *sk, int optname, sockptr_t optval, int optlen)if (sockptr_is_null (optval) && !optlen) {xfrm_sk_policy_insert (sk,XFRM_POLICY_IN ,NULL );xfrm_sk_policy_insert (sk,XFRM_POLICY_OUT ,NULL ); -__sk_dst_reset (sk); +sk_dst_reset (sk);return 0 ; }
@@ -2751,7 +2751,7 @@ int xfrm_user_policy(struct sock *sk, int optname, sockptr_t optval, int optlen)if (err >=0 ) {xfrm_sk_policy_insert (sk, err, pol);xfrm_pol_put (pol); -__sk_dst_reset (sk); +sk_dst_reset (sk); err =0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 69/87 Bluetooth: hci_sync: Fix advertising data UAFs
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengfeng Ye <[email protected]>
[ Upstream commit cdc36db204ffd97b947d64374cf23a210dc74777 ]
hci_find_adv_instance() returns an adv_info pointer that is valid only while hdev->lock is held. The advertising command-sync paths perform instance lookups without that lock and, in some cases, retain the pointer while waiting for a controller response.
An advertising termination event can therefore interleave as follows:
hci_cmd_sync_work hci_rx_work
hci_find_adv_instance()
__hci_cmd_sync_status()
wait for controller reply hci_dev_lock()
hci_remove_adv_instance()
kfree(adv)
adv->scan_rsp_changed = false
KASAN reported:
BUG: KASAN: slab-use-after-free in hci_set_ext_scan_rsp_data_sync+0x2e1/0x300 Write of size 1 at addr ffff88810a45d21d by task kworker/u17:0/88 Workqueue: hci0 hci_cmd_sync_work Call Trace: hci_set_ext_scan_rsp_data_sync+0x2e1/0x300 hci_schedule_adv_instance_sync+0x390/0x4c0 hci_cmd_sync_work+0x173/0x300 Allocated by task 87: hci_add_adv_instance+0x538/0xac0 add_advertising+0x885/0x1160 Freed by task 89: kfree+0x131/0x3c0 hci_remove_adv_instance+0x1d8/0x3b0 hci_le_ext_adv_term_evt+0x17b/0x730
Protect the instance lookup and payload construction in the extended advertising, scan response, and periodic advertising data paths. Snapshot the advertising parameters under hdev->lock, but release the lock before waiting for the controller.
Clear advertising-data dirty bits before issuing their commands and restore them after a failure using a fresh lookup. Likewise, update the reported transmit power through a fresh lookup after the parameter command completes. No adv_info pointer then survives an HCI command wait.
--- net/bluetooth/hci_sync.c | 133 ++++++++++++++++++++++++++++----------- 1 file changed, 98 insertions(+), 35 deletions(-)
net/bluetooth/hci_sync.c +98 -35
@@ -1253,10 +1253,11 @@ static int hci_set_adv_set_random_addr_sync(struct hci_dev *hdev, u8 instance, }static int -hci_set_ext_adv_params_sync (struct hci_dev *hdev,struct adv_info *adv, +hci_set_ext_adv_params_sync (struct hci_dev *hdev,u8 instance,const struct hci_cp_le_set_ext_adv_params *cp,struct hci_rp_le_set_ext_adv_params *rp) { +struct adv_info *adv;struct sk_buff *skb; skb = __hci_cmd_sync(hdev, HCI_OP_LE_SET_EXT_ADV_PARAMS, sizeof(*cp),
@@ -1284,11 +1285,15 @@ hci_set_ext_adv_params_sync(struct hci_dev *hdev, struct adv_info *adv,if (!rp->status) { hdev->adv_addr_type = cp->own_addr_type; -if (!cp->handle) { +if (!instance) {/* Store in hdev for instance 0 */ hdev->adv_tx_power = rp->tx_power; - }else if (adv) { - adv->tx_power = rp->tx_power; + }else { +hci_dev_lock (hdev); + adv =hci_find_adv_instance (hdev, instance); +if (adv) + adv->tx_power = rp->tx_power; +hci_dev_unlock (hdev); } }
@@ -1308,9 +1313,13 @@ static int hci_set_ext_adv_data_sync(struct hci_dev *hdev, u8 instance)memset (&pdu,0 ,sizeof (pdu));if (instance) { +hci_dev_lock (hdev); + adv =hci_find_adv_instance (hdev, instance); -if (!adv || !adv->adv_data_changed) +if (!adv || !adv->adv_data_changed) { +hci_dev_unlock (hdev);return 0 ; + } } len =eir_create_adv_data (hdev, instance, pdu.data);
@@ -1320,16 +1329,27 @@ static int hci_set_ext_adv_data_sync(struct hci_dev *hdev, u8 instance) pdu.cp.operation =LE_SET_ADV_DATA_OP_COMPLETE ; pdu.cp.frag_pref =LE_SET_ADV_DATA_NO_FRAG ; +if (adv) { + adv->adv_data_changed = false; +hci_dev_unlock (hdev); + } + err =__hci_cmd_sync_status (hdev,HCI_OP_LE_SET_EXT_ADV_DATA ,sizeof (pdu.cp) + len, &pdu.cp,HCI_CMD_TIMEOUT ); -if (err) +if (err) { +if (instance) { +hci_dev_lock (hdev); + adv =hci_find_adv_instance (hdev, instance); +if (adv) + adv->adv_data_changed = true; +hci_dev_unlock (hdev); + } +return err; + } -/* Update data if the command succeed */ -if (adv) { - adv->adv_data_changed = false; - }else { +if (!instance) {memcpy (hdev->adv_data, pdu.data, len); hdev->adv_data_len = len; }
@@ -1383,22 +1403,22 @@ int hci_setup_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance)struct adv_info *adv;bool secondary_adv; -if (instance >0 ) { - adv =hci_find_adv_instance (hdev, instance); -if (!adv) -return -EINVAL ; - }else { - adv =NULL ; - } -/* Updating parameters of an active instance will return a -* Command Disallowed error, so we must first disable the -* instance if it is active. +* Command Disallowed error, so disable it before taking a snapshot. */ -if (adv) { +if (instance >0 ) { err =hci_disable_ext_adv_instance_sync (hdev, instance);if (err)return err; + +hci_dev_lock (hdev); + adv =hci_find_adv_instance (hdev, instance); +if (!adv) { +hci_dev_unlock (hdev); +return -EINVAL ; + } + }else { + adv =NULL ; } flags =hci_adv_instance_flags (hdev, instance);
@@ -1409,8 +1429,11 @@ int hci_setup_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance) connectable = (flags &MGMT_ADV_FLAG_CONNECTABLE ) ||mgmt_get_connectable (hdev); -if (!is_advertising_allowed (hdev, connectable)) +if (!is_advertising_allowed (hdev, connectable)) { +if (instance) +hci_dev_unlock (hdev);return -EPERM ; + }/* Set require_privacy to true only when non-connectable * advertising is used and it is not periodic.
@@ -1421,8 +1444,11 @@ int hci_setup_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance) err =hci_get_random_address (hdev, require_privacy,adv_use_rpa (hdev, flags), adv, &own_addr_type, &random_addr); -if (err <0 ) +if (err <0 ) { +if (instance) +hci_dev_unlock (hdev);return err; + }memset (&cp,0 ,sizeof (cp));
@@ -1471,6 +1497,9 @@ int hci_setup_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance) cp.channel_map = hdev->le_adv_channel_map; cp.handle = instance; +if (instance) +hci_dev_unlock (hdev); +if (flags &MGMT_ADV_FLAG_SEC_2M ) { cp.primary_phy =HCI_ADV_PHY_1M ; cp.secondary_phy =HCI_ADV_PHY_2M ;
@@ -1483,12 +1512,12 @@ int hci_setup_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance) cp.secondary_phy =HCI_ADV_PHY_1M ; } - err =hci_set_ext_adv_params_sync (hdev, adv, &cp, &rp); + err =hci_set_ext_adv_params_sync (hdev, instance, &cp, &rp);if (err)return err;/* Update adv data as tx power is known now */ - err =hci_set_ext_adv_data_sync (hdev, cp.handle); + err =hci_set_ext_adv_data_sync (hdev, instance);if (err)return err;
@@ -1496,9 +1525,14 @@ int hci_setup_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance) own_addr_type == ADDR_LE_DEV_RANDOM_RESOLVED) && bacmp(&random_addr, BDADDR_ANY)) {/* Check if random address need to be updated */ -if (adv) { -if (!bacmp (&random_addr, &adv->random_addr)) +if (instance) { +hci_dev_lock (hdev); + adv =hci_find_adv_instance (hdev, instance); +if (!adv || !bacmp (&random_addr, &adv->random_addr)) { +hci_dev_unlock (hdev);return 0 ; + } +hci_dev_unlock (hdev); }else {if (!bacmp (&random_addr, &hdev->random_addr))return 0 ;
@@ -1524,9 +1558,13 @@ static int hci_set_ext_scan_rsp_data_sync(struct hci_dev *hdev, u8 instance)memset (&pdu,0 ,sizeof (pdu));if (instance) { +hci_dev_lock (hdev); + adv =hci_find_adv_instance (hdev, instance); -if (!adv || !adv->scan_rsp_changed) +if (!adv || !adv->scan_rsp_changed) { +hci_dev_unlock (hdev);return 0 ; + } } len =eir_create_scan_rsp (hdev, instance, pdu.data);
@@ -1536,15 +1574,27 @@ static int hci_set_ext_scan_rsp_data_sync(struct hci_dev *hdev, u8 instance) pdu.cp.operation =LE_SET_ADV_DATA_OP_COMPLETE ; pdu.cp.frag_pref =LE_SET_ADV_DATA_NO_FRAG ; +if (adv) { + adv->scan_rsp_changed = false; +hci_dev_unlock (hdev); + } + err =__hci_cmd_sync_status (hdev,HCI_OP_LE_SET_EXT_SCAN_RSP_DATA ,sizeof (pdu.cp) + len, &pdu.cp,HCI_CMD_TIMEOUT ); -if (err) +if (err) { +if (instance) { +hci_dev_lock (hdev); + adv =hci_find_adv_instance (hdev, instance); +if (adv) + adv->scan_rsp_changed = true; +hci_dev_unlock (hdev); + } +return err; + } -if (adv) { - adv->scan_rsp_changed = false; - }else { +if (!instance) {memcpy (hdev->scan_rsp_data, pdu.data, len); hdev->scan_rsp_data_len = len; }
@@ -1559,8 +1609,14 @@ static int __hci_set_scan_rsp_data_sync(struct hci_dev *hdev, u8 instance)memset (&cp,0 ,sizeof (cp)); +if (instance) +hci_dev_lock (hdev); + len =eir_create_scan_rsp (hdev, instance, cp.data); +if (instance) +hci_dev_unlock (hdev); +if (hdev->scan_rsp_data_len == len && !memcmp (cp.data, hdev->scan_rsp_data, len))return 0 ;
@@ -1694,14 +1750,18 @@ static int hci_set_per_adv_data_sync(struct hci_dev *hdev, u8 instance)u8 data[HCI_MAX_PER_AD_LENGTH ]; } pdu;u8 len; +struct adv_info *adv =NULL ;memset (&pdu,0 ,sizeof (pdu));if (instance) { -struct adv_info *adv =hci_find_adv_instance (hdev, instance); +hci_dev_lock (hdev); -if (!adv || !adv->periodic) + adv =hci_find_adv_instance (hdev, instance); +if (!adv || !adv->periodic) { +hci_dev_unlock (hdev);return 0 ; + } } len =eir_create_per_adv_data (hdev, instance, pdu.data);
@@ -1710,6 +1770,9 @@ static int hci_set_per_adv_data_sync(struct hci_dev *hdev, u8 instance) pdu.cp.handle = instance; pdu.cp.operation =LE_SET_ADV_DATA_OP_COMPLETE ; +if (adv) +hci_dev_unlock (hdev); +return __hci_cmd_sync_status (hdev,HCI_OP_LE_SET_PER_ADV_DATA ,sizeof (pdu.cp) + len, &pdu,HCI_CMD_TIMEOUT );
@@ -6414,7 +6477,7 @@ static int hci_le_ext_directed_advertising_sync(struct hci_dev *hdev,if (err)return err; - err =hci_set_ext_adv_params_sync (hdev,NULL , &cp, &rp); + err =hci_set_ext_adv_params_sync (hdev,0 , &cp, &rp);if (err)return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 70/87 Input: atkbd - skip deactivate for HONOR FMB-Ps internal keyboard
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cryolitia PukNgae <[email protected]>
[ Upstream commit 2aaf33c6e1e82561d7dce2345298a985a2483266 ]
After commit 9cf6e24c9fbf17e52de9fff07f12be7565ea6d61 ("Input: atkbd - do not skip atkbd_deactivate() when skipping ATKBD_CMD_GETID"), HONOR FMB-P, aka HONOR MagicBook Pro 14 2025's internal keyboard stops working. Adding the atkbd_deactivate_fixup quirk fixes it.
DMI: HONOR FMB-P/FMB-P-PCB, BIOS 1.13 05/08/2025
Stable-dep-of: 410c44b10967 ("Input: atkbd - skip deactivate for HONOR ZQC-P")
--- drivers/input/keyboard/atkbd.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/input/keyboard/atkbd.c +7 -0
@@ -1945,6 +1945,13 @@ static const struct dmi_system_id atkbd_ .callback = atkbd_deactivate_fixup, }, { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"HONOR" ), + DMI_MATCH(DMI_PRODUCT_NAME, "FMB-P"), + }, + .callback = atkbd_deactivate_fixup, + }, + {/* Lenovo Yoga Air 14 (83QK) */ .matches = { DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
Greg Kroah-Hartman
maintainerPATCH 71/87 Input: atkbd - skip deactivate for HONOR ZQC-P
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Donglin Lyu <[email protected]>
[ Upstream commit 410c44b1096789d0c40fbee706520e981dba7bc1 ]
The internal keyboard on the HONOR ZQC-P (HONOR MagicBook Pro 14 2026) does not work after boot.
Using the kernel command line 'i8042.dumbkbd=1' makes the keyboard functional, but the CapsLock LED does not work. Adding the 'atkbd_deactivate_fixup' quirk fixes the keyboard and CapsLock LED natively without requiring boot parameters.
DMI: HONOR ZQC-P/ZQC-P-PCB, BIOS 1.09 03/19/2026
--- drivers/input/keyboard/atkbd.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
drivers/input/keyboard/atkbd.c +13 -5
@@ -1947,22 +1947,30 @@ static const struct dmi_system_id atkbd_ { .matches = { DMI_MATCH(DMI_SYS_VENDOR, "HONOR"), - DMI_MATCH(DMI_PRODUCT_NAME, "FMB-P"), + DMI_MATCH(DMI_PRODUCT_NAME, "BCC-N"), }, .callback = atkbd_deactivate_fixup, }, { - /* Lenovo Yoga Air 14 (83QK) */ .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), - DMI_MATCH(DMI_PRODUCT_NAME, "83QK"), + DMI_MATCH(DMI_SYS_VENDOR, "HONOR"), + DMI_MATCH(DMI_PRODUCT_NAME, "FMB-P"), }, .callback = atkbd_deactivate_fixup, }, { + /* HONOR MagicBook Pro 14 2026 */ .matches = { DMI_MATCH(DMI_SYS_VENDOR, "HONOR"), - DMI_MATCH(DMI_PRODUCT_NAME, "BCC-N"), + DMI_MATCH(DMI_PRODUCT_NAME, "ZQC-P"), + }, + .callback = atkbd_deactivate_fixup, + }, + { + /* Lenovo Yoga Air 14 (83QK) */ + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), + DMI_MATCH(DMI_PRODUCT_NAME, "83QK"), }, .callback = atkbd_deactivate_fixup, },
Greg Kroah-Hartman
maintainerPATCH 72/87 mptcp: pm: fix memory leak from alloc-during-teardown race
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shardul Bankar <[email protected]>
[ Upstream commit efc33b5102ff859bacd390a5f30112d8e0c084c0 ]
mptcp_pm_destroy() empties msk->pm.anno_list and msk->pm.userspace_pm_local_addr_list under msk->pm.lock during socket teardown, dropping the lock between the two.
A concurrent userspace PM genl ANNOUNCE on the same msk holds a sock reference via mptcp_token_get_sock() and, in mptcp_pm_nl_announce_doit(), calls mptcp_userspace_pm_append_new_local_addr() and mptcp_pm_announced_alloc(). Both take msk->pm.lock briefly to add to their respective lists. Because the genl handler holds a sock reference, mptcp_pm_destroy() may run on the same msk via mptcp_disconnect(), which invokes mptcp_destroy_common() without dropping the sock refcount, before the handler completes.
If the lock acquisitions interleave such that mptcp_pm_destroy() empties a list first, the later alloc adds its entry to a list head that nothing else iterates for this msk, and the entry leaks. kmemleak reports both mptcp_pm_add_addr objects (from mptcp_pm_announced_alloc()) and mptcp_pm_addr_entry objects (from mptcp_userspace_pm_append_new_local_addr()) under sustained concurrent ANNOUNCE + close load against the userspace PM.
Add an MPTCP_PM_DESTROYING bit in msk->pm.status, set by mptcp_pm_destroy() under pm.lock before the lists are emptied and checked under pm.lock by the alloc paths. Either the alloc takes pm.lock first, in which case its entry is on the list when mptcp_pm_destroy() frees it; or mptcp_pm_destroy() takes pm.lock first, in which case the later alloc observes the bit and refuses.
Found by an MPTCP protocol-flow harness extending BRF (arXiv:2305.08782).
--- net/mptcp/pm_netlink.c | 3 +++ net/mptcp/pm_userspace.c | 7 ++++--- net/mptcp/protocol.c | 9 +++++++++ net/mptcp/protocol.h | 7 ++++--- 4 files changed, 20 insertions(+), 6 deletions(-)
net/mptcp/pm_netlink.c +3 -0
@@ -398,6 +398,9 @@ bool mptcp_pm_alloc_anno_list(struct mptlockdep_assert_held (&msk->pm.lock); +if (msk->pm.status &BIT (MPTCP_PM_DESTROYING )) +return false; + add_entry =mptcp_lookup_anno_list_by_saddr (msk, addr);if (add_entry) {
net/mptcp/pm_userspace.c +4 -3
@@ -13,9 +13,6 @@ void mptcp_free_local_addr_list(struct mstruct sock *sk = (struct sock *)msk;LIST_HEAD (free_list); -if (!mptcp_pm_is_userspace (msk)) -return ; -spin_lock_bh (&msk->pm.lock);list_splice_init (&msk->pm.userspace_pm_local_addr_list, &free_list);spin_unlock_bh (&msk->pm.lock);
@@ -53,6 +50,10 @@ static int mptcp_userspace_pm_append_newbitmap_zero (id_bitmap,MPTCP_PM_MAX_ADDR_ID +1 );spin_lock_bh (&msk->pm.lock); +if (msk->pm.status &BIT (MPTCP_PM_DESTROYING )) { + ret = -EINVAL ; + goto append_err; + }list_for_each_entry (e, &msk->pm.userspace_pm_local_addr_list, list) { addr_match =mptcp_addresses_equal (&e->addr, &entry->addr, true);if (addr_match && entry->addr.id ==0 && needs_id)
net/mptcp/protocol.c +9 -0
@@ -3536,7 +3536,16 @@ void mptcp_destroy_common(struct mptcp_ssk_forward_alloc_add (sk, msk->rmem_fwd_alloc);WRITE_ONCE (msk->rmem_fwd_alloc,0 );mptcp_token_destroy (msk); + +spin_lock_bh (&msk->pm.lock); + msk->pm.status |=BIT (MPTCP_PM_DESTROYING ); +spin_unlock_bh (&msk->pm.lock); +mptcp_pm_free_anno_list (msk); + +/* Free the userspace local address list unconditionally: the socket +* can be reused (mptcp_disconnect()) and re-selected to a different PM +*/ mptcp_free_local_addr_list (msk); }
net/mptcp/protocol.h +4 -3
@@ -190,9 +190,10 @@ enum mptcp_pm_status {MPTCP_PM_ESTABLISHED ,MPTCP_PM_SUBFLOW_ESTABLISHED ,MPTCP_PM_ALREADY_ESTABLISHED ,/* persistent status, set after ESTABLISHED event */ -MPTCP_PM_MPC_ENDPOINT_ACCOUNTED /* persistent status, set after MPC local address is -* accounted int id_avail_bitmap -*/ +MPTCP_PM_MPC_ENDPOINT_ACCOUNTED ,/* persistent status, set after MPC local address is +* accounted int id_avail_bitmap +*/ + MPTCP_PM_DESTROYING, /* To fence out PM list allocs */ }; enum mptcp_pm_type {
Greg Kroah-Hartman
maintainerPATCH 73/87 selinux: fix style issues in security/selinux/ss/policydb.h
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paul Moore <[email protected]>
[ Upstream commit a32582db36dcf3b23f860e092485e5e06b1b966c ]
As part of on ongoing effort to perform more automated testing and provide more tools for individual developers to validate their patches before submitting, we are trying to make our code "clang-format clean". My hope is that once we have fixed all of our style "quirks", developers will be able to run clang-format on their patches to help avoid silly formatting problems and ensure their changes fit in well with the rest of the SELinux kernel code.
Stable-dep-of: b98a8ac50775 ("selinux: require a class's permission values to cover its permission count")
--- security/selinux/ss/policydb.h | 192 ++++++++++++++++++++--------------------- 1 file changed, 95 insertions(+), 97 deletions(-)
security/selinux/ss/policydb.h +95 -97
@@ -8,15 +8,13 @@/* * Updated: Trusted Computer Solutions, Inc. <[email protected]> +* Support for enhanced MLS infrastructure. +* Copyright (C) 2004-2005 Trusted Computer Solutions, Inc. * -* Support for enhanced MLS infrastructure. -* -* Updated: Frank Mayer <[email protected]> and Karl MacMillan <[email protected]> -* -* Added conditional policy language extensions -* -* Copyright (C) 2004-2005 Trusted Computer Solutions, Inc. -* Copyright (C) 2003 - 2004 Tresys Technology, LLC +* Updated: Frank Mayer <[email protected]> and +* Karl MacMillan <[email protected]> +* Added conditional policy language extensions +* Copyright (C) 2003-2004 Tresys Technology, LLC */ #ifndef _SS_POLICYDB_H_
@@ -39,104 +37,103 @@/* Permission attributes */ struct perm_datum { -u32 value;/* permission bit + 1 */ +u32 value;/* permission bit + 1 */ };/* Attributes of a common prefix for access vectors */ struct common_datum { -u32 value;/* internal common value */ -struct symtab permissions;/* common permissions */ +u32 value;/* internal common value */ +struct symtab permissions;/* common permissions */ };/* Class attributes */ struct class_datum { -u32 value;/* class value */ -char *comkey;/* common name */ -struct common_datum *comdatum;/* common datum */ -struct symtab permissions;/* class-specific permission symbol table */ -struct constraint_node *constraints;/* constraints on class permissions */ -struct constraint_node *validatetrans;/* special transition rules */ +u32 value;/* class value */ +char *comkey;/* common name */ +struct common_datum *comdatum;/* common datum */ +struct symtab permissions;/* class-specific permission symbol table */ +struct constraint_node *constraints;/* constraints on class perms */ +struct constraint_node *validatetrans;/* special transition rules */ /* Options how a new object user, role, and type should be decided */ -#define DEFAULT_SOURCE 1 -#define DEFAULT_TARGET 2 +#define DEFAULT_SOURCE 1 +#define DEFAULT_TARGET 2char default_user;char default_role;char default_type;/* Options how a new object range should be decided */ -#define DEFAULT_SOURCE_LOW 1 -#define DEFAULT_SOURCE_HIGH 2 -#define DEFAULT_SOURCE_LOW_HIGH 3 -#define DEFAULT_TARGET_LOW 4 -#define DEFAULT_TARGET_HIGH 5 -#define DEFAULT_TARGET_LOW_HIGH 6 +#define DEFAULT_SOURCE_LOW 1 +#define DEFAULT_SOURCE_HIGH 2 +#define DEFAULT_SOURCE_LOW_HIGH 3 +#define DEFAULT_TARGET_LOW 4 +#define DEFAULT_TARGET_HIGH 5 +#define DEFAULT_TARGET_LOW_HIGH 6#define DEFAULT_GLBLUB 7char default_range; };/* Role attributes */ struct role_datum { -u32 value;/* internal role value */ -u32 bounds;/* boundary of role */ -struct ebitmap dominates;/* set of roles dominated by this role */ -struct ebitmap types;/* set of authorized types for role */ +u32 value;/* internal role value */ +u32 bounds;/* boundary of role */ +struct ebitmap dominates;/* set of roles dominated by this role */ +struct ebitmap types;/* set of authorized types for role */ };struct role_trans_key { -u32 role;/* current role */ -u32 type;/* program executable type, or new object type */ -u32 tclass;/* process class, or new object class */ +u32 role;/* current role */ +u32 type;/* program executable type, or new object type */ +u32 tclass;/* process class, or new object class */ };struct role_trans_datum { -u32 new_role;/* new role */ +u32 new_role;/* new role */ };struct filename_trans_key { -u32 ttype;/* parent dir context */ -u16 tclass;/* class of new object */ -const char *name;/* last path component */ +u32 ttype;/* parent dir context */ +u16 tclass;/* class of new object */ +const char *name;/* last path component */ };struct filename_trans_datum { -struct ebitmap stypes;/* bitmap of source types for this otype */ -u32 otype;/* resulting type of new object */ -struct filename_trans_datum *next;/* record for next otype*/ +struct ebitmap stypes;/* bitmap of source types for this otype */ +u32 otype;/* resulting type of new object */ +struct filename_trans_datum *next;/* record for next otype*/ };struct role_allow { -u32 role;/* current role */ -u32 new_role;/* new role */ +u32 role;/* current role */ +u32 new_role;/* new role */ struct role_allow *next; };/* Type attributes */ struct type_datum { -u32 value;/* internal type value */ -u32 bounds;/* boundary of type */ -unsigned char primary;/* primary name? */ -unsigned char attribute;/* attribute ?*/ +u32 value;/* internal type value */ +u32 bounds;/* boundary of type */ +unsigned char primary;/* primary name? */ +unsigned char attribute;/* attribute ?*/ };/* User attributes */ struct user_datum { -u32 value;/* internal user value */ -u32 bounds;/* bounds of user */ -struct ebitmap roles;/* set of authorized roles for user */ -struct mls_range range;/* MLS range (min - max) for user */ -struct mls_level dfltlevel;/* default login MLS level for user */ +u32 value;/* internal user value */ +u32 bounds;/* bounds of user */ +struct ebitmap roles;/* set of authorized roles for user */ +struct mls_range range;/* MLS range (min - max) for user */ +struct mls_level dfltlevel;/* default login MLS level for user */ }; -/* Sensitivity attributes */ struct level_datum { -struct mls_level *level;/* sensitivity and associated categories */ -unsigned char isalias;/* is this sensitivity an alias for another? */ +struct mls_level *level;/* sensitivity and associated categories */ +unsigned char isalias;/* is this sensitivity an alias for another? */ };/* Category attributes */ struct cat_datum { -u32 value;/* internal category bit + 1 */ -unsigned char isalias;/* is this category an alias for another? */ +u32 value;/* internal category bit + 1 */ +unsigned char isalias;/* is this category an alias for another? */ };struct range_trans {
@@ -147,7 +144,7 @@ struct range_trans {/* Boolean data type */ struct cond_bool_datum { -__u32 value;/* internal type value */ +__u32 value;/* internal type value */ int state; };
@@ -173,20 +170,20 @@ struct type_set {*/ struct ocontext { union { - char *name; /* name of initial SID, fs, netif, fstype, path */ + char *name; /* name of initial SID, fs, netif, fstype, path */ struct { u8 protocol; u16 low_port; u16 high_port; - } port; /* TCP or UDP port information */ + } port; /* TCP or UDP port information */ struct { u32 addr; u32 mask; - } node; /* node information */ + } node; /* node information */ struct { u32 addr[4]; u32 mask[4]; - } node6; /* IPv6 node information */ + } node6; /* IPv6 node information */ struct { u64 subnet_prefix; u16 low_pkey;
@@ -198,11 +195,11 @@ struct ocontext { } ibendport; } u;union { -u32 sclass;/* security class for genfs */ -u32 behavior;/* labeling behavior for fs_use */ +u32 sclass;/* security class for genfs */ +u32 behavior;/* labeling behavior for fs_use */ } v; -struct context context[2 ];/* security context(s) */ -u32 sid[2 ];/* SID(s) */ +struct context context[2 ];/* security context(s) */ +u32 sid[2 ];/* SID(s) */ struct ocontext *next; };
@@ -221,19 +218,19 @@ struct genfs {#define SYM_BOOLS 5#define SYM_LEVELS 6#define SYM_CATS 7 -#define SYM_NUM 8 +#define SYM_NUM 8/* object context array indices */ -#define OCON_ISID 0/* initial SIDs */ -#define OCON_FS 1/* unlabeled file systems (deprecated) */ -#define OCON_PORT 2/* TCP and UDP port numbers */ -#define OCON_NETIF 3/* network interfaces */ -#define OCON_NODE 4/* nodes */ -#define OCON_FSUSE 5/* fs_use */ -#define OCON_NODE6 6/* IPv6 nodes */ -#define OCON_IBPKEY 7/* Infiniband PKeys */ -#define OCON_IBENDPORT 8/* Infiniband end ports */ -#define OCON_NUM 9 +#define OCON_ISID 0/* initial SIDs */ +#define OCON_FS 1/* unlabeled file systems (deprecated) */ +#define OCON_PORT 2/* TCP and UDP port numbers */ +#define OCON_NETIF 3/* network interfaces */ +#define OCON_NODE 4/* nodes */ +#define OCON_FSUSE 5/* fs_use */ +#define OCON_NODE6 6/* IPv6 nodes */ +#define OCON_IBPKEY 7/* Infiniband PKeys */ +#define OCON_IBENDPORT 8/* Infiniband end ports */ +#define OCON_NUM 9/* The policy database */ struct policydb {
@@ -243,15 +240,15 @@ struct policydb {struct symtab symtab[SYM_NUM ];#define p_commons symtab[SYM_COMMONS]#define p_classes symtab[SYM_CLASSES] -#define p_roles symtab[SYM_ROLES] -#define p_types symtab[SYM_TYPES] -#define p_users symtab[SYM_USERS] -#define p_bools symtab[SYM_BOOLS] -#define p_levels symtab[SYM_LEVELS] -#define p_cats symtab[SYM_CATS] +#define p_roles symtab[SYM_ROLES] +#define p_types symtab[SYM_TYPES] +#define p_users symtab[SYM_USERS] +#define p_bools symtab[SYM_BOOLS] +#define p_levels symtab[SYM_LEVELS] +#define p_cats symtab[SYM_CATS]/* symbol names indexed by (value - 1) */ -char **sym_val_to_name[SYM_NUM ]; +char **sym_val_to_name[SYM_NUM ];/* class, role, and user attributes indexed by (value - 1) */ struct class_datum **class_val_to_struct;
@@ -324,25 +321,25 @@ extern int policydb_role_isvalid(structextern int policydb_read (struct policydb *p,void *fp);extern int policydb_write (struct policydb *p,void *fp); -extern struct filename_trans_datum *policydb_filenametr_search ( -struct policydb *p,struct filename_trans_key *key); +extern struct filename_trans_datum * +policydb_filenametr_search (struct policydb *p,struct filename_trans_key *key); -extern struct mls_range *policydb_rangetr_search ( -struct policydb *p,struct range_trans *key); +extern struct mls_range *policydb_rangetr_search (struct policydb *p, +struct range_trans *key); -extern struct role_trans_datum *policydb_roletr_search ( -struct policydb *p,struct role_trans_key *key); +extern struct role_trans_datum * +policydb_roletr_search (struct policydb *p,struct role_trans_key *key); -#define POLICYDB_CONFIG_MLS 1 +#define POLICYDB_CONFIG_MLS 1/* the config flags related to unknown classes/perms are bits 2 and 3 */ -#define REJECT_UNKNOWN 0x00000002 -#define ALLOW_UNKNOWN 0x00000004 +#define REJECT_UNKNOWN 0x00000002 +#define ALLOW_UNKNOWN 0x00000004 -#define OBJECT_R "object_r" +#define OBJECT_R "object_r"#define OBJECT_R_VAL 1 -#define POLICYDB_MAGIC SELINUX_MAGIC +#define POLICYDB_MAGIC SELINUX_MAGIC#define POLICYDB_STRING "SE Linux"struct policy_file {
@@ -366,7 +363,8 @@ static inline int next_entry(void *buf,return 0 ; } -static inline int put_entry (const void *buf,size_t bytes,size_t num,struct policy_file *fp) +static inline int put_entry (const void *buf,size_t bytes,size_t num, +struct policy_file *fp) {size_t len;
@@ -382,7 +380,8 @@ static inline int put_entry(const void *return 0 ; } -static inline char *sym_name (struct policydb *p,unsigned int sym_num,unsigned int element_nr) +static inline char *sym_name (struct policydb *p,unsigned int sym_num, +unsigned int element_nr) {return p->sym_val_to_name[sym_num][element_nr]; }
@@ -390,5 +389,4 @@ static inline char *sym_name(struct poliextern u16 string_to_security_class (struct policydb *p,const char *name);extern u32 string_to_av_perm (struct policydb *p,u16 tclass,const char *name); -#endif /* _SS_POLICYDB_H_ */ - +#endif /* _SS_POLICYDB_H_ */
Greg Kroah-Hartman
maintainerPATCH 74/87 selinux: fix style issues in security/selinux/ss/policydb.c
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paul Moore <[email protected]>
[ Upstream commit ec12c6ee2ae643693902013f50cade6764eae75c ]
As part of on ongoing effort to perform more automated testing and provide more tools for individual developers to validate their patches before submitting, we are trying to make our code "clang-format clean". My hope is that once we have fixed all of our style "quirks", developers will be able to run clang-format on their patches to help avoid silly formatting problems and ensure their changes fit in well with the rest of the SELinux kernel code.
Stable-dep-of: b98a8ac50775 ("selinux: require a class's permission values to cover its permission count")
--- security/selinux/ss/policydb.c | 388 +++++++++++++++++++++-------------------- 1 file changed, 202 insertions(+), 186 deletions(-)
security/selinux/ss/policydb.c +202 -186
@@ -7,25 +7,21 @@/* * Updated: Trusted Computer Solutions, Inc. <[email protected]> +* Support for enhanced MLS infrastructure. +* Copyright (C) 2004-2005 Trusted Computer Solutions, Inc. * -* Support for enhanced MLS infrastructure. -* -* Updated: Frank Mayer <[email protected]> and Karl MacMillan <[email protected]> -* -* Added conditional policy language extensions +* Updated: Frank Mayer <[email protected]> and +* Karl MacMillan <[email protected]> +* Added conditional policy language extensions +* Copyright (C) 2003-2004 Tresys Technology, LLC * * Updated: Hewlett-Packard <[email protected]> -* -* Added support for the policy capability bitmap +* Added support for the policy capability bitmap +* Copyright (C) 2007 Hewlett-Packard Development Company, L.P. * * Update: Mellanox Techonologies -* -* Added Infiniband support -* -* Copyright (C) 2016 Mellanox Techonologies -* Copyright (C) 2007 Hewlett-Packard Development Company, L.P. -* Copyright (C) 2004-2005 Trusted Computer Solutions, Inc. -* Copyright (C) 2003 - 2004 Tresys Technology, LLC +* Added Infiniband support +* Copyright (C) 2016 Mellanox Techonologies */ #include <linux/kernel.h>
@@ -42,6 +38,7 @@#include "services.h" #ifdef CONFIG_SECURITY_SELINUX_DEBUG +/* clang-format off */ static const char *const symtab_name[SYM_NUM ] = {"common prefixes" , "classes",
@@ -52,6 +49,7 @@ static const char *const symtab_name[SYM"levels" , "categories", }; +/* clang-format off */ #endif struct policydb_compat_info {
@@ -63,103 +61,104 @@ struct policydb_compat_info {/* These need to be updated if SYM_NUM or OCON_NUM changes */ static const struct policydb_compat_info policydb_compat[] = { { - .version =POLICYDB_VERSION_BASE , - .sym_num =SYM_NUM -3 , - .ocon_num =OCON_NUM -3 , + .version =POLICYDB_VERSION_BASE , + .sym_num =SYM_NUM -3 , + .ocon_num =OCON_NUM -3 , }, { - .version =POLICYDB_VERSION_BOOL , - .sym_num =SYM_NUM -2 , - .ocon_num =OCON_NUM -3 , + .version =POLICYDB_VERSION_BOOL , + .sym_num =SYM_NUM -2 , + .ocon_num =OCON_NUM -3 , }, { - .version =POLICYDB_VERSION_IPV6 , - .sym_num =SYM_NUM -2 , - .ocon_num =OCON_NUM -2 , + .version =POLICYDB_VERSION_IPV6 , + .sym_num =SYM_NUM -2 , + .ocon_num =OCON_NUM -2 , }, { - .version =POLICYDB_VERSION_NLCLASS , - .sym_num =SYM_NUM -2 , - .ocon_num =OCON_NUM -2 , + .version =POLICYDB_VERSION_NLCLASS , + .sym_num =SYM_NUM -2 , + .ocon_num =OCON_NUM -2 , }, { - .version =POLICYDB_VERSION_MLS , - .sym_num =SYM_NUM , - .ocon_num =OCON_NUM -2 , + .version =POLICYDB_VERSION_MLS , + .sym_num =SYM_NUM , + .ocon_num =OCON_NUM -2 , }, { - .version =POLICYDB_VERSION_AVTAB , - .sym_num =SYM_NUM , - .ocon_num =OCON_NUM -2 , + .version =POLICYDB_VERSION_AVTAB , + .sym_num =SYM_NUM , + .ocon_num =OCON_NUM -2 , }, { - .version =POLICYDB_VERSION_RANGETRANS , - .sym_num =SYM_NUM , - .ocon_num =OCON_NUM -2 , + .version =POLICYDB_VERSION_RANGETRANS , + .sym_num =SYM_NUM , + .ocon_num =OCON_NUM -2 , }, { - .version =POLICYDB_VERSION_POLCAP , - .sym_num =SYM_NUM , - .ocon_num =OCON_NUM -2 , + .version =POLICYDB_VERSION_POLCAP , + .sym_num =SYM_NUM , + .ocon_num =OCON_NUM -2 , }, { - .version =POLICYDB_VERSION_PERMISSIVE , - .sym_num =SYM_NUM , - .ocon_num =OCON_NUM -2 , + .version =POLICYDB_VERSION_PERMISSIVE , + .sym_num =SYM_NUM , + .ocon_num =OCON_NUM -2 , }, { - .version =POLICYDB_VERSION_BOUNDARY , - .sym_num =SYM_NUM , - .ocon_num =OCON_NUM -2 , + .version =POLICYDB_VERSION_BOUNDARY , + .sym_num =SYM_NUM , + .ocon_num =OCON_NUM -2 , }, { - .version =POLICYDB_VERSION_FILENAME_TRANS , - .sym_num =SYM_NUM , - .ocon_num =OCON_NUM -2 , + .version =POLICYDB_VERSION_FILENAME_TRANS , + .sym_num =SYM_NUM , + .ocon_num =OCON_NUM -2 , }, { - .version =POLICYDB_VERSION_ROLETRANS , - .sym_num =SYM_NUM , - .ocon_num =OCON_NUM -2 , + .version =POLICYDB_VERSION_ROLETRANS , + .sym_num =SYM_NUM , + .ocon_num =OCON_NUM -2 , }, { - .version =POLICYDB_VERSION_NEW_OBJECT_DEFAULTS , - .sym_num =SYM_NUM , - .ocon_num =OCON_NUM -2 , + .version =POLICYDB_VERSION_NEW_OBJECT_DEFAULTS , + .sym_num =SYM_NUM , + .ocon_num =OCON_NUM -2 , }, { - .version =POLICYDB_VERSION_DEFAULT_TYPE , - .sym_num =SYM_NUM , - .ocon_num =OCON_NUM -2 , + .version =POLICYDB_VERSION_DEFAULT_TYPE , + .sym_num =SYM_NUM , + .ocon_num =OCON_NUM -2 , }, { - .version =POLICYDB_VERSION_CONSTRAINT_NAMES , - .sym_num =SYM_NUM , - .ocon_num =OCON_NUM -2 , + .version =POLICYDB_VERSION_CONSTRAINT_NAMES , + .sym_num =SYM_NUM , + .ocon_num =OCON_NUM -2 , }, { - .version =POLICYDB_VERSION_XPERMS_IOCTL , - .sym_num =SYM_NUM , - .ocon_num =OCON_NUM -2 , + .version =POLICYDB_VERSION_XPERMS_IOCTL , + .sym_num =SYM_NUM , + .ocon_num =OCON_NUM -2 , }, { - .version =POLICYDB_VERSION_INFINIBAND , - .sym_num =SYM_NUM , - .ocon_num =OCON_NUM , + .version =POLICYDB_VERSION_INFINIBAND , + .sym_num =SYM_NUM , + .ocon_num =OCON_NUM , }, { - .version =POLICYDB_VERSION_GLBLUB , - .sym_num =SYM_NUM , - .ocon_num =OCON_NUM , + .version =POLICYDB_VERSION_GLBLUB , + .sym_num =SYM_NUM , + .ocon_num =OCON_NUM , }, { - .version =POLICYDB_VERSION_COMP_FTRANS , - .sym_num =SYM_NUM , - .ocon_num =OCON_NUM , + .version =POLICYDB_VERSION_COMP_FTRANS , + .sym_num =SYM_NUM , + .ocon_num =OCON_NUM , }, }; -static const struct policydb_compat_info *policydb_lookup_compat (unsigned int version) +static const struct policydb_compat_info * +policydb_lookup_compat (unsigned int version) {unsigned int i;
@@ -312,7 +311,8 @@ static int cat_destroy(void *key, void *return 0 ; } -static int (*const destroy_f[SYM_NUM ]) (void *key,void *datum,void *datap) = { +/* clang-format off */ +static int (*const destroy_f[SYM_NUM ])(void *key,void *datum,void *datap) = { common_destroy, cls_destroy, role_destroy,
@@ -322,6 +322,7 @@ static int (*const destroy_f[SYM_NUM]) ( sens_destroy, cat_destroy, }; +/* clang-format on */ static int filenametr_destroy (void *key,void *datum,void *p) {
@@ -366,8 +367,8 @@ static void ocontext_destroy(struct oconcontext_destroy (&c->context[0 ]);context_destroy (&c->context[1 ]); -if (i ==OCON_ISID || i ==OCON_FS || - i ==OCON_NETIF || i ==OCON_FSUSE ) +if (i ==OCON_ISID || i ==OCON_FS || i ==OCON_NETIF || + i ==OCON_FSUSE )kfree (c->u.name);kfree (c); }
@@ -436,7 +437,6 @@ static int filenametr_cmp(const void *k1return v;return strcmp (ft1->name, ft2->name); - }static const struct hashtab_key_params filenametr_key_params = {
@@ -444,8 +444,8 @@ static const struct hashtab_key_params f .cmp = filenametr_cmp, }; -struct filename_trans_datum *policydb_filenametr_search ( -struct policydb *p,struct filename_trans_key *key) +struct filename_trans_datum * +policydb_filenametr_search (struct policydb *p,struct filename_trans_key *key) {return hashtab_search (&p->filename_trans, key, filenametr_key_params); }
@@ -455,7 +455,7 @@ static u32 rangetr_hash(const void *k)const struct range_trans *key = k;return key->source_type + (key->target_type <<3 ) + - (key->target_class <<5 ); + (key->target_class <<5 ); }static int rangetr_cmp (const void *k1,const void *k2)
@@ -583,9 +583,8 @@ static int role_index(void *key, void *d role = datum; p = datap; -if (!role->value - || role->value > p->p_roles.nprim - || role->bounds > p->p_roles.nprim) +if (!role->value || role->value > p->p_roles.nprim || + role->bounds > p->p_roles.nprim)return -EINVAL ; p->sym_val_to_name[SYM_ROLES ][role->value -1 ] = key;
@@ -602,9 +601,8 @@ static int type_index(void *key, void *d p = datap;if (typdatum->primary) { -if (!typdatum->value - || typdatum->value > p->p_types.nprim - || typdatum->bounds > p->p_types.nprim) +if (!typdatum->value || typdatum->value > p->p_types.nprim || + typdatum->bounds > p->p_types.nprim)return -EINVAL ; p->sym_val_to_name[SYM_TYPES ][typdatum->value -1 ] = key; p->type_val_to_struct[typdatum->value -1 ] = typdatum;
@@ -620,9 +618,8 @@ static int user_index(void *key, void *d usrdatum = datum; p = datap; -if (!usrdatum->value - || usrdatum->value > p->p_users.nprim - || usrdatum->bounds > p->p_users.nprim) +if (!usrdatum->value || usrdatum->value > p->p_users.nprim || + usrdatum->bounds > p->p_users.nprim)return -EINVAL ; p->sym_val_to_name[SYM_USERS ][usrdatum->value -1 ] = key;
@@ -667,7 +664,8 @@ static int cat_index(void *key, void *dareturn 0 ; } -static int (*const index_f[SYM_NUM ]) (void *key,void *datum,void *datap) = { +/* clang-format off */ +static int (*const index_f[SYM_NUM ])(void *key,void *datum,void *datap) = { common_index, class_index, role_index,
@@ -677,6 +675,7 @@ static int (*const index_f[SYM_NUM]) (vo sens_index, cat_index, }; +/* clang-format on */ #ifdef CONFIG_SECURITY_SELINUX_DEBUG static void hash_eval (struct hashtab *h,const char *hash_name)
@@ -684,9 +683,9 @@ static void hash_eval(struct hashtab *h,struct hashtab_info info;hashtab_stat (h, &info); -pr_debug ("SELinux: %s: %d entries and %d/%d buckets used, longest chain length %d\n" , - hash_name, h->nel, info.slots_used, h->size, - info.max_chain_len); +pr_debug ( +"SELinux: %s: %d entries and %d/%d buckets used, longest chain length %d\n" , + hash_name, h->nel, info.slots_used, h->size, info.max_chain_len); }static void symtab_hash_eval (struct symtab *s)
@@ -718,16 +717,17 @@ static int policydb_index(struct policydu32 v;if (p->mls_enabled) -pr_debug ("SELinux: %d users, %d roles, %d types, %d bools, %d sens, %d cats\n" , - p->p_users.nprim, p->p_roles.nprim, p->p_types.nprim, - p->p_bools.nprim, p->p_levels.nprim, p->p_cats.nprim); +pr_debug ( +"SELinux: %d users, %d roles, %d types, %d bools, %d sens, %d cats\n" , + p->p_users.nprim, p->p_roles.nprim, p->p_types.nprim, + p->p_bools.nprim, p->p_levels.nprim, p->p_cats.nprim);else pr_debug ("SELinux: %d users, %d roles, %d types, %d bools\n" , p->p_users.nprim, p->p_roles.nprim, p->p_types.nprim, p->p_bools.nprim); -pr_debug ("SELinux: %d classes, %d rules\n" , - p->p_classes.nprim, p->te_avtab.nel); +pr_debug ("SELinux: %d classes, %d rules\n" , p->p_classes.nprim, + p->te_avtab.nel);avtab_hash_eval (&p->te_avtab,"rules" );symtab_hash_eval (p->symtab);
@@ -738,21 +738,18 @@ static int policydb_index(struct policydif (!p->class_val_to_struct)return -ENOMEM ; - p->role_val_to_struct =kcalloc (p->p_roles.nprim, -sizeof (*p->role_val_to_struct), -GFP_KERNEL ); + p->role_val_to_struct =kcalloc ( + p->p_roles.nprim,sizeof (*p->role_val_to_struct),GFP_KERNEL );if (!p->role_val_to_struct)return -ENOMEM ; - p->user_val_to_struct =kcalloc (p->p_users.nprim, -sizeof (*p->user_val_to_struct), -GFP_KERNEL ); + p->user_val_to_struct =kcalloc ( + p->p_users.nprim,sizeof (*p->user_val_to_struct),GFP_KERNEL );if (!p->user_val_to_struct)return -ENOMEM ; - p->type_val_to_struct =kvcalloc (p->p_types.nprim, -sizeof (*p->type_val_to_struct), -GFP_KERNEL ); + p->type_val_to_struct =kvcalloc ( + p->p_types.nprim,sizeof (*p->type_val_to_struct),GFP_KERNEL );if (!p->type_val_to_struct)return -ENOMEM ;
@@ -762,8 +759,7 @@ static int policydb_index(struct policydfor (i =0 ; i <SYM_NUM ; i++) { p->sym_val_to_name[i] =kvcalloc (p->symtab[i].nprim, -sizeof (char *), -GFP_KERNEL ); +sizeof (char *),GFP_KERNEL );if (!p->sym_val_to_name[i])return -ENOMEM ;
@@ -1046,8 +1042,7 @@ out:* Read and validate a security context structure * from a policydb binary representation file. */ -static int context_read_and_validate (struct context *c, -struct policydb *p, +static int context_read_and_validate (struct context *c,struct policydb *p,void *fp) {__le32 buf[3 ];
@@ -1210,10 +1205,8 @@ static int type_set_read(struct type_setreturn 0 ; } - -static int read_cons_helper (struct policydb *p, -struct constraint_node **nodep, -u32 ncons,int allowxtarget,void *fp) +static int read_cons_helper (struct policydb *p,struct constraint_node **nodep, +u32 ncons,int allowxtarget,void *fp) {struct constraint_node *c, *lc;struct constraint_expr *e, *le;
@@ -1283,8 +1276,9 @@ static int read_cons_helper(struct policreturn rc;if (p->policyvers >=POLICYDB_VERSION_CONSTRAINT_NAMES ) { - e->type_names =kzalloc (sizeof - (*e->type_names),GFP_KERNEL ); + e->type_names = +kzalloc (sizeof (*e->type_names), +GFP_KERNEL );if (!e->type_names)return -ENOMEM ;type_set_init (e->type_names);
@@ -1318,7 +1312,7 @@ static int class_read(struct policydb *pif (!cladatum)return -ENOMEM ; - rc =next_entry (buf, fp,sizeof (u32)*6 ); + rc =next_entry (buf, fp,sizeof (u32) *6 );if (rc) goto bad;
@@ -1344,8 +1338,8 @@ static int class_read(struct policydb *p goto bad; rc = -EINVAL ; - cladatum->comdatum =symtab_search (&p->p_commons, - cladatum->comkey); + cladatum->comdatum = +symtab_search (&p->p_commons, cladatum->comkey);if (!cladatum->comdatum) {pr_err ("SELinux: unknown common %s\n" , cladatum->comkey);
@@ -1380,8 +1374,8 @@ static int class_read(struct policydb *pif (rc) goto bad; ncons =le32_to_cpu (buf[0 ]); - rc =read_cons_helper (p, &cladatum->validatetrans, - ncons,1 , fp); + rc =read_cons_helper (p, &cladatum->validatetrans, ncons,1 , + fp);if (rc) goto bad; }
@@ -1518,7 +1512,6 @@ bad:return rc; } -/* * Read a MLS level structure from a policydb binary * representation file.
@@ -1670,8 +1663,9 @@ bad:return rc; } -static int (*const read_f[SYM_NUM ]) (struct policydb *p, -struct symtab *s,void *fp) = { +/* clang-format off */ +static int (*const read_f[SYM_NUM ])(struct policydb *p,struct symtab *s, +void *fp) = { common_read, class_read, role_read,
@@ -1681,6 +1675,7 @@ static int (*const read_f[SYM_NUM]) (str sens_read, cat_read, }; +/* clang-format on */ static int user_bounds_sanity_check (void *key,void *datum,void *datap) {
@@ -1696,12 +1691,13 @@ static int user_bounds_sanity_check(voidif (++depth ==POLICYDB_BOUNDS_MAXDEPTH ) {pr_err ("SELinux: user %s: " "too deep or looped boundary\n" , - (char *) key); + (char *)key);return -EINVAL ; } upper = p->user_val_to_struct[upper->bounds -1 ]; -ebitmap_for_each_positive_bit (&user->roles, node, bit) { +ebitmap_for_each_positive_bit (&user->roles, node, bit) + {if (ebitmap_get_bit (&upper->roles, bit))continue ;
@@ -1732,12 +1728,13 @@ static int role_bounds_sanity_check(voidif (++depth ==POLICYDB_BOUNDS_MAXDEPTH ) {pr_err ("SELinux: role %s: " "too deep or looped bounds\n" , - (char *) key); + (char *)key);return -EINVAL ; } upper = p->role_val_to_struct[upper->bounds -1 ]; -ebitmap_for_each_positive_bit (&role->types, node, bit) { +ebitmap_for_each_positive_bit (&role->types, node, bit) + {if (ebitmap_get_bit (&upper->types, bit))continue ;
@@ -1765,7 +1762,7 @@ static int type_bounds_sanity_check(voidif (++depth ==POLICYDB_BOUNDS_MAXDEPTH ) {pr_err ("SELinux: type %s: " "too deep or looped boundary\n" , - (char *) key); + (char *)key);return -EINVAL ; }
@@ -1775,7 +1772,7 @@ static int type_bounds_sanity_check(voidif (upper->attribute) {pr_err ("SELinux: type %s: " "bounded by attribute %s\n" , - (char *) key, + (char *)key,sym_name (p,SYM_TYPES , upper->value -1 ));return -EINVAL ; }
@@ -1826,7 +1823,7 @@ u32 string_to_av_perm(struct policydb *pif (!tclass || tclass > p->p_classes.nprim)return 0 ; - cladatum = p->class_val_to_struct[tclass-1 ]; + cladatum = p->class_val_to_struct[tclass -1 ]; comdatum = cladatum->comdatum;if (comdatum) perdatum =symtab_search (&comdatum->permissions, name);
@@ -1835,7 +1832,7 @@ u32 string_to_av_perm(struct policydb *pif (!perdatum)return 0 ; -return 1U << (perdatum->value-1 ); +return 1U << (perdatum->value -1 ); }static int range_read (struct policydb *p,void *fp)
@@ -2203,12 +2200,12 @@ static int genfs_read(struct policydb *p goto out; newc->v.sclass =le32_to_cpu (buf[0 ]); - rc =context_read_and_validate (&newc->context[0 ], p, fp); + rc =context_read_and_validate (&newc->context[0 ], p, + fp);if (rc) goto out; -for (l =NULL , c = genfs->head; c; - l = c, c = c->next) { +for (l =NULL , c = genfs->head; c; l = c, c = c->next) { rc = -EINVAL ; if (!strcmp(newc->u.name, c->u.name) && (!c->v.sclass || !newc->v.sclass ||
@@ -2242,8 +2239,8 @@ out:return rc; } -static int ocontext_read (struct policydb *p,const struct policydb_compat_info *info, -void *fp) +static int ocontext_read (struct policydb *p, +const struct policydb_compat_info *info,void *fp) {int rc;unsigned int i;
@@ -2278,7 +2275,8 @@ static int ocontext_read(struct policydb goto out; c->sid[0 ] =le32_to_cpu (buf[0 ]); - rc =context_read_and_validate (&c->context[0 ], p, fp); + rc =context_read_and_validate (&c->context[0 ], + p, fp);if (rc) goto out;break ;
@@ -2297,21 +2295,24 @@ static int ocontext_read(struct policydbpr_warn ("SELinux: void and deprecated fs ocon %s\n" , c->u.name); - rc =context_read_and_validate (&c->context[0 ], p, fp); + rc =context_read_and_validate (&c->context[0 ], + p, fp);if (rc) goto out; - rc =context_read_and_validate (&c->context[1 ], p, fp); + rc =context_read_and_validate (&c->context[1 ], + p, fp);if (rc) goto out;break ;case OCON_PORT : - rc =next_entry (buf, fp,sizeof (u32)*3 ); + rc =next_entry (buf, fp,sizeof (u32) *3 );if (rc) goto out; c->u.port.protocol =le32_to_cpu (buf[0 ]); c->u.port.low_port =le32_to_cpu (buf[1 ]); c->u.port.high_port =le32_to_cpu (buf[2 ]); - rc =context_read_and_validate (&c->context[0 ], p, fp); + rc =context_read_and_validate (&c->context[0 ], + p, fp);if (rc) goto out;break ;
@@ -2321,12 +2322,13 @@ static int ocontext_read(struct policydb goto out; c->u.node.addr = nodebuf[0 ];/* network order */ c->u.node.mask = nodebuf[1 ];/* network order */ - rc =context_read_and_validate (&c->context[0 ], p, fp); + rc =context_read_and_validate (&c->context[0 ], + p, fp);if (rc) goto out;break ;case OCON_FSUSE : - rc =next_entry (buf, fp,sizeof (u32)*2 ); + rc =next_entry (buf, fp,sizeof (u32) *2 );if (rc) goto out;
@@ -2343,7 +2345,8 @@ static int ocontext_read(struct policydbif (rc) goto out; - rc =context_read_and_validate (&c->context[0 ], p, fp); + rc =context_read_and_validate (&c->context[0 ], + p, fp);if (rc) goto out;break ;
@@ -2356,8 +2359,9 @@ static int ocontext_read(struct policydbfor (k =0 ; k <4 ; k++) c->u.node6.addr[k] = nodebuf[k];for (k =0 ; k <4 ; k++) - c->u.node6.mask[k] = nodebuf[k+4 ]; - rc =context_read_and_validate (&c->context[0 ], p, fp); + c->u.node6.mask[k] = nodebuf[k +4 ]; + rc =context_read_and_validate (&c->context[0 ], + p, fp);if (rc) goto out;break ;
@@ -2370,7 +2374,8 @@ static int ocontext_read(struct policydb goto out;/* we need to have subnet_prefix in CPU order */ - c->u.ibpkey.subnet_prefix =be64_to_cpu (prefixbuf[0 ]); + c->u.ibpkey.subnet_prefix = +be64_to_cpu (prefixbuf[0 ]); rc =next_entry (buf, fp,sizeof (u32) *2 );if (rc)
@@ -2384,12 +2389,11 @@ static int ocontext_read(struct policydb goto out; } - c->u.ibpkey.low_pkey = pkey_lo; + c->u.ibpkey.low_pkey = pkey_lo; c->u.ibpkey.high_pkey = pkey_hi; rc =context_read_and_validate (&c->context[0 ], - p, - fp); + p, fp);if (rc) goto out;break ;
@@ -2402,7 +2406,8 @@ static int ocontext_read(struct policydb goto out; len =le32_to_cpu (buf[0 ]); - rc =str_read (&c->u.ibendport.dev_name,GFP_KERNEL , fp, len); + rc =str_read (&c->u.ibendport.dev_name, +GFP_KERNEL , fp, len);if (rc) goto out;
@@ -2415,8 +2420,7 @@ static int ocontext_read(struct policydb c->u.ibendport.port = port; rc =context_read_and_validate (&c->context[0 ], - p, - fp); + p, fp);if (rc) goto out;break ;
@@ -2473,7 +2477,8 @@ int policydb_read(struct policydb *p, vo policydb_str =kmalloc (len +1 ,GFP_KERNEL );if (!policydb_str) {pr_err ("SELinux: unable to allocate memory for policydb " -"string of length %d\n" , len); +"string of length %d\n" , + len); goto bad; }
@@ -2488,7 +2493,8 @@ int policydb_read(struct policydb *p, vo policydb_str[len] ='\0' ;if (strcmp (policydb_str,POLICYDB_STRING )) {pr_err ("SELinux: policydb string %s does not match " -"my string %s\n" , policydb_str,POLICYDB_STRING ); +"my string %s\n" , + policydb_str,POLICYDB_STRING );kfree (policydb_str); goto bad; }
@@ -2497,7 +2503,7 @@ int policydb_read(struct policydb *p, vo policydb_str =NULL ;/* Read the version and table sizes. */ - rc =next_entry (buf, fp,sizeof (u32)*4 ); + rc =next_entry (buf, fp,sizeof (u32) *4 );if (rc) goto bad;
@@ -2507,7 +2513,8 @@ int policydb_read(struct policydb *p, vo p->policyvers > POLICYDB_VERSION_MAX) {pr_err ("SELinux: policydb version %d does not match " "my version range %d-%d\n" , -le32_to_cpu (buf[0 ]),POLICYDB_VERSION_MIN ,POLICYDB_VERSION_MAX ); +le32_to_cpu (buf[0 ]),POLICYDB_VERSION_MIN , +POLICYDB_VERSION_MAX ); goto bad; }
@@ -2517,8 +2524,8 @@ int policydb_read(struct policydb *p, vo rc = -EINVAL ;if (p->policyvers <POLICYDB_VERSION_MLS ) {pr_err ("SELinux: security policydb version %d " -"(MLS) not backwards compatible\n" , - p->policyvers); +"(MLS) not backwards compatible\n" , + p->policyvers); goto bad; } }
@@ -2541,22 +2548,23 @@ int policydb_read(struct policydb *p, vo info =policydb_lookup_compat (p->policyvers);if (!info) {pr_err ("SELinux: unable to find policy compat info " -"for version %d\n" , p->policyvers); +"for version %d\n" , + p->policyvers); goto bad; } rc = -EINVAL ;if (le32_to_cpu (buf[2 ]) != info->sym_num || -le32_to_cpu (buf[3 ]) != info->ocon_num) { +le32_to_cpu (buf[3 ]) != info->ocon_num) {pr_err ("SELinux: policydb table sizes (%d,%d) do " -"not match mine (%d,%d)\n" ,le32_to_cpu (buf[2 ]), -le32_to_cpu (buf[3 ]), - info->sym_num, info->ocon_num); +"not match mine (%d,%d)\n" , +le32_to_cpu (buf[2 ]),le32_to_cpu (buf[3 ]), info->sym_num, + info->ocon_num); goto bad; }for (i =0 ; i < info->sym_num; i++) { - rc =next_entry (buf, fp,sizeof (u32)*2 ); + rc =next_entry (buf, fp,sizeof (u32) *2 );if (rc) goto bad; nprim =le32_to_cpu (buf[0 ]);
@@ -2617,7 +2625,7 @@ int policydb_read(struct policydb *p, voif (!rtd) goto bad; - rc =next_entry (buf, fp,sizeof (u32)*3 ); + rc =next_entry (buf, fp,sizeof (u32) *3 );if (rc) goto bad;
@@ -2661,7 +2669,7 @@ int policydb_read(struct policydb *p, vo lra->next = ra; else p->role_allow = ra; - rc =next_entry (buf, fp,sizeof (u32)*2 ); + rc =next_entry (buf, fp,sizeof (u32) *2 );if (rc) goto bad;
@@ -2709,9 +2717,8 @@ int policydb_read(struct policydb *p, vo goto bad; rc = -ENOMEM ; - p->type_attr_map_array =kvcalloc (p->p_types.nprim, -sizeof (*p->type_attr_map_array), -GFP_KERNEL ); + p->type_attr_map_array =kvcalloc ( + p->p_types.nprim,sizeof (*p->type_attr_map_array),GFP_KERNEL );if (!p->type_attr_map_array) goto bad;
@@ -2784,7 +2791,7 @@ static int mls_write_range_helper(struct items =2 ; else items =3 ; - buf[0 ] =cpu_to_le32 (items-1 ); + buf[0 ] =cpu_to_le32 (items -1 ); buf[1 ] =cpu_to_le32 (r->level[0 ].sens);if (!eq) buf[2 ] =cpu_to_le32 (r->level[1 ].sens);
@@ -2927,8 +2934,7 @@ static int role_allow_write(struct role_* Write a security context structure * to a policydb binary representation file. */ -static int context_write (struct policydb *p,struct context *c, -void *fp) +static int context_write (struct policydb *p,struct context *c,void *fp) {int rc;__le32 buf[3 ];
@@ -3056,7 +3062,7 @@ static int write_cons_helper(struct poliif (rc)return rc;if (p->policyvers >= -POLICYDB_VERSION_CONSTRAINT_NAMES ) { +POLICYDB_VERSION_CONSTRAINT_NAMES ) { rc =type_set_write (e->type_names, fp);if (rc)return rc;
@@ -3277,7 +3283,8 @@ static int user_write(void *vkey, void *return 0 ; } -static int (*const write_f[SYM_NUM ]) (void *key,void *datum,void *datap) = { +/* clang-format off */ +static int (*const write_f[SYM_NUM ])(void *key,void *datum,void *datap) = { common_write, class_write, role_write,
@@ -3287,9 +3294,10 @@ static int (*const write_f[SYM_NUM]) (vo sens_write, cat_write, }; +/* clang-format on */ -static int ocontext_write (struct policydb *p,const struct policydb_compat_info *info, -void *fp) +static int ocontext_write (struct policydb *p, +const struct policydb_compat_info *info,void *fp) {unsigned int i, j;int rc;
@@ -3371,9 +3379,13 @@ static int ocontext_write(struct policydbreak ;case OCON_NODE6 :for (j =0 ; j <4 ; j++) - nodebuf[j] = c->u.node6.addr[j];/* network order */ + nodebuf[j] = + c->u.node6.addr + [j];/* network order */ for (j =0 ; j <4 ; j++) - nodebuf[j +4 ] = c->u.node6.mask[j];/* network order */ + nodebuf[j +4 ] = + c->u.node6.mask + [j];/* network order */ rc =put_entry (nodebuf,sizeof (u32),8 , fp);if (rc)return rc;
@@ -3383,7 +3395,8 @@ static int ocontext_write(struct policydbreak ;case OCON_IBPKEY :/* subnet_prefix is in CPU order */ - prefixbuf[0 ] =cpu_to_be64 (c->u.ibpkey.subnet_prefix); + prefixbuf[0 ] = +cpu_to_be64 (c->u.ibpkey.subnet_prefix); rc =put_entry (prefixbuf,sizeof (u64),1 , fp);if (rc)
@@ -3406,7 +3419,8 @@ static int ocontext_write(struct policyd rc =put_entry (buf,sizeof (u32),2 , fp);if (rc)return rc; - rc =put_entry (c->u.ibendport.dev_name,1 , len, fp); + rc =put_entry (c->u.ibendport.dev_name,1 , len, + fp);if (rc)return rc; rc =context_write (p, &c->context[0 ], fp);
@@ -3532,7 +3546,8 @@ static int filename_write_helper_compat(u32 bit, len =strlen (ft->name); do { - ebitmap_for_each_positive_bit(&datum->stypes, node, bit) { + ebitmap_for_each_positive_bit(&datum->stypes, node, bit) + { buf[0] = cpu_to_le32(len); rc = put_entry(buf, sizeof(u32), 1, fp); if (rc)
@@ -3656,8 +3671,8 @@ int policydb_write(struct policydb *p, v*/ if (p->policyvers <POLICYDB_VERSION_AVTAB ) {pr_err ("SELinux: refusing to write policy version %d." -" Because it is less than version %d\n" , p->policyvers, -POLICYDB_VERSION_AVTAB ); +" Because it is less than version %d\n" , + p->policyvers,POLICYDB_VERSION_AVTAB );return -EINVAL ; }
@@ -3685,7 +3700,8 @@ int policydb_write(struct policydb *p, v info =policydb_lookup_compat (p->policyvers);if (!info) {pr_err ("SELinux: compatibility lookup failed for policy " -"version %d\n" , p->policyvers); +"version %d\n" , + p->policyvers);return -EINVAL ; }
Greg Kroah-Hartman
maintainerPATCH 75/87 selinux: use known type instead of void pointer
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Göttsche <[email protected]>
[ Upstream commit f07586160fd5492f8d48e7667e7a5d8797aa5090 ]
Improve type safety and readability by using the known type.
Stable-dep-of: b98a8ac50775 ("selinux: require a class's permission values to cover its permission count")
--- security/selinux/ss/avtab.c | 8 +-- security/selinux/ss/avtab.h | 10 ++-- security/selinux/ss/conditional.c | 12 ++--- security/selinux/ss/conditional.h | 6 +- security/selinux/ss/ebitmap.c | 4 - security/selinux/ss/ebitmap.h | 5 +- security/selinux/ss/policydb.c | 91 +++++++++++++++++++------------------- security/selinux/ss/policydb.h | 16 +++--- 8 files changed, 78 insertions(+), 74 deletions(-)
security/selinux/ss/avtab.c +4 -4
@@ -367,7 +367,7 @@ static const uint16_t spec_order[] = { AVTAB_XPERMS_DONTAUDIT }; -int avtab_read_item (struct avtab *a,void *fp,struct policydb *pol, +int avtab_read_item (struct avtab *a,struct policy_file *fp,struct policydb *pol,int (*insertf)(struct avtab *a,const struct avtab_key *k,const struct avtab_datum *d,void *p),void *p)
@@ -535,7 +535,7 @@ static int avtab_insertf(struct avtab *areturn avtab_insert (a, k, d); } -int avtab_read (struct avtab *a,void *fp,struct policydb *pol) +int avtab_read (struct avtab *a,struct policy_file *fp,struct policydb *pol) {int rc;__le32 buf[1 ];
@@ -579,7 +579,7 @@ bad: goto out; } -int avtab_write_item (struct policydb *p,const struct avtab_node *cur,void *fp) +int avtab_write_item (struct policydb *p,const struct avtab_node *cur,struct policy_file *fp) {__le16 buf16[4 ];__le32 buf32[ARRAY_SIZE (cur->datum.u.xperms->perms.p)];
@@ -614,7 +614,7 @@ int avtab_write_item(struct policydb *p,return 0 ; } -int avtab_write (struct policydb *p,struct avtab *a,void *fp) +int avtab_write (struct policydb *p,struct avtab *a,struct policy_file *fp) {u32 i;int rc =0 ;
security/selinux/ss/avtab.h +6 -4
@@ -101,14 +101,16 @@ static inline void avtab_hash_eval(struc#endif struct policydb ; -int avtab_read_item (struct avtab *a,void *fp,struct policydb *pol, +struct policy_file ; +int avtab_read_item (struct avtab *a,struct policy_file *fp,struct policydb *pol,int (*insert)(struct avtab *a,const struct avtab_key *k,const struct avtab_datum *d,void *p),void *p); -int avtab_read (struct avtab *a,void *fp,struct policydb *pol); -int avtab_write_item (struct policydb *p,const struct avtab_node *cur,void *fp); -int avtab_write (struct policydb *p,struct avtab *a,void *fp); +int avtab_read (struct avtab *a,struct policy_file *fp,struct policydb *pol); +int avtab_write_item (struct policydb *p,const struct avtab_node *cur, +struct policy_file *fp); +int avtab_write (struct policydb *p,struct avtab *a,struct policy_file *fp); struct avtab_node *avtab_insert_nonunique(struct avtab *h, const struct avtab_key *key,
security/selinux/ss/conditional.c +6 -6
@@ -205,7 +205,7 @@ static int bool_isvalid(struct cond_boolreturn 1 ; } -int cond_read_bool (struct policydb *p,struct symtab *s,void *fp) +int cond_read_bool (struct policydb *p,struct symtab *s,struct policy_file *fp) {char *key =NULL ;struct cond_bool_datum *booldatum;
@@ -321,7 +321,7 @@ static int cond_insertf(struct avtab *a,return 0 ; } -static int cond_read_av_list (struct policydb *p,void *fp, +static int cond_read_av_list (struct policydb *p,struct policy_file *fp,struct cond_av_list *list,struct cond_av_list *other) {
@@ -373,7 +373,7 @@ static int expr_node_isvalid(struct polireturn 1 ; } -static int cond_read_node (struct policydb *p,struct cond_node *node,void *fp) +static int cond_read_node (struct policydb *p,struct cond_node *node,struct policy_file *fp) {__le32 buf[2 ];u32 i, len;
@@ -413,7 +413,7 @@ static int cond_read_node(struct policydreturn cond_read_av_list (p, fp, &node->false_list, &node->true_list); } -int cond_read_list (struct policydb *p,void *fp) +int cond_read_list (struct policydb *p,struct policy_file *fp) {__le32 buf[1 ];u32 i, len;
@@ -451,7 +451,7 @@ int cond_write_bool(void *vkey, void *dachar *key = vkey;struct cond_bool_datum *booldatum = datum;struct policy_data *pd = ptr; -void *fp = pd->fp; +struct policy_file *fp = pd->fp;__le32 buf[3 ];u32 len;int rc;
@@ -534,7 +534,7 @@ static int cond_write_node(struct policyreturn 0 ; } -int cond_write_list (struct policydb *p,void *fp) +int cond_write_list (struct policydb *p,struct policy_file *fp) {u32 i;__le32 buf[1 ];
security/selinux/ss/conditional.h +3 -3
@@ -69,10 +69,10 @@ int cond_destroy_bool(void *key, void *dint cond_index_bool (void *key,void *datum,void *datap); -int cond_read_bool (struct policydb *p,struct symtab *s,void *fp); -int cond_read_list (struct policydb *p,void *fp); +int cond_read_bool (struct policydb *p,struct symtab *s,struct policy_file *fp); +int cond_read_list (struct policydb *p,struct policy_file *fp);int cond_write_bool (void *key,void *datum,void *ptr); -int cond_write_list (struct policydb *p,void *fp); +int cond_write_list (struct policydb *p,struct policy_file *fp);void cond_compute_av (struct avtab *ctab,struct avtab_key *key,struct av_decision *avd,struct extended_perms *xperms);
security/selinux/ss/ebitmap.c +2 -2
@@ -362,7 +362,7 @@ void ebitmap_destroy(struct ebitmap *e) e->node =NULL ; } -int ebitmap_read (struct ebitmap *e,void *fp) +int ebitmap_read (struct ebitmap *e,struct policy_file *fp) {struct ebitmap_node *n =NULL ;u32 mapunit, count, startbit, index;
@@ -468,7 +468,7 @@ bad: goto out; } -int ebitmap_write (const struct ebitmap *e,void *fp) +int ebitmap_write (const struct ebitmap *e,struct policy_file *fp) {struct ebitmap_node *n;u32 count;
security/selinux/ss/ebitmap.h +3 -2
@@ -129,8 +129,9 @@ int ebitmap_contains(const struct ebitmaint ebitmap_get_bit (const struct ebitmap *e,unsigned long bit);int ebitmap_set_bit (struct ebitmap *e,unsigned long bit,int value);void ebitmap_destroy (struct ebitmap *e); -int ebitmap_read (struct ebitmap *e,void *fp); -int ebitmap_write (const struct ebitmap *e,void *fp); +struct policy_file ; +int ebitmap_read (struct ebitmap *e,struct policy_file *fp); +int ebitmap_write (const struct ebitmap *e,struct policy_file *fp);u32 ebitmap_hash (const struct ebitmap *e,u32 hash);#ifdef CONFIG_NETLABEL
security/selinux/ss/policydb.c +46 -45
361 lines not on this page · raw message
security/selinux/ss/policydb.h +8 -8
@@ -312,14 +312,19 @@ struct policydb {u32 process_trans_perms; } __randomize_layout; +struct policy_file { +char *data; +size_t len; +}; +extern void policydb_destroy (struct policydb *p);extern int policydb_load_isids (struct policydb *p,struct sidtab *s);extern int policydb_context_isvalid (struct policydb *p,struct context *c);extern int policydb_class_isvalid (struct policydb *p,unsigned int class);extern int policydb_type_isvalid (struct policydb *p,unsigned int type);extern int policydb_role_isvalid (struct policydb *p,unsigned int role); -extern int policydb_read (struct policydb *p,void *fp); -extern int policydb_write (struct policydb *p,void *fp); +extern int policydb_read (struct policydb *p,struct policy_file *fp); +extern int policydb_write (struct policydb *p,struct policy_file *fp);extern struct filename_trans_datum *policydb_filenametr_search (struct policydb *p,struct filename_trans_key *key);
@@ -342,14 +347,9 @@ policydb_roletr_search(struct policydb *#define POLICYDB_MAGIC SELINUX_MAGIC#define POLICYDB_STRING "SE Linux" -struct policy_file { -char *data; -size_t len; -}; -struct policy_data {struct policydb *p; -void *fp; +struct policy_file *fp; };static inline int next_entry (void *buf,struct policy_file *fp,size_t bytes)
Greg Kroah-Hartman
maintainerPATCH 76/87 selinux: avoid unnecessary indirection in struct level_datum
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Göttsche <[email protected]>
[ Upstream commit 749153636643aaa793f14e84e864fdaf5ed0620d ]
Store the owned member of type struct mls_level directly in the parent struct instead of an extra heap allocation.
Stable-dep-of: b98a8ac50775 ("selinux: require a class's permission values to cover its permission count")
--- security/selinux/ss/mls.c | 6 +++--- security/selinux/ss/policydb.c | 19 ++++++------------- security/selinux/ss/policydb.h | 2 +- 3 files changed, 10 insertions(+), 17 deletions(-)
security/selinux/ss/mls.c +3 -3
@@ -174,7 +174,7 @@ int mls_level_isvalid(struct policydb *p* levdatum->level->cat and no bit in l->cat is larger than * p->p_cats.nprim. */ -return ebitmap_contains (&levdatum->level->cat, &l->cat, +return ebitmap_contains (&levdatum->level.cat, &l->cat, p->p_cats.nprim); }
@@ -296,7 +296,7 @@ int mls_context_to_sid(struct policydb * levdatum =symtab_search (&pol->p_levels, sensitivity);if (!levdatum)return -EINVAL ; - context->range.level[l].sens = levdatum->level->sens; + context->range.level[l].sens = levdatum->level.sens;/* Extract category set. */ while (next_cat !=NULL ) {
@@ -466,7 +466,7 @@ int mls_convert_context(struct policydbif (!levdatum)return -EINVAL ; - newc->range.level[l].sens = levdatum->level->sens; + newc->range.level[l].sens = levdatum->level.sens;ebitmap_for_each_positive_bit (&oldc->range.level[l].cat, node, i) {
security/selinux/ss/policydb.c +6 -13
@@ -296,9 +296,7 @@ static int sens_destroy(void *key, voidkfree (key);if (datum) { levdatum = datum; -if (levdatum->level) -ebitmap_destroy (&levdatum->level->cat); -kfree (levdatum->level); +ebitmap_destroy (&levdatum->level.cat); }kfree (datum);return 0 ;
@@ -636,11 +634,11 @@ static int sens_index(void *key, void *d p = datap;if (!levdatum->isalias) { -if (!levdatum->level->sens || - levdatum->level->sens > p->p_levels.nprim) +if (!levdatum->level.sens || + levdatum->level.sens > p->p_levels.nprim)return -EINVAL ; - p->sym_val_to_name[SYM_LEVELS ][levdatum->level->sens -1 ] = key; + p->sym_val_to_name[SYM_LEVELS ][levdatum->level.sens -1 ] = key; }return 0 ;
@@ -1612,12 +1610,7 @@ static int sens_read(struct policydb *p,if (rc) goto bad; - rc = -ENOMEM ; - levdatum->level =kmalloc (sizeof (*levdatum->level),GFP_KERNEL ); -if (!levdatum->level) - goto bad; - - rc =mls_read_level (levdatum->level, fp); + rc =mls_read_level (&levdatum->level, fp);if (rc) goto bad;
@@ -2835,7 +2828,7 @@ static int sens_write(void *vkey, void *if (rc)return rc; - rc =mls_write_level (levdatum->level, fp); + rc =mls_write_level (&levdatum->level, fp);if (rc)return rc;
security/selinux/ss/policydb.h +1 -1
@@ -126,7 +126,7 @@ struct user_datum {/* Sensitivity attributes */ struct level_datum { -struct mls_level *level;/* sensitivity and associated categories */ +struct mls_level level;/* sensitivity and associated categories */ unsigned char isalias;/* is this sensitivity an alias for another? */ };
Greg Kroah-Hartman
maintainerPATCH 77/87 selinux: make more use of str_read() when loading the policy
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Göttsche <[email protected]>
[ Upstream commit 01c2253a0fbdccb58cd79d4ff9ab39964bfb4474 ]
Simplify the call sites, and enable future string validation in a single place.
Stable-dep-of: b98a8ac50775 ("selinux: require a class's permission values to cover its permission count")
--- security/selinux/ss/conditional.c | 10 ++-------- security/selinux/ss/policydb.c | 22 ++++++++-------------- security/selinux/ss/policydb.h | 2 ++ 3 files changed, 12 insertions(+), 22 deletions(-)
security/selinux/ss/conditional.c +2 -8
@@ -229,17 +229,11 @@ int cond_read_bool(struct policydb *p, s goto err; len =le32_to_cpu (buf[2 ]); -if (((len ==0 ) || (len == (u32)-1 ))) - goto err; - rc = -ENOMEM ; - key =kmalloc (len +1 ,GFP_KERNEL ); -if (!key) - goto err; - rc =next_entry (key, fp, len); + rc =str_read (&key,GFP_KERNEL , fp, len);if (rc) goto err; - key[len] ='\0' ; + rc =symtab_insert (s, key, booldatum);if (rc) goto err;
security/selinux/ss/policydb.c +8 -14
@@ -1079,7 +1079,7 @@ out:* binary representation file. */ -static int str_read (char **strp,gfp_t flags,struct policy_file *fp,u32 len) +int str_read (char **strp,gfp_t flags,struct policy_file *fp,u32 len) {int rc;char *str;
@@ -2466,24 +2466,18 @@ int policydb_read(struct policydb *p, st goto bad; } - rc = -ENOMEM ; - policydb_str =kmalloc (len +1 ,GFP_KERNEL ); -if (!policydb_str) { -pr_err ("SELinux: unable to allocate memory for policydb " -"string of length %d\n" , - len); - goto bad; - } - - rc =next_entry (policydb_str, fp, len); + rc =str_read (&policydb_str,GFP_KERNEL , fp, len);if (rc) { -pr_err ("SELinux: truncated policydb string identifier\n" ); -kfree (policydb_str); +if (rc == -ENOMEM ) { +pr_err ("SELinux: unable to allocate memory for policydb string of length %d\n" , + len); + }else { +pr_err ("SELinux: truncated policydb string identifier\n" ); + } goto bad; } rc = -EINVAL ; - policydb_str[len] ='\0' ;if (strcmp (policydb_str,POLICYDB_STRING )) { pr_err("SELinux: policydb string %s does not match " "my string %s\n",
security/selinux/ss/policydb.h +2 -0
@@ -386,6 +386,8 @@ static inline char *sym_name(struct polireturn p->sym_val_to_name[sym_num][element_nr]; } +extern int str_read (char **strp,gfp_t flags,struct policy_file *fp,u32 len); +extern u16 string_to_security_class (struct policydb *p,const char *name);extern u32 string_to_av_perm (struct policydb *p,u16 tclass,const char *name);
Greg Kroah-Hartman
maintainerPATCH 78/87 selinux: use u16 for security classes
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Göttsche <[email protected]>
[ Upstream commit fa79a596848fe38c55ccab8832ac35dac07fb00c ]
Security class identifiers are limited to 2^16, thus use the appropriate type u16 consistently.
Stable-dep-of: b98a8ac50775 ("selinux: require a class's permission values to cover its permission count")
--- security/selinux/ss/policydb.c | 5 +++-- security/selinux/ss/policydb.h | 10 +++++----- security/selinux/ss/services.c | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-)
security/selinux/ss/policydb.c +3 -2
@@ -911,7 +911,7 @@ int policydb_load_isids(struct policydbreturn 0 ; } -int policydb_class_isvalid (struct policydb *p,unsigned int class) +int policydb_class_isvalid (struct policydb *p,u16 class) {if (!class || class > p->p_classes.nprim)return 0 ;
@@ -1994,7 +1994,8 @@ static int filename_trans_read_helper(ststruct filename_trans_key *ft =NULL ;struct filename_trans_datum **dst, *datum, *first =NULL ;char *name =NULL ; -u32 len, ttype, tclass, ndatum, i; +u32 len, ttype, ndatum, i; +u16 tclass;__le32 buf[3 ];int rc;
security/selinux/ss/policydb.h +5 -5
@@ -48,7 +48,7 @@ struct common_datum {/* Class attributes */ struct class_datum { -u32 value;/* class value */ +u16 value;/* class value */ char *comkey;/* common name */ struct common_datum *comdatum;/* common datum */ struct symtab permissions;/* class-specific permission symbol table */
@@ -82,7 +82,7 @@ struct role_datum {struct role_trans_key {u32 role;/* current role */ u32 type;/* program executable type, or new object type */ -u32 tclass;/* process class, or new object class */ +u16 tclass;/* process class, or new object class */ };struct role_trans_datum {
@@ -139,7 +139,7 @@ struct cat_datum {struct range_trans {u32 source_type;u32 target_type; -u32 target_class; +u16 target_class; };/* Boolean data type */
@@ -195,7 +195,7 @@ struct ocontext { } ibendport; } u;union { -u32 sclass;/* security class for genfs */ +u16 sclass;/* security class for genfs */ u32 behavior;/* labeling behavior for fs_use */ } v;struct context context[2 ];/* security context(s) */
@@ -320,7 +320,7 @@ struct policy_file {extern void policydb_destroy (struct policydb *p);extern int policydb_load_isids (struct policydb *p,struct sidtab *s);extern int policydb_context_isvalid (struct policydb *p,struct context *c); -extern int policydb_class_isvalid (struct policydb *p,unsigned int class); +extern int policydb_class_isvalid (struct policydb *p,u16 class);extern int policydb_type_isvalid (struct policydb *p,unsigned int type);extern int policydb_role_isvalid (struct policydb *p,unsigned int role);extern int policydb_read (struct policydb *p,struct policy_file *fp);
security/selinux/ss/services.c +1 -1
@@ -3336,7 +3336,7 @@ static int get_classes_callback(void *k, {struct class_datum *datum = d;char *name = k, **classes = args; -u32 value = datum->value -1 ; +u16 value = datum->value -1 ; classes[value] =kstrdup (name,GFP_ATOMIC );if (!classes[value])
Greg Kroah-Hartman
maintainerPATCH 79/87 selinux: more strict policy parsing
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Göttsche <[email protected]>
[ Upstream commit 18fa21f10d008a0fc22565109c7d38f304295912 ]
Be more strict during parsing of policies and reject invalid values.
Add some error messages in the case of policy parse failures, to enhance debugging, either on a malformed policy or a too strict check.
Stable-dep-of: b98a8ac50775 ("selinux: require a class's permission values to cover its permission count")
--- security/selinux/include/security.h | 1 security/selinux/ss/avtab.c | 37 +++++- security/selinux/ss/avtab.h | 13 ++ security/selinux/ss/conditional.c | 18 +-- security/selinux/ss/constraint.h | 1 security/selinux/ss/policydb.c | 196 +++++++++++++++++++++++++++++------- security/selinux/ss/policydb.h | 23 +++- security/selinux/ss/services.c | 6 - 8 files changed, 232 insertions(+), 63 deletions(-)
security/selinux/include/security.h +1 -0
@@ -205,6 +205,7 @@ int security_read_policy(void **data, siint security_read_state_kernel (void **data,size_t *len);int security_policycap_supported (unsigned int req_cap); +/* Maximum supported number of permissions per class */ #define SEL_VEC_MAX 32struct av_decision {u32 allowed;
security/selinux/ss/avtab.c +28 -9
@@ -380,7 +380,7 @@ int avtab_read_item(struct avtab *a, strstruct avtab_extended_perms xperms;__le32 buf32[ARRAY_SIZE (xperms.perms.p)];int rc; -unsigned int set, vers = pol->policyvers; +unsigned int vers = pol->policyvers;memset (&key,0 ,sizeof (struct avtab_key ));memset (&datum,0 ,sizeof (struct avtab_datum ));
@@ -391,9 +391,12 @@ int avtab_read_item(struct avtab *a, strpr_err ("SELinux: avtab: truncated entry\n" );return rc; } +/* Read five or more items: source type, target type, +* target class, AV type, and at least one datum. +*/ items2 =le32_to_cpu (buf32[0 ]); -if (items2 >ARRAY_SIZE (buf32)) { -pr_err ("SELinux: avtab: entry overflow\n" ); +if (items2 <5 || items2 >ARRAY_SIZE (buf32)) { +pr_err ("SELinux: avtab: invalid item count\n" );return -EINVAL ; }
@@ -423,6 +426,13 @@ int avtab_read_item(struct avtab *a, strreturn -EINVAL ; } +if (!policydb_type_isvalid (pol, key.source_type) || + !policydb_type_isvalid (pol, key.target_type) || + !policydb_class_isvalid (pol, key.target_class)) { +pr_err ("SELinux: avtab: invalid type or class\n" ); +return -EINVAL ; + } + val =le32_to_cpu (buf32[items++]); enabled = (val &AVTAB_ENABLED_OLD ) ?AVTAB_ENABLED :0 ;
@@ -442,6 +452,11 @@ int avtab_read_item(struct avtab *a, strfor (i =0 ; i <ARRAY_SIZE (spec_order); i++) {if (val & spec_order[i]) { +if (items >= items2) { +pr_err ("SELinux: avtab: entry has too many items (%d/%d)\n" , + items +1 , items2); +return -EINVAL ; + } key.specified = spec_order[i] | enabled; datum.u.data =le32_to_cpu (buf32[items++]); rc =insertf (a, &key, &datum, p);
@@ -477,13 +492,13 @@ int avtab_read_item(struct avtab *a, strreturn -EINVAL ; } - set =0 ; -for (i =0 ; i <ARRAY_SIZE (spec_order); i++) { -if (key.specified & spec_order[i]) - set++; +if (hweight16 (key.specified & ~AVTAB_ENABLED ) !=1 ) { +pr_err ("SELinux: avtab: not exactly one specifier\n" ); +return -EINVAL ; } -if (!set || set >1 ) { -pr_err ("SELinux: avtab: more than one specifier\n" ); + +if (key.specified & ~AVTAB_SPECIFIER_MASK ) { +pr_err ("SELinux: avtab: invalid specifier\n" );return -EINVAL ; }
@@ -500,6 +515,10 @@ int avtab_read_item(struct avtab *a, strpr_err ("SELinux: avtab: truncated entry\n" );return rc; } +if (!avtab_is_valid_xperm_specified (xperms.specified)) +pr_warn_once_policyload (pol, +"SELinux: avtab: unsupported xperm specifier %#x\n" , + xperms.specified); rc =next_entry (&xperms.driver, fp,sizeof (u8));if (rc) {pr_err ("SELinux: avtab: truncated entry\n" );
security/selinux/ss/avtab.h +13 -0
@@ -44,6 +44,8 @@ struct avtab_key { AVTAB_XPERMS_DONTAUDIT)#define AVTAB_ENABLED_OLD 0x80000000/* reserved for used in cond_avtab */ #define AVTAB_ENABLED 0x8000/* reserved for used in cond_avtab */ +#define AVTAB_SPECIFIER_MASK (AVTAB_AV | AVTAB_TYPE | AVTAB_XPERMS | \ + AVTAB_ENABLED)u16 specified;/* what field is specified */ };
@@ -67,6 +69,17 @@ struct avtab_extended_perms {struct extended_perms_data perms; }; +static inline bool avtab_is_valid_xperm_specified (u8 specified) +{ +switch (specified) { +case AVTAB_XPERMS_IOCTLFUNCTION : +case AVTAB_XPERMS_IOCTLDRIVER : +return true; +default : +return false; + } +} +struct avtab_datum {union {u32 data;/* access vector or type value */
security/selinux/ss/conditional.c +7 -11
@@ -198,19 +198,12 @@ int cond_index_bool(void *key, void *datreturn 0 ; } -static int bool_isvalid (struct cond_bool_datum *b) -{ -if (!(b->state ==0 || b->state ==1 )) -return 0 ; -return 1 ; -} -int cond_read_bool (struct policydb *p,struct symtab *s,struct policy_file *fp) {char *key =NULL ;struct cond_bool_datum *booldatum;__le32 buf[3 ]; -u32 len; +u32 len, val;int rc; booldatum =kzalloc (sizeof (*booldatum),GFP_KERNEL );
@@ -222,11 +215,12 @@ int cond_read_bool(struct policydb *p, s goto err; booldatum->value =le32_to_cpu (buf[0 ]); - booldatum->state =le32_to_cpu (buf[1 ]); + val =le32_to_cpu (buf[1 ]); rc = -EINVAL ; -if (!bool_isvalid (booldatum)) +if (!val_is_boolean (val)) goto err; + booldatum->state = (int )val; len =le32_to_cpu (buf[2 ]);
@@ -240,6 +234,7 @@ int cond_read_bool(struct policydb *p, sreturn 0 ; err: +pr_err ("SELinux: conditional: failed to read boolean\n" );cond_destroy_bool (key, booldatum,NULL );return rc; }
@@ -360,7 +355,8 @@ static int expr_node_isvalid(struct polireturn 0 ; } -if (expr->boolean > p->p_bools.nprim) { +if (expr->expr_type ==COND_BOOL && + (expr->boolean ==0 || expr->boolean > p->p_bools.nprim)) {pr_err ("SELinux: conditional expressions uses unknown bool.\n" );return 0 ; }
security/selinux/ss/constraint.h +1 -0
@@ -49,6 +49,7 @@ struct constraint_expr {u32 op;/* operator */ struct ebitmap names;/* names */ +/* internally unused, only forwarded via policydb_write() */ struct type_set *type_names;struct constraint_expr *next;/* next expression */
security/selinux/ss/policydb.c +161 -35
402 lines not on this page · raw message
security/selinux/ss/policydb.h +19 -4
@@ -74,7 +74,7 @@ struct class_datum {/* Role attributes */ struct role_datum {u32 value;/* internal role value */ -u32 bounds;/* boundary of role */ +u32 bounds;/* boundary of role, 0 for none */ struct ebitmap dominates;/* set of roles dominated by this role */ struct ebitmap types;/* set of authorized types for role */ };
@@ -110,7 +110,8 @@ struct role_allow {/* Type attributes */ struct type_datum {u32 value;/* internal type value */ -u32 bounds;/* boundary of type */ +u32 bounds;/* boundary of type, 0 for none */ +/* internally unused, only forwarded via policydb_write() */ unsigned char primary;/* primary name? */ unsigned char attribute;/* attribute ?*/ };
@@ -118,7 +119,7 @@ struct type_datum {/* User attributes */ struct user_datum {u32 value;/* internal user value */ -u32 bounds;/* bounds of user */ +u32 bounds;/* bounds of user, 0 for none */ struct ebitmap roles;/* set of authorized roles for user */ struct mls_range range;/* MLS range (min - max) for user */ struct mls_level dfltlevel;/* default login MLS level for user */
@@ -195,7 +196,7 @@ struct ocontext { } ibendport; } u;union { -u16 sclass;/* security class for genfs */ +u16 sclass;/* security class for genfs (can be 0 for wildcard) */ u32 behavior;/* labeling behavior for fs_use */ } v;struct context context[2 ];/* security context(s) */
@@ -386,9 +387,23 @@ static inline char *sym_name(struct poli return p->sym_val_to_name[sym_num][element_nr]; } +static inline bool val_is_boolean (u32 value) +{ +return value ==0 || value ==1 ; +} +extern int str_read (char **strp,gfp_t flags,struct policy_file *fp,u32 len);extern u16 string_to_security_class (struct policydb *p,const char *name);extern u32 string_to_av_perm (struct policydb *p,u16 tclass,const char *name); +#define pr_warn_once_policyload (policy, fmt, ...) \ + do { \ + static const void *prev_policy__; \ + if (prev_policy__ != policy) { \ + pr_warn(fmt, ##__VA_ARGS__); \ + prev_policy__ = policy; \ + } \ + } while (0) +#endif /* _SS_POLICYDB_H_ */
security/selinux/ss/services.c +2 -4
@@ -445,8 +445,6 @@ static int dump_masked_av_helper(void *kstruct perm_datum *pdatum = d;char **permission_names = args; -BUG_ON (pdatum->value <1 || pdatum->value >32 ); - permission_names[pdatum->value -1 ] = (char *)k;return 0 ;
@@ -465,7 +463,7 @@ static void security_dump_masked_av(struchar *tclass_name;char *scontext_name =NULL ;char *tcontext_name =NULL ; -char *permission_names[32 ]; +char *permission_names[SEL_VEC_MAX ];int index;u32 length;bool need_comma = false;
@@ -506,7 +504,7 @@ static void security_dump_masked_av(stru"scontext=%s tcontext=%s tclass=%s perms=" , reason, scontext_name, tcontext_name, tclass_name); -for (index =0 ; index <32 ; index++) { +for (index =0 ; index <SEL_VEC_MAX ; index++) {u32 mask = (1 << index);if ((mask & permissions) ==0 )
Greg Kroah-Hartman
maintainerPATCH 80/87 selinux: reject a permission value exceeding the class permission count
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
[ Upstream commit d14b5d0e97fccd27974fedc03b903408872907fd ]
perm_read() bounds a permission value by SEL_VEC_MAX but never by the nprim of the owning class or common, which is taken verbatim from the policy image. security_get_permissions() then writes perms[value - 1] into an nprim-sized kcalloc() array, so a class declaring fewer permissions than its largest permission value drives an out-of-bounds heap write. The top-level symbol tables are validated this way; the nested per-class permission table is not.
Reject a permission whose value exceeds nprim, which is already set when perm_read() runs. Well-formed policies are unaffected.
Stable-dep-of: b98a8ac50775 ("selinux: require a class's permission values to cover its permission count")
--- security/selinux/ss/policydb.c | 3 +++ 1 file changed, 3 insertions(+)
security/selinux/ss/policydb.c +3 -0
@@ -1120,6 +1120,9 @@ static int perm_read(struct policydb *p, rc = -EINVAL ;if (perdatum->value <1 || perdatum->value >SEL_VEC_MAX ) goto bad; +/* indexes an nprim-sized array in security_get_permissions() */ +if (perdatum->value > s->nprim) + goto bad; rc =str_read (&key,GFP_KERNEL , fp, len);if (rc)
Greg Kroah-Hartman
maintainerPATCH 81/87 selinux: require a classs permission values to cover its permission count
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
[ Upstream commit b98a8ac50775540f3804397ed08f61ef9910bcab ]
security_get_permissions() sizes an array by the class's permissions.nprim and fills it at value - 1, from the inherited common's permission table and then the class's own. A value no permission defines leaves a NULL that sel_make_perm_files() passes to d_alloc_name(), an oops inside sel_write_load() that strands selinux_state.policy_mutex and leaves every later load in uninterruptible sleep; two permissions sharing a value overwrite the first kstrdup(). Bounding each value by nprim catches neither, and neither would a count: the symbol table is keyed on the permission name, so duplicates pass.
Track the values each permission table claims and require them to cover exactly what its count declares, rejecting a count no value can reach. Conforming policies are unaffected.
--- security/selinux/ss/policydb.c | 51 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 5 deletions(-)
security/selinux/ss/policydb.c +46 -5
@@ -1099,7 +1099,18 @@ int str_read(char **strp, gfp_t flags, sreturn 0 ; } -static int perm_read (struct policydb *p,struct symtab *s,struct policy_file *fp) +/* +* Bitmap of the permission values a symtab has claimed. Values are 1-based +* and bounded by SEL_VEC_MAX, the width of an access vector, so the whole set +* fits in a u32 and the callers reject an nprim past that width. +*/ +static u32 perm_claimed_mask (u32 nprim) +{ +return nprim ?U32_MAX >> (SEL_VEC_MAX - nprim) :0 ; +} + +static int perm_read (struct policydb *p,struct symtab *s, +struct policy_file *fp,u32 *claimed) {char *key =NULL ;struct perm_datum *perdatum;
@@ -1123,6 +1134,10 @@ static int perm_read(struct policydb *p,/* indexes an nprim-sized array in security_get_permissions() */ if (perdatum->value > s->nprim) goto bad; +/* two permissions cannot share one slot of that array */ +if (*claimed & (1U << (perdatum->value -1 ))) + goto bad; + *claimed |=1U << (perdatum->value -1 ); rc =str_read (&key,GFP_KERNEL , fp, len);if (rc)
@@ -1143,7 +1158,7 @@ static int common_read(struct policydb *char *key =NULL ;struct common_datum *comdatum;__le32 buf[4 ]; -u32 i, len, nel; +u32 i, len, nel, claimed =0 ;int rc; comdatum =kzalloc (sizeof (*comdatum),GFP_KERNEL );
@@ -1165,17 +1180,28 @@ static int common_read(struct policydb *if (rc) goto bad; comdatum->permissions.nprim =le32_to_cpu (buf[2 ]); +/* no permission value can reach a slot past SEL_VEC_MAX */ + rc = -EINVAL ; +if (comdatum->permissions.nprim >SEL_VEC_MAX ) + goto bad; rc =str_read (&key,GFP_KERNEL , fp, len);if (rc) goto bad;for (i =0 ; i < nel; i++) { - rc =perm_read (p, &comdatum->permissions, fp); + rc =perm_read (p, &comdatum->permissions, fp, &claimed);if (rc) goto bad; } + rc = -EINVAL ; +if (claimed !=perm_claimed_mask (comdatum->permissions.nprim)) { +pr_err ("SELinux: common %s does not define every permission it declares\n" , + key); + goto bad; + } + rc =symtab_insert (s, key, comdatum);if (rc) goto bad;
@@ -1309,7 +1335,7 @@ static int class_read(struct policydb *pchar *key =NULL ;struct class_datum *cladatum;__le32 buf[6 ]; -u32 i, len, len2, ncons, nel, val; +u32 i, len, len2, ncons, nel, val, claimed =0 , inherited =0 ;int rc; cladatum =kzalloc (sizeof (*cladatum),GFP_KERNEL );
@@ -1337,6 +1363,10 @@ static int class_read(struct policydb *pif (rc) goto bad; cladatum->permissions.nprim =le32_to_cpu (buf[3 ]); +/* no permission value can reach a slot past SEL_VEC_MAX */ + rc = -EINVAL ; +if (cladatum->permissions.nprim >SEL_VEC_MAX ) + goto bad; ncons =le32_to_cpu (buf[5 ]);
@@ -1371,11 +1401,22 @@ static int class_read(struct policydb *p } }for (i =0 ; i < nel; i++) { - rc =perm_read (p, &cladatum->permissions, fp); + rc =perm_read (p, &cladatum->permissions, fp, &claimed);if (rc) goto bad; } +/* the class's own permissions must claim the slots the common leaves */ +if (cladatum->comdatum) + inherited = cladatum->comdatum->permissions.nprim; + rc = -EINVAL ; +if (claimed != (perm_claimed_mask (cladatum->permissions.nprim) & + ~perm_claimed_mask (inherited))) { +pr_err ("SELinux: class %s does not define every permission it declares\n" , + key); + goto bad; + } + rc =read_cons_helper (p, &cladatum->constraints, ncons,0 , fp);if (rc) goto bad;
Greg Kroah-Hartman
maintainerPATCH 82/87 HID: nintendo: fix out-of-bounds read in joycon_ctlr_read_handler()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ibrahim Hashimov <[email protected]>
commit 27b376b945c0aac46fcdfcc950b14a85b874b557 upstream.
joycon_ctlr_read_handler() casts an incoming HID input report to struct joycon_input_report and parses it, guarding the cast only with a 12-byte length check:
if (size >= 12) /* make sure it contains the input report */ joycon_parse_report(ctlr, (struct joycon_input_report *)data);
struct joycon_input_report is 49 bytes: a 13-byte header followed by a union whose IMU arm is 36 bytes. For an IMU report joycon_parse_report() -> joycon_parse_imu_report() walks that union (struct offsets 13..48), so a report of exactly 12 bytes with data[0] == JC_INPUT_IMU_DATA passes the guard yet is read up to 37 bytes past its declared length. The over-read bytes are decoded into accelerometer/gyroscope values and forwarded to userspace through the "(IMU)" input device, leaking driver-internal memory. data[0] and size are fully controlled by a malicious or spoofed Joy-Con/Pro Controller.
Receive buffers are sized to the maximum report length, so this is an over-read within the allocation rather than a slab OOB, but the decoded bytes still reach userspace.
The sibling subcmd path in joycon_ctlr_handle_event() already bounds the same cast correctly:
if (size < sizeof(struct joycon_input_report) || data[0] != JC_INPUT_SUBCMD_REPLY) break;
Use the same sizeof(struct joycon_input_report) bound here.
--- drivers/hid/hid-nintendo.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/hid/hid-nintendo.c +6 -1
@@ -2217,7 +2217,12 @@ static int joycon_ctlr_read_handler(stru {if (data[0 ] ==JC_INPUT_SUBCMD_REPLY || data[0 ] ==JC_INPUT_IMU_DATA || data[0 ] ==JC_INPUT_MCU_DATA ) { -if (size >=12 )/* make sure it contains the input report */ +/* +* The whole struct is cast and parsed below, including the +* IMU/subcmd union, not just the 12-byte partial header this +* used to check for. +*/ +if (size >=sizeof (struct joycon_input_report ))joycon_parse_report (ctlr, (struct joycon_input_report *)data); }
Greg Kroah-Hartman
maintainerPATCH 83/87 HID: core: fix number/pointer type confusion on long items
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jann Horn <[email protected]>
commit 28abce951343fcec26e397610868efa4e1395c3f upstream.
When fetch_item() is called by hid_scan_report() on an item with HID_ITEM_TAG_LONG, it stores a pointer to the item data in item->data.longdata instead of storing a value directly in item->data.{u8/u16/u32}.
When item_udata() or item_sdata() encounters such an item, it incorrectly assumes that the item is in short format, and therefore returns the lower part of a kernel pointer reinterpreted as a number.
When a HID device is connected whose descriptor contains a HID_GLOBAL_ITEM_TAG_REPORT_SIZE encoded in long format with size=4, this causes the lower half of a kernel pointer to be printed into dmesg as a number, like this:
hid (null): invalid report_size 107953555
To fix it, let item_udata() and item_sdata() verify that the item is in short format.
Note that this bug only affects hid_scan_report(), while the main parsing pass hid_parse_collections() will always bail out when encountering a long item.
Sidenote: There are currently no users of data.longdata; maybe we should just remove any parsing of long-format descriptors as a follow-up.
--- drivers/hid/hid-core.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/hid/hid-core.c +6 -0
@@ -344,6 +344,9 @@ static int hid_add_field(struct hid_parsstatic u32 item_udata (struct hid_item *item) { +if (item->format !=HID_ITEM_FORMAT_SHORT ) +return 0 ; +switch (item->size) {case 1 :return item->data.u8;case 2 :return item->data.u16;
@@ -354,6 +357,9 @@ static u32 item_udata(struct hid_item *istatic s32 item_sdata (struct hid_item *item) { +if (item->format !=HID_ITEM_FORMAT_SHORT ) +return 0 ; +switch (item->size) {case 1 :return item->data.s8;case 2 :return item->data.s16;
Greg Kroah-Hartman
maintainerPATCH 84/87 HID: sensor: custom: Fix use-after-free in enable_sensor
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haoxiang Li <[email protected]>
commit ad8fb82b04422f49530d2aa2753cc81d1c60102c upstream.
enable_sensor_store() can call set_power_report_state(), which dereferences sensor_inst->power_state and sensor_inst->report_state. These pointers refer to entries in sensor_inst->fields.
Create the field attributes before exposing the enable_sensor sysfs attribute, so enable_sensor cannot be accessed before the state it depends on has been initialized.
On remove, delete enable_sensor before freeing the field attributes, so a concurrent sysfs write cannot dereference freed memory through power_state or report_state.
--- drivers/hid/hid-sensor-custom.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/hid/hid-sensor-custom.c +9 -8
@@ -1006,26 +1006,26 @@ static int hid_sensor_custom_probe(strucreturn ret; } - ret =sysfs_create_group (&sensor_inst->pdev->dev.kobj, - &enable_sensor_attr_group); + ret =hid_sensor_custom_add_attributes (sensor_inst);if (ret) goto err_remove_callback; - ret =hid_sensor_custom_add_attributes (sensor_inst); + ret =sysfs_create_group (&sensor_inst->pdev->dev.kobj, + &enable_sensor_attr_group);if (ret) - goto err_remove_group; + goto err_remove_attributes; ret =hid_sensor_custom_dev_if_add (sensor_inst);if (ret) - goto err_remove_attributes; + goto err_remove_group;return 0 ; -err_remove_attributes: -hid_sensor_custom_remove_attributes (sensor_inst); err_remove_group:sysfs_remove_group (&sensor_inst->pdev->dev.kobj, &enable_sensor_attr_group); +err_remove_attributes: +hid_sensor_custom_remove_attributes (sensor_inst); err_remove_callback:sensor_hub_remove_callback (hsdev, hsdev->usage);
@@ -1043,9 +1043,10 @@ static int hid_sensor_custom_remove(stru }hid_sensor_custom_dev_if_remove (sensor_inst); -hid_sensor_custom_remove_attributes (sensor_inst); +/* Remove enable_sensor first as it uses fields via power_state/report_state. */ sysfs_remove_group (&sensor_inst->pdev->dev.kobj, &enable_sensor_attr_group); +hid_sensor_custom_remove_attributes (sensor_inst);sensor_hub_remove_callback (hsdev, hsdev->usage);return 0 ;
Greg Kroah-Hartman
maintainerPATCH 85/87 HID: hyperv: validate initial device info bounds
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
commit 934b7778aa7b7c8f6bb073d2a73ba3674885bae0 upstream.
The Hyper-V synthetic HID host supplies SYNTH_HID_INITIAL_DEVICE_INFO messages that contain a HID descriptor followed by the report descriptor bytes. mousevsc_on_receive_device_info() trusts bLength and wDescriptorLength without checking that the received packet contains both byte ranges.
A malformed host or backend message can therefore make the guest read past the received VMBus packet while copying the report descriptor. Pass the received initial-device-info size into the parser and reject descriptor lengths that exceed the packet.
Impact: A malicious Hyper-V host or backend can crash a guest by sending a short initial device-info message with an oversized HID report descriptor length.
--- drivers/hid/hid-hyperv.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-)
drivers/hid/hid-hyperv.c +24 -3
@@ -171,18 +171,32 @@ static void mousevsc_free_device(struct }static void mousevsc_on_receive_device_info (struct mousevsc_dev *input_device, -struct synthhid_device_info *device_info) +struct synthhid_device_info *device_info, +u32 device_info_size) {int ret =0 ;struct hid_descriptor *desc;struct mousevsc_prt_msg ack; +size_t desc_offset; +size_t desc_size; input_device->dev_info_status = -ENOMEM ; +if (device_info_size <sizeof (*device_info)) { + input_device->dev_info_status = -EINVAL ; + goto cleanup; + } + input_device->hid_dev_info = device_info->hid_dev_info; desc = &device_info->hid_descriptor; + desc_offset = offsetof(struct synthhid_device_info , hid_descriptor); + desc_size = device_info_size - desc_offset;if (desc->bLength ==0 ) goto cleanup; +if (desc->bLength <sizeof (*desc) || desc->bLength > desc_size) { + input_device->dev_info_status = -EINVAL ; + goto cleanup; + }/* The pointer is not NULL when we resume from hibernation */ kfree (input_device->hid_desc);
@@ -197,6 +211,10 @@ static void mousevsc_on_receive_device_i input_device->dev_info_status = -EINVAL ; goto cleanup; } +if (input_device->report_desc_size > desc_size - desc->bLength) { + input_device->dev_info_status = -EINVAL ; + goto cleanup; + }/* The pointer is not NULL when we resume from hibernation */ kfree (input_device->report_desc);
@@ -273,14 +291,17 @@ static void mousevsc_on_receive(struct hbreak ;case SYNTH_HID_INITIAL_DEVICE_INFO : -WARN_ON (pipe_msg->size <sizeof (struct hv_input_dev_info )); +if (WARN_ON_ONCE (pipe_msg->size < +sizeof (struct synthhid_device_info ))) +break ;/* * Parse out the device info into device attr, * hid desc and report desc */ mousevsc_on_receive_device_info (input_dev, - (struct synthhid_device_info *)pipe_msg->data); + (struct synthhid_device_info *)pipe_msg->data, + pipe_msg->size);break ;case SYNTH_HID_INPUT_REPORT : input_report =
Greg Kroah-Hartman
maintainerPATCH 86/87 Bluetooth: hci_event: fix LE list UAF on reset
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengfeng Ye <[email protected]>
commit 33af47e847fe4a28b109673affb5874015d54f5a upstream.
hci_cc_reset() clears the LE accept and resolving lists without taking hdev->lock. Other command-complete handlers serialize updates to these lists with that lock, and the debugfs readers hold it while walking them.
This permits the reset completion and a debugfs read to interleave as follows:
hci_rx_work debugfs reader
----------- --------------
lock hdev->lock
fetch current entry
list_del(entry)
kfree(entry)
read entry fields
The reader then dereferences a freed list entry and may follow its stale next pointer.
KASAN reported:
BUG: KASAN: slab-use-after-free in white_list_show+0x15f/0x180 Read of size 1 at addr ffff8881015dab16 by task poc/95 Call Trace: white_list_show+0x15f/0x180 seq_read_iter+0x3ff/0x1190 seq_read+0x267/0x3d0 vfs_read+0x177/0xa20 ksys_read+0xf7/0x1c0 Allocated by task 91: hci_bdaddr_list_add+0x1a6/0x3a0 hci_cc_le_add_to_accept_list+0xab/0x140 hci_cmd_complete_evt+0x26c/0x9a0 hci_event_packet+0x454/0xb20 hci_rx_work+0x293/0x730 Freed by task 90: kfree+0x131/0x3c0 hci_bdaddr_list_clear+0xd8/0x160 hci_cc_reset+0x28a/0x370 hci_cmd_complete_evt+0x26c/0x9a0 hci_event_packet+0x454/0xb20 hci_rx_work+0x293/0x730
Take hdev->lock around both list clears. This matches the existing mutation and traversal locking convention.
--- net/bluetooth/hci_event.c | 2 ++ 1 file changed, 2 insertions(+)
net/bluetooth/hci_event.c +2 -0
@@ -294,8 +294,10 @@ static u8 hci_cc_reset(struct hci_dev *h hdev->ssp_debug_mode =0 ; +hci_dev_lock (hdev);hci_bdaddr_list_clear (&hdev->le_accept_list);hci_bdaddr_list_clear (&hdev->le_resolv_list); +hci_dev_unlock (hdev);return rp->status; }
Greg Kroah-Hartman
maintainerPATCH 87/87 Bluetooth: hci_event: validate LE Set CIG Parameters response
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Laxman Acharya Padhya <[email protected]>
commit 0acd4eeb4b225b9bebbf9ef96cc10cdd79b94899 upstream.
The Command Complete dispatch validates only the fixed part of the LE Set CIG Parameters response. After that part is pulled from the skb, hci_cc_le_set_cig_params() trusts num_handles and reads each entry in the trailing handle array.
Matching num_handles against the command's num_cis does not guarantee that the response contains the advertised handles. A truncated response from a malfunctioning controller can therefore make the handler read beyond the skb data.
Validate that the remaining skb data contains all advertised handles. Include this in the existing response validation so malformed responses also follow the established CIG failure handling.
--- net/bluetooth/hci_event.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/bluetooth/hci_event.c +4 -2
@@ -3798,8 +3798,10 @@ static u8 hci_cc_le_set_cig_params(strucbt_dev_dbg (hdev,"status 0x%2.2x" , rp->status); cp =hci_sent_cmd_data (hdev,HCI_OP_LE_SET_CIG_PARAMS ); -if (!rp->status && (!cp || rp->num_handles != cp->num_cis || - rp->cig_id != cp->cig_id)) { +if (!rp->status && + (!cp || rp->num_handles != cp->num_cis || + rp->cig_id != cp->cig_id || + skb->len <array_size (rp->num_handles,sizeof (*rp->handle)))) {bt_dev_err (hdev,"unexpected Set CIG Parameters response data" ); status =HCI_ERROR_UNSPECIFIED ; }
Hi!
Quoted 4 lines
This is the start of the stable review cycle for the 6.6.154 release. There are 87 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.
This seems to have same problem as 6.1-stable.
https://gitlab.com/cip-project/cip-testing/linux-stable-rc-ci/-/jobs/16096629443
Best regards,
Pavel
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 6.6.154 release. There are 87 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 Thu, 27 Aug 2026 13:25:02 +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.6.154-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-6.6.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.6.154 release. There are 87 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 Thu, 27 Aug 2026 13:25:02 +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.6.154-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-6.6.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 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 6.6.154 release. There are 87 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 Thu, 27 Aug 2026 13:25:02 +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.6.154-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-6.6.y
and the diffstat can be found below.thanks,
greg k-h
Built and booted successfully on RISC-V RV64 (HiFive Unmatched).
Build tested in our x86,arm64,loongarch,riscv config successfully without error.
Best Regards
Wentao Guan
Log:
Linux version 6.6.154-rc1-arm64-desktop-hwe-g8147a3c12dd2 (guanwentao@uos-PC) (aarch64-linux-gnu-gcc-12 (Deepin 12.3.0-17deepin8) 12.3.0, GNU ld (GNU Binutils for Deepin) 2.41) # SMP PREEMPT Linux version 6.6.154-rc1-arm64-desktop-hwe-g8147a3c12dd2 (guanwentao@uos-PC) (aarch64-linux-gnu-gcc-12 (Deepin 12.3.0-17deepin8) 12.3.0, GNU ld (GNU Binutils for Deepin) 2.41) #2 SMP PREEMPT Wed Aug 26 15:06:21 CST 2026 Linux version 6.6.154-rc1-loong64-desktop-hwe-g8147a3c12dd2 (guanwentao@uos-PC) (loongarch64-linux-gnu-gcc-12 (Deepin 12.3.0-17deepin8) 12.3.0, GNU ld (GNU Binutils for Deepin) 2.41) # SMP PREEMPT Linux version 6.6.154-rc1-loong64-desktop-hwe-g8147a3c12dd2 (guanwentao@uos-PC) (loongarch64-linux-gnu-gcc-12 (Deepin 12.3.0-17deepin8) 12.3.0, GNU ld (GNU Binutils for Deepin) 2.41) #3 SMP PREEMPT Wed Aug 26 15:24:02 CST 2026 Linux version 6.6.154-rc1-riscv64-desktop-hwe+ (guanwentao@uos-PC) (riscv64-linux-gnu-gcc-12 (Deepin 12.3.0-17deepin8) 12.3.0, GNU ld (GNU Binutils for Deepin) 2.41) # SMP
Linux version 6.6.154-rc1-riscv64-desktop-hwe+ (guanwentao@uos-PC) (riscv64-linux-gnu-gcc-12 (Deepin 12.3.0-17deepin8) 12.3.0, GNU ld (GNU Binutils for Deepin) 2.41) #4 SMP Wed Aug 26 15:40:33 CST 2026 Linux version 6.6.154-rc1-amd64-desktop-hwe-g8147a3c12dd2 (guanwentao@uos-PC) (gcc (Deepin 12.3.0-17deepin15) 12.3.0, GNU ld (GNU Binutils for Deepin) 2.41) # SMP PREEMPT_DYNAMIC
Linux version 6.6.154-rc1-amd64-desktop-hwe-g8147a3c12dd2 (guanwentao@uos-PC) (gcc (Deepin 12.3.0-17deepin15) 12.3.0, GNU ld (GNU Binutils for Deepin) 2.41) #1 SMP PREEMPT_DYNAMIC Wed Aug 26 14:47:41 CST 2026
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 6.6.154 release. There are 87 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 Thu, 27 Aug 2026 13:25:02 +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.6.154-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-6.6.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]>
# Librecast Test Results
020/020 [ OK ] liblcrq
010/010 [ OK ] libmld
120/120 [ OK ] liblibrecast
CPU/kernel: Linux auntie 6.6.154-rc1-g8147a3c12dd2 #1 SMP PREEMPT_DYNAMIC Wed Aug 26 10:13:27 -00 2026 x86_64 AMD Ryzen 9 9950X 16-Core Processor AuthenticAMD GNU/Linux
Quoted 8 lines · On Tue, 25 Aug 2026 15:25:23 +0200 Greg Kroah-Hartman…
This is the start of the stable review cycle for the 6.6.154 release. There are 87 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 Thu, 27 Aug 2026 13:25:02 +0000. Anything received after that time might be too late.
Boot-tested under QEMU for Rust x86_64:
I don't have the Pavel's reported build error on my config.
Thanks!
Cheers,
Miguel
Am 25.08.2026 um 15:25 schrieb Greg Kroah-Hartman:
Quoted 4 lines
This is the start of the stable review cycle for the 6.6.154 release. There are 87 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]