6.6.160-rc1 review
Subsystems (12)
Greg Kroah-Hartman
maintainerPATCH 1466/1674 scsi: ufs: core: Convert string descriptor format macros to enum
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bean Huo <[email protected]>
[ Upstream commit 0d9a7085ec24983b5b8a4971c0eb6c756c75f1bf ]
Convert SD_ASCII_STD and SD_RAW from boolean macros to enum values for improved code readability. This makes ufshcd_read_string_desc() calls self-documenting by using explicit enum values instead of true/false.
Move the ufshcd_read_string_desc() declaration from include/ufs/ufshcd.h to drivers/ufs/core/ufshcd-priv.h since this function is not exported.
Stable-dep-of: d96e83d028d7 ("scsi: ufs: core: Validate string descriptors")
--- drivers/ufs/core/ufshcd-priv.h | 14 ++++++++++---- drivers/ufs/core/ufshcd.c | 8 +++----- include/ufs/ufshcd.h | 4 ---- 3 files changed, 13 insertions(+), 13 deletions(-)
drivers/ufs/core/ufshcd-priv.h +10 -4
@@ -83,11 +83,17 @@ int ufshcd_try_to_abort_task(struct ufs_hba *hba, int tag);void ufshcd_release_scsi_cmd (struct ufs_hba *hba,struct ufshcd_lrb *lrbp); -#define SD_ASCII_STD true -#define SD_RAW false -int ufshcd_read_string_desc (struct ufs_hba *hba,u8 desc_index, -u8 **buf,bool ascii); +/** +* enum ufs_descr_fmt - UFS string descriptor format +* @SD_RAW: Raw UTF-16 format +* @SD_ASCII_STD: Convert to null-terminated ASCII string +*/ +enum ufs_descr_fmt { +SD_RAW =0 , +SD_ASCII_STD =1 , +}; +int ufshcd_read_string_desc (struct ufs_hba *hba,u8 desc_index,u8 **buf,enum ufs_descr_fmt fmt);int ufshcd_send_uic_cmd (struct ufs_hba *hba,struct uic_command *uic_cmd);int ufshcd_send_bsg_uic_cmd (struct ufs_hba *hba,struct uic_command *uic_cmd);
drivers/ufs/core/ufshcd.c +3 -5
@@ -3672,16 +3672,14 @@ static inline char ufshcd_remove_non_printable(u8 ch)* @desc_index: descriptor index * @buf: pointer to buffer where descriptor would be read, * the caller should free the memory. -* @ascii: if true convert from unicode to ascii characters -* null terminated string. +* @fmt: if %SD_ASCII_STD, convert from UTF-16 to ASCII * * Return: * * string size on success. * * -ENOMEM: on allocation failure * * -EINVAL: on a wrong parameter */ -int ufshcd_read_string_desc (struct ufs_hba *hba,u8 desc_index, -u8 **buf,bool ascii) +int ufshcd_read_string_desc (struct ufs_hba *hba,u8 desc_index,u8 **buf,enum ufs_descr_fmt fmt) {struct uc_string_id *uc_str;u8 *str;
@@ -3710,7 +3708,7 @@ int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index, goto out; } -if (ascii) { +if (fmt ==SD_ASCII_STD ) {ssize_t ascii_len;int i;/* remove header and divide by 2 to move from UTF16 to UTF8 */
include/ufs/ufshcd.h +0 -4
@@ -1410,10 +1410,6 @@ void ufshcd_auto_hibern8_enable(struct ufs_hba *hba);void ufshcd_auto_hibern8_update (struct ufs_hba *hba,u32 ahit);void ufshcd_fixup_dev_quirks (struct ufs_hba *hba,const struct ufs_dev_quirk *fixups); -#define SD_ASCII_STD true -#define SD_RAW false -int ufshcd_read_string_desc (struct ufs_hba *hba,u8 desc_index, -u8 **buf,bool ascii);void ufshcd_hold (struct ufs_hba *hba);void ufshcd_release (struct ufs_hba *hba);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1467/1674 scsi: ufs: core: Validate string descriptors
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li Qiang <[email protected]>
[ Upstream commit d96e83d028d7d8762e424e49c671d49ac2ecf14f ]
The string descriptor length includes a two-byte header while the UTF-16 payload starts after it. utf16s_to_utf8s() expects a count of UTF-16 code units, not bytes. Passing the payload byte count can make it read beyond the descriptor buffer.
Validate that the payload has an even byte count, pass a code-unit count to the converter, and allocate sufficient UTF-8 output space.
The raw string buffer starts after the descriptor header but its size is bLength. Copying bLength bytes from that pointer can read beyond the response buffer.
Allocate a zeroed bLength-sized buffer and copy only the UTF-16 payload. This preserves the raw buffer size consumed by the RPMB device-ID ABI while avoiding the overread.
--- drivers/ufs/core/ufshcd.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)
drivers/ufs/core/ufshcd.c +19 -5
@@ -3683,7 +3683,7 @@ int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index, u8 **buf, enum u {struct uc_string_id *uc_str;u8 *str; -int ret; +int ret, uc_len;if (!buf)return -EINVAL ;
@@ -3708,11 +3708,19 @@ int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index, u8 **buf, enum u goto out; } + uc_len = uc_str->len -QUERY_DESC_HDR_SIZE ; +if (uc_len %sizeof (*uc_str->uc)) { +dev_err (hba->dev,"String Desc has an odd UTF-16 payload length\n" ); + str =NULL ; + ret = -EINVAL ; + goto out; + } +if (fmt ==SD_ASCII_STD ) {ssize_t ascii_len;int i; -/* remove header and divide by 2 to move from UTF16 to UTF8 */ - ascii_len = (uc_str->len -QUERY_DESC_HDR_SIZE ) /2 +1 ; +/* Allow up to three UTF-8 bytes per UTF-16 code unit plus a NUL. */ + ascii_len = uc_len /sizeof (*uc_str->uc) *3 +1 ; str =kzalloc (ascii_len,GFP_KERNEL );if (!str) { ret = -ENOMEM ;
@@ -3724,7 +3732,7 @@ int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index, u8 **buf, enum u* we need to convert to utf-8 so it can be displayed */ ret =utf16s_to_utf8s (uc_str->uc, - uc_str->len -QUERY_DESC_HDR_SIZE , + uc_len /sizeof (*uc_str->uc),UTF16_BIG_ENDIAN , str, ascii_len -1 );/* replace non-printable or non-ASCII characters with spaces */
@@ -3734,11 +3742,17 @@ int ufshcd_read_string_desc(struct ufs_hba *hba, u8 desc_index, u8 **buf, enum u str[ret++] ='\0' ; }else { - str =kmemdup (uc_str->uc, uc_str->len,GFP_KERNEL ); +/* +* Keep the bLength-sized raw output for the RPMB device ID ABI. +* The two bytes beyond the UTF-16 payload are explicitly zeroed +* instead of being read past the descriptor buffer. +*/ + str =kzalloc (uc_str->len,GFP_KERNEL );if (!str) { ret = -ENOMEM ; goto out; } +memcpy (str, uc_str->uc, uc_len); ret = uc_str->len; } out:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1468/1674 pinctrl: mediatek: use devm_gpiochip_add_data() for GPIO chip
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Justin Yeh <[email protected]>
[ Upstream commit 9c650317ba553d297f3fc5f0ae40ec53d86f9dab ]
The gpio_chip is allocated with device-managed memory but registered with the non-managed gpiochip_add_data(). This was harmless while the drivers were built-in, but once they can be built as modules and unbound/rmmod'd, devm frees the gpio_chip's memory while it is still registered, causing a use-after-free.
Register it with devm_gpiochip_add_data() so it shares the same device-managed lifecycle, which also lets the manual gpiochip_remove() error paths go away.
--- drivers/pinctrl/mediatek/pinctrl-moore.c | 6 ++---- drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 14 ++++---------- drivers/pinctrl/mediatek/pinctrl-paris.c | 2 +- 3 files changed, 7 insertions(+), 15 deletions(-)
drivers/pinctrl/mediatek/pinctrl-moore.c +2 -4
@@ -575,7 +575,7 @@ static int mtk_build_gpiochip(struct mtk_pinctrl *hw) chip->base =-1 ; chip->ngpio = hw->soc->npins; - ret =gpiochip_add_data (chip, hw); + ret =devm_gpiochip_add_data (hw->dev, chip, hw);if (ret <0 )return ret;
@@ -589,10 +589,8 @@ static int mtk_build_gpiochip(struct mtk_pinctrl *hw)if (!of_property_present (hw->dev->of_node,"gpio-ranges" )) { ret =gpiochip_add_pin_range (chip,dev_name (hw->dev),0 ,0 , chip->ngpio); -if (ret <0 ) { -gpiochip_remove (chip); +if (ret <0 )return ret; - } }return 0 ;
drivers/pinctrl/mediatek/pinctrl-mtk-common.c +4 -10
@@ -1127,30 +1127,24 @@ int mtk_pctrl_init(struct platform_device *pdev, pctl->chip->parent = &pdev->dev; pctl->chip->base =-1 ; - ret =gpiochip_add_data (pctl->chip, pctl); + ret =devm_gpiochip_add_data (&pdev->dev, pctl->chip, pctl);if (ret)return -EINVAL ;/* Register the GPIO to pin mappings. */ ret =gpiochip_add_pin_range (pctl->chip,dev_name (&pdev->dev),0 ,0 , pctl->devdata->npins); -if (ret) { - ret = -EINVAL ; - goto chip_error; - } +if (ret) +return -EINVAL ;/* Only initialize EINT if we have EINT pins */ if (data->eint_hw.ap_num >0 ) { ret =mtk_eint_init (pctl, pdev);if (ret) - goto chip_error; +return ret; }return 0 ; - -chip_error: -gpiochip_remove (pctl->chip); -return ret; }int mtk_pctrl_common_probe (struct platform_device *pdev)
drivers/pinctrl/mediatek/pinctrl-paris.c +1 -1
@@ -974,7 +974,7 @@ static int mtk_build_gpiochip(struct mtk_pinctrl *hw) chip->base =-1 ; chip->ngpio = hw->soc->npins; - ret =gpiochip_add_data (chip, hw); + ret =devm_gpiochip_add_data (hw->dev, chip, hw);if (ret <0 )return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1469/1674 bpf: Fix WARNING in bpf_tracing_link_release
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leon Hwang <[email protected]>
[ Upstream commit 61aaa8782bec59ecffd22e030f54ef9351bcabf9 ]
The trampoline could be corrupted by the blindly 'tr->flags = BPF_TRAMP_F_TAIL_CALL_CTX' in verifier.
1. A fexit attached to a tail_call_reachable prog. 'tr->flags' became 'BPF_TRAMP_F_CALL_ORIG | BPF_TRAMP_F_TAIL_CALL_CTX'. And, the trampoline would poke the target prog's nop insn using jmp insn instead of call insn.
2. Another fexit loaded with the same tail_call_reachable prog target. 'tr->flags' became 'BPF_TRAMP_F_TAIL_CALL_CTX'.
3. Close the first fexit link. Due to no BPF_TRAMP_F_CALL_ORIG in 'tr->flags', the trampoline will fail to restore the prog's nop insn using call insn.
[ 3.410719] WARNING: kernel/bpf/syscall.c:3551 at bpf_tracing_link_release+0x53/0x60, CPU#1: test_progs/98 ... [ 3.428793] bpf_link_free+0x58/0x130 [ 3.429293] bpf_link_release+0x23/0x30
Fix the warning by updating 'tr->flags' with '|=' and lock.
--- include/linux/bpf.h | 2 ++ kernel/bpf/trampoline.c | 7 +++++++ kernel/bpf/verifier.c | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-)
include/linux/bpf.h +2 -0
@@ -1267,6 +1267,7 @@ int bpf_trampoline_unlink_prog(struct bpf_tramp_link *link,struct bpf_trampoline *bpf_trampoline_get (u64 key,struct bpf_attach_target_info *tgt_info);void bpf_trampoline_put (struct bpf_trampoline *tr); +void bpf_trampoline_set_flags (struct bpf_trampoline *tr,u32 flags);int arch_prepare_bpf_dispatcher (void *image,void *buf,s64 *funcs,int num_funcs);/*
@@ -1361,6 +1362,7 @@ static inline struct bpf_trampoline *bpf_trampoline_get(u64 key,return NULL ; }static inline void bpf_trampoline_put (struct bpf_trampoline *tr) {} +static inline void bpf_trampoline_set_flags (struct bpf_trampoline *tr,u32 flags) {}#define DEFINE_BPF_DISPATCHER (name)#define DECLARE_BPF_DISPATCHER (name)#define BPF_DISPATCHER_FUNC (name) bpf_dispatcher_nop_func
kernel/bpf/trampoline.c +7 -0
@@ -392,6 +392,13 @@ static struct bpf_tramp_image *bpf_tramp_image_alloc(u64 key)return ERR_PTR (err); } +void bpf_trampoline_set_flags (struct bpf_trampoline *tr,u32 flags) +{ +mutex_lock (&tr->mutex); + tr->flags |= flags; +mutex_unlock (&tr->mutex); +} +static int bpf_trampoline_update (struct bpf_trampoline *tr,bool lock_direct_mutex) {struct bpf_tramp_image *im;
kernel/bpf/verifier.c +1 -1
@@ -20652,7 +20652,7 @@ static int check_attach_btf_id(struct bpf_verifier_env *env)return -ENOMEM ;if (tgt_prog && tgt_prog->aux->tail_call_reachable) - tr->flags =BPF_TRAMP_F_TAIL_CALL_CTX ; +bpf_trampoline_set_flags (tr,BPF_TRAMP_F_TAIL_CALL_CTX ); prog->aux->dst_trampoline = tr;return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1470/1674 RDMA/erdma: complete object teardown when the destroy command fails
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leon Romanovsky <[email protected]>
[ Upstream commit 652befcba956ef357f480525ccbe25c59bc81d4d ]
erdma_destroy_qp(), erdma_destroy_cq(), erdma_dereg_mr(), and erdma_destroy_ah() returned early when erdma_post_cmd_wait() failed, leaking the queue buffers, MTTs, doorbells and the STAG, QPN, CQN and AHN identifiers. A command timeout clears ERDMA_CMDQ_STATE_OK_BIT and permanently disables the command queue, so no retry can succeed; the RDMA core keeps the object after a failed destructor and forced uverbs cleanup then nulls the pointers, making the resources unreachable.
Warn on failure but release every software-owned resource and return success, since during terminal destruction the hardware command result is only diagnostic.
--- drivers/infiniband/hw/erdma/erdma_verbs.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/infiniband/hw/erdma/erdma_verbs.c +14 -3
@@ -1211,8 +1211,15 @@ int erdma_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata)FIELD_PREP (ERDMA_CMD_MR_KEY_MASK , ibmr->lkey &0xFF ); ret =erdma_post_cmd_wait (&dev->cmdq, &req,sizeof (req),NULL ,NULL ); +/* +* A timeout disables the command queue, so retry cannot succeed. Treat +* terminal command failures as diagnostic; propagating them can make +* forced uverbs cleanup discard the last software resource pointers. +*/ if (ret) -return ret; +ibdev_warn_ratelimited (&dev->ibdev, +"failed to deregister MR 0x%x: %d\n" , + ibmr->lkey, ret);erdma_free_idx (&dev->res_cb[ERDMA_RES_TYPE_STAG_IDX ], ibmr->lkey >>8 );
@@ -1238,7 +1245,9 @@ int erdma_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata) err =erdma_post_cmd_wait (&dev->cmdq, &req,sizeof (req),NULL ,NULL );if (err) -return err; +ibdev_warn_ratelimited (&dev->ibdev, +"failed to destroy CQ %u: %d\n" , + cq->cqn, err);xa_lock_irqsave (&dev->cq_xa, flags);__xa_erase (&dev->cq_xa, cq->cqn);
@@ -1283,7 +1292,9 @@ int erdma_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata) err =erdma_post_cmd_wait (&dev->cmdq, &req,sizeof (req),NULL ,NULL );if (err) -return err; +ibdev_warn_ratelimited (&dev->ibdev, +"failed to destroy QP %u: %d\n" , +QP_ID (qp), err);xa_lock_irqsave (&dev->qp_xa, flags);__xa_erase (&dev->qp_xa,QP_ID (qp));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1471/1674 ext4: fix ABBA deadlock in ext4_xattr_inode_cache_find()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aditya Prakash Srivastava <[email protected]>
[ Upstream commit 03438084a7b8621fb5c762dd3d04cff5f2630fb2 ]
Syzbot/stress-ng reported an ABBA deadlock in ext4 when exercising concurrent xattr workloads (using the ea_inode mount/format option).
The deadlock occurs between the running transaction and the eviction thread:
- Task 1 (stress-ng): Holds a reference to a shared mbcache_entry (ce) and calls ext4_xattr_inode_cache_find() -> ext4_iget() to retrieve the corresponding EA inode. Since the EA inode is currently being evicted, ext4_iget() blocks in __wait_on_freeing_inode() waiting for eviction to complete.
- Task 2 (eviction thread): Currently evicting the same EA inode in ext4_evict_ea_inode(). It calls mb_cache_entry_wait_unused(oe) which blocks waiting for Task 1 to release the reference to the mbcache_entry.
To break this deadlock, implement a new ext4_iget() configuration flag named EXT4_IGET_NOWAIT. When set, perform a non-blocking lookup of the inode via VFS's find_inode_nowait() API.
If the inode is currently being evicted (marked with I_FREEING or I_WILL_FREE) or created (I_CREATING), or if it is not present in the VFS inode cache (cache miss), simply skip it (returning -ENOENT) rather than waiting for eviction/creation to complete, breaking the ABBA cycle.
Since we return -ENOENT immediately on a cache miss, we never attempt to allocate a new inode or call iget_locked(), completely eliminating any TOCTOU race window.
If the returned inode is I_NEW, wait for its initialization to clear via wait_on_new_inode(). If initialization fails and the inode is unhashed during wait_on_new_inode() waking up (e.g., due to an I/O read error in another thread), safely drop the reference and return -ENOENT. This unhashed check is executed unconditionally on all cache-hit pathways to properly handle concurrent initialization failures.
Finally, standard validation checks (including is_bad_inode, EXT4_EA_INODE_FL, file_acl, and xattr flags) are executed as normal inside check_igot_inode() to fully guarantee VFS-layer safety.
In ext4_xattr_inode_cache_find(), invoke ext4_iget() with the new EXT4_IGET_NOWAIT flag to perform the non-blocking cache search.
--- fs/ext4/ext4.h | 3 ++- fs/ext4/inode.c | 32 +++++++++++++++++++++++++++++--- fs/ext4/xattr.c | 2 +- 3 files changed, 32 insertions(+), 5 deletions(-)
fs/ext4/ext4.h +2 -1
@@ -2979,7 +2979,8 @@ typedef enum {EXT4_IGET_SPECIAL =0x0001 ,/* OK to iget a system inode */ EXT4_IGET_HANDLE =0x0002 ,/* Inode # is from a handle */ EXT4_IGET_BAD =0x0004 ,/* Allow to iget a bad inode */ - EXT4_IGET_EA_INODE = 0x0008 /* Inode should contain an EA value */ +EXT4_IGET_EA_INODE =0x0008 ,/* Inode should contain an EA value */ + EXT4_IGET_NOWAIT = 0x0010 /* Non-blocking lookup (skip if freeing) */ } ext4_iget_flags; extern struct inode *__ext4_iget(struct super_block *sb, unsigned long ino,
fs/ext4/inode.c +29 -3
@@ -4823,6 +4823,17 @@ error:return -EFSCORRUPTED ; } +static int ext4_iget_match (struct inode *inode,unsigned long ino,void *data) +{ +if (inode->i_ino != ino) +return 0 ; +if (READ_ONCE (inode->i_state) &I_CREATING ) +return -1 ; +if (!igrab (inode)) +return -1 ; +return 1 ; +} +struct inode *__ext4_iget (struct super_block *sb,unsigned long ino,ext4_iget_flags flags,const char *function,unsigned int line)
@@ -4856,9 +4867,24 @@ struct inode *__ext4_iget(struct super_breturn ERR_PTR (-EFSCORRUPTED ); } - inode =iget_locked (sb, ino); -if (!inode) -return ERR_PTR (-ENOMEM ); +if (flags &EXT4_IGET_NOWAIT ) { + inode =find_inode_nowait (sb, ino, ext4_iget_match,NULL ); +if (!inode) +return ERR_PTR (-ENOENT ); + +if (inode->i_state &I_NEW ) +wait_on_inode (inode); + +if (unlikely (inode_unhashed (inode))) { +iput (inode); +return ERR_PTR (-ENOENT ); + } + }else { + inode =iget_locked (sb, ino); +if (!inode) +return ERR_PTR (-ENOMEM ); + } +if (!(inode->i_state &I_NEW )) { ret =check_igot_inode (inode, flags, function, line);if (ret) {
fs/ext4/xattr.c +1 -1
@@ -1550,7 +1550,7 @@ ext4_xattr_inode_cache_find(struct inodewhile (ce) { ea_inode =ext4_iget (inode->i_sb, ce->e_value, -EXT4_IGET_EA_INODE ); +EXT4_IGET_EA_INODE |EXT4_IGET_NOWAIT );if (IS_ERR (ea_inode)) goto next_entry;ext4_xattr_inode_set_class (ea_inode);
Greg Kroah-Hartman
maintainerPATCH 1472/1674 powerpc/bpf: rename powerpc64_jit_data to powerpc_jit_data
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hari Bathini <[email protected]>
[ Upstream commit de04e40600ae15fa5e484be242e74aad6de7418f ]
powerpc64_jit_data is a misnomer as it is meant for both ppc32 and ppc64. Rename it to powerpc_jit_data.
Stable-dep-of: 369e4635d048 ("riscv, bpf: Fix memory leak in bpf_jit_free")
--- arch/powerpc/net/bpf_jit_comp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/net/bpf_jit_comp.c +2 -2
@@ -39,7 +39,7 @@ int bpf_jit_emit_exit_insn(u32 *image, struct codegen_context *ctx, int tmp_reg,return 0 ; } -struct powerpc64_jit_data { +struct powerpc_jit_data {struct bpf_binary_header *header;u32 *addrs;u8 *image;
@@ -59,7 +59,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)u8 *image =NULL ;u32 *code_base;u32 *addrs; -struct powerpc64_jit_data *jit_data; +struct powerpc_jit_data *jit_data;struct codegen_context cgctx;int pass;int flen;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1473/1674 bpf: remove unused parameter in bpf_jit_binary_pack_finalize
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael Passos <[email protected]>
[ Upstream commit 9919c5c98cb25dbf7e76aadb9beab55a2a25f830 ]
Fixes a compiler warning. the bpf_jit_binary_pack_finalize function was taking an extra bpf_prog parameter that went unused. This removves it and updates the callers accordingly.
Stable-dep-of: 369e4635d048 ("riscv, bpf: Fix memory leak in bpf_jit_free")
--- arch/riscv/net/bpf_jit_core.c | 5 ++--- arch/x86/net/bpf_jit_comp.c | 4 ++-- include/linux/filter.h | 3 +-- kernel/bpf/core.c | 3 +-- 4 files changed, 6 insertions(+), 9 deletions(-)
arch/riscv/net/bpf_jit_core.c +2 -3
@@ -176,8 +176,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog) prog->jited_len = prog_size;if (!prog->is_func || extra_pass) { -if (WARN_ON (bpf_jit_binary_pack_finalize (prog, jit_data->ro_header, - jit_data->header))) { +if (WARN_ON (bpf_jit_binary_pack_finalize (jit_data->ro_header, jit_data->header))) {/* ro_header has been freed */ jit_data->ro_header =NULL ; prog = orig_prog;
@@ -269,7 +268,7 @@ void bpf_jit_free(struct bpf_prog *prog)* before freeing it. */ if (jit_data) { -bpf_jit_binary_pack_finalize (prog, jit_data->ro_header, jit_data->header); +bpf_jit_binary_pack_finalize (jit_data->ro_header, jit_data->header);kfree (jit_data); } hdr =bpf_jit_binary_pack_hdr (prog);
arch/x86/net/bpf_jit_comp.c +2 -2
@@ -2949,7 +2949,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)* * Both cases are serious bugs and justify WARN_ON. */ -if (WARN_ON (bpf_jit_binary_pack_finalize (prog, header, rw_header))) { +if (WARN_ON (bpf_jit_binary_pack_finalize (header, rw_header))) {/* header has been freed */ header =NULL ; goto out_image;
@@ -3016,7 +3016,7 @@ void bpf_jit_free(struct bpf_prog *prog)* before freeing it. */ if (jit_data) { -bpf_jit_binary_pack_finalize (prog, jit_data->header, +bpf_jit_binary_pack_finalize (jit_data->header, jit_data->rw_header);kvfree (jit_data->addrs);kfree (jit_data);
include/linux/filter.h +1 -2
@@ -1083,8 +1083,7 @@ bpf_jit_binary_pack_alloc(unsigned int proglen, u8 **ro_image,u8 **rw_image, bpf_jit_fill_hole_t bpf_fill_ill_insns, bool was_classic); -int bpf_jit_binary_pack_finalize (struct bpf_prog *prog, -struct bpf_binary_header *ro_header, +int bpf_jit_binary_pack_finalize (struct bpf_binary_header *ro_header,struct bpf_binary_header *rw_header);void bpf_jit_binary_pack_free (struct bpf_binary_header *ro_header,struct bpf_binary_header *rw_header);
kernel/bpf/core.c +1 -2
@@ -1191,8 +1191,7 @@ bpf_jit_binary_pack_alloc(unsigned int proglen, u8 **image_ptr, }/* Copy JITed text from rw_header to its final location, the ro_header. */ -int bpf_jit_binary_pack_finalize (struct bpf_prog *prog, -struct bpf_binary_header *ro_header, +int bpf_jit_binary_pack_finalize (struct bpf_binary_header *ro_header,struct bpf_binary_header *rw_header) {void *ptr;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1474/1674 riscv, bpf: Fix memory leak in bpf_jit_free
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pu Lehui <[email protected]>
[ Upstream commit 369e4635d04801f394d5bd42556f21029e95ff93 ]
When bpf_int_jit_compile() is called for subprograms, it returns early during the first pass (!prog->is_func || extra_pass is false), keeping ctx->offset alive for the subsequent extra pass.
If JIT compilation fails for a later subprogram, the BPF core aborts and calls bpf_jit_free() to clean up the first subprogram. However, bpf_jit_free() fails to free jit_data->ctx.offset, which causes a memory leak of the JIT context offsets array.
Fix this by adding the missing kfree(jit_data->ctx.offset) in bpf_jit_free().
--- arch/riscv/net/bpf_jit_core.c | 1 + 1 file changed, 1 insertion(+)
arch/riscv/net/bpf_jit_core.c +1 -0
@@ -269,6 +269,7 @@ void bpf_jit_free(struct bpf_prog *prog)*/ if (jit_data) {bpf_jit_binary_pack_finalize (jit_data->ro_header, jit_data->header); +kfree (jit_data->ctx.offset);kfree (jit_data); } hdr =bpf_jit_binary_pack_hdr (prog);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1475/1674 bpf: Zero queue and stack outputs on lock failure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kumar Kartikeya Dwivedi <[email protected]>
[ Upstream commit 7ac6e1ae41a09f1dd4baeeff1d028ae49ee01232 ]
Queue and stack pop/peek helpers accept an uninitialized output buffer because the verifier expects the helper to initialize it. The empty-map error path clears the buffer, but a failed lock acquisition returns -EBUSY without writing it.
Clear the output before returning -EBUSY so BPF programs cannot observe uninitialized stack contents after a failed helper call.
--- kernel/bpf/queue_stack_maps.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
kernel/bpf/queue_stack_maps.c +6 -2
@@ -99,8 +99,10 @@ static long __queue_map_get(struct bpf_map *map, void *value, bool delete)void *ptr;if (in_nmi ()) { -if (!raw_spin_trylock_irqsave (&qs->lock, flags)) +if (!raw_spin_trylock_irqsave (&qs->lock, flags)) { +memset (value,0 , qs->map.value_size);return -EBUSY ; + } }else {raw_spin_lock_irqsave (&qs->lock, flags); }
@@ -134,8 +136,10 @@ static long __stack_map_get(struct bpf_map *map, void *value, bool delete)u32 index;if (in_nmi ()) { -if (!raw_spin_trylock_irqsave (&qs->lock, flags)) +if (!raw_spin_trylock_irqsave (&qs->lock, flags)) { +memset (value,0 , qs->map.value_size);return -EBUSY ; + } }else {raw_spin_lock_irqsave (&qs->lock, flags); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1476/1674 drm/sched: Use struct for drm_sched_init() params
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Philipp Stanner <[email protected]>
[ Upstream commit 796a9f55a8d1d85387b973df9a06cbf4bc2d6327 ]
drm_sched_init() has a great many parameters and upcoming new functionality for the scheduler might add even more. Generally, the great number of parameters reduces readability and has already caused one missnaming, addressed in:
commit 6f1cacf4eba7 ("drm/nouveau: Improve variable name in nouveau_sched_init()").
Introduce a new struct for the scheduler init parameters and port all users.
[ Adapted to this tree: the init args struct only carries the fields the
scheduler has here (no submit_wq, num_rqs or credit_limit), and only the drivers present here are converted. ]
Stable-dep-of: e2332abed2a4 ("drm/msm: Only fini scheduler after successful init")
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 16 +++++--- drivers/gpu/drm/etnaviv/etnaviv_sched.c | 13 ++++-- drivers/gpu/drm/lima/lima_sched.c | 13 ++++-- drivers/gpu/drm/msm/msm_ringbuffer.c | 15 +++---- drivers/gpu/drm/nouveau/nouveau_sched.c | 12 ++++-- drivers/gpu/drm/panfrost/panfrost_job.c | 15 ++++--- drivers/gpu/drm/scheduler/sched_main.c | 34 +++++---------- drivers/gpu/drm/v3d/v3d_sched.c | 48 +++++++++------------- include/drm/gpu_scheduler.h | 29 +++++++++++-- 9 files changed, 110 insertions(+), 85 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +11 -5
@@ -2356,6 +2356,11 @@ static int amdgpu_device_fw_loading(struct amdgpu_device *adev)static int amdgpu_device_init_schedulers (struct amdgpu_device *adev) { +struct drm_sched_init_args args = { + .ops = &amdgpu_sched_ops, + .timeout_wq = adev->reset_domain->wq, + .dev = adev->dev, + };long timeout;int r, i;
@@ -2381,11 +2386,12 @@ static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)break ; } - r =drm_sched_init (&ring->sched, &amdgpu_sched_ops, - ring->num_hw_submission,0 , - timeout, adev->reset_domain->wq, - ring->sched_score, ring->name, - adev->dev); + args.hw_submission = ring->num_hw_submission; + args.timeout = timeout; + args.score = ring->sched_score; + args.name = ring->name; + + r =drm_sched_init (&ring->sched, &args);if (r) {DRM_ERROR ("Failed to create scheduler on ring %s.\n" , ring->name);
drivers/gpu/drm/etnaviv/etnaviv_sched.c +9 -4
@@ -134,12 +134,17 @@ int etnaviv_sched_push_job(struct etnaviv_gem_submit *submit)int etnaviv_sched_init (struct etnaviv_gpu *gpu) { +const struct drm_sched_init_args args = { + .ops = &etnaviv_sched_ops, + .hw_submission = etnaviv_hw_jobs_limit, + .hang_limit = etnaviv_job_hang_limit, + .timeout =msecs_to_jiffies (500 ), + .name =dev_name (gpu->dev), + .dev = gpu->dev, + };int ret; - ret =drm_sched_init (&gpu->sched, &etnaviv_sched_ops, - etnaviv_hw_jobs_limit, etnaviv_job_hang_limit, -msecs_to_jiffies (500 ),NULL ,NULL , -dev_name (gpu->dev), gpu->dev); + ret =drm_sched_init (&gpu->sched, &args);if (ret)return ret;
drivers/gpu/drm/lima/lima_sched.c +9 -4
@@ -489,16 +489,21 @@ int lima_sched_pipe_init(struct lima_sched_pipe *pipe, const char *name) {unsigned int timeout = lima_sched_timeout_ms >0 ? lima_sched_timeout_ms :500 ; +struct drm_sched_init_args args = { + .ops = &lima_sched_ops, + .hw_submission =1 , + .hang_limit = lima_job_hang_limit, + .timeout =msecs_to_jiffies (timeout), + .name = name, + .dev = pipe->ldev->dev, + }; pipe->fence_context =dma_fence_context_alloc (1 );spin_lock_init (&pipe->fence_lock);INIT_WORK (&pipe->recover_work, lima_sched_recover_work); -return drm_sched_init (&pipe->base, &lima_sched_ops,1 , - lima_job_hang_limit, -msecs_to_jiffies (timeout),NULL , -NULL , name, pipe->ldev->dev); +return drm_sched_init (&pipe->base, &args); }void lima_sched_pipe_fini (struct lima_sched_pipe *pipe)
drivers/gpu/drm/msm/msm_ringbuffer.c +8 -7
@@ -58,8 +58,13 @@ static const struct drm_sched_backend_ops msm_sched_ops = {struct msm_ringbuffer *msm_ringbuffer_new (struct msm_gpu *gpu,int id,void *memptrs,uint64_t memptrs_iova) { +struct drm_sched_init_args args = { + .ops = &msm_sched_ops, + .hw_submission = num_hw_submissions, + .timeout =MAX_SCHEDULE_TIMEOUT , + .dev = gpu->dev->dev, + };struct msm_ringbuffer *ring; -long sched_timeout;char name[32 ];int ret;
@@ -86,6 +91,7 @@ struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id, }msm_gem_object_set_name (ring->bo,"ring%d" , id); + args.name =to_msm_bo (ring->bo)->name; ring->end = ring->start + (MSM_GPU_RINGBUFFER_SZ >>2 ); ring->next = ring->start;
@@ -94,12 +100,7 @@ struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id, ring->memptrs = memptrs; ring->memptrs_iova = memptrs_iova; -/* currently managing hangcheck ourselves: */ - sched_timeout =MAX_SCHEDULE_TIMEOUT ; - - ret =drm_sched_init (&ring->sched, &msm_sched_ops, - num_hw_submissions,0 , sched_timeout, -NULL ,NULL ,to_msm_bo (ring->bo)->name, gpu->dev->dev); + ret =drm_sched_init (&ring->sched, &args);if (ret) { goto fail; }
drivers/gpu/drm/nouveau/nouveau_sched.c +8 -4
@@ -429,15 +429,19 @@ static const struct drm_sched_backend_ops nouveau_sched_ops = {int nouveau_sched_init (struct nouveau_drm *drm) {struct drm_gpu_scheduler *sched = &drm->sched; -long job_hang_limit =msecs_to_jiffies (NOUVEAU_SCHED_JOB_TIMEOUT_MS ); +struct drm_sched_init_args args = { + .ops = &nouveau_sched_ops, + .hw_submission =NOUVEAU_SCHED_HW_SUBMISSIONS , + .timeout =msecs_to_jiffies (NOUVEAU_SCHED_JOB_TIMEOUT_MS ), + .name ="nouveau_sched" , + .dev = drm->dev->dev, + }; drm->sched_wq =create_singlethread_workqueue ("nouveau_sched_wq" );if (!drm->sched_wq)return -ENOMEM ; -return drm_sched_init (sched, &nouveau_sched_ops, -NOUVEAU_SCHED_HW_SUBMISSIONS ,0 , job_hang_limit, -NULL ,NULL ,"nouveau_sched" , drm->dev->dev); +return drm_sched_init (sched, &args); }void nouveau_sched_fini (struct nouveau_drm *drm)
drivers/gpu/drm/panfrost/panfrost_job.c +9 -6
@@ -791,6 +791,12 @@ static irqreturn_t panfrost_job_irq_handler(int irq, void *data)int panfrost_job_init (struct panfrost_device *pfdev) { +struct drm_sched_init_args args = { + .ops = &panfrost_sched_ops, + .timeout =msecs_to_jiffies (JOB_TIMEOUT_MS ), + .name ="pan_js" , + .dev = pfdev->dev, + };struct panfrost_job_slot *js;unsigned int nentries =2 ;int ret, j;
@@ -826,16 +832,13 @@ int panfrost_job_init(struct panfrost_device *pfdev) pfdev->reset.wq =alloc_ordered_workqueue ("panfrost-reset" ,0 );if (!pfdev->reset.wq)return -ENOMEM ; + args.timeout_wq = pfdev->reset.wq; + args.hw_submission = nentries;for (j =0 ; j <NUM_JOB_SLOTS ; j++) { js->queue[j].fence_context =dma_fence_context_alloc (1 ); - ret =drm_sched_init (&js->queue[j].sched, - &panfrost_sched_ops, - nentries,0 , -msecs_to_jiffies (JOB_TIMEOUT_MS ), - pfdev->reset.wq, -NULL ,"pan_js" , pfdev->dev); + ret =drm_sched_init (&js->queue[j].sched, &args);if (ret) {dev_err (pfdev->dev,"Failed to create scheduler: %d." , ret); goto err_sched;
drivers/gpu/drm/scheduler/sched_main.c +11 -23
@@ -1080,33 +1080,21 @@ static int drm_sched_main(void *param)* drm_sched_init - Init a gpu scheduler instance * * @sched: scheduler instance -* @ops: backend operations for this scheduler -* @hw_submission: number of hw submissions that can be in flight -* @hang_limit: number of times to allow a job to hang before dropping it -* @timeout: timeout value in jiffies for the scheduler -* @timeout_wq: workqueue to use for timeout work. If NULL, the system_wq is -* used -* @score: optional score atomic shared with other schedulers -* @name: name used for debugging -* @dev: target &struct device +* @args: scheduler initialization arguments * * Return 0 on success, otherwise error code. */ -int drm_sched_init (struct drm_gpu_scheduler *sched, -const struct drm_sched_backend_ops *ops, -unsigned hw_submission,unsigned hang_limit, -long timeout,struct workqueue_struct *timeout_wq, -atomic_t *score,const char *name,struct device *dev) +int drm_sched_init (struct drm_gpu_scheduler *sched,const struct drm_sched_init_args *args) {int i, ret; - sched->ops = ops; - sched->hw_submission_limit = hw_submission; - sched->name = name; - sched->timeout = timeout; - sched->timeout_wq = timeout_wq ? : system_wq; - sched->hang_limit = hang_limit; - sched->score = score ? score : &sched->_score; - sched->dev = dev; + sched->ops = args->ops; + sched->hw_submission_limit = args->hw_submission; + sched->name = args->name; + sched->timeout = args->timeout; + sched->timeout_wq = args->timeout_wq ? args->timeout_wq : system_wq; + sched->hang_limit = args->hang_limit; + sched->score = args->score ? args->score : &sched->_score; + sched->dev = args->dev;for (i =DRM_SCHED_PRIORITY_MIN ; i <DRM_SCHED_PRIORITY_COUNT ; i++)drm_sched_rq_init (sched, &sched->sched_rq[i]);
@@ -1124,7 +1112,7 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,if (IS_ERR (sched->thread)) { ret =PTR_ERR (sched->thread); sched->thread =NULL ; -DRM_DEV_ERROR (sched->dev,"Failed to create scheduler for %s.\n" , name); +DRM_DEV_ERROR (sched->dev,"Failed to create scheduler for %s.\n" , args->name);return ret; }
drivers/gpu/drm/v3d/v3d_sched.c +20 -28
69 lines not on this page · raw message
include/drm/gpu_scheduler.h +25 -4
@@ -518,11 +518,32 @@ struct drm_gpu_scheduler {struct device *dev; }; +/** +* struct drm_sched_init_args - parameters for initializing a DRM GPU scheduler +* +* @ops: backend operations provided by the driver +* @timeout_wq: workqueue to use for timeout work. If NULL, the system_wq is used. +* @hw_submission: number of hw submissions that can be in flight +* @hang_limit: number of times to allow a job to hang before dropping it. +* This mechanism is DEPRECATED. Set it to 0. +* @timeout: timeout value in jiffies for submitted jobs. +* @score: score atomic shared with other schedulers. May be NULL. +* @name: name (typically the driver's name). Used for debugging +* @dev: associated device. Used for debugging +*/ +struct drm_sched_init_args { +const struct drm_sched_backend_ops *ops; +struct workqueue_struct *timeout_wq; +uint32_t hw_submission; +unsigned int hang_limit; +long timeout; +atomic_t *score; +const char *name; +struct device *dev; +}; +int drm_sched_init (struct drm_gpu_scheduler *sched, -const struct drm_sched_backend_ops *ops, -uint32_t hw_submission,unsigned hang_limit, -long timeout,struct workqueue_struct *timeout_wq, -atomic_t *score,const char *name,struct device *dev); +const struct drm_sched_init_args *args);void drm_sched_fini (struct drm_gpu_scheduler *sched); int drm_sched_job_init(struct drm_sched_job *job,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1477/1674 drm/msm: Only fini scheduler after successful init
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruoyu Wang <[email protected]>
[ Upstream commit e2332abed2a4d3caa59052095dc16e4ce44791ea ]
msm_ringbuffer_new() destroys a partially initialized ring through msm_ringbuffer_destroy() when an allocation or scheduler setup step fails.
If drm_sched_init() fails before it finishes initializing the scheduler, the failure path still calls drm_sched_fini(). That teardown path assumes the scheduler work items, lists, and workqueue state were initialized.
Track successful scheduler initialization and call drm_sched_fini() only after drm_sched_init() returned 0.
This issue was found by a static analysis checker and confirmed by manual source review.
Patchwork: https://patchwork.freedesktop.org/patch/738905/
Message-ID: <[email protected]>
--- drivers/gpu/drm/msm/msm_ringbuffer.c | 7 ++++--- drivers/gpu/drm/msm/msm_ringbuffer.h | 1 + 2 files changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/msm/msm_ringbuffer.c +4 -3
@@ -101,9 +101,9 @@ struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id, ring->memptrs_iova = memptrs_iova; ret =drm_sched_init (&ring->sched, &args); -if (ret) { +if (ret) goto fail; - } + ring->sched_initialized = true;INIT_LIST_HEAD (&ring->submits);spin_lock_init (&ring->submit_lock);
@@ -125,7 +125,8 @@ void msm_ringbuffer_destroy(struct msm_ringbuffer *ring)if (IS_ERR_OR_NULL (ring))return ; -drm_sched_fini (&ring->sched); +if (ring->sched_initialized) +drm_sched_fini (&ring->sched);msm_fence_context_free (ring->fctx);
drivers/gpu/drm/msm/msm_ringbuffer.h +1 -0
@@ -50,6 +50,7 @@ struct msm_ringbuffer {* The job scheduler for this ring. */ struct drm_gpu_scheduler sched; +bool sched_initialized;/* * List of in-flight submits on this ring. Protected by submit_lock.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1478/1674 firmware: arm_scmi: Fix SCMI device destroy lifetimes
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sudeep Holla <[email protected]>
[ Upstream commit 6abe8fe36b29ff51d1a42c2f338972883f4751a5 ]
scmi_child_dev_find() drops the reference returned by device_find_child() before returning the scmi_device pointer. A concurrent unregister can then release the device while the destroy path is still using the returned pointer.
Make the lookup helper return the device_find_child() reference and keep it until scmi_device_destroy() has finished unregistering the child.
Also split device_unregister() in __scmi_device_destroy() so the SCMI bus ID is not made reusable until after device_del() has removed the old scmi_dev.N name from sysfs. This avoids a new SCMI device reusing the same ID while the old device is still registered.
The final device release callback is also a possible cleanup path when SCMI children are deleted by driver core recursion rather than __scmi_device_destroy(). Release the SCMI bus ID from a common helper used by destroy, register-failure and final-release paths, and clear scmi_dev->id after freeing it so the final release cannot free the same ID again.
--- drivers/firmware/arm_scmi/bus.c | 36 ++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 12 deletions(-)
drivers/firmware/arm_scmi/bus.c +24 -12
@@ -249,8 +249,9 @@ static int scmi_match_by_id_table(struct device *dev, void *data) (id_table->name && !strcmp (sdev->name, id_table->name)); } -static struct scmi_device *scmi_child_dev_find (struct device *parent, -int prot_id,const char *name) +/* Returns a device_find_child() reference which must be dropped by caller. */ +static struct scmi_device * +scmi_child_dev_find_get (struct device *parent,int prot_id,const char *name) {struct scmi_device_id id_table;struct device *dev;
@@ -262,9 +263,6 @@ static struct scmi_device *scmi_child_dev_find(struct device *parent,if (!dev)return NULL ; -/* Drop the refcnt bumped implicitly by device_find_child */ -put_device (dev); -return to_scmi_dev (dev); }
@@ -332,10 +330,19 @@ void scmi_driver_unregister(struct scmi_driver *driver) }EXPORT_SYMBOL_GPL (scmi_driver_unregister); +static void scmi_device_release_resources (struct scmi_device *scmi_dev) +{ +if (scmi_dev->id) { +ida_free (&scmi_bus_id, scmi_dev->id); + scmi_dev->id =0 ; + } +} +static void scmi_device_release (struct device *dev) {struct scmi_device *scmi_dev =to_scmi_dev (dev); +scmi_device_release_resources (scmi_dev);kfree_const (scmi_dev->name);kfree (scmi_dev); }
@@ -350,8 +357,9 @@ static void __scmi_device_destroy(struct scmi_device *scmi_dev)if (scmi_dev->protocol_id ==SCMI_PROTOCOL_SYSTEM )atomic_set (&scmi_syspower_registered,0 ); -ida_free (&scmi_bus_id, scmi_dev->id); -device_unregister (&scmi_dev->dev); +device_del (&scmi_dev->dev); +scmi_device_release_resources (scmi_dev); +put_device (&scmi_dev->dev); } static struct scmi_device *
@@ -368,9 +376,11 @@ __scmi_device_create(struct device_node *np, struct device *parent,* each DT defined protocol at probe time, and the concurrent * registration of SCMI drivers. */ - scmi_dev =scmi_child_dev_find (parent, protocol, name); -if (scmi_dev) + scmi_dev =scmi_child_dev_find_get (parent, protocol, name); +if (scmi_dev) { +put_device (&scmi_dev->dev);return scmi_dev; + }/* * Ignore any possible subsequent failures while creating the device
@@ -421,8 +431,8 @@ __scmi_device_create(struct device_node *np, struct device *parent,return scmi_dev; put_dev: +scmi_device_release_resources (scmi_dev);put_device (&scmi_dev->dev); -ida_free (&scmi_bus_id, id);return NULL ; }
@@ -494,9 +504,11 @@ void scmi_device_destroy(struct device *parent, int protocol, const char *name) {struct scmi_device *scmi_dev; - scmi_dev =scmi_child_dev_find (parent, protocol, name); -if (scmi_dev) + scmi_dev =scmi_child_dev_find_get (parent, protocol, name); +if (scmi_dev) {__scmi_device_destroy (scmi_dev); +put_device (&scmi_dev->dev); + } }EXPORT_SYMBOL_GPL (scmi_device_destroy);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1479/1674 firmware: arm_scmi: Clean up channels on setup failure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sudeep Holla <[email protected]>
[ Upstream commit 687d67be3d87894ef12e8a164434612e0b53cfae ]
scmi_channels_setup() can fail after the common BASE channel or earlier protocol channels have already been registered in the TX/RX IDRs.
Route this failure through the existing channel cleanup label so the transport channels, transport devices and IDR state created before the failure are released before the probe error path frees the SCMI instance ID.
--- drivers/firmware/arm_scmi/driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/arm_scmi/driver.c +1 -1
@@ -2830,7 +2830,7 @@ static int scmi_probe(struct platform_device *pdev)/* Setup all channels described in the DT at first */ ret =scmi_channels_setup (info);if (ret) - goto clear_ida; + goto clear_txrx_setup; ret =bus_register_notifier (&scmi_bus_type, &info->bus_nb);if (ret)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1480/1674 RDMA/rvt: Return NULL after port allocation failure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leon Romanovsky <[email protected]>
[ Upstream commit 2982eaf3b9d2d953318c74cd6f1b7576ea6d7b1f ]
rvt_alloc_device() deallocates the IB device when its port array cannot be allocated but then returns the pointer to the released allocation. Callers treat any non-NULL value as valid and dereference it, resulting in a use-after-free.
Return NULL immediately after deallocation so callers can propagate the allocation failure.
--- drivers/infiniband/sw/rdmavt/vt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/infiniband/sw/rdmavt/vt.c +3 -1
@@ -54,8 +54,10 @@ struct rvt_dev_info *rvt_alloc_device(size_t size, int nports)return rdi; rdi->ports =kcalloc (nports,sizeof (*rdi->ports),GFP_KERNEL ); -if (!rdi->ports) +if (!rdi->ports) {ib_dealloc_device (&rdi->ibdev); +return NULL ; + }return rdi; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1481/1674 esp: do not unref managed frag pages in esp_ssg_unref()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maher Azzouzi <[email protected]>
[ Upstream commit 21697720ff43b8dfa25b8e8d9ca7f56f4597fc80 ]
esp_ssg_unref() releases the page references held on the source scatterlist after the AEAD operation completes. It calls skb_page_unref() on every frag page for an out-of-place transform (req->src != req->dst), and in the error path of esp_output_tail() (already_unref == true) on the request's own scatterlist.
This is wrong when the skb carries managed frags (SKBFL_MANAGED_FRAG_REFS). Managed frags are owned by a zerocopy ubuf and the skb does not hold a per-frag page reference; io_uring SEND_ZC with a registered buffer attaches the bvec pages this way via io_sg_from_iter(). The rest of the stack honours this invariant:skb_release_data() skips the per-frag unref when SKBFL_MANAGED_FRAG_REFS is set, and skb_zcopy_managed() is the guard used at the other unref sites.
esp_ssg_unref() is missing that guard, so for a managed-frag skb it drops a page reference the skb never acquired. This can underflow the page reference count and free a page that is still in use.
Guard the function with skb_zcopy_managed() so both unref paths are skipped for managed-frag skbs, matching skb_release_data().
--- net/ipv4/esp4.c | 7 +++++++ net/ipv6/esp6.c | 7 +++++++ 2 files changed, 14 insertions(+)
net/ipv4/esp4.c +7 -0
@@ -103,6 +103,13 @@ static void esp_ssg_unref(struct xfrm_state *x, void *tmp, struct sk_buff *skb)struct aead_request *req;struct scatterlist *sg; +/* Managed frags are owned by the zerocopy ubuf; the skb holds no +* per-frag page reference, so we must not drop one here. Mirrors +* the SKBFL_MANAGED_FRAG_REFS handling in skb_release_data(). +*/ +if (skb_zcopy_managed (skb)) +return ; +if (x->props.flags &XFRM_STATE_ESN ) extralen +=sizeof (struct esp_output_extra );
net/ipv6/esp6.c +7 -0
@@ -120,6 +120,13 @@ static void esp_ssg_unref(struct xfrm_state *x, void *tmp, struct sk_buff *skb)struct aead_request *req;struct scatterlist *sg; +/* Managed frags are owned by the zerocopy ubuf; the skb holds no +* per-frag page reference, so we must not drop one here. Mirrors +* the SKBFL_MANAGED_FRAG_REFS handling in skb_release_data(). +*/ +if (skb_zcopy_managed (skb)) +return ; +if (x->props.flags &XFRM_STATE_ESN ) extralen +=sizeof (struct esp_output_extra );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1482/1674 platform/x86: asus-wmi: disable USB0 hub on ROG Ally before suspend
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luke D. Jones <[email protected]>
[ Upstream commit e0894ff038d86f30614ec16ec26dacb88c8d2bd4 ]
ASUS have worked around an issue in XInput where it doesn't support USB selective suspend, which causes suspend issues in Windows. They worked around this by adjusting the MCU firmware to disable the USB0 hub when the screen is switched off during the Microsoft DSM suspend path in ACPI.
The issue we have with this however is one of timing - the call the tells the MCU to this isn't able to complete before suspend is done so we call this in a prepare() and add a small msleep() to ensure it is done. This must be done before the screen is switched off to prevent a variety of possible races.
Further to this the MCU powersave option must also be disabled as it can cause a number of issues such as:
- unreliable resume connection of N-Key
- complete loss of N-Key if the power is plugged in while suspended Disabling the powersave option prevents this.
Without this the MCU is unable to initialise itself correctly on resume.
Stable-dep-of: ef3daa2b84a2 ("platform/x86: asus-wmi: fix resource leaks on probe failure")
--- drivers/platform/x86/asus-wmi.c | 50 ++++++++++++++++++++++ include/linux/platform_data/x86/asus-wmi.h | 3 ++ 2 files changed, 53 insertions(+)
drivers/platform/x86/asus-wmi.c +50 -0
@@ -16,6 +16,7 @@#include <linux/acpi.h> #include <linux/backlight.h> #include <linux/debugfs.h> +#include <linux/delay.h> #include <linux/dmi.h> #include <linux/fb.h> #include <linux/hwmon.h>
@@ -133,6 +134,11 @@ module_param(fnlock_default, bool, 0444);#define NVIDIA_TEMP_MIN 75#define NVIDIA_TEMP_MAX 87 +/* Controls the power state of the USB0 hub on ROG Ally which input is on */ +#define ASUS_USB0_PWR_EC0_CSEE "\\_SB.PCI0.SBRG.EC0.CSEE" +/* 300ms so far seems to produce a reliable result on AC and battery */ +#define ASUS_USB0_PWR_EC0_CSEE_WAIT 300 +static const char *const ashs_ids[] = {"ATK4001" ,"ATK4002" ,NULL };static int throttle_thermal_policy_write (struct asus_wmi *);
@@ -300,6 +306,9 @@ struct asus_wmi {bool fnlock_locked; +/* The ROG Ally device requires the MCU USB device be disconnected before suspend */ +bool ally_mcu_usb_switch; +struct asus_wmi_debug debug;struct asus_wmi_driver *driver;
@@ -4367,6 +4376,8 @@ static int asus_wmi_add(struct platform_device *pdev) asus->nv_temp_tgt_available =asus_wmi_dev_is_present (asus,ASUS_WMI_DEVID_NV_THERM_TARGET ); asus->panel_overdrive_available =asus_wmi_dev_is_present (asus,ASUS_WMI_DEVID_PANEL_OD ); asus->mini_led_mode_available =asus_wmi_dev_is_present (asus,ASUS_WMI_DEVID_MINI_LED_MODE ); + asus->ally_mcu_usb_switch =acpi_has_method (NULL ,ASUS_USB0_PWR_EC0_CSEE ) + &&dmi_match (DMI_BOARD_NAME ,"RC71L" );if (asus_wmi_dev_is_present (asus,ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY )) asus->throttle_thermal_policy_dev =ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY ;
@@ -4531,6 +4542,43 @@ static int asus_hotk_resume(struct device *device)asus_wmi_fnlock_update (asus);asus_wmi_tablet_mode_get_state (asus); + +return 0 ; +} + +static int asus_hotk_resume_early (struct device *device) +{ +struct asus_wmi *asus =dev_get_drvdata (device); + +if (asus->ally_mcu_usb_switch) { +if (ACPI_FAILURE (acpi_execute_simple_method (NULL ,ASUS_USB0_PWR_EC0_CSEE ,0xB8 ))) +dev_err (device,"ROG Ally MCU failed to connect USB dev\n" ); +else +msleep (ASUS_USB0_PWR_EC0_CSEE_WAIT ); + } +return 0 ; +} + +static int asus_hotk_prepare (struct device *device) +{ +struct asus_wmi *asus =dev_get_drvdata (device); +int result, err; + +if (asus->ally_mcu_usb_switch) { +/* When powersave is enabled it causes many issues with resume of USB hub */ + result =asus_wmi_get_devstate_simple (asus,ASUS_WMI_DEVID_MCU_POWERSAVE ); +if (result ==1 ) { +dev_warn (device,"MCU powersave enabled, disabling to prevent resume issues" ); + err =asus_wmi_set_devstate (ASUS_WMI_DEVID_MCU_POWERSAVE ,0 , &result); +if (err || result !=1 ) +dev_err (device,"Failed to set MCU powersave mode: %d\n" , err); + } +/* sleep required to ensure USB0 is disabled before sleep continues */ +if (ACPI_FAILURE (acpi_execute_simple_method (NULL ,ASUS_USB0_PWR_EC0_CSEE ,0xB7 ))) +dev_err (device,"ROG Ally MCU failed to disconnect USB dev\n" ); +else +msleep (ASUS_USB0_PWR_EC0_CSEE_WAIT ); + }return 0 ; }
@@ -4578,6 +4626,8 @@ static const struct dev_pm_ops asus_pm_ops = { .thaw = asus_hotk_thaw, .restore = asus_hotk_restore, .resume = asus_hotk_resume, + .resume_early = asus_hotk_resume_early, + .prepare = asus_hotk_prepare, };/* Registration ***************************************************************/
include/linux/platform_data/x86/asus-wmi.h +3 -0
@@ -111,6 +111,9 @@/* Charging mode - 1=Barrel, 2=USB */ #define ASUS_WMI_DEVID_CHARGE_MODE 0x0012006C +/* MCU powersave mode */ +#define ASUS_WMI_DEVID_MCU_POWERSAVE 0x001200E2 +/* epu is connected? 1 == true */ #define ASUS_WMI_DEVID_EGPU_CONNECTED 0x00090018/* egpu on/off */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1483/1674 platform/x86: asus-wmi: fix resource leaks on probe failure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marco Scardovi <[email protected]>
[ Upstream commit ef3daa2b84a2b8499ce9e2ce1c865dca36d39f95 ]
During driver initialization in asus_wmi_add(), various subsystems are registered sequentially. However, the error path labels are out of order relative to the registration sequence.
Specifically:
1. If asus_wmi_custom_fan_curve_init() fails, the driver jumps to fail_custom_fan_curve. Because this label is placed below fail_sysfs, it bypasses the cleanup calls for the input device and sysfs groups, which were successfully registered before, leaking those resources.
2. If asus_screenpad_init() fails, the driver jumps to fail_screenpad. Because fail_screenpad is placed below fail_backlight, it bypasses the cleanup calls for backlight and rfkill, leaking those resources.
Fix these resource leaks by reordering the error path labels in asus_wmi_add() to match the exact reverse order of the resource allocations.
--- drivers/platform/x86/asus-wmi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/asus-wmi.c +1 -1
@@ -4470,12 +4470,12 @@ static int asus_wmi_add(struct platform_device *pdev) fail_rfkill:asus_wmi_led_exit (asus); fail_leds: +fail_custom_fan_curve: fail_hwmon:asus_wmi_input_exit (asus); fail_input:asus_wmi_sysfs_exit (asus->platform_device); fail_sysfs: -fail_custom_fan_curve: fail_platform_profile_setup:if (asus->platform_profile_support)platform_profile_remove ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1484/1674 usb: gadget: uac: validate rate list length before storing
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qing Ming <[email protected]>
[ Upstream commit 844d83d5964b87919b958ff48405188c6ddae9cc ]
UAC1 and UAC2 configfs rate-list attributes parse a comma-separated list of sampling rates and store each parsed value in fixed-size arrays. The arrays have UAC_MAX_RATES entries, but the store paths do not check that the input contains at most that many tokens before writing through opts->name##s[i++].
Writing more than ten rates therefore writes past the end of the p_srates[] or c_srates[] array in struct f_uac1_opts or struct f_uac2_opts.
With CONFIG_UBSAN_BOUNDS enabled, writing an 11-entry rate list to the UAC1 p_srate attribute reports:
UBSAN: array-index-out-of-bounds drivers/usb/gadget/function/f_uac1.c:1669:1 index 10 is out of range for type 'int [10]' __ubsan_handle_out_of_bounds.cold f_uac1_opts_p_srate_store configfs_write_iter vfs_write ksys_write do_syscall_64
The same reproducer against the UAC2 p_srate attribute reports:
UBSAN: array-index-out-of-bounds drivers/usb/gadget/function/f_uac2.c:2087:1 index 10 is out of range for type 'int [10]' __ubsan_handle_out_of_bounds.cold f_uac2_opts_p_srate_store configfs_write_iter vfs_write ksys_write do_syscall_64
Reject additional tokens once UAC_MAX_RATES entries have been parsed. Also keep the original kstrdup() pointer for kfree(), because strsep() advances the parsing cursor. Freeing the advanced cursor leaks the original buffer on successful parses and can free an interior pointer on some error paths.
--- drivers/usb/gadget/function/f_uac1.c | 13 +++++++++---- drivers/usb/gadget/function/f_uac2.c | 13 +++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-)
drivers/usb/gadget/function/f_uac1.c +9 -4
@@ -1521,7 +1521,8 @@ static ssize_t f_uac1_opts_##name##_store(struct config_item *item, \ const char *page, size_t len) \ { \struct f_uac1_opts *opts =to_f_uac1_opts (item); \ -char *split_page =NULL ; \ +char *buf =NULL ; \ +char *split_page; \int ret = -EINVAL ; \char *token; \u32 num; \
@@ -1535,18 +1536,22 @@ static ssize_t f_uac1_opts_##name##_store(struct config_item *item, \ \ i =0 ; \ memset(opts->name##s, 0x00, sizeof(opts->name##s)); \ - split_page = kstrdup(page, GFP_KERNEL); \ + buf = kstrdup(page, GFP_KERNEL); \ + split_page = buf; \ while ((token = strsep(&split_page, ",")) != NULL) { \ ret = kstrtou32(token, 0, &num); \ if (ret) \ goto end; \ - \ + if (i >= UAC_MAX_RATES) { \ + ret = -EINVAL; \ + goto end; \ + } \ opts->name##s[i++] = num; \ ret = len; \ }; \ \ end: \ - kfree(split_page); \ + kfree(buf); \ mutex_unlock(&opts->lock); \ return ret; \ } \
drivers/usb/gadget/function/f_uac2.c +9 -4
@@ -2003,7 +2003,8 @@ static ssize_t f_uac2_opts_##name##_store(struct config_item *item, \ const char *page, size_t len) \ { \struct f_uac2_opts *opts =to_f_uac2_opts (item); \ -char *split_page =NULL ; \ +char *buf =NULL ; \ +char *split_page; \int ret = -EINVAL ; \char *token; \u32 num; \
@@ -2017,18 +2018,22 @@ static ssize_t f_uac2_opts_##name##_store(struct config_item *item, \ \ i =0 ; \ memset(opts->name##s, 0x00, sizeof(opts->name##s)); \ - split_page = kstrdup(page, GFP_KERNEL); \ + buf = kstrdup(page, GFP_KERNEL); \ + split_page = buf; \ while ((token = strsep(&split_page, ",")) != NULL) { \ ret = kstrtou32(token, 0, &num); \ if (ret) \ goto end; \ - \ + if (i >= UAC_MAX_RATES) { \ + ret = -EINVAL; \ + goto end; \ + } \ opts->name##s[i++] = num; \ ret = len; \ }; \ \ end: \ - kfree(split_page); \ + kfree(buf); \ mutex_unlock(&opts->lock); \ return ret; \ } \
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1485/1674 bpf: Reject rdonly/rdwr_buf_size kfunc arguments that exceed u32 max
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicholas Dudar <[email protected]>
[ Upstream commit 2aaf67f0516fde29620d0edfc29c01b9ea7ad430 ]
check_kfunc_args() detects a kfunc argument named rdonly_buf_size or rdwr_buf_size and stores reg->var_off.value into meta->r0_size, a u64, and does not bound it. check_kfunc_call() later copies that value into the returned register's mem_size field:
meta->r0_size = reg->var_off.value; ... regs[BPF_REG_0].mem_size = meta.r0_size;
regs[BPF_REG_0].mem_size is u32. A constant whose upper 32 bits are set gets truncated instead of causing a load-time rejection, so the verifier records a PTR_TO_MEM register with an approximately 4 GiB mem_size for whatever allocation the kfunc returned. A later access check against that register uses the truncated, wrong bound.
Reject rdonly_buf_size/rdwr_buf_size values that exceed U32_MAX at the point meta->r0_size is set.
--- kernel/bpf/verifier.c | 4 ++++ 1 file changed, 4 insertions(+)
kernel/bpf/verifier.c +4 -0
@@ -11493,6 +11493,10 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_ } meta->r0_size = reg->var_off.value; +if (meta->r0_size >U32_MAX ) { +verbose (env,"R%d rdonly/rdwr_buf_size exceeds u32 max\n" , regno); +return -EINVAL ; + } ret =mark_chain_precision (env, regno);if (ret)return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1486/1674 platform/x86: lg-laptop: Fix LED resource handling
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Armin Wolf <[email protected]>
[ Upstream commit 3e91964aa74ab261aa15d9d96318eded2fd9d22a ]
The event notification callback might access kbd_backlight even when it was not successfully registered with the LED subsystem. The same happens inside acpi_remove(), where the LED devices are unregistered unconditionally.
Fix this by tracking the availability of the kbd_backlight LED device and use devm_led_classdev_register() to let devres take care of unregistering the LED devices during removal. For this the parent device of the LED devices is changed to the native platform device.
--- drivers/platform/x86/lg-laptop.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-)
drivers/platform/x86/lg-laptop.c +21 -7
@@ -71,6 +71,8 @@ static u32 inited;#define INIT_SPARSE_KEYMAP 0x80static int battery_limit_use_wmbb; +static bool kbd_backlight_available; +static bool tpad_led_available;static struct led_classdev kbd_backlight;static enum led_brightness get_kbd_backlight_level (struct device *dev);
@@ -188,6 +190,7 @@ static void wmi_notify(u32 value, void *context)union acpi_object *obj;acpi_status status;long data = (long )context; +unsigned int brightness;pr_debug ("event guid %li\n" , data); status =wmi_get_event_data (value, &response);
@@ -205,8 +208,11 @@ static void wmi_notify(u32 value, void *context)struct key_entry *key;if (eventcode ==0x10000000 ) { -led_classdev_notify_brightness_hw_changed ( - &kbd_backlight,get_kbd_backlight_level (kbd_backlight.dev->parent)); +if (kbd_backlight_available) { + brightness =get_kbd_backlight_level (kbd_backlight.dev->parent); +led_classdev_notify_brightness_hw_changed (&kbd_backlight, + brightness); + } }else { key =sparse_keymap_entry_from_scancode ( wmi_input_dev, eventcode);
@@ -725,8 +731,11 @@ static int acpi_add(struct acpi_device *device) goto out_platform_device;/* LEDs are optional */ -led_classdev_register (&pf_device->dev, &kbd_backlight); -led_classdev_register (&pf_device->dev, &tpad_led); + ret =led_classdev_register (&pf_device->dev, &kbd_backlight); + kbd_backlight_available = !ret; + + ret =led_classdev_register (&pf_device->dev, &tpad_led); + tpad_led_available = !ret;wmi_input_setup ();battery_hook_register (&battery_hook);
@@ -744,11 +753,16 @@ static void acpi_remove(struct acpi_device *device) {sysfs_remove_group (&pf_device->dev.kobj, &dev_attribute_group); -led_classdev_unregister (&tpad_led); -led_classdev_unregister (&kbd_backlight); -battery_hook_unregister (&battery_hook);wmi_input_destroy (); + +if (tpad_led_available) +led_classdev_unregister (&tpad_led); +if (kbd_backlight_available) { + kbd_backlight_available = false; +led_classdev_unregister (&kbd_backlight); + } +platform_device_unregister (pf_device); pf_device =NULL ;platform_driver_unregister (&pf_driver);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1487/1674 platform/x86: dell-wmi-base: Fix handling of ultra performance key
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Armin Wolf <[email protected]>
[ Upstream commit adfd6846bea13667ff28f8aaf00c32fbd69825ab ]
The commit message of commit 5fbd827eb9c2 ("platform/x86: dell-wmi: Recognise or support new switches") states that the ultra performance key contains additional data
after the type and code fields. The event data passed todell_wmi_process_key() is already parsed, so "buffer" already
starts after those two fields.
Use the correct index for accessing the first data field to avoid a potential buffer overread.
--- drivers/platform/x86/dell/dell-wmi-base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/dell/dell-wmi-base.c +1 -1
@@ -442,7 +442,7 @@ static int dell_wmi_process_key(struct wmi_device *wdev, int type, int code, u16 SW_TABLET_MODE, !buffer[0]);return 1 ; }else if (type ==0x0012 && code ==0x000d && remaining >0 ) { - value = (buffer[2 ] ==2 ); + value = (buffer[0 ] ==2 ); used =1 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1488/1674 bpf: Reject writes through untrusted BTF pointers
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicholas Dudar <[email protected]>
[ Upstream commit ac65c710cc643cbc52b899627577357867249530 ]
check_ptr_to_btf_access() lets program-type btf_struct_access callbacks validate writes before the default BTF access path rejects non-read accesses. That bypasses the read-only policy for untrusted BTF pointers created by helpers such as bpf_rdonly_cast().
Reject non-read accesses through PTR_UNTRUSTED BTF pointers at the common entry point, before the callback branch to handle all cases.
--- kernel/bpf/verifier.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
kernel/bpf/verifier.c +6 -2
@@ -6579,6 +6579,11 @@ static int check_ptr_to_btf_access(struct bpf_verifier_env *env,return -EACCES ; } +if (atype !=BPF_READ && (type_flag (reg->type) &PTR_UNTRUSTED )) { +verbose (env,"only read is supported\n" ); +return -EACCES ; + } +if (env->ops->btf_struct_access && !type_is_alloc (reg->type) && atype ==BPF_WRITE ) {if (!btf_is_kernel (reg->btf)) {verbose (env,"verifier internal error: reg->btf must be kernel btf\n" );
@@ -6587,8 +6592,7 @@ static int check_ptr_to_btf_access(struct bpf_verifier_env *env, ret = env->ops->btf_struct_access (&env->log, reg, off, size); }else {/* Writes are permitted with default btf_struct_access for -* program allocated objects (which always have ref_obj_id > 0), -* but not for untrusted PTR_TO_BTF_ID | MEM_ALLOC. +* program allocated objects (which always have ref_obj_id > 0). */ if (atype !=BPF_READ && !type_is_ptr_alloc_obj (reg->type)) {verbose (env,"only read is supported\n" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1489/1674 time/namespace: Validate nanosecond field in proc_timens_set_offset()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Malaya Kumar Rout <[email protected]>
[ Upstream commit 06aba58e58492d2b8eae059274caed29025ea96e ]
The function validates tv_sec to be within [-KTIME_SEC_MAX, KTIME_SEC_MAX] but never validates that tv_nsec is within the valid range of [0, NSEC_PER_SEC-1] before using it in timespec64_add().
timespec64_add() expects both timespec64 structures to have normalized values with tv_nsec in the range [0, 999999999]. If off->val.tv_nsec contains invalid values (negative or >= NSEC_PER_SEC), it could lead to incorrect calculations or unexpected behavior.
Add validation to ensure tv_nsec is within the valid range before performing the addition.
--- kernel/time/namespace.c | 5 +++++ 1 file changed, 5 insertions(+)
kernel/time/namespace.c +5 -0
@@ -416,6 +416,11 @@ int proc_timens_set_offset(struct file *file, struct task_struct *p, off->val.tv_sec < -KTIME_SEC_MAX) goto out; +if (off->val.tv_nsec <0 || off->val.tv_nsec >=NSEC_PER_SEC ) { + err = -EINVAL ; + goto out; + } + tp =timespec64_add (tp, off->val);/* * KTIME_SEC_MAX is divided by 2 to be sure that KTIME_MAX is
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1490/1674 bpf: Reject MEM_ALLOC BTF accesses past object bounds
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yiyang Chen <[email protected]>
[ Upstream commit 9c9ee0324c774490ae953162aaaf4561d222bd93 ]
BTF struct walks relax the struct-size check for accesses through a trailing flexible array. That is valid for ordinary BTF type walking, but PTR_TO_BTF_ID | MEM_ALLOC values point to objects allocated with the static BTF type size.
When walking a MEM_ALLOC object, reject the access before applying the flexible-array relaxation if the access range extends past the struct size. Apply the same policy to struct ID matching so kfunc and kptr type checks do not walk past the allocated object bounds either.
--- include/linux/bpf.h | 2 +- kernel/bpf/btf.c | 17 +++++++++++------ kernel/bpf/verifier.c | 11 +++++++---- 3 files changed, 19 insertions(+), 11 deletions(-)
include/linux/bpf.h +1 -1
@@ -2475,7 +2475,7 @@ int btf_struct_access(struct bpf_verifier_log *log,bool btf_struct_ids_match (struct bpf_verifier_log *log,const struct btf *btf,u32 id,int off,const struct btf *need_btf,u32 need_type_id, -bool strict); +bool strict,bool walk_flex_arrays); int btf_distill_func_proto(struct bpf_verifier_log *log, struct btf *btf,
kernel/bpf/btf.c +11 -6
@@ -6164,7 +6164,7 @@ enum bpf_struct_walk_result {static int btf_struct_walk (struct bpf_verifier_log *log,const struct btf *btf,const struct btf_type *t,int off,int size,u32 *next_btf_id,enum bpf_type_flag *flag, -const char **field_name) +const char **field_name,bool walk_flex_arrays) {u32 i, moff, mtrue_end, msize =0 , total_nelems =0 ;const struct btf_type *mtype, *elem_type =NULL ;
@@ -6191,11 +6191,14 @@ static int btf_struct_walk(struct bpf_verifier_log *log, const struct btf *btf, *flag |=PTR_UNTRUSTED ;if (off + size > t->size) { +struct btf_array *array_elem; + +if (!walk_flex_arrays) + goto error; +/* If the last element is a variable size array, we may * need to relax the rule. */ -struct btf_array *array_elem; -if (vlen ==0 ) goto error;
@@ -6456,7 +6459,8 @@ int btf_struct_access(struct bpf_verifier_log *log, t =btf_type_by_id (btf, id); do { - err = btf_struct_walk(log, btf, t, off, size, &id, &tmp_flag, field_name); + err = btf_struct_walk(log, btf, t, off, size, &id, &tmp_flag, + field_name, !type_is_alloc(reg->type)); switch (err) { case WALK_PTR:
@@ -6512,7 +6516,7 @@ bool btf_types_are_same(const struct btf *btf1, u32 id1,bool btf_struct_ids_match (struct bpf_verifier_log *log,const struct btf *btf,u32 id,int off,const struct btf *need_btf,u32 need_type_id, -bool strict) +bool strict,bool walk_flex_arrays) {const struct btf_type *type;enum bpf_type_flag flag =0 ;
@@ -6531,7 +6535,8 @@ bool btf_struct_ids_match(struct bpf_verifier_log *log, type =btf_type_by_id (btf, id);if (!type)return false; - err =btf_struct_walk (log, btf, type, off,1 , &id, &flag,NULL ); + err =btf_struct_walk (log, btf, type, off,1 , &id, &flag,NULL , + walk_flex_arrays);if (err !=WALK_STRUCT )return false;
kernel/bpf/verifier.c +7 -4
@@ -5433,7 +5433,8 @@ static int map_kptr_match_type(struct bpf_verifier_env *env,*/ if (!btf_struct_ids_match (&env->log, reg->btf, reg->btf_id, reg->off, kptr_field->kptr.btf, kptr_field->kptr.btf_id, - kptr_field->type ==BPF_KPTR_REF )) + kptr_field->type ==BPF_KPTR_REF , + !type_is_alloc (reg->type))) goto bad_type;return 0 ; bad_type:
@@ -8400,7 +8401,7 @@ static int check_reg_type(struct bpf_verifier_env *env, u32 regno,if (!btf_struct_ids_match (&env->log, reg->btf, reg->btf_id, reg->off, btf_vmlinux, *arg_btf_id, - strict_type_match)) { + strict_type_match, !type_is_alloc (reg->type))) {verbose (env,"R%d is of type %s but %s is expected\n" , regno,btf_type_name (reg->btf, reg->btf_id),btf_type_name (btf_vmlinux, *arg_btf_id));
@@ -11054,7 +11055,8 @@ static int process_kf_arg_ptr_to_btf_id(struct bpf_verifier_env *env, reg_ref_t =btf_type_skip_modifiers (reg_btf, reg_ref_id, ®_ref_id); reg_ref_tname =btf_name_by_offset (reg_btf, reg_ref_t->name_off); -if (!btf_struct_ids_match (&env->log, reg_btf, reg_ref_id, reg->off, meta->btf, ref_id, strict_type_match)) { +if (!btf_struct_ids_match (&env->log, reg_btf, reg_ref_id, reg->off, meta->btf, ref_id, strict_type_match, + !type_is_alloc (reg->type))) {verbose (env,"kernel function %s args#%d expected pointer to %s %s but R%d has a pointer to %s %s\n" , meta->func_name, argno,btf_type_str (ref_t), ref_tname, argno +1 ,btf_type_str (reg_ref_t), reg_ref_tname);
@@ -11382,7 +11384,8 @@ __process_kf_arg_ptr_to_graph_node(struct bpf_verifier_env *env, et =btf_type_by_id (field->graph_root.btf, field->graph_root.value_btf_id); t =btf_type_by_id (reg->btf, reg->btf_id);if (!btf_struct_ids_match (&env->log, reg->btf, reg->btf_id,0 , field->graph_root.btf, - field->graph_root.value_btf_id, true)) { + field->graph_root.value_btf_id, true, + !type_is_alloc (reg->type))) { verbose(env, "operation on %s expects arg#1 %s at offset=%d " "in struct %s, but arg is at offset=%d in struct %s\n", btf_field_type_name(head_field_type),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1491/1674 cgroup/cpuset: introduce cpuset-v1.c
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chen Ridong <[email protected]>
[ Upstream commit 71e934a80863c2a9f4d27ee3360dc17e0a609aa6 ]
This patch introduces the cgroup/cpuset-v1.c source file which will be used for all legacy (cgroup v1) cpuset cgroup code. It also introduces cgroup/cpuset-internal.h to keep declarations shared between cgroup/cpuset.c and cpuset/cpuset-v1.c.
As of now, let's compile it if CONFIG_CPUSET is set. Later on it can be switched to use a separate config option, so that the legacy code won't be compiled if not required.
Stable-dep-of: 95220e1f18f6 ("cgroup/cpuset: Make nr_deadline_tasks an atomic_t")
--- MAINTAINERS | 2 ++ kernel/cgroup/Makefile | 2 +- kernel/cgroup/cpuset-internal.h | 6 ++++++ kernel/cgroup/cpuset-v1.c | 3 +++ 4 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 kernel/cgroup/cpuset-internal.h create mode 100644 kernel/cgroup/cpuset-v1.c
MAINTAINERS +2 -0
@@ -5280,6 +5280,8 @@ S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git F: Documentation/admin-guide/cgroup-v1/cpusets.rst F: include/linux/cpuset.h +F: kernel/cgroup/cpuset-internal.h +F: kernel/cgroup/cpuset-v1.c F: kernel/cgroup/cpuset.c F: tools/testing/selftests/cgroup/test_cpuset.c F: tools/testing/selftests/cgroup/test_cpuset_prs.sh
kernel/cgroup/Makefile +1 -1
@@ -4,6 +4,6 @@ obj-y := cgroup.o rstat.o namespace.o cgroup-v1.o freezer.o obj-$(CONFIG_CGROUP_FREEZER) += legacy_freezer.o obj-$(CONFIG_CGROUP_PIDS) += pids.o obj-$(CONFIG_CGROUP_RDMA) += rdma.o -obj-$(CONFIG_CPUSETS) += cpuset.o +obj-$(CONFIG_CPUSETS) += cpuset.o cpuset-v1.o obj-$(CONFIG_CGROUP_MISC) += misc.o obj-$(CONFIG_CGROUP_DEBUG) += debug.o
kernel/cgroup/cpuset-internal.h new file +6 -0
@@ -0,0 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef __CPUSET_INTERNAL_H +#define __CPUSET_INTERNAL_H + +#endif /* __CPUSET_INTERNAL_H */
kernel/cgroup/cpuset-v1.c new file +3 -0
@@ -0,0 +1,3 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "cpuset-internal.h"
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1492/1674 cgroup/cpuset: move common code to cpuset-internal.h
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chen Ridong <[email protected]>
[ Upstream commit 619a33efa0b0cd566f928d60d128033673e478cf ]
Move some declarations that will be used for cpuset v1 and v2, including 'cpuset struct', 'cpuset_flagbits_t', cpuset_filetype_t,etc. No logical change.
Stable-dep-of: 95220e1f18f6 ("cgroup/cpuset: Make nr_deadline_tasks an atomic_t")
--- kernel/cgroup/cpuset-internal.h | 216 ++++++++++++++++++++++++++++++++ kernel/cgroup/cpuset.c | 216 +------------------------------- 2 files changed, 217 insertions(+), 215 deletions(-)
kernel/cgroup/cpuset-internal.h +216 -0
@@ -3,4 +3,220 @@#ifndef __CPUSET_INTERNAL_H#define __CPUSET_INTERNAL_H +#include <linux/cpumask.h> +#include <linux/spinlock.h> +#include <linux/cpuset.h> +#include <linux/cgroup.h> + +/* See "Frequency meter" comments, below. */ + +struct fmeter { +int cnt;/* unprocessed events count */ +int val;/* most recent output value */ +time64_t time;/* clock (secs) when val computed */ +spinlock_t lock;/* guards read or write of above */ +}; + +/* +* Invalid partition error code +*/ +enum prs_errcode { +PERR_NONE =0 , +PERR_INVCPUS , +PERR_INVPARENT , +PERR_NOTPART , +PERR_NOTEXCL , +PERR_NOCPUS , +PERR_HOTPLUG , +PERR_CPUSEMPTY , +}; + +/* bits in struct cpuset flags field */ +typedef enum { +CS_ONLINE , +CS_CPU_EXCLUSIVE , +CS_MEM_EXCLUSIVE , +CS_MEM_HARDWALL , +CS_MEMORY_MIGRATE , +CS_SCHED_LOAD_BALANCE , +CS_SPREAD_PAGE , +CS_SPREAD_SLAB , +}cpuset_flagbits_t ; + +/* The various types of files and directories in a cpuset file system */ + +typedef enum { +FILE_MEMORY_MIGRATE , +FILE_CPULIST , +FILE_MEMLIST , +FILE_EFFECTIVE_CPULIST , +FILE_EFFECTIVE_MEMLIST , +FILE_SUBPARTS_CPULIST , +FILE_CPU_EXCLUSIVE , +FILE_MEM_EXCLUSIVE , +FILE_MEM_HARDWALL , +FILE_SCHED_LOAD_BALANCE , +FILE_PARTITION_ROOT , +FILE_SCHED_RELAX_DOMAIN_LEVEL , +FILE_MEMORY_PRESSURE_ENABLED , +FILE_MEMORY_PRESSURE , +FILE_SPREAD_PAGE , +FILE_SPREAD_SLAB , +}cpuset_filetype_t ; + +struct cpuset { +struct cgroup_subsys_state css; + +unsigned long flags;/* "unsigned long" so bitops work */ + +/* +* On default hierarchy: +* +* The user-configured masks can only be changed by writing to +* cpuset.cpus and cpuset.mems, and won't be limited by the +* parent masks. +* +* The effective masks is the real masks that apply to the tasks +* in the cpuset. They may be changed if the configured masks are +* changed or hotplug happens. +* +* effective_mask == configured_mask & parent's effective_mask, +* and if it ends up empty, it will inherit the parent's mask. +* +* +* On legacy hierarchy: +* +* The user-configured masks are always the same with effective masks. +*/ + +/* user-configured CPUs and Memory Nodes allow to tasks */ +cpumask_var_t cpus_allowed; +nodemask_t mems_allowed; + +/* effective CPUs and Memory Nodes allow to tasks */ +cpumask_var_t effective_cpus; +nodemask_t effective_mems; + +/* +* CPUs allocated to child sub-partitions (default hierarchy only) +* - CPUs granted by the parent = effective_cpus U subparts_cpus +* - effective_cpus and subparts_cpus are mutually exclusive. +* +* effective_cpus contains only onlined CPUs, but subparts_cpus +* may have offlined ones. +*/ +cpumask_var_t subparts_cpus; + +/* +* This is old Memory Nodes tasks took on. +* +* - top_cpuset.old_mems_allowed is initialized to mems_allowed. +* - A new cpuset's old_mems_allowed is initialized when some +* task is moved into it. +* - old_mems_allowed is used in cpuset_migrate_mm() when we change +* cpuset.mems_allowed and have tasks' nodemask updated, and +* then old_mems_allowed is updated to mems_allowed. +*/ +nodemask_t old_mems_allowed; + +struct fmeter fmeter;/* memory_pressure filter */ + +/* +* Tasks are being attached to this cpuset. Used to prevent +* zeroing cpus/mems_allowed between ->can_attach() and ->attach(). +*/ +int attach_in_progress; + +/* partition number for rebuild_sched_domains() */ +int pn; + +/* for custom sched domain */ +int relax_domain_level; + +/* number of CPUs in subparts_cpus */ +int nr_subparts_cpus; + +/* partition root state */ +int partition_root_state; + +/* +* Default hierarchy only: +* use_parent_ecpus - set if using parent's effective_cpus +* child_ecpus_count - # of children with use_parent_ecpus set +*/ +int use_parent_ecpus; +int child_ecpus_count; + +/* +* number of SCHED_DEADLINE tasks attached to this cpuset, so that we +* know when to rebuild associated root domain bandwidth information. +*/ +int nr_deadline_tasks; +int nr_migrate_dl_tasks; +u64 sum_migrate_dl_bw; + +/* Invalid partition error code, not lock protected */ +enum prs_errcode prs_err; + +/* Handle for cpuset.cpus.partition */ +struct cgroup_file partition_file; +}; + +static inline struct cpuset *css_cs (struct cgroup_subsys_state *css) +{ + return css ? container_of(css, struct cpuset, css) : NULL; +} + +/* Retrieve the cpuset for a task */ +static inline struct cpuset *task_cs (struct task_struct *task) +{ +return css_cs (task_css (task, cpuset_cgrp_id)); +} + +static inline struct cpuset *parent_cs (struct cpuset *cs) +{ +return css_cs (cs->css.parent); +} + +/* convenient tests for these bits */ +static inline bool is_cpuset_online (struct cpuset *cs) +{ +return test_bit (CS_ONLINE , &cs->flags) && !css_is_dying (&cs->css); +} + +static inline int is_cpu_exclusive (const struct cpuset *cs) +{ +return test_bit (CS_CPU_EXCLUSIVE , &cs->flags); +} + +static inline int is_mem_exclusive (const struct cpuset *cs) +{ +return test_bit (CS_MEM_EXCLUSIVE , &cs->flags); +} + +static inline int is_mem_hardwall (const struct cpuset *cs) +{ +return test_bit (CS_MEM_HARDWALL , &cs->flags); +} + +static inline int is_sched_load_balance (const struct cpuset *cs) +{ +return test_bit (CS_SCHED_LOAD_BALANCE , &cs->flags); +} + +static inline int is_memory_migrate (const struct cpuset *cs) +{ +return test_bit (CS_MEMORY_MIGRATE , &cs->flags); +} + +static inline int is_spread_page (const struct cpuset *cs) +{ +return test_bit (CS_SPREAD_PAGE , &cs->flags); +} + +static inline int is_spread_slab (const struct cpuset *cs) +{ +return test_bit (CS_SPREAD_SLAB , &cs->flags); +} +#endif /* __CPUSET_INTERNAL_H */
kernel/cgroup/cpuset.c +1 -215
262 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1493/1674 cgroup/cpuset: Make nr_deadline_tasks an atomic_t
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Waiman Long <[email protected]>
[ Upstream commit 95220e1f18f6321008f021abc7d6f581f64bcb82 ]
The nr_deadline_tasks variable in the cpuset structure was introduced by commit 6c24849f5515 ("sched/cpuset: Keep track of SCHED_DEADLINE task in cpusets"). It is reported by sashiko [1] that nr_deadline_tasks can currently be modified by inc_dl_tasks_cs() under rq->lock and by cpuset_attach() under cpuset_mutex. So if both updates happen simultaneously, the nr_deadline_tasks variable can be corrupted leading to incorrect operations down the road.
Fix that by changing its type to atomic_t so that nr_deadline_tasks are always atomically updated. This fix patch is a low hanging fruit. It can handle some of the races between a concurrent sched_setscheduler() and cpuset_can_attach()/cpuset_attach() calls, but not all of them like the other issue raised by sashiko [2]. This will be handled hopefully in a future follow up patch.
[1] https://sashiko.dev/#/patchset/20260626181923.133658-1-longman%40redhat.com
[2] https://sashiko.dev/#/patchset/20260630033344.352702-1-longman%40redhat.com
--- kernel/cgroup/cpuset-internal.h | 2 +- kernel/cgroup/cpuset.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-)
kernel/cgroup/cpuset-internal.h +1 -1
@@ -151,7 +151,7 @@ struct cpuset {* number of SCHED_DEADLINE tasks attached to this cpuset, so that we * know when to rebuild associated root domain bandwidth information. */ -int nr_deadline_tasks; +atomic_t nr_deadline_tasks;int nr_migrate_dl_tasks;u64 sum_migrate_dl_bw;
kernel/cgroup/cpuset.c +5 -5
@@ -95,14 +95,14 @@ void inc_dl_tasks_cs(struct task_struct *p) {struct cpuset *cs =task_cs (p); - cs->nr_deadline_tasks++; +atomic_inc (&cs->nr_deadline_tasks); }void dec_dl_tasks_cs (struct task_struct *p) {struct cpuset *cs =task_cs (p); - cs->nr_deadline_tasks--; +atomic_dec (&cs->nr_deadline_tasks); }static inline int is_partition_valid (const struct cpuset *cs)
@@ -898,7 +898,7 @@ static void dl_update_tasks_root_domain(struct cpuset *cs)struct css_task_iter it;struct task_struct *task; -if (cs->nr_deadline_tasks ==0 ) +if (atomic_read (&cs->nr_deadline_tasks) ==0 )return ;css_task_iter_start (&cs->css,0 , &it);
@@ -2564,8 +2564,8 @@ static void cpuset_attach(struct cgroup_taskset *tset) cs->old_mems_allowed = cpuset_attach_nodemask_to;if (cs->nr_migrate_dl_tasks) { - cs->nr_deadline_tasks += cs->nr_migrate_dl_tasks; - oldcs->nr_deadline_tasks -= cs->nr_migrate_dl_tasks; +atomic_add (cs->nr_migrate_dl_tasks, &cs->nr_deadline_tasks); +atomic_sub (cs->nr_migrate_dl_tasks, &oldcs->nr_deadline_tasks);reset_migrate_dl_data (cs); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1494/1674 hwrng: core - fix rng list on registration error
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manos Pitsidianakis <[email protected]>
[ Upstream commit 3a5834db2b1ce25649f330e78efe1ccde78967fd ]
hwrng_register(rng) does the following:
1. Checks if rng has name and read methods set
2. Checks if the name already exists
3. Adds rng to global rng_list
4. May try to set rng to current_rng
If step 4 fails, it returns an error. However, it does not remove the rng from rng_list, causing a dangling reference which can result in use-after-free if the caller frees rng, since registration failed.
Add a list_del_init() cleanup step.
--- drivers/char/hw_random/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/char/hw_random/core.c +3 -1
@@ -574,7 +574,7 @@ int hwrng_register(struct hwrng *rng)*/ err =set_current_rng (rng);if (err) - goto out_unlock; + goto out_list_del;/* to use current_rng in add_early_randomness() we need * to take a ref */
@@ -595,6 +595,8 @@ int hwrng_register(struct hwrng *rng)if (is_new_current)put_rng (rng);return 0 ; +out_list_del: +list_del_init (&rng->list); out_unlock:mutex_unlock (&rng_mutex); out:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1495/1674 dmaengine: xilinx_dma: Fix CPU stall in xilinx_dma_poll_timeout
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Bereza <[email protected]>
[ Upstream commit aa99c4d1d63bbc26a5fc4c667d89b2595743c19d ]
Currently when calling xilinx_dma_poll_timeout with delay_us=0 and a condition that is never fulfilled, the CPU busy-waits for prolonged time and the timeout triggers only with a massive delay causing a CPU stall.
This happens due to a huge underestimation of wall clock time in poll_timeout_us_atomic. Commit 7349a69cf312 ("iopoll: Do not use timekeeping in read_poll_timeout_atomic()") changed the behavior to no longer use ktime_get at the expense of underestimation of wall clock time which appears to be very large for delay_us=0. Instead of timing out after approximately XILINX_DMA_LOOP_COUNT microseconds, the timeout takes XILINX_DMA_LOOP_COUNT * 1000 * (time that the overhead of the for loop in poll_timeout_us_atomic takes) which is in the range of several minutes for XILINX_DMA_LOOP_COUNT=1000000. Fix this by using a non-zero value for delay_us. Use delay_us=10 to keep the delay in the hot path of starting DMA transfers minimal but still avoid CPU stalls in case of unexpected hardware failures.
One-off measurement with delay_us=0 causes the cpu to busy wait around 7 minutes in the timeout case. After applying this patch with delay_us=10 the measured timeout was 1053428 microseconds which is roughly equivalent to the expected 1000000 microseconds specified in XILINX_DMA_LOOP_COUNT.
Add a constant XILINX_DMA_POLL_DELAY_US for delay_us value.
--- drivers/dma/xilinx/xilinx_dma.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/dma/xilinx/xilinx_dma.c +10 -4
@@ -164,6 +164,8 @@/* Delay loop counter to prevent hardware failure */ #define XILINX_DMA_LOOP_COUNT 1000000 +/* Delay between polls (avoid a delay of 0 to prevent CPU stalls) */ +#define XILINX_DMA_POLL_DELAY_US 10/* AXI DMA Specific Registers/Offsets */ #define XILINX_DMA_REG_SRCDSTADDR 0x18
@@ -1313,7 +1315,8 @@ static int xilinx_dma_stop_transfer(struct xilinx_dma_chan *chan)/* Wait for the hardware to halt */ return xilinx_dma_poll_timeout (chan,XILINX_DMA_REG_DMASR , val, - val &XILINX_DMA_DMASR_HALTED ,0 , + val &XILINX_DMA_DMASR_HALTED , +XILINX_DMA_POLL_DELAY_US ,XILINX_DMA_LOOP_COUNT ); }
@@ -1328,7 +1331,8 @@ static int xilinx_cdma_stop_transfer(struct xilinx_dma_chan *chan)u32 val;return xilinx_dma_poll_timeout (chan,XILINX_DMA_REG_DMASR , val, - val &XILINX_DMA_DMASR_IDLE ,0 , + val &XILINX_DMA_DMASR_IDLE , +XILINX_DMA_POLL_DELAY_US ,XILINX_DMA_LOOP_COUNT ); }
@@ -1345,7 +1349,8 @@ static void xilinx_dma_start(struct xilinx_dma_chan *chan)/* Wait for the hardware to start */ err =xilinx_dma_poll_timeout (chan,XILINX_DMA_REG_DMASR , val, - !(val &XILINX_DMA_DMASR_HALTED ),0 , + !(val &XILINX_DMA_DMASR_HALTED ), +XILINX_DMA_POLL_DELAY_US ,XILINX_DMA_LOOP_COUNT );if (err) {
@@ -1778,7 +1783,8 @@ static int xilinx_dma_reset(struct xilinx_dma_chan *chan)/* Wait for the hardware to finish reset */ err =xilinx_dma_poll_timeout (chan,XILINX_DMA_REG_DMACR , tmp, - !(tmp &XILINX_DMA_DMACR_RESET ),0 , + !(tmp &XILINX_DMA_DMACR_RESET ), +XILINX_DMA_POLL_DELAY_US ,XILINX_DMA_LOOP_COUNT );if (err) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1496/1674 mm: change type of state in struct memory_block
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Israel Batista <[email protected]>
[ Upstream commit 8bc7ba3d265d6ee698de4b1941b7e8f7d91a0562 ]
The state of a memory block should be restricted to values specified in the documentation of the memory hotplug API. However, since the state field in the memory_block struct was defined as an unsigned long, this restriction was not enforced at compile time.
With the introduction of the enum memory_block_state, it is now possible to incorporate the desired semantics in the field declaration and enforce these restrictions at compile time.
Stable-dep-of: 2ebce860bdd7 ("mm/mm_init: handle alloc_percpu failure in free_area_init_core_hotplug")
--- drivers/base/memory.c | 2 +- include/linux/memory.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/base/memory.c +1 -1
@@ -160,7 +160,7 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr,break ;default :WARN_ON (1 ); -return sysfs_emit (buf,"ERROR-UNKNOWN-%ld\n" , mem->state); +return sysfs_emit (buf,"ERROR-UNKNOWN-%d\n" , mem->state); }return sysfs_emit (buf,"%s\n" , output);
include/linux/memory.h +1 -1
@@ -66,7 +66,7 @@ struct memory_group {struct memory_block {unsigned long start_section_nr; -unsigned long state;/* serialized by the dev->lock */ +enum memory_block_state state;/* serialized by the dev->lock */ int online_type;/* for passing data to online routine */ int nid;/* NID for this memory block */ /*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1497/1674 mm: name the anonymous MMOP enum as enum mmop
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gregory Price <[email protected]>
[ Upstream commit c5c48345135ff04e039377020df23294d59aa59a ]
Give the MMOP enum (MMOP_OFFLINE, MMOP_ONLINE, etc) a proper type name so the compiler can help catch invalid values being assigned to variables of this type.
Leave the existing functions returning int alone to allow for value-or-error pattern to remain unchanged without churn.
mmop_default_online_type is left as int because it uses the -1 sentinal value to signal it hasn't been initialized yet.
Keep the uint8_t buffer in offline_and_remove_memory() as-is for space efficiency, with an explicit cast when we consume the value.
Move the enum definition before the CONFIG_MEMORY_HOTPLUG guard so it is unconditionally available for struct memory_block in memory.h.
No functional change.
Adapt to this tree: the preceding change in struct memory_block already uses enum memory_block_state, which does not exist here, so define it in memory.h with the existing MEM_* values in place of the macros. Drop the mhp_get/set_default_online_type hunks, which have no counterpart here, and keep the enum definition ahead of the CONFIG_MEMORY_HOTPLUG guard so it is always available to struct memory_block.
Stable-dep-of: 2ebce860bdd7 ("mm/mm_init: handle alloc_percpu failure in free_area_init_core_hotplug")
--- drivers/base/memory.c | 2 +- include/linux/memory.h | 21 ++++++++++++--------- include/linux/memory_hotplug.h | 12 ++++++------ mm/memory_hotplug.c | 6 +++--- 4 files changed, 22 insertions(+), 19 deletions(-)
drivers/base/memory.c +1 -1
@@ -414,7 +414,7 @@ static ssize_t phys_device_show(struct device *dev,static int print_allowed_zone (char *buf,int len,int nid,struct memory_group *group,unsigned long start_pfn,unsigned long nr_pages, -int online_type,struct zone *default_zone) +enum mmop online_type,struct zone *default_zone) {struct zone *zone;
include/linux/memory.h +12 -9
@@ -19,6 +19,7 @@#include <linux/node.h> #include <linux/compiler.h> #include <linux/mutex.h> +#include <linux/memory_hotplug.h> #define MIN_MEMORY_BLOCK_SIZE (1UL << SECTION_SIZE_BITS)
@@ -64,10 +65,20 @@ struct memory_group { }; }; +enum memory_block_state { +/* These states are exposed to userspace as text strings in sysfs */ +MEM_ONLINE = (1 <<0 ),/* exposed to userspace */ +MEM_GOING_OFFLINE = (1 <<1 ),/* exposed to userspace */ +MEM_OFFLINE = (1 <<2 ),/* exposed to userspace */ +MEM_GOING_ONLINE = (1 <<3 ), +MEM_CANCEL_ONLINE = (1 <<4 ), +MEM_CANCEL_OFFLINE = (1 <<5 ), +}; +struct memory_block {unsigned long start_section_nr;enum memory_block_state state;/* serialized by the dev->lock */ -int online_type;/* for passing data to online routine */ +enum mmop online_type;/* for passing data to online routine */ int nid;/* NID for this memory block */ /* * The single zone of this memory block if all PFNs of this memory block
@@ -89,14 +100,6 @@ int arch_get_memory_phys_device(unsigned long start_pfn);unsigned long memory_block_size_bytes (void );int set_memory_block_size_order (unsigned int order); -/* These states are exposed to userspace as text strings in sysfs */ -#define MEM_ONLINE (1<<0)/* exposed to userspace */ -#define MEM_GOING_OFFLINE (1<<1)/* exposed to userspace */ -#define MEM_OFFLINE (1<<2)/* exposed to userspace */ -#define MEM_GOING_ONLINE (1<<3) -#define MEM_CANCEL_ONLINE (1<<4) -#define MEM_CANCEL_OFFLINE (1<<5) -struct memory_notify {unsigned long start_pfn;unsigned long nr_pages;
include/linux/memory_hotplug.h +6 -6
@@ -64,11 +64,8 @@ static inline void arch_refresh_nodedata(int nid, pg_data_t *pgdat)#endif /* CONFIG_NUMA */ #endif /* CONFIG_HAVE_ARCH_NODEDATA_EXTENSION */ -#ifdef CONFIG_MEMORY_HOTPLUG -struct page *pfn_to_online_page (unsigned long pfn); -/* Types for control the zone type of onlined and offlined memory */ -enum { +enum mmop {/* Offline the memory. */ MMOP_OFFLINE =0 ,/* Online the memory. Zone depends, see default_zone_for_pfn(). */
@@ -79,6 +76,9 @@ enum { MMOP_ONLINE_MOVABLE, }; +#ifdef CONFIG_MEMORY_HOTPLUG +struct page *pfn_to_online_page (unsigned long pfn); +/* Flags for add_memory() and friends to specify memory hotplug details. */ typedef int __bitwise mhp_t ;
@@ -350,8 +350,8 @@ extern void sparse_remove_section(unsigned long pfn, unsigned long nr_pages, struct vmem_altmap *altmap);extern struct page *sparse_decode_mem_map (unsigned long coded_mem_map,unsigned long pnum); -extern struct zone *zone_for_pfn_range (int online_type,int nid, -struct memory_group *group,unsigned long start_pfn, +extern struct zone *zone_for_pfn_range (enum mmop online_type, +int nid,struct memory_group *group,unsigned long start_pfn,unsigned long nr_pages);extern int arch_create_linear_mapping (int nid,u64 start,u64 size,struct mhp_params *params);
mm/memory_hotplug.c +3 -3
@@ -1044,7 +1044,7 @@ static inline struct zone *default_zone_for_pfn(int nid, unsigned long start_pfnreturn movable_node_enabled ? movable_zone : kernel_zone; } -struct zone *zone_for_pfn_range (int online_type,int nid, +struct zone *zone_for_pfn_range (enum mmop online_type,int nid,struct memory_group *group,unsigned long start_pfn,unsigned long nr_pages) {
@@ -2267,7 +2267,7 @@ EXPORT_SYMBOL_GPL(remove_memory);static int try_offline_memory_block (struct memory_block *mem,void *arg) { -uint8_t online_type =MMOP_ONLINE_KERNEL ; +enum mmop online_type =MMOP_ONLINE_KERNEL ;uint8_t **online_types = arg;struct page *page;int rc;
@@ -2300,7 +2300,7 @@ static int try_reonline_memory_block(struct memory_block *mem, void *arg)int rc;if (**online_types !=MMOP_OFFLINE ) { - mem->online_type = **online_types; + mem->online_type = (enum mmop )**online_types; rc =device_online (&mem->dev);if (rc <0 ) pr_warn("%s: Failed to re-online memory: %d",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1498/1674 mm/mm_init: handle alloc_percpu failure in free_area_init_core_hotplug
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gregory Price <[email protected]>
[ Upstream commit 2ebce860bdd7ae5e13002811bc9bbbf33fcfc221 ]
We miss a failed allocation check for pgdat->per_cpu_nodestats, which results in a NULL deref when we offset into the per-cpu area.
Propagate -ENOMEM up the stack and leave per_cpu_nodestats pointing at boot_nodestats so a later online can retry the allocation.
hotadd_init_pgdat() returns NULL on failure, which __try_online_node() already maps to -ENOMEM.
On failure nothing needs to be unwound:
- the node is never marked online
- per_cpu_nodestats is left pointing at boot_nodestats
- __add_memory_resource() cleans up pending memblock resources
- later online attempts retry the per_cpu_nodestats allocation
--- include/linux/memory_hotplug.h | 2 +- mm/memory_hotplug.c | 3 ++- mm/mm_init.c | 14 +++++++++++--- 3 files changed, 14 insertions(+), 5 deletions(-)
include/linux/memory_hotplug.h +1 -1
@@ -329,7 +329,7 @@ static inline void __remove_memory(u64 start, u64 size) {}#endif /* CONFIG_MEMORY_HOTREMOVE */ #ifdef CONFIG_MEMORY_HOTPLUG -extern void __ref free_area_init_core_hotplug (struct pglist_data *pgdat); +int __ref free_area_init_core_hotplug (struct pglist_data *pgdat);extern int __add_memory (int nid,u64 start,u64 size,mhp_t mhp_flags);extern int add_memory (int nid,u64 start,u64 size,mhp_t mhp_flags); extern int add_memory_resource(int nid, struct resource *resource,
mm/memory_hotplug.c +2 -1
@@ -1237,7 +1237,8 @@ static pg_data_t __ref *hotadd_init_pgdat(int nid) pgdat =NODE_DATA (nid);/* init node's zones as empty zones, we don't have any present pages.*/ -free_area_init_core_hotplug (pgdat); +if (free_area_init_core_hotplug (pgdat)) +return NULL ;/* * The node we allocated has no zone fallback lists. For avoiding
mm/mm_init.c +11 -3
@@ -1509,7 +1509,7 @@ void __init set_pageblock_order(void)* NOTE: this function is only called during memory hotplug */ #ifdef CONFIG_MEMORY_HOTPLUG -void __ref free_area_init_core_hotplug (struct pglist_data *pgdat) +int __ref free_area_init_core_hotplug (struct pglist_data *pgdat) {int nid = pgdat->node_id;enum zone_type z;
@@ -1517,8 +1517,14 @@ void __ref free_area_init_core_hotplug(struct pglist_data *pgdat)pgdat_init_internals (pgdat); -if (pgdat->per_cpu_nodestats == &boot_nodestats) - pgdat->per_cpu_nodestats = alloc_percpu(struct per_cpu_nodestat); +if (pgdat->per_cpu_nodestats == &boot_nodestats) { +struct per_cpu_nodestat __percpu *p; + + p = alloc_percpu(struct per_cpu_nodestat); +if (!p) +return -ENOMEM ; + pgdat->per_cpu_nodestats = p; + }/* * Reset the nr_zones, order and highest_zoneidx before reuse.
@@ -1556,6 +1562,8 @@ void __ref free_area_init_core_hotplug(struct pglist_data *pgdat) zone->present_pages =0 ; zone_init_internals(zone, z, nid, 0); } + +return 0 ; }#endif
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1499/1674 drm/amd/display: Fix dangling pointer in CRTC reset function
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Evgenii Burenchev <[email protected]>
[ Upstream commit 0aeed866cb938943908c3ba46422128e49d2d080 ]
amdgpu_dm_crtc_reset_state() frees the old state before allocating a new one. If kzalloc() fails, the function returns without updating the state pointer, leaving a dangling pointer to already freed memory.
Fix this by allocating the new state first. On allocation failure, the old state remains untouched and the function safely returns.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +4 -4
@@ -270,13 +270,13 @@ static void dm_crtc_reset_state(struct drm_crtc *crtc) {struct dm_crtc_state *state; -if (crtc->state) -dm_crtc_destroy_state (crtc, crtc->state); - state =kzalloc (sizeof (*state),GFP_KERNEL ); -if (WARN_ON (!state)) +if (!state)return ; +if (crtc->state) +dm_crtc_destroy_state (crtc, crtc->state); +__drm_atomic_helper_crtc_reset (crtc, &state->base); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1500/1674 drm/amd/display: Fix dangling pointer in plane reset function
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Evgenii Burenchev <[email protected]>
[ Upstream commit 98cad4bd1443975d972f4c7f705980da03722a22 ]
amdgpu_dm_plane_drm_plane_reset() frees the old state before allocating a new one. If kzalloc() fails, the function returns without updating the state pointer, leaving a dangling pointer to already freed memory.
Fix this by allocating the new state first. On allocation failure, the old state remains untouched and the function safely returns.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c +6 -6
@@ -1316,16 +1316,16 @@ static const struct drm_plane_helper_funcs dm_plane_helper_funcs = {static void dm_drm_plane_reset (struct drm_plane *plane) { -struct dm_plane_state *amdgpu_state =NULL ; +struct dm_plane_state *amdgpu_state; + + amdgpu_state =kzalloc (sizeof (*amdgpu_state),GFP_KERNEL ); +if (!amdgpu_state) +return ;if (plane->state) plane->funcs->atomic_destroy_state (plane, plane->state); - amdgpu_state =kzalloc (sizeof (*amdgpu_state),GFP_KERNEL ); -WARN_ON (amdgpu_state ==NULL ); - -if (amdgpu_state) -__drm_atomic_helper_plane_reset (plane, &amdgpu_state->base); +__drm_atomic_helper_plane_reset (plane, &amdgpu_state->base); } static struct drm_plane_state *
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1501/1674 ASoC: fsl_audmix: rework runtime PM handling in probe
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shengjiu Wang <[email protected]>
[ Upstream commit 3359ba93d01a23b2e4249e9e44ccfe48eb9c5d71 ]
After pm_runtime_enable() the AUDMIX block is powered off and stays suspended until the first runtime resume. Register writes issued between probe() and the first resume (e.g. from DAPM or ALSA control paths) target unpowered hardware and cause a system hang.
Fix this by calling pm_runtime_resume_and_get() immediately after pm_runtime_enable() to power the hardware up and enable its clocks. Release the reference afterwards with pm_runtime_put() to allow the runtime PM framework to suspend the device and switch the regmap to cache-only mode when idle.
When CONFIG_PM is disabled or runtime PM is not enabled, pm_runtime_* calls are stubs that do not power up the hardware. Handle this case explicitly by calling fsl_audmix_runtime_resume() directly so the hardware is always initialised and its clocks are enabled, ensuring register accesses succeed regardless of PM configuration.
--- sound/soc/fsl/fsl_audmix.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-)
sound/soc/fsl/fsl_audmix.c +22 -2
@@ -458,6 +458,9 @@ static const struct of_device_id fsl_audmix_ids[] = { };MODULE_DEVICE_TABLE (of, fsl_audmix_ids); +static int fsl_audmix_runtime_resume (struct device *dev); +static int fsl_audmix_runtime_suspend (struct device *dev); +static int fsl_audmix_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;
@@ -489,13 +492,25 @@ static int fsl_audmix_probe(struct platform_device *pdev)spin_lock_init (&priv->lock);platform_set_drvdata (pdev, priv);pm_runtime_enable (dev); +if (!pm_runtime_enabled (dev)) { + ret =fsl_audmix_runtime_resume (dev); +if (ret) + goto err_disable_pm; + } + + ret =pm_runtime_resume_and_get (dev); +if (ret <0 ) + goto err_pm_get_sync; + +/* To enable regmap cache only when runtime PM enabled */ +pm_runtime_put (dev); ret =devm_snd_soc_register_component (dev, &fsl_audmix_component, fsl_audmix_dai,ARRAY_SIZE (fsl_audmix_dai));if (ret) {dev_err (dev,"failed to register ASoC DAI\n" ); - goto err_disable_pm; + goto err_pm_get_sync; }/*
@@ -507,12 +522,15 @@ static int fsl_audmix_probe(struct platform_device *pdev)if (IS_ERR (priv->pdev)) { ret =PTR_ERR (priv->pdev);dev_err (dev,"failed to register platform: %d\n" , ret); - goto err_disable_pm; + goto err_pm_get_sync; } }return 0 ; +err_pm_get_sync: +if (!pm_runtime_status_suspended (dev)) +fsl_audmix_runtime_suspend (dev); err_disable_pm:pm_runtime_disable (dev);return ret;
@@ -523,6 +541,8 @@ static void fsl_audmix_remove(struct platform_device *pdev)struct fsl_audmix *priv =dev_get_drvdata (&pdev->dev);pm_runtime_disable (&pdev->dev); +if (!pm_runtime_status_suspended (&pdev->dev)) +fsl_audmix_runtime_suspend (&pdev->dev);if (priv->pdev)platform_device_unregister (priv->pdev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1502/1674 cxl/mbox: Clamp mailbox output allocation to the payload size
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Richard Cheng <[email protected]>
[ Upstream commit 8a13db9f899d149c3aab24abcb668121cfda5a4f ]
CXL_MEM_SEND_COMMAND bounds the user's in.size to the mailbox payload size but leaves out.size unbounded, then cxl_mbox_cmd_ctor() calls kvzalloc(out.size). A large out.size drives a huge allocation, above INT_MAX it WARNs and taints, and with panic_on_warn=1 it panics.
The transport __cxl_pci_mbox_send_cmd() already clamps the response copy to min(out.size, payload_size, device len), so the output buffer is never written beyond payload_size. Clamp the allocation to payload_size too, matching the RAW path.
--- drivers/cxl/core/mbox.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/cxl/core/mbox.c +1 -5
@@ -364,11 +364,7 @@ static int cxl_mbox_cmd_ctor(struct cxl_mbox_cmd *mbox, } } -/* Prepare to handle a full payload for variable sized output */ -if (out_size ==CXL_VARIABLE_PAYLOAD ) - mbox->size_out = mds->payload_size; -else - mbox->size_out = out_size; + mbox->size_out =min_t (size_t, out_size, mds->payload_size);if (mbox->size_out) { mbox->payload_out =kvzalloc (mbox->size_out,GFP_KERNEL );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1503/1674 drm/v3d: Clear queue->active_job when v3d_fence_create() fails
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maíra Canal <[email protected]>
[ Upstream commit 25a1669907512e927fab9ad4d4fb74ff57f63cd9 ]
The run_job() callbacks for BIN, RENDER, TFU and CSD assign the incoming job to queue->active_job before calling v3d_fence_create(). If v3d_fence_create() fails, the callback returns NULL without clearing active_job, leaving a dangling pointer.
Create a failure path in all run_job() callbacks that clears the active job before returning NULL. The BIN path takes queue->queue_lock around the clear as it races against v3d_overflow_mem_work(); RENDER, TFU and CSD paths have no concurrent reader, so the clear is lock-free.
--- drivers/gpu/drm/v3d/v3d_sched.c | 60 +++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 26 deletions(-)
drivers/gpu/drm/v3d/v3d_sched.c +34 -26
@@ -77,15 +77,11 @@ static struct dma_fence *v3d_bin_job_run(struct drm_sched_job *sched_job)struct v3d_bin_job *job =to_bin_job (sched_job);struct v3d_dev *v3d = job->base.v3d;struct drm_device *dev = &v3d->drm; -struct dma_fence *fence; +struct dma_fence *fence =NULL ;unsigned long irqflags; -if (unlikely (job->base.base.s_fence->finished.error)) { -spin_lock_irqsave (&v3d->job_lock, irqflags); - v3d->queue[V3D_BIN ].active_job =NULL ; -spin_unlock_irqrestore (&v3d->job_lock, irqflags); -return NULL ; - } +if (unlikely (job->base.base.s_fence->finished.error)) + goto out_clean_job;/* Lock required around bin_job update vs * v3d_overflow_mem_work().
@@ -102,7 +98,7 @@ static struct dma_fence *v3d_bin_job_run(struct drm_sched_job *sched_job) fence =v3d_fence_create (v3d,V3D_BIN );if (IS_ERR (fence)) -return NULL ; + goto out_clean_job;if (job->base.irq_fence)dma_fence_put (job->base.irq_fence);
@@ -129,6 +125,12 @@ static struct dma_fence *v3d_bin_job_run(struct drm_sched_job *sched_job)V3D_CORE_WRITE (0 ,V3D_CLE_CT0QEA , job->end);return fence; + +out_clean_job: +spin_lock_irqsave (&v3d->job_lock, irqflags); + v3d->queue[V3D_BIN ].active_job =NULL ; +spin_unlock_irqrestore (&v3d->job_lock, irqflags); +return fence; }static struct dma_fence *v3d_render_job_run (struct drm_sched_job *sched_job)
@@ -136,12 +138,10 @@ static struct dma_fence *v3d_render_job_run(struct drm_sched_job *sched_job)struct v3d_render_job *job =to_render_job (sched_job);struct v3d_dev *v3d = job->base.v3d;struct drm_device *dev = &v3d->drm; -struct dma_fence *fence; +struct dma_fence *fence =NULL ; -if (unlikely (job->base.base.s_fence->finished.error)) { - v3d->queue[V3D_RENDER ].active_job =NULL ; -return NULL ; - } +if (unlikely (job->base.base.s_fence->finished.error)) + goto out_clean_job; v3d->queue[V3D_RENDER ].active_job = &job->base;
@@ -155,7 +155,7 @@ static struct dma_fence *v3d_render_job_run(struct drm_sched_job *sched_job) fence =v3d_fence_create (v3d,V3D_RENDER );if (IS_ERR (fence)) -return NULL ; + goto out_clean_job;if (job->base.irq_fence)dma_fence_put (job->base.irq_fence);
@@ -175,6 +175,10 @@ static struct dma_fence *v3d_render_job_run(struct drm_sched_job *sched_job)V3D_CORE_WRITE (0 ,V3D_CLE_CT1QEA , job->end);return fence; + +out_clean_job: + v3d->queue[V3D_RENDER ].active_job =NULL ; +return fence; } static struct dma_fence *
@@ -183,18 +187,16 @@ v3d_tfu_job_run(struct drm_sched_job *sched_job)struct v3d_tfu_job *job =to_tfu_job (sched_job);struct v3d_dev *v3d = job->base.v3d;struct drm_device *dev = &v3d->drm; -struct dma_fence *fence; +struct dma_fence *fence =NULL ; -if (unlikely (job->base.base.s_fence->finished.error)) { - v3d->queue[V3D_TFU ].active_job =NULL ; -return NULL ; - } +if (unlikely (job->base.base.s_fence->finished.error)) + goto out_clean_job; v3d->queue[V3D_TFU ].active_job = &job->base; fence =v3d_fence_create (v3d,V3D_TFU );if (IS_ERR (fence)) -return NULL ; + goto out_clean_job;if (job->base.irq_fence)dma_fence_put (job->base.irq_fence);
@@ -218,6 +220,10 @@ v3d_tfu_job_run(struct drm_sched_job *sched_job)V3D_WRITE (V3D_TFU_ICFG , job->args.icfg |V3D_TFU_ICFG_IOC );return fence; + +out_clean_job: + v3d->queue[V3D_TFU ].active_job =NULL ; +return fence; } static struct dma_fence *
@@ -226,13 +232,11 @@ v3d_csd_job_run(struct drm_sched_job *sched_job)struct v3d_csd_job *job =to_csd_job (sched_job);struct v3d_dev *v3d = job->base.v3d;struct drm_device *dev = &v3d->drm; -struct dma_fence *fence; +struct dma_fence *fence =NULL ;int i; -if (unlikely (job->base.base.s_fence->finished.error)) { - v3d->queue[V3D_CSD ].active_job =NULL ; -return NULL ; - } +if (unlikely (job->base.base.s_fence->finished.error)) + goto out_clean_job;/* The HW interprets a workgroup size of 0 as 65536; however, the * user-space driver exposes a maximum of 65535. Therefore, a 0 in
@@ -250,7 +254,7 @@ v3d_csd_job_run(struct drm_sched_job *sched_job) fence =v3d_fence_create (v3d,V3D_CSD );if (IS_ERR (fence)) -return NULL ; + goto out_clean_job;if (job->base.irq_fence)dma_fence_put (job->base.irq_fence);
@@ -266,6 +270,10 @@ v3d_csd_job_run(struct drm_sched_job *sched_job)V3D_CORE_WRITE (0 ,V3D_CSD_QUEUED_CFG0 , job->args.cfg[0 ]);return fence; + +out_clean_job: + v3d->queue[V3D_CSD ].active_job =NULL ; +return fence; } static struct dma_fence *
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1504/1674 nvdimm: virtio_pmem: refcount requests for token lifetime
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li Chen <[email protected]>
[ Upstream commit e57140944b5a47a7fd5a142faab29a02af040bc8 ]
KASAN reports slab-use-after-free in __wake_up_common():
BUG: KASAN: slab-use-after-free in __wake_up_common+0x114/0x160 Read of size 8 at addr ffff88810fdcb710 by task swapper/0/0 CPU: 0 UID: 0 PID: 0 Comm: swapper/0 Not tainted 6.19.0-next-20260220-00006-g1eae5f204ec3 #4 PREEMPT(full) Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Arch Linux 1.17.0-2-2 04/01/2014 Call Trace: <IRQ> dump_stack_lvl+0x6d/0xb0 print_report+0x170/0x4e2 ? __pfx__raw_spin_lock_irqsave+0x10/0x10 ? __virt_addr_valid+0x1dc/0x380 kasan_report+0xbc/0xf0 ? __wake_up_common+0x114/0x160 ? __wake_up_common+0x114/0x160 __wake_up_common+0x114/0x160 ? __pfx__raw_spin_lock_irqsave+0x10/0x10 __wake_up+0x36/0x60 virtio_pmem_host_ack+0x11d/0x3b0 ? sched_balance_domains+0x29f/0xb00 ? __pfx_virtio_pmem_host_ack+0x10/0x10 ? _raw_spin_lock_irqsave+0x98/0x100 ? __pfx__raw_spin_lock_irqsave+0x10/0x10 vring_interrupt+0x1c9/0x5e0 ? __pfx_vp_interrupt+0x10/0x10 vp_vring_interrupt+0x87/0x100 ? __pfx_vp_interrupt+0x10/0x10 __handle_irq_event_percpu+0x17f/0x550 ? __pfx__raw_spin_lock+0x10/0x10 handle_irq_event+0xab/0x1c0 handle_fasteoi_irq+0x276/0xae0 __common_interrupt+0x65/0x130 common_interrupt+0x78/0xa0 </IRQ>
virtio_pmem_host_ack() wakes a request that has already been freed by the submitter.
This happens when the request token is still reachable via the virtqueue, but virtio_pmem_flush() returns and frees it.
Fix the token lifetime by refcounting struct virtio_pmem_request. virtio_pmem_flush() holds a submitter reference, and the virtqueue holds an extra reference once the request is queued. The completion path drops the virtqueue reference, and the submitter drops its reference before returning.
Message-ID: <[email protected]>
--- drivers/nvdimm/nd_virtio.c | 32 ++++++++++++++++++++++++++++---- drivers/nvdimm/virtio_pmem.h | 2 ++ 2 files changed, 30 insertions(+), 4 deletions(-)
drivers/nvdimm/nd_virtio.c +28 -4
@@ -9,6 +9,14 @@#include "virtio_pmem.h" #include "nd.h" +static void virtio_pmem_req_release (struct kref *kref) +{ +struct virtio_pmem_request *req; + + req = container_of(kref, struct virtio_pmem_request, kref); +kfree (req); +} +/* The interrupt handler */ void virtio_pmem_host_ack (struct virtqueue *vq) {
@@ -29,6 +37,7 @@ void virtio_pmem_host_ack(struct virtqueue *vq)wake_up (&req_buf->wq_buf);list_del (&req_buf->list); } +kref_put (&req_data->kref, virtio_pmem_req_release); }spin_unlock_irqrestore (&vpmem->pmem_lock, flags); }
@@ -59,6 +68,7 @@ static int virtio_pmem_flush(struct nd_region *nd_region)if (!req_data)return -ENOMEM ; +kref_init (&req_data->kref); req_data->done = false;init_waitqueue_head (&req_data->host_acked);init_waitqueue_head (&req_data->wq_buf);
@@ -76,10 +86,23 @@ static int virtio_pmem_flush(struct nd_region *nd_region)* to req_list and wait for host_ack to wake us up when free * slots are available. */ -while ((err =virtqueue_add_sgs (vpmem->req_vq, sgs,1 ,1 , req_data, -GFP_ATOMIC )) == -ENOSPC ) { +for (;;) { + err =virtqueue_add_sgs (vpmem->req_vq, sgs,1 ,1 , req_data, +GFP_ATOMIC ); +if (!err) { +/* +* Take the virtqueue reference while @pmem_lock is +* held so completion cannot run concurrently. +*/ +kref_get (&req_data->kref); +break ; + } + +if (err != -ENOSPC ) +break ; -dev_info (&vdev->dev,"failed to send command to virtio pmem device, no free slots in the virtqueue\n" ); +dev_info_ratelimited (&vdev->dev, +"failed to send command to virtio pmem device, no free slots in the virtqueue\n" ); req_data->wq_buf_avail = false;list_add_tail (&req_data->list, &vpmem->req_list);spin_unlock_irqrestore (&vpmem->pmem_lock, flags);
@@ -88,6 +111,7 @@ static int virtio_pmem_flush(struct nd_region *nd_region)wait_event (req_data->wq_buf, req_data->wq_buf_avail);spin_lock_irqsave (&vpmem->pmem_lock, flags); } + err1 =virtqueue_kick (vpmem->req_vq);spin_unlock_irqrestore (&vpmem->pmem_lock, flags);/*
@@ -103,7 +127,7 @@ static int virtio_pmem_flush(struct nd_region *nd_region) err =le32_to_cpu (req_data->resp.ret); } -kfree (req_data); +kref_put (&req_data->kref, virtio_pmem_req_release);return err; };
drivers/nvdimm/virtio_pmem.h +2 -0
@@ -12,11 +12,13 @@#include <linux/module.h> #include <uapi/linux/virtio_pmem.h> +#include <linux/kref.h> #include <linux/libnvdimm.h> #include <linux/mutex.h> #include <linux/spinlock.h> struct virtio_pmem_request { +struct kref kref;struct virtio_pmem_req req;struct virtio_pmem_resp resp;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1505/1674 i3c: master: Fix recursive locking during device registration
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
[ Upstream commit 456f832e5fc26fbfd3b8200fd4553eee520cc377 ]
i3c_master_register_new_i3c_devs() registers newly discovered devices while holding i3c_bus_normaluse_lock(), a down_read(). device_register() can immediately probe the device, and probe callbacks typically invoke I3C helpers that take i3c_bus_normaluse_lock() again, leading to a recursive acquisition of the same rwsem. rwsems do not support recursive read locking and can deadlock when a writer is waiting. See the "Recursive read locks" section of Documentation/locking/lockdep-design.rst.
For example, with Intel LPSS I3C, LOCKDEP generates a WARNING like:
# echo intel-lpss-i3c.0 > /sys/bus/platform/drivers/mipi-i3c-hci/unbind
# echo intel-lpss-i3c.0 > /sys/bus/platform/drivers/mipi-i3c-hci/bind
WARNING: possible recursive locking detected
kworker/5:1/94 is trying to acquire lock:
ffff88811c810d78 (&i3cbus->lock){++++}-{4:4}, at: i3c_device_match_id+0x45/0x370
but task is already holding lock:
ffff88811c810d78 (&i3cbus->lock){++++}-{4:4}, at: i3c_master_reg_work_fn+0x21/0x5f0Fix this by separating device creation from device registration. Populate desc->dev under the maintenance lock, collect the devices that still need registration into a local list, then release the lock before calling device_register(). Finally retake the lock and clean up any devices that failed to register.
Use the maintenance lock rather than the normal-use lock while adding device objects. A write-side maintenance lock prevents readers from observing a partially initialized desc->dev during initial device population, or desc->dev disappearing if registration fails.
The local list requires a list node, so add a list node member to struct i3c_device.
--- drivers/i3c/master.c | 39 ++++++++++++++++++++++++++------------ include/linux/i3c/master.h | 3 +++ 2 files changed, 30 insertions(+), 12 deletions(-)
drivers/i3c/master.c +27 -12
@@ -1620,12 +1620,16 @@ static int i3c_master_early_i3c_dev_add(struct i3c_master_controller *master,static void i3c_master_register_new_i3c_devs (struct i3c_master_controller *master) { +struct i3c_device *i3cdev, *tmp;struct i3c_dev_desc *desc; +LIST_HEAD (i3c_unreg_devs);int ret;if (!master->init_done)return ; +i3c_bus_maintenance_lock (&master->bus); +i3c_bus_for_each_i3cdev (&master->bus, desc) {if (desc->dev || !desc->info.dyn_addr || desc == master->this)continue ;
@@ -1646,15 +1650,30 @@ i3c_master_register_new_i3c_devs(struct i3c_master_controller *master)if (desc->boardinfo) desc->dev->dev.of_node = desc->boardinfo->of_node; - ret =device_register (&desc->dev->dev); -if (ret) { -dev_err (&master->dev, -"Failed to add I3C device (err = %d)\n" , ret); - desc->dev->desc =NULL ; -put_device (&desc->dev->dev); - desc->dev =NULL ; - } +list_add_tail (&desc->dev->node, &i3c_unreg_devs); + } + +i3c_bus_maintenance_unlock (&master->bus); + +list_for_each_entry_safe (i3cdev, tmp, &i3c_unreg_devs, node) { + ret =device_register (&i3cdev->dev); +if (ret) +dev_err (&master->dev,"Failed to add I3C device (err = %d)\n" , ret); +else +list_del_init (&i3cdev->node); } + +i3c_bus_maintenance_lock (&master->bus); + +list_for_each_entry_safe (i3cdev, tmp, &i3c_unreg_devs, node) { +list_del (&i3cdev->node); + desc = i3cdev->desc; + i3cdev->desc =NULL ; +put_device (&i3cdev->dev); + desc->dev =NULL ; + } + +i3c_bus_maintenance_unlock (&master->bus); }/**
@@ -1683,9 +1702,7 @@ int i3c_master_do_daa(struct i3c_master_controller *master)if (ret)return ret; -i3c_bus_normaluse_lock (&master->bus);i3c_master_register_new_i3c_devs (master); -i3c_bus_normaluse_unlock (&master->bus);return 0 ; }
@@ -2857,9 +2874,7 @@ int i3c_master_register(struct i3c_master_controller *master,* register I3C devices discovered during the initial DAA. */ master->init_done = true; -i3c_bus_normaluse_lock (&master->bus);i3c_master_register_new_i3c_devs (master); -i3c_bus_normaluse_unlock (&master->bus);return 0 ;
include/linux/i3c/master.h +3 -0
@@ -220,6 +220,8 @@ struct i3c_dev_desc {* every time the I3C device is rediscovered with a different dynamic * address assigned * @bus: I3C bus this device is attached to +* @node: unregistered device list node, only for use by +* i3c_master_register_new_i3c_devs(), it is not protected by a lock * * I3C device object exposed to I3C device drivers. The takes care of linking * this object to the relevant &struct_i3c_dev_desc one.
@@ -230,6 +232,7 @@ struct i3c_device {struct device dev;struct i3c_dev_desc *desc;struct i3c_bus *bus; +struct list_head node; };/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1506/1674 iommu/arm-smmu-v3: Manage teardown with devm
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shameer Kolothum <[email protected]>
[ Upstream commit 2bd22a0d40503a65d243b011de146603c8ce1cbc ]
arm_smmu_device_remove() manually frees the IOPF queue, destroys the vmid_map and disables the device, while the IRQs and queues are devm managed. devm unwinds only after remove() returns, so the cleanup runs in the wrong order. The IOPF queue is freed before the event-queue IRQ whose handler uses it.
Manage all of it with devm so the unwind order is correct. Free the IOPF queue and vmid_map via devm actions, and disable the device from one registered after arm_smmu_device_reset().
This is also a prerequisite for fixing a Tegra241 CMDQV CMD_SYNC use-after-free in the subsequent patch.
--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 56 +++++++++++++++------ 1 file changed, 40 insertions(+), 16 deletions(-)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +40 -16
@@ -2962,6 +2962,20 @@ static int arm_smmu_cmdq_init(struct arm_smmu_device *smmu)return 0 ; } +static void arm_smmu_free_iopf_action (void *data) +{ +struct iopf_queue *queue = data; + +iopf_queue_free (queue); +} + +static void arm_smmu_destroy_vmid_map (void *data) +{ +struct ida *ida = data; + +ida_destroy (ida); +} +static int arm_smmu_init_queues (struct arm_smmu_device *smmu) {int ret;
@@ -2989,6 +3003,11 @@ static int arm_smmu_init_queues(struct arm_smmu_device *smmu) smmu->evtq.iopf =iopf_queue_alloc (dev_name (smmu->dev));if (!smmu->evtq.iopf)return -ENOMEM ; + ret =devm_add_action_or_reset (smmu->dev, + arm_smmu_free_iopf_action, + smmu->evtq.iopf); +if (ret) +return ret; }/* priq */
@@ -3105,7 +3124,8 @@ static int arm_smmu_init_strtab(struct arm_smmu_device *smmu)ida_init (&smmu->vmid_map); -return 0 ; +return devm_add_action_or_reset (smmu->dev, arm_smmu_destroy_vmid_map, + &smmu->vmid_map); }static int arm_smmu_init_structures (struct arm_smmu_device *smmu)
@@ -3311,6 +3331,13 @@ static int arm_smmu_device_disable(struct arm_smmu_device *smmu)return ret; } +static void arm_smmu_disable_action (void *data) +{ +struct arm_smmu_device *smmu = data; + +arm_smmu_device_disable (smmu); +} +static int arm_smmu_device_reset (struct arm_smmu_device *smmu,bool bypass) {int ret;
@@ -3892,7 +3919,7 @@ static int arm_smmu_device_probe(struct platform_device *pdev)/* Initialise in-memory data structures */ ret =arm_smmu_init_structures (smmu);if (ret) - goto err_free_iopf; +return ret;/* Record our private device structure */ platform_set_drvdata (pdev, smmu);
@@ -3902,30 +3929,30 @@ static int arm_smmu_device_probe(struct platform_device *pdev)/* Reset the device */ ret =arm_smmu_device_reset (smmu, bypass); +if (ret) { +arm_smmu_device_disable (smmu); +return ret; + } + +/* Register last so it unwinds first, while the CMDQ is still up. */ + ret =devm_add_action_or_reset (smmu->dev, arm_smmu_disable_action, smmu);if (ret) - goto err_disable; +return ret;/* And we're up. Go go go! */ ret =iommu_device_sysfs_add (&smmu->iommu, dev,NULL ,"smmu3.%pa" , &ioaddr);if (ret) - goto err_disable; +return ret; ret =iommu_device_register (&smmu->iommu, &arm_smmu_ops, dev);if (ret) {dev_err (dev,"Failed to register iommu\n" ); - goto err_free_sysfs; +iommu_device_sysfs_remove (&smmu->iommu); +return ret; }return 0 ; - -err_free_sysfs: -iommu_device_sysfs_remove (&smmu->iommu); -err_disable: -arm_smmu_device_disable (smmu); -err_free_iopf: -iopf_queue_free (smmu->evtq.iopf); -return ret; }static void arm_smmu_device_remove (struct platform_device *pdev)
@@ -3934,9 +3961,6 @@ static void arm_smmu_device_remove(struct platform_device *pdev)iommu_device_unregister (&smmu->iommu);iommu_device_sysfs_remove (&smmu->iommu); -arm_smmu_device_disable (smmu); -iopf_queue_free (smmu->evtq.iopf); -ida_destroy (&smmu->vmid_map); }static void arm_smmu_device_shutdown (struct platform_device *pdev)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1507/1674 mm/page_owner: use memcg_data snapshot to avoid TOCTOU in print_page_owner_memcg()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ye Liu <[email protected]>
[ Upstream commit 90f095b816e25c6a9e4446d299bac5007fdcb3df ]
print_page_owner_memcg() reads page->memcg_data via READ_ONCE() at the start to guard against tail pages and NULL data. However, it later re-reads page->memcg_data locklessly in two places:
1: page_memcg_check(page)
2: PageMemcgKmem(page) (via folio_memcg_kmem(), which includes
VM_BUG_ON assertions for tail pages and MEMCG_DATA_OBJEXTS)
If the page is concurrently freed and reallocated as a THP tail page or slab page between these calls, the VM_BUG_ON assertions can trigger on CONFIG_DEBUG_VM=y builds, crashing the kernel.
Fix both TOCTOU issues by using the memcg_data snapshot throughout.
--- mm/page_owner.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
mm/page_owner.c +11 -3
@@ -363,6 +363,7 @@ static inline int print_page_owner_memcg(char *kbuf, size_t count, int ret, {#ifdef CONFIG_MEMCG unsigned long memcg_data; +struct obj_cgroup *objcg;struct mem_cgroup *memcg;bool online;char name[80 ];
@@ -372,11 +373,18 @@ static inline int print_page_owner_memcg(char *kbuf, size_t count, int ret,if (!memcg_data) goto out_unlock; -if (memcg_data &MEMCG_DATA_OBJCGS ) +if (memcg_data &MEMCG_DATA_OBJCGS ) { ret +=scnprintf (kbuf + ret, count - ret,"Slab cache page\n" ); + goto out_unlock; + } - memcg =page_memcg_check (page); +if (memcg_data &MEMCG_DATA_KMEM ) { + objcg = (void *)(memcg_data & ~MEMCG_DATA_FLAGS_MASK ); + memcg =obj_cgroup_memcg (objcg); + }else { + memcg = (void *)(memcg_data & ~MEMCG_DATA_FLAGS_MASK ); + }if (!memcg) goto out_unlock;
@@ -384,7 +392,7 @@ static inline int print_page_owner_memcg(char *kbuf, size_t count, int ret,cgroup_name (memcg->css.cgroup, name,sizeof (name)); ret +=scnprintf (kbuf + ret, count - ret,"Charged %sto %smemcg %s\n" , -PageMemcgKmem (page) ?"(via objcg) " :"" , + (memcg_data &MEMCG_DATA_KMEM ) ?"(via objcg) " :"" , online ?"" :"offline " , name); out_unlock:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1508/1674 nfsd: convert nfsd_net boolean flags to unsigned long flags word
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit 11a5fe42e1811f793e04ef885b639ea7668f439d ]
nfsd_net contains several boolean fields that are accessed from concurrent contexts without serialization. In particular, nfsd4_end_grace() guards its drain path with a plain bool:
if (nn->grace_ended)
return;
nn->grace_ended = true;The read and the write are independent, and nothing in struct nfsd_net serializes them. At least two contexts can reach this code with no lock held:
laundromat path
laundry_wq kworker
nfs4_laundromat()
nfsd4_end_grace()
RECLAIM_COMPLETE path
nfsd compound kthread
nfsd4_reclaim_complete()
inc_reclaim_complete()
nfsd4_end_grace()Both callers can observe grace_ended == false on different CPUs, both store true, and both proceed into nfsd4_record_grace_done(), which invokes the active client_tracking_ops->grace_done callback. For tracking ops that drain reclaim_str_hashtbl (legacy_tracking_ops via nfsd4_recdir_purge_old, and the cld v1+ ops via nfsd4_cld_grace_done), grace_done calls nfs4_release_reclaim(), which walks every bucket of reclaim_str_hashtbl with no lock and calls nfs4_remove_reclaim_record() (list_del + kfree) on each entry. Two concurrent walkers corrupt the list and double-free every nfs4_client_reclaim. A concurrent nfsd4_find_reclaim_client() iterating the same bucket reads through freed memory.
A third call site exists in nfs4_state_start_net() on the skip_grace startup path, but it runs under nfsd_mutex before any client has connected and before the laundromat's first delayed work fires, so it cannot race with the two callers above.
Replace the scattered boolean fields in nfsd_net with a single unsigned long flags word and an enum nfsd_net_flag for the bit positions. The grace_ended race is fixed by using test_and_set_bit(), which is atomic on all architectures. The remaining flags (grace_end_forced, in_grace, somebody_reclaimed, track_reclaim_completes, nfsd_net_up, lockd_up) are converted to use test_bit/set_bit/clear_bit for consistency. This avoids sub-word cmpxchg issues on architectures like Hexagon that only support word-sized atomic operations.
--- fs/nfsd/netns.h | 19 +++++++++++-------- fs/nfsd/nfs4proc.c | 2 +- fs/nfsd/nfs4recover.c | 12 ++++++------ fs/nfsd/nfs4state.c | 40 ++++++++++++++++++++++++---------------- fs/nfsd/nfsctl.c | 2 +- fs/nfsd/nfssvc.c | 20 ++++++++++---------- 6 files changed, 53 insertions(+), 42 deletions(-)
fs/nfsd/netns.h +11 -8
@@ -26,6 +26,16 @@struct cld_net ;struct nfsd4_client_tracking_ops ; +enum nfsd_net_flag { +NFSD_NET_GRACE_ENDED , +NFSD_NET_GRACE_END_FORCED , +NFSD_NET_IN_GRACE , +NFSD_NET_SOMEBODY_RECLAIMED , +NFSD_NET_TRACK_RECLAIM_COMPLETES , +NFSD_NET_UP , +NFSD_NET_LOCKD_UP , +}; +enum {/* cache misses due only to checksum comparison failures */ NFSD_STATS_PAYLOAD_MISSES ,
@@ -64,8 +74,7 @@ struct nfsd_net {struct cache_detail *nametoid_cache;struct lock_manager nfsd4_manager; -bool grace_ended; -bool grace_end_forced; +unsigned long flags;bool client_tracking_active;time64_t boot_time;time64_t boot_time_bt;/* same instant in CLOCK_BOOTTIME */
@@ -114,19 +123,13 @@ struct nfsd_net {spinlock_t blocked_locks_lock;struct file *rec_file; -bool in_grace;const struct nfsd4_client_tracking_ops *client_tracking_ops;time64_t nfsd4_lease;time64_t nfsd4_grace; -bool somebody_reclaimed; -bool track_reclaim_completes;atomic_t nr_reclaim_complete; -bool nfsd_net_up; -bool lockd_up; -seqlock_t writeverf_lock;unsigned char writeverf[8 ];
fs/nfsd/nfs4proc.c +1 -1
@@ -626,7 +626,7 @@ nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,pr_warn ("nfsd4_process_open2 failed to open newly-created file: status=%u\n" ,be32_to_cpu (status));if (reclaim && !status) - nn->somebody_reclaimed = true; +set_bit (NFSD_NET_SOMEBODY_RECLAIMED , &nn->flags); out:if (open->op_filp) {fput (open->op_filp);
fs/nfsd/nfs4recover.c +6 -6
@@ -228,7 +228,7 @@ nfsd4_create_clid_dir(struct nfs4_client *clp) out_unlock:inode_unlock (d_inode (dir));if (status ==0 ) { -if (nn->in_grace) +if (test_bit (NFSD_NET_IN_GRACE , &nn->flags))__nfsd4_create_reclaim_record_grace (clp, dname, nn);vfs_fsync (nn->rec_file,0 ); }else {
@@ -388,7 +388,7 @@ nfsd4_remove_clid_dir(struct nfs4_client *clp)nfs4_reset_creds (original_cred);if (status ==0 ) {vfs_fsync (nn->rec_file,0 ); -if (nn->in_grace) +if (test_bit (NFSD_NET_IN_GRACE , &nn->flags))__nfsd4_remove_reclaim_record_grace (dname,HEXDIR_LEN , nn); }
@@ -446,7 +446,7 @@ nfsd4_recdir_purge_old(struct nfsd_net *nn) {int status; - nn->in_grace = false; +clear_bit (NFSD_NET_IN_GRACE , &nn->flags);if (!nn->rec_file)return ; status =mnt_want_write_file (nn->rec_file);
@@ -528,7 +528,7 @@ nfsd4_init_recdir(struct net *net)nfs4_reset_creds (original_cred);if (!status) - nn->in_grace = true; +set_bit (NFSD_NET_IN_GRACE , &nn->flags);return status; }
@@ -1476,7 +1476,7 @@ nfs4_cld_state_init(struct net *net)for (i =0 ; i <CLIENT_HASH_SIZE ; i++)INIT_LIST_HEAD (&nn->reclaim_str_hashtbl[i]); nn->reclaim_str_hashtbl_size =0 ; - nn->track_reclaim_completes = true; +set_bit (NFSD_NET_TRACK_RECLAIM_COMPLETES , &nn->flags);atomic_set (&nn->nr_reclaim_complete,0 );return 0 ;
@@ -1487,7 +1487,7 @@ nfs4_cld_state_shutdown(struct net *net) {struct nfsd_net *nn =net_generic (net, nfsd_net_id); - nn->track_reclaim_completes = false; +clear_bit (NFSD_NET_TRACK_RECLAIM_COMPLETES , &nn->flags);kfree (nn->reclaim_str_hashtbl); }
fs/nfsd/nfs4state.c +24 -16
@@ -2382,7 +2382,7 @@ static void inc_reclaim_complete(struct nfs4_client *clp) {struct nfsd_net *nn =net_generic (clp->net, nfsd_net_id); -if (!nn->track_reclaim_completes) +if (!test_bit (NFSD_NET_TRACK_RECLAIM_COMPLETES , &nn->flags))return ;if (!nfsd4_find_reclaim_client (clp->cl_name, nn))return ;
@@ -4544,8 +4544,6 @@ nfsd4_init_leases_net(struct nfsd_net *nn) nn->nfsd4_lease =90 ;/* default lease time */ nn->nfsd4_grace =90 ; - nn->somebody_reclaimed = false; - nn->track_reclaim_completes = false; nn->clverifier_counter =get_random_u32 (); nn->clientid_base =get_random_u32 (); nn->clientid_counter = nn->clientid_base +1 ;
@@ -6012,12 +6010,21 @@ nfsd4_renew(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,static void nfsd4_end_grace (struct nfsd_net *nn) { -/* do nothing if grace period already ended */ -if (nn->grace_ended) +/* +* nfsd4_end_grace() can be entered concurrently from the +* laundromat workqueue and from an nfsd compound thread +* handling RECLAIM_COMPLETE. Without serialization, both +* callers can observe NFSD_NET_GRACE_ENDED clear and proceed +* into nfsd4_record_grace_done(). For tracking ops whose +* grace_done drains reclaim_str_hashtbl, that results in +* list corruption and a double free of every +* nfs4_client_reclaim entry. Use an atomic test-and-set so +* exactly one caller proceeds. +*/ +if (test_and_set_bit (NFSD_NET_GRACE_ENDED , &nn->flags))return ;trace_nfsd_grace_complete (nn); - nn->grace_ended = true;/* * If the server goes down again right now, an NFSv4 * client will still be allowed to reclaim after it comes back up,
@@ -6059,11 +6066,11 @@ bool nfsd4_force_end_grace(struct nfsd_net *nn)if (!nn->client_tracking_ops)return false;spin_lock (&nn->client_lock); -if (nn->grace_ended || !nn->client_tracking_active) { +if (test_bit (NFSD_NET_GRACE_ENDED , &nn->flags) || !nn->client_tracking_active) {spin_unlock (&nn->client_lock);return false; } -WRITE_ONCE (nn->grace_end_forced, true); +set_bit (NFSD_NET_GRACE_END_FORCED , &nn->flags);mod_delayed_work (laundry_wq, &nn->laundromat_work,0 );spin_unlock (&nn->client_lock);return true;
@@ -6078,15 +6085,15 @@ static bool clients_still_reclaiming(struct nfsd_net *nn)time64_t double_grace_period_end = nn->boot_time_bt +2 * nn->nfsd4_lease; -if (READ_ONCE (nn->grace_end_forced)) +if (test_bit (NFSD_NET_GRACE_END_FORCED , &nn->flags))return false; -if (nn->track_reclaim_completes && +if (test_bit (NFSD_NET_TRACK_RECLAIM_COMPLETES , &nn->flags) &&atomic_read (&nn->nr_reclaim_complete) == nn->reclaim_str_hashtbl_size)return false; -if (!nn->somebody_reclaimed) +if (!test_bit (NFSD_NET_SOMEBODY_RECLAIMED , &nn->flags))return false; - nn->somebody_reclaimed = false; +clear_bit (NFSD_NET_SOMEBODY_RECLAIMED , &nn->flags);/* * If we've given them *two* lease times to reclaim, and they're * still not done, give up:
@@ -7884,7 +7891,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,nfs4_inc_and_copy_stateid (&lock->lk_resp_stateid, &lock_stp->st_stid); status =0 ;if (lock->lk_reclaim) - nn->somebody_reclaimed = true; +set_bit (NFSD_NET_SOMEBODY_RECLAIMED , &nn->flags);break ;case FILE_LOCK_DEFERRED :kref_put (&nbl->nbl_kref, free_nbl);
@@ -8395,8 +8402,8 @@ static int nfs4_state_create_net(struct net *net) nn->unconf_name_tree =RB_ROOT ; nn->boot_time =ktime_get_real_seconds (); nn->boot_time_bt =ktime_get_boottime_seconds (); - nn->grace_ended = false; - nn->grace_end_forced = false; +clear_bit (NFSD_NET_GRACE_ENDED , &nn->flags); +clear_bit (NFSD_NET_GRACE_END_FORCED , &nn->flags); nn->client_tracking_active = false; nn->nfsd4_manager.block_opens = true;INIT_LIST_HEAD (&nn->nfsd4_manager.list);
@@ -8478,7 +8485,8 @@ nfs4_state_start_net(struct net *net)spin_lock (&nn->client_lock); nn->client_tracking_active = true;spin_unlock (&nn->client_lock); -if (nn->track_reclaim_completes && nn->reclaim_str_hashtbl_size ==0 ) +if (test_bit (NFSD_NET_TRACK_RECLAIM_COMPLETES , &nn->flags) && + nn->reclaim_str_hashtbl_size ==0 ) goto skip_grace;printk (KERN_INFO "NFSD: starting %lld-second grace period (net %x)\n" , nn->nfsd4_grace, net->ns.inum);
fs/nfsd/nfsctl.c +1 -1
@@ -1130,7 +1130,7 @@ static ssize_t write_v4_end_grace(struct file *file, char *buf, size_t size) }return scnprintf (buf,SIMPLE_TRANSACTION_LIMIT ,"%c\n" , - nn->grace_ended ?'Y' :'N' ); +test_bit (NFSD_NET_GRACE_ENDED , &nn->flags) ?'Y' :'N' ); }#endif
fs/nfsd/nfssvc.c +10 -10
@@ -407,7 +407,7 @@ static int nfsd_startup_net(struct net *net, const struct cred *cred)struct nfsd_net *nn =net_generic (net, nfsd_net_id);int ret; -if (nn->nfsd_net_up) +if (test_bit (NFSD_NET_UP , &nn->flags))return 0 ; ret =nfsd_startup_generic ();
@@ -417,11 +417,11 @@ static int nfsd_startup_net(struct net *net, const struct cred *cred)if (ret) goto out_socks; -if (nfsd_needs_lockd (nn) && !nn->lockd_up) { +if (nfsd_needs_lockd (nn) && !test_bit (NFSD_NET_LOCKD_UP , &nn->flags)) { ret =lockd_up (net, cred);if (ret) goto out_socks; - nn->lockd_up = true; +set_bit (NFSD_NET_LOCKD_UP , &nn->flags); } ret =nfsd_file_cache_start_net (net);
@@ -439,7 +439,7 @@ static int nfsd_startup_net(struct net *net, const struct cred *cred)if (ret) goto out_reply_cache; - nn->nfsd_net_up = true; +set_bit (NFSD_NET_UP , &nn->flags);return 0 ; out_reply_cache:
@@ -447,9 +447,9 @@ static int nfsd_startup_net(struct net *net, const struct cred *cred) out_filecache:nfsd_file_cache_shutdown_net (net); out_lockd: -if (nn->lockd_up) { +if (test_bit (NFSD_NET_LOCKD_UP , &nn->flags)) {lockd_down (net); - nn->lockd_up = false; +clear_bit (NFSD_NET_LOCKD_UP , &nn->flags); } out_socks:nfsd_shutdown_generic ();
@@ -463,11 +463,11 @@ static void nfsd_shutdown_net(struct net *net)nfs4_state_shutdown_net (net);nfsd_reply_cache_shutdown (nn);nfsd_file_cache_shutdown_net (net); -if (nn->lockd_up) { +if (test_bit (NFSD_NET_LOCKD_UP , &nn->flags)) {lockd_down (net); - nn->lockd_up = false; +clear_bit (NFSD_NET_LOCKD_UP , &nn->flags); } - nn->nfsd_net_up = false; +clear_bit (NFSD_NET_UP , &nn->flags);nfsd_shutdown_generic (); }
@@ -563,7 +563,7 @@ void nfsd_last_thread(struct net *net)* other initialization has been done except the rpcb information. */ svc_rpcb_cleanup (serv, net); -if (!nn->nfsd_net_up) +if (!test_bit (NFSD_NET_UP , &nn->flags))return ;nfsd_shutdown_net (net);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1509/1674 svcrdma: Reject Write/Reply chunks with segcount 0
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit 9808eb7656666acc7291bae9ab6b987bd16e47e0 ]
A peer can send a Write or Reply chunk whose segcount field is zero. xdr_check_write_chunk() only rejects segcount > rc_maxpages, so zero passes the range check, and xdr_inline_decode(stream, 0) returns the current (non-NULL) cursor without advancing. The function returns true and pcl_alloc_write() then links a struct svc_rdma_chunk with ch_segcount == 0 onto rc_write_pcl or rc_reply_pcl.
An earlier patch in this series made pcl_for_each_segment() safe for ch_segcount == 0, so this no longer drives the memory walk it used to. Rejecting the malformed frame at the decode boundary is still worthwhile as defense in depth: it keeps degenerate zero-segment chunks off the parsed chunk lists entirely, so any future consumer that walks ch_segments directly cannot observe one, and it makes the zero-floor easy to backport to trees where the macro change is more intrusive. RFC 8166 has no meaning for a Write/Reply chunk that describes no remote buffer, so no legitimate client is affected.
xdr_check_reply_chunk() funnels Reply chunks through xdr_check_write_chunk() and inherits the same rejection.
pcl_alloc_write() also links each chunk onto the parsed chunk list before filling its segment array. If a future change weakens the segcount-0 rejection, an incomplete chunk is visible to consumers during the fill loop. Reorder so that list_add_tail() follows the segment fill loop, ensuring only fully-populated chunks appear on the list.
--- net/sunrpc/xprtrdma/svc_rdma_pcl.c | 2 +- net/sunrpc/xprtrdma/svc_rdma_recvfrom.c | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-)
net/sunrpc/xprtrdma/svc_rdma_pcl.c +1 -1
@@ -213,7 +213,6 @@ bool pcl_alloc_write(struct svc_rdma_recv_ctxt *rctxt, chunk =pcl_alloc_chunk (segcount,0 );if (!chunk)return false; -list_add_tail (&chunk->ch_list, &pcl->cl_chunks);for (j =0 ; j < segcount; j++) { segment = &chunk->ch_segments[j];
@@ -225,6 +224,7 @@ bool pcl_alloc_write(struct svc_rdma_recv_ctxt *rctxt, chunk->ch_length += segment->rs_length; chunk->ch_segcount++; } +list_add_tail (&chunk->ch_list, &pcl->cl_chunks); }return true; }
net/sunrpc/xprtrdma/svc_rdma_recvfrom.c +6 -3
@@ -487,10 +487,13 @@ static bool xdr_check_write_chunk(struct svc_rdma_recv_ctxt *rctxt)return false;/* Before trusting the segcount value enough to use it in -* a computation, perform a simple range check. This is an -* arbitrary but sensible limit (ie, not architectural). +* a computation, perform a simple range check. A zero +* segcount describes no remote buffer and is rejected so +* downstream consumers never see a degenerate ch_segcount==0 +* chunk. The upper bound is an arbitrary but sensible limit +* (ie, not architectural). */ -if (unlikely (segcount >RPCSVC_MAXPAGES )) +if (segcount ==0 ||unlikely (segcount >RPCSVC_MAXPAGES ))return false; p = xdr_inline_decode(&rctxt->rc_stream,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1510/1674 memcg: make the v1 soft limit knob inert
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shakeel Butt <[email protected]>
[ Upstream commit a3417097fb107cea3358b19bcbb4eb655fd67f8c ]
The v1 soft limit has been deprecated since v6.12 and nobody has reported depending on it. Start the removal by decoupling the interface from the
implementation: keep memory.soft_limit_in_bytes, but ignore writes to it and always report the maximum value on read similar to what memory.kmem.limit_in_bytes already does.
Writes are still parsed, so malformed input keeps returning -EINVAL. The knob now also behaves the same everywhere: it used to return -EOPNOTSUPP on PREEMPT_RT, where soft limit reclaim has always been disabled.
This also fixes the syzbot report linked below. Soft limit reclaim is the only caller that runs shrink_lruvec() from kswapd against a specific memcg, so it is the only way to reach lru_gen_shrink_lruvec() and in turn set_mm_walk(), which warns when called from kswapd.
--- .../admin-guide/cgroup-v1/memory.rst | 47 +++---------------- mm/memcontrol.c | 40 ++++++++++------ 2 files changed, 32 insertions(+), 55 deletions(-)
Documentation/admin-guide/cgroup-v1/memory.rst +6 -41
@@ -47,7 +47,6 @@ Features: - pages are linked to per-memcg LRU exclusively, and there is no global LRU. - optionally, memory+swap usage can be accounted and limited. - hierarchical accounting - - soft limit - moving (recharging) account at moving a task is selectable. - usage threshold notifier - memory pressure notifier
@@ -76,8 +75,9 @@ Brief summary of control files. memory.memsw.failcnt show the number of memory+Swap hits limits memory.max_usage_in_bytes show max memory usage recorded memory.memsw.max_usage_in_bytes show max memory+Swap usage recorded - memory.soft_limit_in_bytes set/show soft limit of memory usage - This knob is not available on CONFIG_PREEMPT_RT systems. + memory.soft_limit_in_bytes This knob is deprecated and has no effect. + Writes are ignored and reads always + return the maximum value. memory.stat show various statistics memory.use_hierarchy set/show hierarchical account enabled This knob is deprecated and shouldn't be
@@ -332,9 +332,6 @@ memory.kmem.usage_in_bytes, or in a separate counter when it makes sense. The main "kmem" counter is fed into the main counter, so kmem charges will also be visible from the user counter. -Currently no soft limit is implemented for kernel memory. It is future work -to trigger slab reclaim when those limits are reached. - 2.7.1 Current Kernel Memory resources accounted -----------------------------------------------
@@ -695,42 +692,10 @@ For compatibility reasons writing 1 to memory.use_hierarchy will always pass:: 7. Soft limits ============== -Soft limits allow for greater sharing of memory. The idea behind soft limits -is to allow control groups to use as much of the memory as needed, provided - -a. There is no memory contention -b. They do not exceed their hard limit - -When the system detects memory contention or low memory, control groups -are pushed back to their soft limits. If the soft limit of each control -group is very high, they are pushed back as much as possible to make -sure that one control group does not starve the others of memory. - -Please note that soft limits is a best-effort feature; it comes with -no guarantees, but it does its best to make sure that when memory is -heavily contended for, memory is allocated based on the soft limit -hints/setup. Currently soft limit based reclaim is set up such that -it gets invoked from balance_pgdat (kswapd). - -7.1 Interface -------------- - -Soft limits can be setup by using the following commands (in this example we -assume a soft limit of 256 MiB):: - - # echo 256M > memory.soft_limit_in_bytes - -If we want to change this to 1G, we can at any time use:: - - # echo 1G > memory.soft_limit_in_bytes +Writing to memory.soft_limit_in_bytes has no effect and reading it will +always return the maximum value. -.. note:: - Soft limits take effect over a long period of time, since they involve - reclaiming memory for balancing between memory cgroups - -.. note:: - It is recommended to set the soft limit always below the hard limit, - otherwise the hard limit will take precedence. +Use memory.low and memory.min in cgroup v2 instead. .. _cgroup-v1-memory-move-charges:
mm/memcontrol.c +26 -14
@@ -3721,9 +3721,32 @@ enum {RES_LIMIT ,RES_MAX_USAGE , RES_FAILCNT, - RES_SOFT_LIMIT, }; +static u64 mem_cgroup_soft_limit_read (struct cgroup_subsys_state *css, +struct cftype *cft) +{ +return (u64 )PAGE_COUNTER_MAX *PAGE_SIZE ; +} + +static ssize_t mem_cgroup_soft_limit_write (struct kernfs_open_file *of, +char *buf,size_t nbytes,loff_t off) +{ +unsigned long nr_pages; +int ret; + + ret =page_counter_memparse (strstrip (buf),"-1" , &nr_pages); +if (ret) +return ret; + +pr_warn_once ("soft_limit_in_bytes is deprecated and will be removed. " +"Writing any value to this file has no effect. " +"Please report your usecase to [email protected] if you " +"depend on this functionality.\n" ); + +return nbytes; +} +static u64 mem_cgroup_read_u64 (struct cgroup_subsys_state *css,struct cftype *cft) {
@@ -3760,8 +3783,6 @@ static u64 mem_cgroup_read_u64(struct cgroup_subsys_state *css,return (u64 )counter->watermark *PAGE_SIZE ;case RES_FAILCNT :return counter->failcnt; -case RES_SOFT_LIMIT : -return (u64 )READ_ONCE (memcg->soft_limit) *PAGE_SIZE ;default :BUG (); }
@@ -3912,14 +3933,6 @@ static ssize_t mem_cgroup_write(struct kernfs_open_file *of,break ; }break ; -case RES_SOFT_LIMIT : -if (IS_ENABLED (CONFIG_PREEMPT_RT )) { - ret = -EOPNOTSUPP ; - }else { -WRITE_ONCE (memcg->soft_limit, nr_pages); - ret =0 ; - } -break ; }return ret ?: nbytes; }
@@ -5067,9 +5080,8 @@ static struct cftype mem_cgroup_legacy_files[] = { }, { .name = "soft_limit_in_bytes", - .private = MEMFILE_PRIVATE(_MEM, RES_SOFT_LIMIT), - .write = mem_cgroup_write, - .read_u64 = mem_cgroup_read_u64, + .write = mem_cgroup_soft_limit_write, + .read_u64 = mem_cgroup_soft_limit_read, }, { .name = "failcnt",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1511/1674 ACPI: bus: Introduce acpi_bus_get_primary_device()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
[ Upstream commit 72530e1f72b0515a73fd88292254d04fecf03649 ]
The function used for obtaining the first "physical" device for which the given ACPI one is the ACPI companion, acpi_get_first_physical_node(), may return a stale device pointer (mostly in theory) because acpi_unbind_one() may run as a whole after dropping the ACPI device's physical_node_lock in acpi_get_first_physical_node() and before it returns. The last reference to the "physical" device may be dropped then before the pointer to it is returned to the caller.
If that happens and the acpi_get_first_physical_node() caller invokes get_device() on the pointer obtained from it, which is done by the majority of its callers, a use-after-free will occur.
To prepare for addressing this problem, introduce a new function for getting the first "physical" device associated with the given ACPI one (the "primary physical device") that will also reference count the device in question before returning a pointer to it.
Make that new function and acpi_get_first_physical_node() share the physical node list lookup code.
No intentional functional impact.
--- drivers/acpi/bus.c | 54 +++++++++++++++++++++++++++++------------ include/acpi/acpi_bus.h | 6 +++++ 2 files changed, 44 insertions(+), 16 deletions(-)
drivers/acpi/bus.c +38 -16
@@ -703,30 +703,52 @@ static int __init acpi_setup_sb_notify_handler(void)Device Matching -------------------------------------------------------------------------- */ + +static struct device *primary_physical_device (struct acpi_device *adev) +{ +struct acpi_device_physical_node *pn; + + pn =list_first_entry_or_null (&adev->physical_node_list, + struct acpi_device_physical_node, node); +if (pn) +return pn->dev; + +return NULL ; +} +/** -* acpi_get_first_physical_node - Get first physical node of an ACPI device +* acpi_bus_get_primary_device - Get first physical device for a given ACPI one +* @adev: ACPI device to get the first physical device for. +* +* Find the first physical device for which @adev is the ACPI companion and +* reference count it if present. +* +* Return: Pointer to the first physical counterpart of @adev or NULL if there +* are none. Callers are responsible for invoking put_device() on the returned +* device. +*/ +struct device *acpi_bus_get_primary_device (struct acpi_device *adev) +{ +if (!adev) +return NULL ; + +guard (mutex)(&adev->physical_node_lock); + +return get_device (primary_physical_device (adev)); +} +EXPORT_SYMBOL_GPL (acpi_bus_get_primary_device); + +/** +* acpi_get_first_physical_node - Find first physical node of an ACPI device * @adev: ACPI device in question * * Return: First physical node of ACPI device @adev */ struct device *acpi_get_first_physical_node (struct acpi_device *adev) { -struct mutex *physical_node_lock = &adev->physical_node_lock; -struct device *phys_dev; - -mutex_lock (physical_node_lock); -if (list_empty (&adev->physical_node_list)) { - phys_dev =NULL ; - }else { -const struct acpi_device_physical_node *node; +guard (mutex)(&adev->physical_node_lock); - node =list_first_entry (&adev->physical_node_list, - struct acpi_device_physical_node, node); - - phys_dev = node->dev; - } -mutex_unlock (physical_node_lock); -return phys_dev; +return primary_physical_device (adev); }EXPORT_SYMBOL_GPL (acpi_get_first_physical_node);
include/acpi/acpi_bus.h +6 -0
@@ -568,6 +568,7 @@ void acpi_bus_unregister_driver(struct acpi_driver *driver);int acpi_bus_scan (acpi_handle handle);void acpi_bus_trim (struct acpi_device *start);acpi_status acpi_bus_get_ejd (acpi_handle handle,acpi_handle * ejd); +struct device *acpi_bus_get_primary_device (struct acpi_device *adev);int acpi_match_device_ids (struct acpi_device *device,const struct acpi_device_id *ids); void acpi_set_modalias(struct acpi_device *adev, const char *default_id,
@@ -821,6 +822,11 @@ static inline void acpi_put_acpi_dev(struct acpi_device *adev) }#else /* CONFIG_ACPI */ +static inline struct device *acpi_bus_get_primary_device (struct acpi_device *adev) +{ +return NULL ; +} +static inline int register_acpi_bus_type (void *bus) {return 0 ; }static inline int unregister_acpi_bus_type (void *bus) {return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1512/1674 powerpc/xive: add error return value to xive_smp_probe()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gou Hao <[email protected]>
[ Upstream commit ab5ae5dceb86614f6c9e7488f91b652000edfdc5 ]
xive_smp_probe() calls xive_init_ipis() which can fail, but its return value is currently ignored. Change xive_smp_probe() to return int so that errors can be propagated to callers.
This is a preparatory patch for the next one.
No functional change yet; the return value is always 0 at this point.
Stable-dep-of: 411a3c016e7a ("powerpc/xive: propagate IPI init errors to prevent use-after-free")
--- arch/powerpc/include/asm/xive.h | 4 ++-- arch/powerpc/sysdev/xive/common.c | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-)
arch/powerpc/include/asm/xive.h +2 -2
@@ -91,7 +91,7 @@ static inline bool xive_enabled(void) { return __xive_enabled; }bool xive_spapr_init (void );bool xive_native_init (void ); -void xive_smp_probe (void ); +int xive_smp_probe (void );int xive_smp_prepare_cpu (unsigned int cpu);void xive_smp_setup_cpu (void );void xive_smp_disable_cpu (void );
@@ -154,7 +154,7 @@ static inline bool xive_enabled(void) { return false; }static inline bool xive_spapr_init (void ) {return false; }static inline bool xive_native_init (void ) {return false; } -static inline void xive_smp_probe (void ) { } +static inline int xive_smp_probe (void ) {return -EINVAL ; }static inline int xive_smp_prepare_cpu (unsigned int cpu) {return -EINVAL ; }static inline void xive_smp_setup_cpu (void ) { }static inline void xive_smp_disable_cpu (void ) { }
arch/powerpc/sysdev/xive/common.c +3 -1
@@ -1270,7 +1270,7 @@ noinstr static void xive_cleanup_cpu_ipi(unsigned int cpu, struct xive_cpu *xc) xive_ops->put_ipi (cpu, xc); } -void __init xive_smp_probe (void ) +int __init xive_smp_probe (void ) { smp_ops->cause_ipi = xive_cause_ipi;
@@ -1279,6 +1279,8 @@ void __init xive_smp_probe(void)/* Allocate and setup IPI for the boot CPU */ xive_setup_cpu_ipi (smp_processor_id ()); + + return 0; }#endif /* CONFIG_SMP */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1513/1674 powerpc/xive: propagate IPI init errors to prevent use-after-free
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gou Hao <[email protected]>
[ Upstream commit 411a3c016e7a95f5fa105a0587e07d0647a77727 ]
When xive_init_ipis() fails (e.g. irq_domain_alloc_irqs() fails), the error path frees the global xive_ipis array. However, xive_smp_probe() previously ignored this failure and proceeded to call xive_setup_cpu_ipi(), which dereferences the already-freed xive_ipis pointer -- a use-after-free.
Now that xive_smp_probe() returns int (previous patch), propagate the error from xive_init_ipis() and xive_setup_cpu_ipi() through xive_smp_probe(). Check the return value in both pnv_smp_probe() and pSeries_smp_probe() so that IPI setup is aborted cleanly on failure, avoiding the use-after-free.
--- arch/powerpc/platforms/powernv/smp.c | 8 +++++--- arch/powerpc/platforms/pseries/smp.c | 8 +++++--- arch/powerpc/sysdev/xive/common.c | 10 ++++++---- 3 files changed, 16 insertions(+), 10 deletions(-)
arch/powerpc/platforms/powernv/smp.c +5 -3
@@ -329,10 +329,12 @@ static void pnv_cause_ipi(int cpu)static void __init pnv_smp_probe (void ) { -if (xive_enabled ()) -xive_smp_probe (); -else +if (xive_enabled ()) { +if (xive_smp_probe () <0 ) +return ; + }else {xics_smp_probe (); + }if (cpu_has_feature (CPU_FTR_DBELL )) { ic_cause_ipi = smp_ops->cause_ipi;
arch/powerpc/platforms/pseries/smp.c +5 -3
@@ -194,10 +194,12 @@ static int pseries_cause_nmi_ipi(int cpu)static __init void pSeries_smp_probe (void ) { -if (xive_enabled ()) -xive_smp_probe (); -else +if (xive_enabled ()) { +if (xive_smp_probe () <0 ) +return ; + }else {xics_smp_probe (); + }/* No doorbell facility, must use the interrupt controller for IPIs */ if (!cpu_has_feature (CPU_FTR_DBELL ))
arch/powerpc/sysdev/xive/common.c +6 -4
@@ -1272,15 +1272,17 @@ noinstr static void xive_cleanup_cpu_ipi(unsigned int cpu, struct xive_cpu *xc)int __init xive_smp_probe (void ) { +int ret; + smp_ops->cause_ipi = xive_cause_ipi;/* Register the IPI */ -xive_init_ipis (); + ret =xive_init_ipis (); +if (ret <0 ) +return ret;/* Allocate and setup IPI for the boot CPU */ -xive_setup_cpu_ipi (smp_processor_id ()); - -return 0 ; +return xive_setup_cpu_ipi (smp_processor_id ()); }#endif /* CONFIG_SMP */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1514/1674 remoteproc: qcom_wcnss: Fix handling the lack of PD regulators in v3
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Val Packett <[email protected]>
[ Upstream commit 3dbc90b9c22ea96e37bf55f6011e63b5123ec668 ]
The changes introduced to handle single power domain platforms have swapped the info pointer increment from num_pd_vregs to num_pds, which would shift the info pointer past the end of the array for pronto-v3, which does not list power domain regulators in vregs.
This showed up as a difference between GCC- and LLVM-compiled kernels on SDM632 devices, where only with LLVM one would get the "regulator request with no identifier" error, because the out-of-bounds memory ended up being zeroed. Fix by skipping the increment when there are more power domains than regulators.
--- drivers/remoteproc/qcom_wcnss.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
drivers/remoteproc/qcom_wcnss.c +14 -9
@@ -441,25 +441,31 @@ static void wcnss_release_pds(struct qcom_wcnss *wcnss) }static int wcnss_init_regulators (struct qcom_wcnss *wcnss, -const struct wcnss_vreg_info *info, -int num_vregs,int num_pd_vregs) +const struct wcnss_data *data) { +const struct wcnss_vreg_info *info = data->vregs;struct regulator_bulk_data *bulk; +size_t i, possible_pds =0 , num_vregs = data->num_vregs;int ret; -int i; + +for (i =0 ; i <WCNSS_MAX_PDS ; i++) +if (data->pd_names[i]) + possible_pds++;/* * If attaching the power domains suceeded we can skip requesting * the regulators for the power domains. For old device trees we need to * reserve extra space to manage them through the regulator interface. */ -if (wcnss->num_pds) { +if (possible_pds >= num_vregs) { +/* Do nothing if vregs do not include PD regulators (pronto-v3) */ + }else if (wcnss->num_pds) { info += wcnss->num_pds;/* Handle single power domain case */ -if (wcnss->num_pds < num_pd_vregs) - num_vregs += num_pd_vregs - wcnss->num_pds; +if (wcnss->num_pds < data->num_pd_vregs) + num_vregs += data->num_pd_vregs - wcnss->num_pds; }else { - num_vregs += num_pd_vregs; + num_vregs += data->num_pd_vregs; } bulk = devm_kcalloc(wcnss->dev,
@@ -614,8 +620,7 @@ static int wcnss_probe(struct platform_device *pdev)if (ret && (ret != -ENODATA || !data->num_pd_vregs)) goto free_rproc; - ret =wcnss_init_regulators (wcnss, data->vregs, data->num_vregs, - data->num_pd_vregs); + ret =wcnss_init_regulators (wcnss, data);if (ret) goto detach_pds;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1515/1674 perf/x86/intel/pt: Fix stop/start with no update
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
[ Upstream commit 2e17bf3a469a41457a3bc31b1f8fd66b6ce94a6d ]
If pt_event_stop() is called without PERF_EF_UPDATE flag, then perf_aux_output_end() is not called. A subsequent call to pt_event_start() will call perf_aux_output_begin() again which violates the rule against nesting and triggers a WARNING in perf_aux_output_begin().
Originally, pt_event_stop() was never called without PERF_EF_UPDATE, because the only code paths to do so are from event overflow, and Intel PT does not do that.
However the introduction of group throttling by commit 9734e25fbf5ae ("perf: Fix the throttle logic for a group") meant that an Intel PT event could be throttled if it was part of a group. Throttling calls PMU
->stop() / ->start() callbacks without flags.
An example is when AUX area sampling is used. The following commands hit the issue:
echo 10000 > /proc/sys/kernel/perf_event_max_sample_rate
perf record -F32000 --aux-sample -e '{intel_pt//u,cycles:u}' \
-- bash -c 'for i in `seq 1 100000` ; do true ; done'Use PERF_HES_UPTODATE to track whether perf_aux_output_begin() and perf_aux_output_end() are balanced. A cleared PERF_HES_UPTODATE bit indicates that an AUX output context is still open.
Amend pt_event_start() / pt_event_stop() accordingly so that begin/end stay balanced:
- In non-snapshot mode, stop() always closes the buffer (the buffer may have run out of space, and that accounting is done by the update), so a following start() opens a fresh one as before.
- In snapshot/overwrite mode, stop() without PERF_EF_UPDATE leaves the buffer open so that pt_event_snapshot_aux() can still copy from it, and start() then only re-enables tracing instead of calling perf_aux_output_begin() again.
Note that pt_event_del() calls pt_event_stop() with PERF_EF_UPDATE flag set (as is required by the documentation), so a final call to perf_aux_output_end() is assured.
--- arch/x86/events/intel/pt.c | 56 ++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 14 deletions(-)
arch/x86/events/intel/pt.c +42 -14
@@ -1506,12 +1506,14 @@ void intel_pt_interrupt(void)perf_aux_output_end (&pt->handle,local_xchg (&buf->data_size,0 )); -if (!event->hw.state) { + event->hw.state |=PERF_HES_UPTODATE ; + +if (!(event->hw.state &PERF_HES_STOPPED )) {int ret; buf =perf_aux_output_begin (&pt->handle, event);if (!buf) { - event->hw.state =PERF_HES_STOPPED ; + event->hw.state |=PERF_HES_STOPPED ;return ; }
@@ -1525,6 +1527,8 @@ void intel_pt_interrupt(void)pt_config_buffer (buf);pt_config_start (event); + + event->hw.state &= ~PERF_HES_UPTODATE ; } }
@@ -1574,6 +1578,19 @@ static void pt_event_start(struct perf_event *event, int mode)struct pt *pt =this_cpu_ptr (&pt_ctx);struct pt_buffer *buf; +/* +* Re-start subsequent to a call to pt_event_stop() without the +* PERF_EF_UPDATE flag. Absence of PERF_HES_UPTODATE indicates that +* perf_aux_output_begin() has already been called. This path can +* come about only in snapshot/overwrite mode - see pt_event_stop(). +*/ +if (!(hwc->state &PERF_HES_UPTODATE )) { + hwc->state &= ~PERF_HES_STOPPED ; +WRITE_ONCE (pt->handle_nmi,1 ); +pt_config_start (event); +return ; + } + buf =perf_aux_output_begin (&pt->handle, event);if (!buf) goto fail_stop;
@@ -1585,7 +1602,7 @@ static void pt_event_start(struct perf_event *event, int mode) }WRITE_ONCE (pt->handle_nmi,1 ); - hwc->state =0 ; + hwc->state &= ~(PERF_HES_STOPPED |PERF_HES_UPTODATE );pt_config_buffer (buf);pt_config (event);
@@ -1595,12 +1612,13 @@ static void pt_event_start(struct perf_event *event, int mode) fail_end_stop:perf_aux_output_end (&pt->handle,0 ); fail_stop: - hwc->state =PERF_HES_STOPPED ; + hwc->state |=PERF_HES_STOPPED |PERF_HES_UPTODATE ; }static void pt_event_stop (struct perf_event *event,int mode) {struct pt *pt =this_cpu_ptr (&pt_ctx); +struct pt_buffer *buf;/* * Protect against the PMI racing with disabling wrmsr,
@@ -1611,17 +1629,24 @@ static void pt_event_stop(struct perf_event *event, int mode)pt_config_stop (event); -if (event->hw.state ==PERF_HES_STOPPED ) -return ; + event->hw.state |=PERF_HES_STOPPED ; - event->hw.state =PERF_HES_STOPPED ; - -if (mode &PERF_EF_UPDATE ) { -struct pt_buffer *buf =perf_get_aux (&pt->handle); +if (event->hw.state &PERF_HES_UPTODATE ) +return ; -if (!buf) -return ; + buf =perf_get_aux (&pt->handle); +if (!buf) +return ; +/* +* When not in snapshot/overwrite mode, there is a possibility that the +* buffer has run out of space. The accounting for that is handled by +* the update, so always update in that case. Snapshot/overwrite mode is +* treated differently to allow for pt_event_snapshot_aux() which can +* still get called if the AUX-sampling event is not stopped until after +* PT is stopped. +*/ +if ((mode &PERF_EF_UPDATE ) || !buf->snapshot) {if (WARN_ON_ONCE (pt->handle.event != event))return ;
@@ -1636,6 +1661,7 @@ static void pt_event_stop(struct perf_event *event, int mode)local_xchg (&buf->data_size, buf->nr_pages <<PAGE_SHIFT );perf_aux_output_end (&pt->handle,local_xchg (&buf->data_size,0 )); + event->hw.state |=PERF_HES_UPTODATE ; } }
@@ -1697,13 +1723,15 @@ static int pt_event_add(struct perf_event *event, int mode)if (pt->handle.event) goto fail; + event->hw.state |=PERF_HES_UPTODATE ; +if (mode &PERF_EF_START ) {pt_event_start (event,0 ); ret = -EINVAL ; -if (hwc->state ==PERF_HES_STOPPED ) +if (hwc->state &PERF_HES_STOPPED ) goto fail; }else { - hwc->state =PERF_HES_STOPPED ; + hwc->state |=PERF_HES_STOPPED ; } ret =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1516/1674 ksmbd: remove redundant DACL check in smb_check_perm_dacl
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexey Velichayshiy <[email protected]>
[ Upstream commit 8dd2e58b62731a96e276ee0545fb910ffb2057d9 ]
A zero value of pdacl->num_aces is already handled at the start of smb_check_perm_dacl() so the second check is useless.
Drop the unreachable code block, no functional impact intended.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Stable-dep-of: cc2f133e80eb ("ksmbd: fix maximum allowed access checks")
--- fs/smb/server/smbacl.c | 3 --- 1 file changed, 3 deletions(-)
fs/smb/server/smbacl.c +0 -3
@@ -1498,9 +1498,6 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path, granted |=le32_to_cpu (ace->access_req); ace = (struct smb_ace *)((char *)ace +le16_to_cpu (ace->size)); } - -if (!pdacl->num_aces) - granted =GENERIC_ALL_FLAGS ; }if (!uid)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1517/1674 ksmbd: fix maximum allowed access checks
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
[ Upstream commit cc2f133e80eb2c4a04bfa77a2f207749fe2f516a ]
The DACL permission check looks for an ACE matching the current user and falls back to the Everyone ACE. It does not consider an Authenticated Users ACE, even though an authenticated session is a member of that well-known group.
As a result, opening a file whose access is granted through S-1-5-11 can incorrectly fail with STATUS_ACCESS_DENIED. Treat an Authenticated Users ACE as a fallback entry alongside Everyone.
The maximal access calculation also combines access masks from every ACE, regardless of whether its SID applies to the current user. This can grant rights belonging to an unrelated principal. Process only ACEs applying to the user, Everyone, or Authenticated Users, and accumulate allowed and denied masks in ACL order. Preserve explicitly requested access bits so they are validated against the resulting maximal mask.
When ACCESS_SYSTEM_SECURITY is denied, report STATUS_PRIVILEGE_NOT_HELD instead of the generic STATUS_ACCESS_DENIED. Access to the system ACL requires a security privilege that ksmbd does not grant.
For regular files, include FILE_EXECUTE in maximal access when the client requested GENERIC_EXECUTE and the DACL grants the complete file-read set. Keep a direct FILE_EXECUTE request subject to the explicit DACL bit. This matches the POSIX file ACL mapping without broadening specific execute requests.
Do not replace rights from an applicable NT ACE with a POSIX ACL entry. The POSIX ACL is only a fallback when no user, Everyone, or Authenticated Users ACE applies; otherwise it can incorrectly broaden the stored DACL.
This fixes smb2.maximum_allowed.maximum_allowed.
--- fs/smb/server/smb2pdu.c | 9 ++++- fs/smb/server/smbacl.c | 83 ++++++++++++++++++++++++++--------------- fs/smb/server/smbacl.h | 2 +- 3 files changed, 61 insertions(+), 33 deletions(-)
fs/smb/server/smb2pdu.c +7 -2
@@ -3252,6 +3252,7 @@ int smb2_open(struct ksmbd_work *work)if (file_present && !(req->CreateOptions &FILE_DELETE_ON_CLOSE_LE )) { rc =smb_check_perm_dacl (conn, &path, &daccess, + req->DesiredAccess, sess->user->uid);if (rc) goto err_out;
@@ -3795,8 +3796,12 @@ int smb2_open(struct ksmbd_work *work) rsp->hdr.Status =STATUS_INVALID_PARAMETER ; else if (rc == -EOPNOTSUPP) rsp->hdr.Status = STATUS_NOT_SUPPORTED; - else if (rc == -EACCES || rc == -ESTALE || rc == -EXDEV) - rsp->hdr.Status =STATUS_ACCESS_DENIED ; + else if (rc == -EACCES || rc == -ESTALE || rc == -EXDEV) { +if (req->DesiredAccess &FILE_ACCESS_SYSTEM_SECURITY_LE ) + rsp->hdr.Status =STATUS_PRIVILEGE_NOT_HELD ; +else + rsp->hdr.Status =STATUS_ACCESS_DENIED ; + } else if (rc == -ENOENT) rsp->hdr.Status = STATUS_OBJECT_NAME_INVALID; else if (rc == -EPERM)
fs/smb/server/smbacl.c +53 -30
134 lines not on this page · raw message
fs/smb/server/smbacl.h +1 -1
@@ -95,7 +95,7 @@ bool smb_inherit_flags(int flags, bool is_dir);int smb_inherit_dacl (struct ksmbd_conn *conn,const struct path *path,unsigned int uid,unsigned int gid);int smb_check_perm_dacl (struct ksmbd_conn *conn,const struct path *path, -__le32 *pdaccess,int uid); +__le32 *pdaccess,__le32 raw_daccess,int uid);int set_info_sec (struct ksmbd_conn *conn,struct ksmbd_tree_connect *tcon,const struct path *path,struct smb_ntsd *pntsd,int ntsd_len,bool type_check,bool get_write);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1518/1674 wifi: iwlwifi: mvm: remove mvm prefix from iwl_mvm_tx_resp*
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Miri Korenblit <[email protected]>
[ Upstream commit 5b0c478378e5c82c4c372cf194a2438f8743abcf ]
These are not mvm specific
Stable-dep-of: 8d70881707b4 ("wifi: iwlwifi: mvm: validate TX_CMD response layout")
--- drivers/net/wireless/intel/iwlwifi/fw/api/commands.h | 4 ++-- drivers/net/wireless/intel/iwlwifi/fw/api/tx.h | 12 ++++++------ drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c | 2 +- drivers/net/wireless/intel/iwlwifi/mvm/mvm.h | 4 ++-- drivers/net/wireless/intel/iwlwifi/mvm/ops.c | 2 +- drivers/net/wireless/intel/iwlwifi/mvm/tx.c | 12 ++++++------ 6 files changed, 18 insertions(+), 18 deletions(-)
drivers/net/wireless/intel/iwlwifi/fw/api/commands.h +2 -2
@@ -141,8 +141,8 @@ enum iwl_legacy_cmds {/** * @TX_CMD: uses &struct iwl_tx_cmd or &struct iwl_tx_cmd_gen2 or * &struct iwl_tx_cmd_gen3, -* response in &struct iwl_mvm_tx_resp or -* &struct iwl_mvm_tx_resp_v3 +* response in &struct iwl_tx_resp or +* &struct iwl_tx_resp_v3 */ TX_CMD = 0x1c,
drivers/net/wireless/intel/iwlwifi/fw/api/tx.h +6 -6
@@ -484,7 +484,7 @@ struct agg_tx_status {#define IWL_MVM_TX_RES_GET_RA (_ra_tid) ((_ra_tid) >> 4)/** -* struct iwl_mvm_tx_resp_v3 - notifies that fw is TXing a packet +* struct iwl_tx_resp_v3 - notifies that fw is TXing a packet * ( REPLY_TX = 0x1c ) * @frame_count: 1 no aggregation, >1 aggregation * @bt_kill_count: num of times blocked by bluetooth (unused for agg)
@@ -515,7 +515,7 @@ struct agg_tx_status {* After the array of statuses comes the SSN of the SCD. Look at * %iwl_mvm_get_scd_ssn for more details. */ -struct iwl_mvm_tx_resp_v3 { +struct iwl_tx_resp_v3 {u8 frame_count;u8 bt_kill_count;u8 failure_rts;
@@ -541,7 +541,7 @@ struct iwl_mvm_tx_resp_v3 { } __packed;/* TX_RSP_API_S_VER_3 */ /** -* struct iwl_mvm_tx_resp - notifies that fw is TXing a packet +* struct iwl_tx_resp - notifies that fw is TXing a packet * ( REPLY_TX = 0x1c ) * @frame_count: 1 no aggregation, >1 aggregation * @bt_kill_count: num of times blocked by bluetooth (unused for agg)
@@ -573,7 +573,7 @@ struct iwl_mvm_tx_resp_v3 {* After the array of statuses comes the SSN of the SCD. Look at * %iwl_mvm_get_scd_ssn for more details. */ -struct iwl_mvm_tx_resp { +struct iwl_tx_resp {u8 frame_count;u8 bt_kill_count;u8 failure_rts;
@@ -814,7 +814,7 @@ struct iwl_mac_beacon_cmd {*/ struct iwl_beacon_notif { -struct iwl_mvm_tx_resp beacon_notify_hdr; +struct iwl_tx_resp beacon_notify_hdr;__le64 tsf;__le32 ibss_mgr_status; } __packed;
@@ -827,7 +827,7 @@ struct iwl_beacon_notif {* @gp2: last beacon time in gp2 */ struct iwl_extended_beacon_notif_v5 { -struct iwl_mvm_tx_resp beacon_notify_hdr; +struct iwl_tx_resp beacon_notify_hdr;__le64 tsf;__le32 ibss_mgr_status;__le32 gp2;
drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c +1 -1
@@ -1496,7 +1496,7 @@ void iwl_mvm_rx_beacon_notif(struct iwl_mvm *mvm, mvm->ap_last_beacon_gp2 =le32_to_cpu (beacon->gp2);if (!iwl_mvm_is_short_beacon_notif_supported (mvm)) { -struct iwl_mvm_tx_resp *beacon_notify_hdr = +struct iwl_tx_resp *beacon_notify_hdr = &beacon_v5->beacon_notify_hdr;if (unlikely (pkt_len <sizeof (*beacon_v5)))
drivers/net/wireless/intel/iwlwifi/mvm/mvm.h +2 -2
@@ -1526,9 +1526,9 @@ static inline struct agg_tx_status * iwl_mvm_get_agg_status(struct iwl_mvm *mvm, void *tx_resp) { if (iwl_mvm_has_new_tx_api(mvm)) - return &((struct iwl_mvm_tx_resp *)tx_resp)->status; + return &((struct iwl_tx_resp *)tx_resp)->status; else - return ((struct iwl_mvm_tx_resp_v3 *)tx_resp)->status; + return ((struct iwl_tx_resp_v3 *)tx_resp)->status; }static inline bool iwl_mvm_is_tt_in_fw (struct iwl_mvm *mvm)
drivers/net/wireless/intel/iwlwifi/mvm/ops.c +1 -1
@@ -309,7 +309,7 @@ struct iwl_rx_handlers {*/ static const struct iwl_rx_handlers iwl_mvm_rx_handlers[] = {RX_HANDLER (TX_CMD , iwl_mvm_rx_tx_cmd,RX_HANDLER_SYNC , - struct iwl_mvm_tx_resp), + struct iwl_tx_resp),RX_HANDLER (BA_NOTIF , iwl_mvm_rx_ba_notif,RX_HANDLER_SYNC , struct iwl_mvm_ba_notif),
drivers/net/wireless/intel/iwlwifi/mvm/tx.c +6 -6
@@ -1622,7 +1622,7 @@ static void iwl_mvm_tx_status_check_trigger(struct iwl_mvm *mvm,* For 22000-series and lower, this is just 12 bits. For later, 16 bits. */ static inline u32 iwl_mvm_get_scd_ssn (struct iwl_mvm *mvm, -struct iwl_mvm_tx_resp *tx_resp) +struct iwl_tx_resp *tx_resp) {u32 val =le32_to_cpup ((__le32 *)iwl_mvm_get_agg_status (mvm, tx_resp) + tx_resp->frame_count);
@@ -1638,8 +1638,8 @@ static void iwl_mvm_rx_tx_cmd_single(struct iwl_mvm *mvm,struct ieee80211_sta *sta;u16 sequence =le16_to_cpu (pkt->hdr.sequence);int txq_id =SEQ_TO_QUEUE (sequence); -/* struct iwl_mvm_tx_resp_v3 is almost the same */ -struct iwl_mvm_tx_resp *tx_resp = (void *)pkt->data; +/* struct iwl_tx_resp_v3 is almost the same */ +struct iwl_tx_resp *tx_resp = (void *)pkt->data;int sta_id =IWL_MVM_TX_RES_GET_RA (tx_resp->ra_tid);int tid =IWL_MVM_TX_RES_GET_TID (tx_resp->ra_tid); struct agg_tx_status *agg_status =
@@ -1895,7 +1895,7 @@ static const char *iwl_get_agg_tx_status(u16 status)static void iwl_mvm_rx_tx_cmd_agg_dbg (struct iwl_mvm *mvm,struct iwl_rx_packet *pkt) { -struct iwl_mvm_tx_resp *tx_resp = (void *)pkt->data; +struct iwl_tx_resp *tx_resp = (void *)pkt->data;struct agg_tx_status *frame_status =iwl_mvm_get_agg_status (mvm, tx_resp);int i;
@@ -1929,7 +1929,7 @@ static void iwl_mvm_rx_tx_cmd_agg_dbg(struct iwl_mvm *mvm,static void iwl_mvm_rx_tx_cmd_agg (struct iwl_mvm *mvm,struct iwl_rx_packet *pkt) { -struct iwl_mvm_tx_resp *tx_resp = (void *)pkt->data; +struct iwl_tx_resp *tx_resp = (void *)pkt->data;int sta_id =IWL_MVM_TX_RES_GET_RA (tx_resp->ra_tid);int tid =IWL_MVM_TX_RES_GET_TID (tx_resp->ra_tid);u16 sequence =le16_to_cpu (pkt->hdr.sequence);
@@ -1970,7 +1970,7 @@ static void iwl_mvm_rx_tx_cmd_agg(struct iwl_mvm *mvm,void iwl_mvm_rx_tx_cmd (struct iwl_mvm *mvm,struct iwl_rx_cmd_buffer *rxb) {struct iwl_rx_packet *pkt =rxb_addr (rxb); -struct iwl_mvm_tx_resp *tx_resp = (void *)pkt->data; +struct iwl_tx_resp *tx_resp = (void *)pkt->data;if (tx_resp->frame_count ==1 )iwl_mvm_rx_tx_cmd_single (mvm, pkt);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1519/1674 wifi: iwlwifi: mvm: validate TX_CMD response layout
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Emmanuel Grumbach <[email protected]>
[ Upstream commit 8d70881707b47353359df57df12f6de67fdacdd2 ]
TX_CMD parsing uses frame_count to walk status entries and then read the trailing SCD SSN. Make the minimum-length check follow that exact runtime layout calculation before parsing the payload.
For new TX API, reject TX_CMD responses with frame_count != 1 and warn/return in the aggregation handler to document that aggregated accounting is expected via BA notifications.
--- drivers/net/wireless/intel/iwlwifi/mvm/tx.c | 34 +++++++++++++++++++++ 1 file changed, 34 insertions(+)
drivers/net/wireless/intel/iwlwifi/mvm/tx.c +34 -0
@@ -1632,6 +1632,17 @@ static inline u32 iwl_mvm_get_scd_ssn(struct iwl_mvm *mvm,return val &0xFFF ; } +static inline size_t iwl_mvm_tx_resp_min_len (struct iwl_mvm *mvm, +struct iwl_tx_resp *tx_resp) +{ +struct agg_tx_status *agg_status = +iwl_mvm_get_agg_status (mvm, tx_resp); + +/* The aggregate response ends with a trailing SCD SSN __le32 word. */ +return (u8 *)(agg_status + tx_resp->frame_count) - (u8 *)tx_resp + +sizeof (__le32); +} +static void iwl_mvm_rx_tx_cmd_single (struct iwl_mvm *mvm,struct iwl_rx_packet *pkt) {
@@ -1937,6 +1948,9 @@ static void iwl_mvm_rx_tx_cmd_agg(struct iwl_mvm *mvm,int queue =SEQ_TO_QUEUE (sequence);struct ieee80211_sta *sta; +if (WARN_ON_ONCE (iwl_mvm_has_new_tx_api (mvm))) +return ; +if (WARN_ON_ONCE (queue <IWL_MVM_DQA_MIN_DATA_QUEUE && (queue !=IWL_MVM_DQA_BSS_CLIENT_QUEUE )))return ;
@@ -1971,6 +1985,26 @@ void iwl_mvm_rx_tx_cmd(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb) {struct iwl_rx_packet *pkt =rxb_addr (rxb);struct iwl_tx_resp *tx_resp = (void *)pkt->data; +size_t min_len; + +if (IWL_FW_CHECK (mvm, !tx_resp->frame_count, +"invalid TX_CMD frame_count %u\n" , + tx_resp->frame_count)) +return ; + +if (IWL_FW_CHECK (mvm, +iwl_mvm_has_new_tx_api (mvm) && + tx_resp->frame_count !=1 , +"invalid TX_CMD frame_count %u for new TX API\n" , + tx_resp->frame_count)) +return ; + + min_len =iwl_mvm_tx_resp_min_len (mvm, tx_resp); +if (IWL_FW_CHECK (mvm,iwl_rx_packet_payload_len (pkt) < min_len, +"invalid TX_CMD len %u (frame_count %u, min %zu)\n" , +iwl_rx_packet_payload_len (pkt), tx_resp->frame_count, + min_len)) +return ;if (tx_resp->frame_count ==1 )iwl_mvm_rx_tx_cmd_single (mvm, pkt);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1520/1674 wifi: iwlwifi: pcie: null RX pointers after free
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Emmanuel Grumbach <[email protected]>
[ Upstream commit 2c79d7a7b583050c9f58041465cb46fe3483ab5d ]
When iwl_pcie_tx_init() fails after RX init, nic init unwinds via iwl_pcie_rx_free().
The freed RX members stayed non-NULL on the live transport object, so later teardown or retry could touch stale RX state. Set rx_pool, global_table, rxq, and alloc_page to NULL after free to make repeated cleanup and retry paths safe.
--- drivers/net/wireless/intel/iwlwifi/pcie/rx.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/net/wireless/intel/iwlwifi/pcie/rx.c +7 -2
@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause /* -* Copyright (C) 2003-2014, 2018-2023 Intel Corporation +* Copyright (C) 2003-2014, 2018-2023, 2026 Intel Corporation * Copyright (C) 2013-2015 Intel Mobile Communications GmbH * Copyright (C) 2016-2017 Intel Deutschland GmbH */
@@ -1236,11 +1236,16 @@ void iwl_pcie_rx_free(struct iwl_trans *trans) } }kfree (trans_pcie->rx_pool); + trans_pcie->rx_pool =NULL ;kfree (trans_pcie->global_table); + trans_pcie->global_table =NULL ;kfree (trans_pcie->rxq); + trans_pcie->rxq =NULL ; -if (trans_pcie->alloc_page) +if (trans_pcie->alloc_page) {__free_pages (trans_pcie->alloc_page, trans_pcie->rx_page_order); + trans_pcie->alloc_page =NULL ; + } } static void iwl_pcie_rx_move_to_allocator(struct iwl_rxq *rxq,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1521/1674 smb/client: zero-initialize stack-allocated cifs_open_info_data
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: ChenXiaoSong <[email protected]>
[ Upstream commit 8fce4cf4369c766a3293a05419500cbfde72e60d ]
Stack-allocated cifs_open_info_data may contain random data. This can make some fields have wrong value if they are not set later.
--- fs/smb/client/link.c | 2 +- fs/smb/client/smb1ops.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
fs/smb/client/link.c +1 -1
@@ -257,7 +257,7 @@ cifs_query_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,struct cifs_open_parms oparms;struct cifs_io_parms io_parms = {0 };int buf_type =CIFS_NO_BUFFER ; -struct cifs_open_info_data query_data; +struct cifs_open_info_data query_data = {}; oparms = (struct cifs_open_parms ) { .tcon = tcon,
fs/smb/client/smb1ops.c +1 -1
@@ -990,7 +990,7 @@ smb_set_file_info(struct inode *inode, const char *full_path,struct cifs_open_parms oparms;struct cifsFileInfo *open_file;FILE_BASIC_INFO new_buf; -struct cifs_open_info_data query_data; +struct cifs_open_info_data query_data = {};__le64 write_time = buf->LastWriteTime;struct cifsInodeInfo *cinode =CIFS_I (inode);struct cifs_sb_info *cifs_sb =CIFS_SB (inode->i_sb);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1522/1674 wifi: mac80211: ibss: wait for in-flight TX on disconnect
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pagadala Yesu Anjaneyulu <[email protected]>
[ Upstream commit d0e69d9afa59b93c30294eba89b1f15f69e91105 ]
While leaving an IBSS in ieee80211_ibss_disconnect() mac80211 flushes stations, turns the carrier off and immediately tells the driver to leave as well. While there may be synchronize_net() in station flush and in this code later, packets can still be transmitted due to cross-CPU race conditions after carrier off is set. Therefore, it's possible for a race to happen where a TX to the driver occurs while or after telling it to leave the IBSS. This can be confusing to drivers, and in the case of iwlwifi leads to an attempt to use invalid queues.
Move netif_carrier_off() to occur before sta_info_flush() during IBSS disconnect, and add synchronize_net() if flushing didn't, so that the synchronize_net() always happens between turning the carrier off and telling the driver, avoiding this race.
--- net/mac80211/ibss.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
net/mac80211/ibss.c +3 -6
@@ -695,7 +695,9 @@ static void ieee80211_ibss_disconnect(struct ieee80211_sub_if_data *sdata) ifibss->state =IEEE80211_IBSS_MLME_SEARCH ; -sta_info_flush (sdata); +netif_carrier_off (sdata->dev); +if (!sta_info_flush (sdata)) +synchronize_net ();spin_lock_bh (&ifibss->incomplete_lock);while (!list_empty (&ifibss->incomplete_stations)) {
@@ -709,8 +711,6 @@ static void ieee80211_ibss_disconnect(struct ieee80211_sub_if_data *sdata) }spin_unlock_bh (&ifibss->incomplete_lock); -netif_carrier_off (sdata->dev); - sdata->vif.cfg.ibss_joined = false; sdata->vif.cfg.ibss_creator = false; sdata->vif.bss_conf.enable_beacon = false;
@@ -741,7 +741,6 @@ static void ieee80211_csa_connection_drop_work(struct wiphy *wiphy,sdata_lock (sdata);ieee80211_ibss_disconnect (sdata); -synchronize_rcu ();skb_queue_purge (&sdata->skb_queue);/* trigger a scan to find another IBSS network to join */
@@ -1882,8 +1881,6 @@ int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata)memset (&ifibss->ht_capa,0 ,sizeof (ifibss->ht_capa));memset (&ifibss->ht_capa_mask,0 ,sizeof (ifibss->ht_capa_mask)); -synchronize_rcu (); -skb_queue_purge (&sdata->skb_queue);del_timer_sync (&sdata->u.ibss.timer);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1523/1674 perf: Fix addr_filter_ranges lifetime
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 e62d4192e593630f355094adc467058a05bdc935 ]
Lee Jia Jie reported that since event::addr_filter_ranges is used under RCU, it should be RCU freed.
--- kernel/events/core.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/events/core.c +1 -3
@@ -5022,6 +5022,7 @@ static void free_event_rcu(struct rcu_head *head)if (event->ns)put_pid_ns (event->ns);perf_event_free_filter (event); +kfree (event->addr_filter_ranges);kmem_cache_free (perf_event_cache, event); }
@@ -5257,7 +5258,6 @@ static void _free_event(struct perf_event *event)perf_event_free_bpf_prog (event);perf_addr_filters_splice (event,NULL ); -kfree (event->addr_filter_ranges);if (event->destroy) event->destroy (event);
@@ -12276,8 +12276,6 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,put_callchain_buffers (); } err_addr_filters: -kfree (event->addr_filter_ranges); - err_per_task:exclusive_event_destroy (event);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1524/1674 exfat: resolve memory leak from exfat_create_upcase_table()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Yang <[email protected]>
[ Upstream commit c290fe508eee36df1640c3cb35dc8f89e073c8a8 ]
If exfat_load_upcase_table reaches end and returns -EINVAL, allocated memory doesn't get freed and while exfat_load_default_upcase_table allocates more memory, leading to a memory leak.
Here's link to syzkaller crash report illustrating this issue:
https://syzkaller.appspot.com/text?tag=CrashReport&x=1406c201980000
Stable-dep-of: 20dd3185d138 ("exfat: fix handling of damaged volume in exfat_create_upcase_table()")
--- fs/exfat/nls.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/exfat/nls.c +4 -1
@@ -785,8 +785,11 @@ int exfat_create_upcase_table(struct super_block *sb) le32_to_cpu(ep->dentry.upcase.checksum));brelse (bh); -if (ret && ret != -EIO ) +if (ret && ret != -EIO ) { +/* free memory from exfat_load_upcase_table call */ +exfat_free_upcase_table (sbi); goto load_default; + }/* load successfully */ return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1525/1674 exfat: fix handling of damaged volume in exfat_create_upcase_table()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Timber <[email protected]>
[ Upstream commit 20dd3185d13865214ff25b0bf7b931e8d73be1ac ]
When the size of the upcase table is set to zero in the dentry for any reason(e.g. corrupted media or misbehaving device), an integer overflow causes the module to loop indefinitely.
If the size of the upcase table is read zero, do not attempt to load the table. Instead, fallback to loading the default upcase table. If the size of the upcase table is zero or no upcase table is found, raise exfat_fs_error() to mark the volume read-only.
--- fs/exfat/nls.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
fs/exfat/nls.c +13 -6
@@ -778,13 +778,18 @@ int exfat_create_upcase_table(struct super_block *sb) tbl_clu =le32_to_cpu (ep->dentry.upcase.start_clu); tbl_size =le64_to_cpu (ep->dentry.upcase.size); - - sector =exfat_cluster_to_sector (sbi, tbl_clu); - num_sectors = ((tbl_size -1 ) >> blksize_bits) +1 ; - ret =exfat_load_upcase_table (sb, sector, num_sectors, -le32_to_cpu (ep->dentry.upcase.checksum)); - +if (tbl_size) { + sector =exfat_cluster_to_sector (sbi, tbl_clu); + num_sectors = ((tbl_size -1 ) >> blksize_bits) +1 ; + ret =exfat_load_upcase_table (sb, sector, num_sectors, +le32_to_cpu (ep->dentry.upcase.checksum)); + }else { +exfat_fs_error (sb, +"bad upcase table size (0 bytes). Please run fsck" ); + ret = -EINVAL ; + }brelse (bh); +if (ret && ret != -EIO ) {/* free memory from exfat_load_upcase_table call */ exfat_free_upcase_table (sbi);
@@ -799,6 +804,8 @@ int exfat_create_upcase_table(struct super_block *sb)return -EIO ; } +exfat_fs_error (sb,"no upcase table entry. Please run fsck" ); + load_default:/* load default upcase table */ return exfat_load_default_upcase_table (sb);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1526/1674 pds_core: quiesce DMA before freeing resources
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nikhil P. Rao <[email protected]>
[ Upstream commit 6443f4f20bdae726fe01cf5946fba9742a0ffda6 ]
pdsc_teardown() frees DMA buffers but does not disable bus mastering, leaving the device able to perform DMA after the buffers are freed. This can lead to use-after-free if the device writes to freed memory.
Add pci_clear_master() to pdsc_teardown() to disable bus mastering before freeing resources, ensuring all DMA is quiesced.
Add pci_set_master() to pdsc_setup() to re-enable bus mastering, which is needed for the firmware recovery path since pdsc_teardown() now disables it.
--- drivers/net/ethernet/amd/pds_core/core.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/ethernet/amd/pds_core/core.c +4 -0
@@ -452,6 +452,8 @@ int pdsc_setup(struct pdsc *pdsc, bool init) {int err; +pci_set_master (pdsc->pdev); + err =pdsc_dev_init (pdsc);if (err)return err;
@@ -483,6 +485,8 @@ void pdsc_teardown(struct pdsc *pdsc, bool removing)if (!pdsc->pdev->is_virtfn)pdsc_devcmd_reset (pdsc); +pci_clear_master (pdsc->pdev); +pdsc_core_uninit (pdsc);kfree (pdsc->viftype_status);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1527/1674 drm/amdkfd: fix SMI event cross-process information leak
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yongqiang Sun <[email protected]>
[ Upstream commit 92a8dba246d371fe268280e5fd74b0955688e6df ]
kfd_smi_ev_enabled() skips the suser privilege check when pid=0. PROCESS_START, PROCESS_END, and VMFAULT events are emitted with pid=0 while carrying another process's PID and command name, so any /dev/kfd user in the render group can monitor all GPU workloads.
Pass the target process PID into kfd_smi_event_add() for these events so the existing per-client filter restricts delivery to the owning process or CAP_SYS_ADMIN subscribers.
--- drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c +1 -1
@@ -244,7 +244,7 @@ void kfd_smi_event_update_vmfault(struct kfd_node *dev, uint16_t pasid)if (task_info) {/* Report VM faults from user applications, not retry from kernel */ if (task_info->pid) -kfd_smi_event_add (0 , dev,KFD_SMI_EVENT_VMFAULT ,"%x:%s\n" , +kfd_smi_event_add (task_info->tgid, dev,KFD_SMI_EVENT_VMFAULT ,"%x:%s\n" , task_info->pid, task_info->task_name);amdgpu_vm_put_task_info (task_info); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1528/1674 drm/amdgpu/ras: add ras_suspend callback and use it for cp_ecc_error_irq
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yunxiang Li <[email protected]>
[ Upstream commit e3829992dd9fa0a82511af4f01733fc854cd15a5 ]
cp_ecc_error_irq is acquired in amdgpu_gfx_ras_late_init() but released in gfx_v9_0_hw_fini(), so the put site has to query amdgpu_irq_enabled() because the get is skipped on SR-IOV VF.
ras_late_init / ras_fini have no suspend counterpart, so move the put to amdgpu_gfx_ras_suspend() / amdgpu_gfx_ras_fini() and add a matching ras_suspend callback that is invoked from amdgpu_ras_suspend() before disable_all_features(). The get and put now sit in the same place and check the same condition (not VF, funcs registered), no refcount querying needed.
An active flag gates ras_fini so the suspend-then-unload-without-resume path falls into amdgpu_ras_block_late_fini_default() instead of double-releasing what ras_suspend already cleaned up.
Drop the cp_ecc_error_irq put from gfx_v9_0_hw_fini(). gfx_v8_0 manages cp_ecc_error_irq locally and is unaffected; no other GFX generation has this IRQ.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 25 ++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 3 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 32 +++++++++++++++++++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h | 1 + drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 2 -- 5 files changed, 55 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +24 -1
@@ -803,7 +803,7 @@ int amdgpu_gfx_ras_late_init(struct amdgpu_device *adev, struct ras_common_if *rif (r)return r; -if (adev->gfx.cp_ecc_error_irq.funcs) { +if (!amdgpu_sriov_vf (adev) && adev->gfx.cp_ecc_error_irq.funcs) { r =amdgpu_irq_get (adev, &adev->gfx.cp_ecc_error_irq,0 );if (r) goto late_fini;
@@ -818,6 +818,23 @@ int amdgpu_gfx_ras_late_init(struct amdgpu_device *adev, struct ras_common_if *rreturn r; } +void amdgpu_gfx_ras_suspend (struct amdgpu_device *adev, +struct ras_common_if *ras_block) +{ +if (amdgpu_ras_is_supported (adev, ras_block->block) && + !amdgpu_sriov_vf (adev) && adev->gfx.cp_ecc_error_irq.funcs) +amdgpu_irq_put (adev, &adev->gfx.cp_ecc_error_irq,0 ); +} + +void amdgpu_gfx_ras_fini (struct amdgpu_device *adev, +struct ras_common_if *ras_block) +{ +if (amdgpu_ras_is_supported (adev, ras_block->block) && + !amdgpu_sriov_vf (adev) && adev->gfx.cp_ecc_error_irq.funcs) +amdgpu_irq_put (adev, &adev->gfx.cp_ecc_error_irq,0 ); +amdgpu_ras_block_late_fini (adev, ras_block); +} +int amdgpu_gfx_ras_sw_init (struct amdgpu_device *adev) {int err =0 ;
@@ -846,6 +863,12 @@ int amdgpu_gfx_ras_sw_init(struct amdgpu_device *adev)if (!ras->ras_block.ras_late_init) ras->ras_block.ras_late_init = amdgpu_gfx_ras_late_init; +if (!ras->ras_block.ras_suspend) + ras->ras_block.ras_suspend = amdgpu_gfx_ras_suspend; + +if (!ras->ras_block.ras_fini) + ras->ras_block.ras_fini = amdgpu_gfx_ras_fini; +/* If not defined special ras_cb function, use default ras_cb */ if (!ras->ras_block.ras_cb) ras->ras_block.ras_cb = amdgpu_gfx_process_ras_data_cb;
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +2 -1
@@ -516,7 +516,8 @@ bool amdgpu_gfx_is_me_queue_enabled(struct amdgpu_device *adev, int me,void amdgpu_gfx_off_ctrl (struct amdgpu_device *adev,bool enable);int amdgpu_get_gfx_off_status (struct amdgpu_device *adev,uint32_t *value);int amdgpu_gfx_ras_late_init (struct amdgpu_device *adev,struct ras_common_if *ras_block); -void amdgpu_gfx_ras_fini (struct amdgpu_device *adev); +void amdgpu_gfx_ras_suspend (struct amdgpu_device *adev,struct ras_common_if *ras_block); +void amdgpu_gfx_ras_fini (struct amdgpu_device *adev,struct ras_common_if *ras_block);int amdgpu_get_gfx_off_entrycount (struct amdgpu_device *adev,u64 *value);int amdgpu_get_gfx_off_residency (struct amdgpu_device *adev,u32 *residency);int amdgpu_set_gfx_off_residency (struct amdgpu_device *adev,bool value);
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +28 -4
@@ -86,6 +86,9 @@ struct amdgpu_ras_block_list {struct list_head node;struct amdgpu_ras_block_object *ras_obj; + +/* set by ras_late_init, cleared by ras_suspend/ras_fini */ +bool active; };const char *get_ras_block_str (struct ras_common_if *ras_block)
@@ -2886,10 +2889,23 @@ void amdgpu_ras_resume(struct amdgpu_device *adev)void amdgpu_ras_suspend (struct amdgpu_device *adev) {struct amdgpu_ras *con =amdgpu_ras_get_context (adev); +struct amdgpu_ras_block_list *node; +struct amdgpu_ras_block_object *obj;if (!adev->ras_enabled || !con)return ; +/* run per-block ras_suspend before tearing down the RAS context */ +list_for_each_entry (node, &adev->ras_list, node) { +if (!node->active) +continue ; + + obj = node->ras_obj; +if (obj && obj->ras_suspend) + obj->ras_suspend (adev, &obj->ras_comm); + node->active = false; + } +amdgpu_ras_disable_all_features (adev,0 );/* Make sure all ras objects are disabled. */ if (con->features)
@@ -2920,8 +2936,15 @@ int amdgpu_ras_late_init(struct amdgpu_device *adev) obj->ras_comm.name, r);return r; } - }else -amdgpu_ras_block_late_init_default (adev, &obj->ras_comm); + }else { + r =amdgpu_ras_block_late_init_default (adev, &obj->ras_comm); +if (r) { +dev_err (adev->dev,"%s failed to execute ras_block_late_init_default! ret:%d\n" , + obj->ras_comm.name, r); +return r; + } + } + node->active = true; }return 0 ;
@@ -2955,11 +2978,12 @@ int amdgpu_ras_fini(struct amdgpu_device *adev)list_for_each_entry_safe (ras_node, tmp, &adev->ras_list, node) {if (ras_node->ras_obj) { obj = ras_node->ras_obj; -if (amdgpu_ras_is_supported (adev, obj->ras_comm.block) && - obj->ras_fini) +/* fall back to default cleanup if ras_suspend already ran */ +if (ras_node->active && obj->ras_fini) obj->ras_fini (adev, &obj->ras_comm);else amdgpu_ras_block_late_fini_default (adev, &obj->ras_comm); + ras_node->active = false; }/* Clear ras blocks from ras_list and free ras block list node */
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +1 -0
@@ -551,6 +551,7 @@ struct amdgpu_ras_block_object {int (*ras_block_match)(struct amdgpu_ras_block_object *block_obj,enum amdgpu_ras_block block,uint32_t sub_block_index);int (*ras_late_init)(struct amdgpu_device *adev,struct ras_common_if *ras_block); +void (*ras_suspend)(struct amdgpu_device *adev,struct ras_common_if *ras_block);void (*ras_fini)(struct amdgpu_device *adev,struct ras_common_if *ras_block);ras_ih_cb ras_cb;const struct amdgpu_ras_block_hw_ops *hw_ops;
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +0 -2
@@ -3776,8 +3776,6 @@ static int gfx_v9_0_hw_fini(void *handle) {struct amdgpu_device *adev = (struct amdgpu_device *)handle; -if (amdgpu_ras_is_supported (adev,AMDGPU_RAS_BLOCK__GFX )) -amdgpu_irq_put (adev, &adev->gfx.cp_ecc_error_irq,0 );amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 );amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1529/1674 drm/amdgpu: Refactor FRU product information
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lijo Lazar <[email protected]>
[ Upstream commit 8a2b51392ac4a5ecc310c6dddd6cb70c71f0ddeb ]
Keep FRU related information together in a separate structure.
Stable-dep-of: c990c05eb6c7 ("drm/amdgpu: harden FRU PIA parsing with bounded helpers")
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 8 +--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 ++ .../gpu/drm/amd/amdgpu/amdgpu_fru_eeprom.c | 46 +++++++++++-------- .../gpu/drm/amd/amdgpu/amdgpu_fru_eeprom.h | 9 ++++ .../gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c | 4 -- .../amd/pm/swsmu/smu11/sienna_cichlid_ppt.c | 2 - .../drm/amd/pm/swsmu/smu13/aldebaran_ppt.c | 2 - .../drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c | 2 - .../drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c | 2 - 9 files changed, 42 insertions(+), 36 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -6
@@ -758,8 +758,8 @@ struct amdgpu_mqd {#define AMDGPU_RESET_MAGIC_NUM 64#define AMDGPU_MAX_DF_PERFMONS 4 -#define AMDGPU_PRODUCT_NAME_LEN 64struct amdgpu_reset_domain ; +struct amdgpu_fru_info ;/* * Non-zero (true) if the GPU has VRAM. Zero (false) otherwise.
@@ -1037,11 +1037,7 @@ struct amdgpu_device {bool ucode_sysfs_en; -/* Chip product information */ -char product_number[20 ]; -char product_name[AMDGPU_PRODUCT_NAME_LEN ]; -char serial[20 ]; - +struct amdgpu_fru_info *fru_info;atomic_t throttling_logging_enabled;struct ratelimit_state throttling_logging_rs;uint32_t ras_hw_enabled;
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
@@ -4172,6 +4172,9 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)amdgpu_bios_release (adev); +kfree (adev->fru_info); + adev->fru_info =NULL ; + px =amdgpu_device_supports_px (adev_to_drm (adev));if (amdgpu_device_should_register_switcheroo (adev, px))
drivers/gpu/drm/amd/amdgpu/amdgpu_fru_eeprom.c +28 -18
106 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_fru_eeprom.h +9 -0
@@ -24,6 +24,15 @@#ifndef __AMDGPU_FRU_EEPROM_H__#define __AMDGPU_FRU_EEPROM_H__ +#define AMDGPU_PRODUCT_NAME_LEN 64 + +/* FRU product information */ +struct amdgpu_fru_info { +char product_number[20 ]; +char product_name[AMDGPU_PRODUCT_NAME_LEN ]; +char serial[20 ]; +}; +int amdgpu_fru_get_product_info (struct amdgpu_device *adev);int amdgpu_fru_sysfs_init (struct amdgpu_device *adev);void amdgpu_fru_sysfs_fini (struct amdgpu_device *adev);
drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c +0 -4
@@ -2237,10 +2237,6 @@ static void arcturus_get_unique_id(struct smu_context *smu) id = ((uint64_t )bottom32 <<32 ) | top32; adev->unique_id = id; -/* For Arcturus-and-later, unique_id == serial_number, so convert it to a -* 16-digit HEX string for convenience and backwards-compatibility -*/ -sprintf (adev->serial,"%llx" , id); } static int arcturus_set_df_cstate(struct smu_context *smu,
drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c +0 -2
@@ -1989,8 +1989,6 @@ static void sienna_cichlid_get_unique_id(struct smu_context *smu) out: adev->unique_id = ((uint64_t )upper32 <<32 ) | lower32; -if (adev->serial[0 ] =='\0' ) -sprintf (adev->serial,"%016llx" , adev->unique_id); }static int sienna_cichlid_get_uclk_dpm_states (struct smu_context *smu,uint32_t *clocks_in_khz,uint32_t *num_states)
drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c +0 -2
@@ -1622,8 +1622,6 @@ static void aldebaran_get_unique_id(struct smu_context *smu) out: adev->unique_id = ((uint64_t )upper32 <<32 ) | lower32; -if (adev->serial[0 ] =='\0' ) -sprintf (adev->serial,"%016llx" , adev->unique_id); }static bool aldebaran_is_baco_supported (struct smu_context *smu)
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c +0 -2
@@ -1931,8 +1931,6 @@ static void smu_v13_0_0_get_unique_id(struct smu_context *smu) out: adev->unique_id = ((uint64_t )upper32 <<32 ) | lower32; -if (adev->serial[0 ] =='\0' ) -sprintf (adev->serial,"%016llx" , adev->unique_id); } static int smu_v13_0_0_get_fan_speed_pwm(struct smu_context *smu,
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c +0 -2
@@ -1858,8 +1858,6 @@ static void smu_v13_0_6_get_unique_id(struct smu_context *smu) (struct PPTable_t *)smu_table->driver_pptable; adev->unique_id = pptable->PublicSerialNumber_AID; -if (adev->serial[0 ] =='\0' ) -sprintf (adev->serial,"%016llx" , adev->unique_id); }static bool smu_v13_0_6_is_baco_supported (struct smu_context *smu)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1530/1674 drm/amdgpu: harden FRU PIA parsing with bounded helpers
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stanley.Yang <[email protected]>
[ Upstream commit c990c05eb6c74c98d1ff3acf67a19015312820b7 ]
Replace the open-coded TLV walk with fru_pia_advance() and fru_pia_copy_field() helpers that bound every read by the actual EEPROM data length, preventing out-of-bounds reads on truncated or malformed FRU data.
--- .../gpu/drm/amd/amdgpu/amdgpu_fru_eeprom.c | 74 ++++++++++++++----- 1 file changed, 55 insertions(+), 19 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_fru_eeprom.c +55 -19
@@ -97,6 +97,43 @@ static bool is_fru_eeprom_supported(struct amdgpu_device *adev, u32 *fru_addr) } } +/* +* IPMI FRU Product Info Area fields are TLV: one type/length byte +* (low 6 bits = data length) followed by that many data bytes. These +* helpers walk the cursor and copy a single field while bounding all +* accesses to the actual buffer length read from the EEPROM. +*/ +#define FRU_FIELD_LEN (p, a) ((p)[a] & 0x3F) + +/* Advance cursor past the current TLV. Returns false if no more data. */ +static bool fru_pia_advance (u32 *addr,const unsigned char *pia,int len) +{ +if (*addr >= (u32 )len) +return false; + *addr +=1 +FRU_FIELD_LEN (pia, *addr); +return true; +} + +/* +* Copy the current TLV's data into dst (NUL-terminated). Returns false if +* the TLV header or data would read past the end of pia. +*/ +static bool fru_pia_copy_field (char *dst,size_t dst_size, +const unsigned char *pia,u32 addr,int len) +{ +size_t fl; + +if (addr +1 >= (u32 )len) +return false; + + fl =min3 ((size_t )FRU_FIELD_LEN (pia, addr), + dst_size -1 , + (size_t )(len - addr -1 )); +memcpy (dst, pia + addr +1 , fl); + dst[fl] ='\0' ; +return true; +} +int amdgpu_fru_get_product_info (struct amdgpu_device *adev) {struct amdgpu_fru_info *fru_info;
@@ -193,32 +230,31 @@ int amdgpu_fru_get_product_info(struct amdgpu_device *adev)* Skip the Manufacturer Name at [3] and go directly to * the Product Name field. */ - addr =3 +1 + (pia[3 ] &0x3F ); -if (addr +1 >= len) + addr =3 ; +if (!fru_pia_advance (&addr, pia, len) || + !fru_pia_copy_field (fru_info->product_name, +sizeof (fru_info->product_name), + pia, addr, len)) goto Out; -memcpy (fru_info->product_name, pia + addr +1 , -min_t (size_t,sizeof (fru_info->product_name), pia[addr] &0x3F )); - fru_info->product_name[sizeof (fru_info->product_name) -1 ] ='\0' ;/* Go to the Product Part/Model Number field. */ - addr +=1 + (pia[addr] &0x3F ); -if (addr +1 >= len) +if (!fru_pia_advance (&addr, pia, len) || + !fru_pia_copy_field (fru_info->product_number, +sizeof (fru_info->product_number), + pia, addr, len)) goto Out; -memcpy (fru_info->product_number, pia + addr +1 , -min_t (size_t,sizeof (fru_info->product_number), - pia[addr] &0x3F )); - fru_info->product_number[sizeof (fru_info->product_number) -1 ] ='\0' ; -/* Go to the Product Version field. */ - addr +=1 + (pia[addr] &0x3F ); +/* Skip the Product Version field. */ +if (!fru_pia_advance (&addr, pia, len)) + goto Out; -/* Go to the Product Serial Number field. */ - addr +=1 + (pia[addr] &0x3F ); -if (addr +1 >= len) +/* Read the Product Serial Number field. */ +if (!fru_pia_advance (&addr, pia, len) || + !fru_pia_copy_field (fru_info->serial, +sizeof (fru_info->serial), + pia, addr, len)) goto Out; -memcpy (fru_info->serial, pia + addr +1 , -min_t (size_t,sizeof (fru_info->serial), pia[addr] &0x3F )); - fru_info->serial[sizeof (fru_info->serial) -1 ] ='\0' ; + Out:kfree (pia);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1531/1674 wifi: iwlwifi: mvm: fix P2P-Device binding handling
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Berg <[email protected]>
[ Upstream commit b74e377cad9271950c57472867c469e4b5b2ff0c ]
Our binding handling for P2P-Device can run into the following scenario, as observed by our testing:
- a station interface is connected on some channel
- the P2P-Device does a remain-on-channel (ROC) on that channel
- the ROC ends, and the P2P-Device is removed from the binding, but the phy_ctxt pointer is left around as a PHY cache so we don't need to recalibrate to the channel again and again in case it's not shared
- a binding update by the station interface, even a removal, will re-add the P2P-Device to the binding
- the P2P-Device is removed, which removes the PHY context, but it's still in the binding so the firmware crashes
Since the P2P device is removed from the binding and only re- added by unrelated code, but we want to keep the phy_ctxt around as a cache for future ROC usage, fix it by adding a boolean that indicates whether or not the P2P-Device should be added to the binding, and handle that in the binding iterator. That way, the station interface cannot re-add the P2P-Device to the binding when that isn't active.
--- drivers/net/wireless/intel/iwlwifi/mvm/binding.c | 5 ++++- drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c | 13 ++++++++++++- drivers/net/wireless/intel/iwlwifi/mvm/mvm.h | 3 +++ drivers/net/wireless/intel/iwlwifi/mvm/time-event.c | 3 ++- 4 files changed, 21 insertions(+), 3 deletions(-)
drivers/net/wireless/intel/iwlwifi/mvm/binding.c +4 -1
@@ -2,7 +2,7 @@/* * Copyright (C) 2012-2014, 2020 Intel Corporation * Copyright (C) 2016 Intel Deutschland GmbH -* Copyright (C) 2022 Intel Corporation +* Copyright (C) 2022, 2026 Intel Corporation */ #include <net/mac80211.h> #include "fw-api.h"
@@ -76,6 +76,9 @@ static void iwl_mvm_iface_iterator(void *_data, u8 *mac,if (vif == data->ignore_vif)return ; +if (vif->type ==NL80211_IFTYPE_P2P_DEVICE && !mvmvif->p2p_in_binding) +return ; +if (mvmvif->deflink.phy_ctxt != data->phyctxt)return ;
drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c +12 -1
@@ -1022,6 +1022,8 @@ static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,iwl_mvm_te_clear_data (mvm, &mvmvif->time_event_data);spin_unlock_bh (&mvm->time_event_lock); + mvmvif->p2p_in_binding = false; +memset (&mvmvif->bf_data,0 ,sizeof (mvmvif->bf_data)); mvmvif->ap_sta =NULL ;
@@ -4582,6 +4584,7 @@ static int iwl_mvm_add_aux_sta_for_hs20(struct iwl_mvm *mvm, u32 lmac_id)static int iwl_mvm_roc_link (struct iwl_mvm *mvm,struct ieee80211_vif *vif) { +struct iwl_mvm_vif *mvmvif =iwl_mvm_vif_from_mac80211 (vif);int ret;lockdep_assert_held (&mvm->mutex);
@@ -4590,10 +4593,18 @@ static int iwl_mvm_roc_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif)if (WARN (ret,"Failed binding P2P_DEVICE\n" ))return ret; + mvmvif->p2p_in_binding = true; +/* The station and queue allocation must be done only after the binding * is done, as otherwise the FW might incorrectly configure its state. */ -return iwl_mvm_add_p2p_bcast_sta (mvm, vif); + ret =iwl_mvm_add_p2p_bcast_sta (mvm, vif); +if (ret) { +iwl_mvm_binding_remove_vif (mvm, vif); + mvmvif->p2p_in_binding = false; + } + +return ret; } static int iwl_mvm_roc(struct ieee80211_hw *hw,
drivers/net/wireless/intel/iwlwifi/mvm/mvm.h +3 -0
@@ -363,6 +363,8 @@ struct iwl_mvm_vif_link_info {* @csa_countdown: indicates that CSA countdown may be started * @csa_failed: CSA failed to schedule time event, report an error later * @csa_bcn_pending: indicates that we are waiting for a beacon on a new channel +* @p2p_in_binding: indicates that this P2P-Device interface should be +* added to the binding, i.e. is running ROC right now * @features: hw features active for this vif */ struct iwl_mvm_vif {
@@ -437,6 +439,7 @@ struct iwl_mvm_vif {struct iwl_mvm_time_event_data time_event_data;struct iwl_mvm_time_event_data hs_time_event_data; +bool p2p_in_binding;/* TCP Checksum Offload */ netdev_features_t features;
drivers/net/wireless/intel/iwlwifi/mvm/time-event.c +2 -1
@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause /* -* Copyright (C) 2012-2014, 2018-2023 Intel Corporation +* Copyright (C) 2012-2014, 2018-2023, 2026 Intel Corporation * Copyright (C) 2013-2015 Intel Mobile Communications GmbH * Copyright (C) 2017 Intel Deutschland GmbH */
@@ -94,6 +94,7 @@ void iwl_mvm_roc_done_wk(struct work_struct *wk) }else {iwl_mvm_rm_p2p_bcast_sta (mvm, vif);iwl_mvm_binding_remove_vif (mvm, vif); + mvmvif->p2p_in_binding = false; }/* Do not remove the PHY context as removing and adding
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1532/1674 RDMA/counter: Fix num_counters leak on bind_qp failure in alloc_and_bind()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tao Cui <[email protected]>
[ Upstream commit 4fbc8230009f5b1bcd13cc74c5a6a43ddba141fd ]
When __rdma_counter_bind_qp() fails in alloc_and_bind(), the error path jumps to err_mode which frees the counter without decrementing port_counter->num_counters. The only place that decrements is rdma_counter_free(), which is unreachable since the counter was never successfully bound.
This leak accumulates across repeated failures, permanently preventing the port from switching to AUTO mode (-EBUSY in __counter_set_mode()) and blocking the MANUAL→NONE auto-revert in rdma_counter_free(). When the mode was NONE before the call, the MANUAL mode set by __counter_set_mode() also leaks since the revert logic is never reached.
Add an err_bind label between the num_counters increment and the existing err_mode label. It decrements num_counters and mirrors the MANUAL→NONE revert from rdma_counter_free(), ensuring the port state is fully restored on bind failure.
--- drivers/infiniband/core/counters.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/infiniband/core/counters.c +8 -1
@@ -190,12 +190,19 @@ static struct rdma_counter *alloc_and_bind(struct ib_device *dev, u32 port, ret =__rdma_counter_bind_qp (counter, qp);if (ret) - goto err_mode; + goto err_bind;rdma_restrack_parent_name (&counter->res, &qp->res);rdma_restrack_add (&counter->res);return counter; +err_bind: +mutex_lock (&port_counter->lock); + port_counter->num_counters--; +if (!port_counter->num_counters && + port_counter->mode.mode ==RDMA_COUNTER_MODE_MANUAL ) +__counter_set_mode (port_counter,RDMA_COUNTER_MODE_NONE ,0 ); +mutex_unlock (&port_counter->lock); err_mode:rdma_free_hw_stats_struct (counter->stats); err_stats:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1533/1674 virt: acrn: Fix irqfd use-after-free during eventfd shutdown
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sicong Huang <[email protected]>
[ Upstream commit 666c7f9e07925aa0863348f960e09bb89f8f05a3 ]
acrn_irqfd_deassign() and the eventfd EPOLLHUP wakeup can race and free the same struct hsm_irqfd:
CPU0 CPU1
---- ----
eventfd_release()
wake_up_poll(EPOLLHUP)
hsm_irqfd_wakeup()
queue_work(&irqfd->shutdown)
acrn_irqfd_deassign()
hsm_irqfd_shutdown()
list_del_init()
eventfd_ctx_remove_wait_queue()
eventfd_ctx_put()
kfree(irqfd) hsm_irqfd_shutdown_work()
container_of(work, ..., shutdown)
irqfd->vm <-- use-after-free
The deassign path freed the irqfd while a shutdown work item was already queued by EPOLLHUP (or vice versa), so the work item could resurrect a dangling pointer through container_of().
Switch to the lifetime model used by KVM irqfds:
- Deassign/deinit only deactivate the irqfd: remove it from vm->irqfds under irqfds_lock and queue the cleanup work.
- hsm_irqfd_shutdown_work() becomes the sole owner that unhooks the eventfd waitqueue entry, drops the eventfd reference and frees the irqfd.
- A new HSM_IRQFD_FLAG_SHUTDOWN bit guarded by test_and_set_bit() ensures the cleanup work is queued at most once, no matter how many of {EPOLLHUP, deassign, deinit} fire concurrently. This is safe to call from the waitqueue callback, which runs with wqh->lock held and IRQs disabled and therefore cannot take irqfds_lock.
- acrn_irqfd_deassign() flushes vm->irqfd_wq before returning so the eventfd is fully detached on return. acrn_irqfd_deinit() deactivates every irqfd, flushes the workqueue and only then destroys it, so no path can queue_work() onto a torn-down workqueue.
- acrn_irqfd_assign() now installs the eventfd waitqueue entry and publishes the irqfd to vm->irqfds under irqfds_lock, so the irqfd is never visible to deassign/deinit before its waitqueue entry is in place, and any EPOLLHUP that fires in the assign window queues cleanup work that blocks on irqfds_lock until publication is done.
--- drivers/virt/acrn/irqfd.c | 71 ++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 27 deletions(-)
drivers/virt/acrn/irqfd.c +44 -27
@@ -18,6 +18,9 @@static LIST_HEAD (acrn_irqfd_clients); +/* Cleanup work has been queued; set via test_and_set_bit(). */ +#define HSM_IRQFD_FLAG_SHUTDOWN 0 +/** * struct hsm_irqfd - Properties of HSM irqfd * @vm: Associated VM pointer
@@ -27,6 +30,7 @@ static LIST_HEAD(acrn_irqfd_clients);* @list: Entry within &acrn_vm.irqfds of irqfds of a VM * @pt: Structure for select/poll on the associated eventfd * @msi: MSI data +* @flags: Internal lifecycle flags (HSM_IRQFD_FLAG_*) */ struct hsm_irqfd {struct acrn_vm *vm;
@@ -36,6 +40,7 @@ struct hsm_irqfd {struct list_head list;poll_table pt;struct acrn_msi_entry msi; +unsigned long flags; };static void acrn_irqfd_inject (struct hsm_irqfd *irqfd)
@@ -46,30 +51,29 @@ static void acrn_irqfd_inject(struct hsm_irqfd *irqfd) irqfd->msi.msi_data); } -static void hsm_irqfd_shutdown (struct hsm_irqfd *irqfd) +/* Queue the cleanup work at most once. Safe from atomic context. */ +static void hsm_irqfd_queue_shutdown (struct hsm_irqfd *irqfd) { -u64 cnt; - -lockdep_assert_held (&irqfd->vm->irqfds_lock); - -/* remove from wait queue */ -list_del_init (&irqfd->list); -eventfd_ctx_remove_wait_queue (irqfd->eventfd, &irqfd->wait, &cnt); -eventfd_ctx_put (irqfd->eventfd); -kfree (irqfd); +if (!test_and_set_bit (HSM_IRQFD_FLAG_SHUTDOWN , &irqfd->flags)) +queue_work (irqfd->vm->irqfd_wq, &irqfd->shutdown); } +/* Sole owner of @irqfd: unhook waitqueue, drop eventfd ref, free. */ static void hsm_irqfd_shutdown_work (struct work_struct *work) { -struct hsm_irqfd *irqfd; -struct acrn_vm *vm; + struct hsm_irqfd *irqfd = container_of(work, struct hsm_irqfd, + shutdown); +struct acrn_vm *vm = irqfd->vm; +u64 cnt; - irqfd = container_of(work, struct hsm_irqfd, shutdown); - vm = irqfd->vm;mutex_lock (&vm->irqfds_lock);if (!list_empty (&irqfd->list)) -hsm_irqfd_shutdown (irqfd); +list_del_init (&irqfd->list);mutex_unlock (&vm->irqfds_lock); + +eventfd_ctx_remove_wait_queue (irqfd->eventfd, &irqfd->wait, &cnt); +eventfd_ctx_put (irqfd->eventfd); +kfree (irqfd); }/* Called with wqh->lock held and interrupts disabled */
@@ -78,17 +82,16 @@ static int hsm_irqfd_wakeup(wait_queue_entry_t *wait, unsigned int mode, {unsigned long poll_bits = (unsigned long )key;struct hsm_irqfd *irqfd; -struct acrn_vm *vm; irqfd = container_of(wait, struct hsm_irqfd, wait); - vm = irqfd->vm; +if (poll_bits &POLLIN )/* An event has been signaled, inject an interrupt */ acrn_irqfd_inject (irqfd);if (poll_bits &POLLHUP ) -/* Do shutdown work in thread to hold wqh->lock */ -queue_work (vm->irqfd_wq, &irqfd->shutdown); +/* Defer teardown to the cleanup work; can't sleep here. */ +hsm_irqfd_queue_shutdown (irqfd);return 0 ; }
@@ -145,6 +148,12 @@ static int acrn_irqfd_assign(struct acrn_vm *vm, struct acrn_irqfd *args)init_waitqueue_func_entry (&irqfd->wait, hsm_irqfd_wakeup);init_poll_funcptr (&irqfd->pt, hsm_irqfd_poll_func); +/* +* Hold irqfds_lock across waitqueue install and list_add so the +* irqfd is not visible to deassign/deinit before its waitqueue +* entry is in place, and any racing EPOLLHUP cleanup work blocks +* on irqfds_lock until publication completes. +*/ mutex_lock (&vm->irqfds_lock);list_for_each_entry (tmp, &vm->irqfds, list) {if (irqfd->eventfd != tmp->eventfd)
@@ -153,14 +162,12 @@ static int acrn_irqfd_assign(struct acrn_vm *vm, struct acrn_irqfd *args)mutex_unlock (&vm->irqfds_lock); goto fail; } -list_add_tail (&irqfd->list, &vm->irqfds); -mutex_unlock (&vm->irqfds_lock); -/* Check the pending event in this stage */ events =vfs_poll (f.file, &irqfd->pt); - +list_add_tail (&irqfd->list, &vm->irqfds);if (events &EPOLLIN )acrn_irqfd_inject (irqfd); +mutex_unlock (&vm->irqfds_lock);fdput (f);return 0 ;
@@ -187,13 +194,17 @@ static int acrn_irqfd_deassign(struct acrn_vm *vm,mutex_lock (&vm->irqfds_lock);list_for_each_entry_safe (irqfd, tmp, &vm->irqfds, list) {if (irqfd->eventfd == eventfd) { -hsm_irqfd_shutdown (irqfd); +list_del_init (&irqfd->list); +hsm_irqfd_queue_shutdown (irqfd);break ; } }mutex_unlock (&vm->irqfds_lock);eventfd_ctx_put (eventfd); +/* Wait for cleanup work to finish so the eventfd is fully detached. */ +flush_workqueue (vm->irqfd_wq); +return 0 ; }
@@ -226,9 +237,15 @@ void acrn_irqfd_deinit(struct acrn_vm *vm)struct hsm_irqfd *irqfd, *next;dev_dbg (acrn_dev.this_device,"VM %u irqfd deinit.\n" , vm->vmid); -destroy_workqueue (vm->irqfd_wq); +mutex_lock (&vm->irqfds_lock); -list_for_each_entry_safe (irqfd, next, &vm->irqfds, list) -hsm_irqfd_shutdown (irqfd); +list_for_each_entry_safe (irqfd, next, &vm->irqfds, list) { +list_del_init (&irqfd->list); +hsm_irqfd_queue_shutdown (irqfd); + }mutex_unlock (&vm->irqfds_lock); + +/* Drain all cleanup work before tearing the workqueue down. */ +flush_workqueue (vm->irqfd_wq); +destroy_workqueue (vm->irqfd_wq); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1534/1674 driver core: Avoid warning when removing a device while its supplier is unbinding
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Herve Codina <[email protected]>
[ Upstream commit 36d74f17e03f7e60e1b08fbe16cfad6e69cc3aa9 ]
During driver removal, the following warning can appear:
WARNING: CPU: 1 PID: 139 at drivers/base/core.c:1497 __device_links_no_driver+0xcc/0xfc
...
Call trace:
__device_links_no_driver+0xcc/0xfc (P)
device_links_driver_cleanup+0xa8/0xf0
device_release_driver_internal+0x208/0x23c
device_links_unbind_consumers+0xe0/0x108
device_release_driver_internal+0xec/0x23c
device_links_unbind_consumers+0xe0/0x108
device_release_driver_internal+0xec/0x23c
device_links_unbind_consumers+0xe0/0x108
device_release_driver_internal+0xec/0x23c
driver_detach+0xa0/0x12c
bus_remove_driver+0x6c/0xbc
driver_unregister+0x30/0x60
pci_unregister_driver+0x20/0x9c
lan966x_pci_driver_exit+0x18/0xa90 [lan966x_pci]This warning is triggered when a consumer is removed because the links status of its supplier is not DL_DEV_DRIVER_BOUND and the link flag DL_FLAG_SYNC_STATE_ONLY is not set.
The topology in terms of consumers/suppliers used was the following (consumer ---> supplier):
i2c -----------> OIC ----> PCI device
| ^
| |
+---> pinctrl ---+When the PCI device is removed, the OIC (interrupt controller) has to be removed. In order to remove the OIC, pinctrl and i2c need to be removed and to remove pinctrl, i2c need to be removed. The removal order is:
1) i2c
2) pinctrl
3) OIC
4) PCI device
In details, the removal sequence is the following (with 0000:01:00.0 the PCI device):
driver_detach: call device_release_driver_internal(0000:01:00.0)...
device_links_busy(0000:01:00.0):
links->status = DL_DEV_UNBINDING
device_links_unbind_consumers(0000:01:00.0):
0000:01:00.0--oic link->status = DL_STATE_SUPPLIER_UNBIND
call device_release_driver_internal(oic)...
device_links_busy(oic):
links->status = DL_DEV_UNBINDING
device_links_unbind_consumers(oic):
oic--pinctrl link->status = DL_STATE_SUPPLIER_UNBIND
call device_release_driver_internal(pinctrl)...
device_links_busy(pinctrl):
links->status = DL_DEV_UNBINDING
device_links_unbind_consumers(pinctrl):
pinctrl--i2c link->status = DL_STATE_SUPPLIER_UNBIND
call device_release_driver_internal(i2c)...
device_links_busy(i2c): links->status = DL_DEV_UNBINDING
__device_links_no_driver(i2c)...
pinctrl--i2c link->status is DL_STATE_SUPPLIER_UNBIND
oic--i2c link->status is DL_STATE_ACTIVE
oic--i2c link->supplier->links.status is DL_DEV_UNBINDINGThe warning is triggered by the i2c removal because the OIC (supplier) links status is not DL_DEV_DRIVER_BOUND. Its links status is indeed set to DL_DEV_UNBINDING.
It is perfectly legit to have the links status set to DL_DEV_UNBINDING in that case. Indeed we had started to unbind the OIC which triggered the consumer unbinding and didn't finish yet when the i2c is unbound.
Avoid the warning when the supplier links status is set to DL_DEV_UNBINDING and thus support this removal sequence without any warnings.
--- drivers/base/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/base/core.c +2 -1
@@ -1508,7 +1508,8 @@ static void __device_links_no_driver(struct device *dev)if (link->supplier->links.status ==DL_DEV_DRIVER_BOUND ) {WRITE_ONCE (link->status,DL_STATE_AVAILABLE ); }else { -WARN_ON (!(link->flags &DL_FLAG_SYNC_STATE_ONLY )); +WARN_ON (link->supplier->links.status !=DL_DEV_UNBINDING && + !(link->flags &DL_FLAG_SYNC_STATE_ONLY ));WRITE_ONCE (link->status,DL_STATE_DORMANT ); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1535/1674 serial: 8250: invert serial8250_register_8250_port() CIR condition
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiri Slaby (SUSE) <[email protected]>
[ Upstream commit 05b537a175442c530593013ea31b3f48d5624916 ]
There is no point in a long 'if' in serial8250_register_8250_port() to just return ENOSPC for PORT_8250_CIR ports. Invert the condition and return immediately.
'gpios' variable was moved to its set location.
And return ENODEV instead of ENOSPC. The latter is a leftover from the previous find-uart 'if'. The former makes a lot more sense in this case.
Stable-dep-of: 941c9f84c9b6 ("tty: serial: 8250: protect against NULL uart->port.dev in register")
--- drivers/tty/serial/8250/8250_core.c | 253 ++++++++++++++-------------- 1 file changed, 127 insertions(+), 126 deletions(-)
drivers/tty/serial/8250/8250_core.c +127 -126
@@ -1034,139 +1034,140 @@ int serial8250_register_8250_port(const struct uart_8250_port *up) nr_uarts++; } -if (uart->port.type !=PORT_8250_CIR ) { -struct mctrl_gpios *gpios; - -if (uart->port.dev) -uart_remove_one_port (&serial8250_reg, &uart->port); - - uart->port.ctrl_id = up->port.ctrl_id; - uart->port.port_id = up->port.port_id; - uart->port.iobase = up->port.iobase; - uart->port.membase = up->port.membase; - uart->port.irq = up->port.irq; - uart->port.irqflags = up->port.irqflags; - uart->port.uartclk = up->port.uartclk; - uart->port.fifosize = up->port.fifosize; - uart->port.regshift = up->port.regshift; - uart->port.iotype = up->port.iotype; - uart->port.flags = up->port.flags |UPF_BOOT_AUTOCONF ; - uart->bugs = up->bugs; - uart->port.mapbase = up->port.mapbase; - uart->port.mapsize = up->port.mapsize; - uart->port.private_data = up->port.private_data; - uart->tx_loadsz = up->tx_loadsz; - uart->capabilities = up->capabilities; - uart->port.throttle = up->port.throttle; - uart->port.unthrottle = up->port.unthrottle; - uart->port.rs485_config = up->port.rs485_config; - uart->port.rs485_supported = up->port.rs485_supported; - uart->port.rs485 = up->port.rs485; - uart->rs485_start_tx = up->rs485_start_tx; - uart->rs485_stop_tx = up->rs485_stop_tx; - uart->lsr_save_mask = up->lsr_save_mask; - uart->dma = up->dma; - -/* Take tx_loadsz from fifosize if it wasn't set separately */ -if (uart->port.fifosize && !uart->tx_loadsz) - uart->tx_loadsz = uart->port.fifosize; - -if (up->port.dev) { - uart->port.dev = up->port.dev; - ret =uart_get_rs485_mode (&uart->port); -if (ret) - goto err; - } +if (uart->port.type ==PORT_8250_CIR ) { + ret = -ENODEV ; + goto unlock; + } -if (up->port.flags &UPF_FIXED_TYPE ) - uart->port.type = up->port.type; +if (uart->port.dev) +uart_remove_one_port (&serial8250_reg, &uart->port); + + uart->port.ctrl_id = up->port.ctrl_id; + uart->port.port_id = up->port.port_id; + uart->port.iobase = up->port.iobase; + uart->port.membase = up->port.membase; + uart->port.irq = up->port.irq; + uart->port.irqflags = up->port.irqflags; + uart->port.uartclk = up->port.uartclk; + uart->port.fifosize = up->port.fifosize; + uart->port.regshift = up->port.regshift; + uart->port.iotype = up->port.iotype; + uart->port.flags = up->port.flags |UPF_BOOT_AUTOCONF ; + uart->bugs = up->bugs; + uart->port.mapbase = up->port.mapbase; + uart->port.mapsize = up->port.mapsize; + uart->port.private_data = up->port.private_data; + uart->tx_loadsz = up->tx_loadsz; + uart->capabilities = up->capabilities; + uart->port.throttle = up->port.throttle; + uart->port.unthrottle = up->port.unthrottle; + uart->port.rs485_config = up->port.rs485_config; + uart->port.rs485_supported = up->port.rs485_supported; + uart->port.rs485 = up->port.rs485; + uart->rs485_start_tx = up->rs485_start_tx; + uart->rs485_stop_tx = up->rs485_stop_tx; + uart->lsr_save_mask = up->lsr_save_mask; + uart->dma = up->dma; + +/* Take tx_loadsz from fifosize if it wasn't set separately */ +if (uart->port.fifosize && !uart->tx_loadsz) + uart->tx_loadsz = uart->port.fifosize; + +if (up->port.dev) { + uart->port.dev = up->port.dev; + ret =uart_get_rs485_mode (&uart->port); +if (ret) + goto err; + } -/* -* Only call mctrl_gpio_init(), if the device has no ACPI -* companion device -*/ -if (!has_acpi_companion (uart->port.dev)) { - gpios =mctrl_gpio_init (&uart->port,0 ); -if (IS_ERR (gpios)) { - ret =PTR_ERR (gpios); - goto err; - }else { - uart->gpios = gpios; - } - } +if (up->port.flags &UPF_FIXED_TYPE ) + uart->port.type = up->port.type; -serial8250_set_defaults (uart); - -/* Possibly override default I/O functions. */ -if (up->port.serial_in) - uart->port.serial_in = up->port.serial_in; -if (up->port.serial_out) - uart->port.serial_out = up->port.serial_out; -if (up->port.handle_irq) - uart->port.handle_irq = up->port.handle_irq; -/* Possibly override set_termios call */ -if (up->port.set_termios) - uart->port.set_termios = up->port.set_termios; -if (up->port.set_ldisc) - uart->port.set_ldisc = up->port.set_ldisc; -if (up->port.get_mctrl) - uart->port.get_mctrl = up->port.get_mctrl; -if (up->port.set_mctrl) - uart->port.set_mctrl = up->port.set_mctrl; -if (up->port.get_divisor) - uart->port.get_divisor = up->port.get_divisor; -if (up->port.set_divisor) - uart->port.set_divisor = up->port.set_divisor; -if (up->port.startup) - uart->port.startup = up->port.startup; -if (up->port.shutdown) - uart->port.shutdown = up->port.shutdown; -if (up->port.pm) - uart->port.pm = up->port.pm; -if (up->port.handle_break) - uart->port.handle_break = up->port.handle_break; -if (up->dl_read) - uart->dl_read = up->dl_read; -if (up->dl_write) - uart->dl_write = up->dl_write; - -if (uart->port.type !=PORT_8250_CIR ) { -if (uart_console_registered (&uart->port)) -pm_runtime_get_sync (uart->port.dev); - -if (serial8250_isa_config !=NULL ) -serial8250_isa_config (0 , &uart->port, - &uart->capabilities); - -serial8250_apply_quirks (uart); - ret =uart_add_one_port (&serial8250_reg, - &uart->port); -if (ret) - goto err; - - ret = uart->port.line; +/* +* Only call mctrl_gpio_init(), if the device has no ACPI +* companion device +*/ +if (!has_acpi_companion (uart->port.dev)) { +struct mctrl_gpios *gpios =mctrl_gpio_init (&uart->port,0 ); +if (IS_ERR (gpios)) { + ret =PTR_ERR (gpios); + goto err; }else { -dev_info (uart->port.dev, -"skipping CIR port at 0x%lx / 0x%llx, IRQ %d\n" , - uart->port.iobase, - (unsigned long long )uart->port.mapbase, - uart->port.irq); - - ret =0 ; + uart->gpios = gpios; } + } -if (!uart->lsr_save_mask) - uart->lsr_save_mask =LSR_SAVE_FLAGS ;/* Use default LSR mask */ +serial8250_set_defaults (uart); + +/* Possibly override default I/O functions. */ +if (up->port.serial_in) + uart->port.serial_in = up->port.serial_in; +if (up->port.serial_out) + uart->port.serial_out = up->port.serial_out; +if (up->port.handle_irq) + uart->port.handle_irq = up->port.handle_irq; +/* Possibly override set_termios call */ +if (up->port.set_termios) + uart->port.set_termios = up->port.set_termios; +if (up->port.set_ldisc) + uart->port.set_ldisc = up->port.set_ldisc; +if (up->port.get_mctrl) + uart->port.get_mctrl = up->port.get_mctrl; +if (up->port.set_mctrl) + uart->port.set_mctrl = up->port.set_mctrl; +if (up->port.get_divisor) + uart->port.get_divisor = up->port.get_divisor; +if (up->port.set_divisor) + uart->port.set_divisor = up->port.set_divisor; +if (up->port.startup) + uart->port.startup = up->port.startup; +if (up->port.shutdown) + uart->port.shutdown = up->port.shutdown; +if (up->port.pm) + uart->port.pm = up->port.pm; +if (up->port.handle_break) + uart->port.handle_break = up->port.handle_break; +if (up->dl_read) + uart->dl_read = up->dl_read; +if (up->dl_write) + uart->dl_write = up->dl_write; -/* Initialise interrupt backoff work if required */ -if (up->overrun_backoff_time_ms >0 ) { - uart->overrun_backoff_time_ms = - up->overrun_backoff_time_ms; -INIT_DELAYED_WORK (&uart->overrun_backoff, - serial_8250_overrun_backoff_work); - }else { - uart->overrun_backoff_time_ms =0 ; - } +if (uart->port.type !=PORT_8250_CIR ) { +if (uart_console_registered (&uart->port)) +pm_runtime_get_sync (uart->port.dev); + +if (serial8250_isa_config !=NULL ) +serial8250_isa_config (0 , &uart->port, + &uart->capabilities); + +serial8250_apply_quirks (uart); + ret =uart_add_one_port (&serial8250_reg, + &uart->port); +if (ret) + goto err; + + ret = uart->port.line; + }else { +dev_info (uart->port.dev, +"skipping CIR port at 0x%lx / 0x%llx, IRQ %d\n" , + uart->port.iobase, + (unsigned long long )uart->port.mapbase, + uart->port.irq); + + ret =0 ; + } + +if (!uart->lsr_save_mask) + uart->lsr_save_mask =LSR_SAVE_FLAGS ;/* Use default LSR mask */ + +/* Initialise interrupt backoff work if required */ +if (up->overrun_backoff_time_ms >0 ) { + uart->overrun_backoff_time_ms = + up->overrun_backoff_time_ms; +INIT_DELAYED_WORK (&uart->overrun_backoff, + serial_8250_overrun_backoff_work); + }else { + uart->overrun_backoff_time_ms =0 ; } unlock:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1536/1674 tty: serial: 8250: protect against NULL uart->port.dev in register
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stepan Ionichev <[email protected]>
[ Upstream commit 941c9f84c9b6310f7aaa1c8c785dcc634ee33050 ]
serial8250_register_8250_port() conditionally copies uart->port.dev from up->port.dev only when up->port.dev is non-NULL:
if (up->port.dev) {
uart->port.dev = up->port.dev;
...
}So if both the existing uart slot and up have a NULL ->dev, uart->port.dev remains NULL. The very next ACPI companion check then dereferences it unconditionally:
if (!has_acpi_companion(uart->port.dev)) {has_acpi_companion() reads dev->fwnode without a NULL guard (include/linux/acpi.h), so this NULL-derefs the kernel for the remaining no-dev case rather than just skipping the mctrl_gpio_init() initialisation as intended.
smatch flags the inconsistency:
drivers/tty/serial/8250/8250_core.c:767 serial8250_register_8250_port() error: 'uart->port.dev' could be null (see line 719)
Guard the call with a NULL check so register continues to work for callers that legitimately have no parent device (legacy non-OF/non-ACPI registrations).
No functional change for callers that pass a non-NULL ->dev.
--- drivers/tty/serial/8250/8250_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/8250/8250_core.c +1 -1
@@ -1087,7 +1087,7 @@ int serial8250_register_8250_port(const struct uart_8250_port *up)* Only call mctrl_gpio_init(), if the device has no ACPI * companion device */ -if (!has_acpi_companion (uart->port.dev)) { +if (uart->port.dev && !has_acpi_companion (uart->port.dev)) {struct mctrl_gpios *gpios =mctrl_gpio_init (&uart->port,0 );if (IS_ERR (gpios)) { ret =PTR_ERR (gpios);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1537/1674 wifi: mac80211: dont call ieee80211_handle_reconfig_failure when not needed
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Miri Korenblit <[email protected]>
[ Upstream commit 7a8a3ff2815501f78f494808355ddf37e08647d0 ]
In case reconfiguration of NAN fails, we call ieee80211_handle_reconfig_failure, that marks all interfaces as not in the driver.
Then, at the error path of the reconfig, cfg80211_shutdown_all_interfaces is called to destroy all the interfaces.
If we have any other interface but the NAN one, for example a BSS station, then when its state (links, stations) will be removed, we won't tell the driver about this, because we will think that the interfaces are not in the driver, and then drivers might remain with dangling pointers to objects like stations and links (at least for iwlwifi this is the case).
ieee80211_handle_reconfig_failure is meant to be called after we cleaned up the state in the driver, there is no reason to call it for NAN reconfiguration failure.
Fix the code to just warn in such a case, as we do in other error paths in reconfig where it is too complicated to rewind.
--- net/mac80211/util.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
net/mac80211/util.c +1 -6
@@ -2814,12 +2814,7 @@ int ieee80211_reconfig(struct ieee80211_local *local) }break ;case NL80211_IFTYPE_NAN : - res =ieee80211_reconfig_nan (sdata); -if (res <0 ) { -sdata_unlock (sdata); -ieee80211_handle_reconfig_failure (local); -return res; - } +WARN_ON (ieee80211_reconfig_nan (sdata));break ;case NL80211_IFTYPE_AP_VLAN :case NL80211_IFTYPE_MONITOR :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1538/1674 drm/amdgpu: Remove unused amdgpu_i2c functions
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dr. David Alan Gilbert <[email protected]>
[ Upstream commit 0ee239911634dd29c3b05e1138d617cc3cab33fa ]
amdgpu_i2c_add and amdgpu_i2c_init were added in 2015's commit d38ceaf99ed0 ("drm/amdgpu: add core driver (v4)") but never used.
Remove them.
Stable-dep-of: a99cd231cd92 ("drm/amdgpu: Bound GPIO I2C table entry count from VBIOS")
--- drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c | 25 ------------------------- drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.h | 4 ---- 2 files changed, 29 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c +0 -25
@@ -226,15 +226,6 @@ void amdgpu_i2c_destroy(struct amdgpu_i2c_chan *i2c)kfree (i2c); } -/* Add the default buses */ -void amdgpu_i2c_init (struct amdgpu_device *adev) -{ -if (amdgpu_hw_i2c) -DRM_INFO ("hw_i2c forced on, you may experience display detection problems!\n" ); - -amdgpu_atombios_i2c_init (adev); -} -/* remove all the buses */ void amdgpu_i2c_fini (struct amdgpu_device *adev) {
@@ -248,22 +239,6 @@ void amdgpu_i2c_fini(struct amdgpu_device *adev) } } -/* Add additional buses */ -void amdgpu_i2c_add (struct amdgpu_device *adev, -const struct amdgpu_i2c_bus_rec *rec, -const char *name) -{ -struct drm_device *dev =adev_to_drm (adev); -int i; - -for (i =0 ; i <AMDGPU_MAX_I2C_BUS ; i++) { -if (!adev->i2c_bus[i]) { - adev->i2c_bus[i] =amdgpu_i2c_create (dev, rec, name); -return ; - } - } -} -/* looks up bus based on id */ struct amdgpu_i2c_chan * amdgpu_i2c_lookup(struct amdgpu_device *adev,
drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.h +0 -4
@@ -28,11 +28,7 @@ struct amdgpu_i2c_chan *amdgpu_i2c_create(struct drm_device *dev,const struct amdgpu_i2c_bus_rec *rec, const char *name);void amdgpu_i2c_destroy (struct amdgpu_i2c_chan *i2c); -void amdgpu_i2c_init (struct amdgpu_device *adev);void amdgpu_i2c_fini (struct amdgpu_device *adev); -void amdgpu_i2c_add (struct amdgpu_device *adev, -const struct amdgpu_i2c_bus_rec *rec, -const char *name);struct amdgpu_i2c_chan *amdgpu_i2c_lookup (struct amdgpu_device *adev,const struct amdgpu_i2c_bus_rec *i2c_bus);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1539/1674 drm/amdgpu/atombios: drop empty function
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Deucher <[email protected]>
[ Upstream commit ba7f8eb7e447a8120f5bcb8e8d72964324ee5b84 ]
This was leftover from when amdgpu was forked from radeon. The function is empty so drop it.
Stable-dep-of: a99cd231cd92 ("drm/amdgpu: Bound GPIO I2C table entry count from VBIOS")
--- drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c | 12 ------------ 1 file changed, 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c +0 -12
@@ -36,13 +36,6 @@#include "atombios_encoders.h" #include "bif/bif_4_1_d.h" -static void amdgpu_atombios_lookup_i2c_gpio_quirks (struct amdgpu_device *adev, -ATOM_GPIO_I2C_ASSIGMENT *gpio, -u8 index) -{ - -} -static struct amdgpu_i2c_bus_rec amdgpu_atombios_get_bus_rec_for_i2c_gpio (ATOM_GPIO_I2C_ASSIGMENT *gpio) {struct amdgpu_i2c_bus_rec i2c;
@@ -108,9 +101,6 @@ struct amdgpu_i2c_bus_rec amdgpu_atombios_lookup_i2c_gpio(struct amdgpu_device * gpio = &i2c_info->asGPIO_Info[0 ];for (i =0 ; i < num_indices; i++) { - -amdgpu_atombios_lookup_i2c_gpio_quirks (adev, gpio, i); -if (gpio->sucI2cId.ucAccess == id) { i2c =amdgpu_atombios_get_bus_rec_for_i2c_gpio (gpio);break ;
@@ -142,8 +132,6 @@ void amdgpu_atombios_i2c_init(struct amdgpu_device *adev) gpio = &i2c_info->asGPIO_Info[0 ];for (i =0 ; i < num_indices; i++) { -amdgpu_atombios_lookup_i2c_gpio_quirks (adev, gpio, i); - i2c =amdgpu_atombios_get_bus_rec_for_i2c_gpio (gpio);if (i2c.valid) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1540/1674 drm/amdgpu: rework i2c init and fini
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Deucher <[email protected]>
[ Upstream commit 1c0b144bf7628a62575a4ec26623f7a6cdf0cb2b ]
No functional change. Rework the code to allow for adding some additional i2c buses in conjunction with DC in the future.
Stable-dep-of: a99cd231cd92 ("drm/amdgpu: Bound GPIO I2C table entry count from VBIOS")
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 6 ++---- drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c | 8 ++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.h | 1 + 3 files changed, 11 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -4
@@ -3903,8 +3903,7 @@ int amdgpu_device_init(struct amdgpu_device *adev, goto failed; }/* init i2c buses */ -if (!amdgpu_device_has_dc_support (adev)) -amdgpu_atombios_i2c_init (adev); +amdgpu_i2c_init (adev); } }
@@ -4164,8 +4163,7 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)amdgpu_reset_fini (adev);/* free i2c buses */ -if (!amdgpu_device_has_dc_support (adev)) -amdgpu_i2c_fini (adev); +amdgpu_i2c_fini (adev);if (amdgpu_emu_mode !=1 )amdgpu_atombios_fini (adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c +8 -0
@@ -226,6 +226,14 @@ void amdgpu_i2c_destroy(struct amdgpu_i2c_chan *i2c)kfree (i2c); } +void amdgpu_i2c_init (struct amdgpu_device *adev) +{ +if (!adev->is_atom_fw) { +if (!amdgpu_device_has_dc_support (adev)) +amdgpu_atombios_i2c_init (adev); + } +} +/* remove all the buses */ void amdgpu_i2c_fini (struct amdgpu_device *adev) {
drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.h +1 -0
@@ -28,6 +28,7 @@ struct amdgpu_i2c_chan *amdgpu_i2c_create(struct drm_device *dev,const struct amdgpu_i2c_bus_rec *rec, const char *name);void amdgpu_i2c_destroy (struct amdgpu_i2c_chan *i2c); +void amdgpu_i2c_init (struct amdgpu_device *adev);void amdgpu_i2c_fini (struct amdgpu_device *adev);struct amdgpu_i2c_chan * amdgpu_i2c_lookup(struct amdgpu_device *adev,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1541/1674 drm/amdgpu: Bound GPIO I2C table entry count from VBIOS
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Candice Li <[email protected]>
[ Upstream commit a99cd231cd924b7160fecb9fb3a94b801522323b ]
Reject undersized tables and cap the derived entry count to AMDGPU_MAX_I2C_BUS so we do not overrun adev->i2c_bus[] or walk an absurd number of entries on corrupt size fields.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c | 21 ++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c +17 -4
@@ -36,6 +36,21 @@#include "atombios_encoders.h" #include "bif/bif_4_1_d.h" +/* VBIOS-reported table size is unchecked against the image; cap iterations and +* adev->i2c_bus[] indexing to AMDGPU_MAX_I2C_BUS. +*/ +static int amdgpu_atombios_gpio_i2c_num_entries (uint16_t size) +{ +u32 bytes; + +if (size <sizeof (ATOM_COMMON_TABLE_HEADER )) +return 0 ; + + bytes = size -sizeof (ATOM_COMMON_TABLE_HEADER ); +return (int )min_t (u32, bytes /sizeof (ATOM_GPIO_I2C_ASSIGMENT ), +AMDGPU_MAX_I2C_BUS ); +} +static struct amdgpu_i2c_bus_rec amdgpu_atombios_get_bus_rec_for_i2c_gpio (ATOM_GPIO_I2C_ASSIGMENT *gpio) {struct amdgpu_i2c_bus_rec i2c;
@@ -96,8 +111,7 @@ struct amdgpu_i2c_bus_rec amdgpu_atombios_lookup_i2c_gpio(struct amdgpu_device *if (amdgpu_atom_parse_data_header (ctx, index, &size,NULL ,NULL , &data_offset)) { i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset); - num_indices = (size -sizeof (ATOM_COMMON_TABLE_HEADER )) / -sizeof (ATOM_GPIO_I2C_ASSIGMENT ); + num_indices =amdgpu_atombios_gpio_i2c_num_entries (size); gpio = &i2c_info->asGPIO_Info[0 ];for (i =0 ; i < num_indices; i++) {
@@ -127,8 +141,7 @@ void amdgpu_atombios_i2c_init(struct amdgpu_device *adev)if (amdgpu_atom_parse_data_header (ctx, index, &size,NULL ,NULL , &data_offset)) { i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset); - num_indices = (size -sizeof (ATOM_COMMON_TABLE_HEADER )) / -sizeof (ATOM_GPIO_I2C_ASSIGMENT ); + num_indices =amdgpu_atombios_gpio_i2c_num_entries (size); gpio = &i2c_info->asGPIO_Info[0 ];for (i =0 ; i < num_indices; i++) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1542/1674 drm/amdgpu: validate and share PSP fw_pri_buf copies via psp_copy_fw
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Candice Li <[email protected]>
[ Upstream commit d1f9f5839bd785a3a06335a01d53282e80f8e5fa ]
Change psp_copy_fw from void to int: return -ENODEV when drm_dev_enter fails, and -EINVAL when the image size is zero or larger than the 1 MiB PSP private buffer.
Replace open-coded memset/memcpy into fw_pri_buf with psp_copy_fw.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 32 ++++++++++++++++++------ drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h | 2 +- drivers/gpu/drm/amd/amdgpu/psp_v11_0.c | 8 ++++-- drivers/gpu/drm/amd/amdgpu/psp_v12_0.c | 8 ++++-- drivers/gpu/drm/amd/amdgpu/psp_v13_0.c | 14 +++++------ drivers/gpu/drm/amd/amdgpu/psp_v13_0_4.c | 14 +++++------ drivers/gpu/drm/amd/amdgpu/psp_v3_1.c | 8 ++++-- 7 files changed, 56 insertions(+), 30 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +25 -7
@@ -759,7 +759,11 @@ static int psp_load_toc(struct psp_context *psp,struct psp_gfx_cmd_resp *cmd =acquire_psp_cmd_buf (psp);/* Copy toc to psp firmware private buffer */ -psp_copy_fw (psp, psp->toc.start_addr, psp->toc.size_bytes); + ret =psp_copy_fw (psp, psp->toc.start_addr, psp->toc.size_bytes); +if (ret) { +release_psp_cmd_buf (psp); +return ret; + }psp_prep_load_toc_cmd_buf (cmd, psp->fw_pri_mc_addr, psp->toc.size_bytes);
@@ -994,8 +998,11 @@ static int psp_rl_load(struct amdgpu_device *adev) cmd =acquire_psp_cmd_buf (psp); -memset (psp->fw_pri_buf,0 ,PSP_1_MEG ); -memcpy (psp->fw_pri_buf, psp->rl.start_addr, psp->rl.size_bytes); + ret =psp_copy_fw (psp, psp->rl.start_addr, psp->rl.size_bytes); +if (ret) { +release_psp_cmd_buf (psp); +return ret; + } cmd->cmd_id =GFX_CMD_ID_LOAD_IP_FW ; cmd->cmd.cmd_load_ip_fw.fw_phy_addr_lo =lower_32_bits (psp->fw_pri_mc_addr);
@@ -1188,8 +1195,12 @@ int psp_ta_load(struct psp_context *psp, struct ta_context *context) cmd =acquire_psp_cmd_buf (psp); -psp_copy_fw (psp, context->bin_desc.start_addr, - context->bin_desc.size_bytes); + ret =psp_copy_fw (psp, context->bin_desc.start_addr, + context->bin_desc.size_bytes); +if (ret) { +release_psp_cmd_buf (psp); +return ret; + }psp_prep_ta_load_cmd_buf (cmd, psp->fw_pri_mc_addr, context);
@@ -3576,17 +3587,24 @@ static ssize_t psp_usbc_pd_fw_sysfs_write(struct device *dev,return count; } -void psp_copy_fw (struct psp_context *psp,uint8_t *start_addr,uint32_t bin_size) +int psp_copy_fw (struct psp_context *psp,uint8_t *start_addr,uint32_t bin_size) {int idx;if (!drm_dev_enter (adev_to_drm (psp->adev), &idx)) -return ; +return -ENODEV ; + +if (!bin_size || bin_size >PSP_1_MEG ) { +dev_err (psp->adev->dev,"PSP firmware is invalid\n" ); +drm_dev_exit (idx); +return -EINVAL ; + }memset (psp->fw_pri_buf,0 ,PSP_1_MEG );memcpy (psp->fw_pri_buf, start_addr, bin_size);drm_dev_exit (idx); +return 0 ; }/**
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +1 -1
@@ -528,7 +528,7 @@ int psp_get_fw_attestation_records_addr(struct psp_context *psp,int psp_load_fw_list (struct psp_context *psp,struct amdgpu_firmware_info **ucode_list,int ucode_count); -void psp_copy_fw (struct psp_context *psp,uint8_t *start_addr,uint32_t bin_size); +int psp_copy_fw (struct psp_context *psp,uint8_t *start_addr,uint32_t bin_size);int psp_spatial_partition (struct psp_context *psp,int mode);
drivers/gpu/drm/amd/amdgpu/psp_v11_0.c +6 -2
@@ -193,7 +193,9 @@ static int psp_v11_0_bootloader_load_component(struct psp_context *psp,return ret;/* Copy PSP System Driver binary to memory */ -psp_copy_fw (psp, bin_desc->start_addr, bin_desc->size_bytes); + ret =psp_copy_fw (psp, bin_desc->start_addr, bin_desc->size_bytes); +if (ret) +return ret;/* Provide the sys driver to bootloader */ WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_36,
@@ -239,7 +241,9 @@ static int psp_v11_0_bootloader_load_sos(struct psp_context *psp)return ret;/* Copy Secure OS binary to PSP memory */ -psp_copy_fw (psp, psp->sos.start_addr, psp->sos.size_bytes); + ret =psp_copy_fw (psp, psp->sos.start_addr, psp->sos.size_bytes); +if (ret) +return ret;/* Provide the PSP secure OS to bootloader */ WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_36,
drivers/gpu/drm/amd/amdgpu/psp_v12_0.c +6 -2
@@ -90,7 +90,9 @@ static int psp_v12_0_bootloader_load_sysdrv(struct psp_context *psp)return ret;/* Copy PSP System Driver binary to memory */ -psp_copy_fw (psp, psp->sys.start_addr, psp->sys.size_bytes); + ret =psp_copy_fw (psp, psp->sys.start_addr, psp->sys.size_bytes); +if (ret) +return ret;/* Provide the sys driver to bootloader */ WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_36,
@@ -129,7 +131,9 @@ static int psp_v12_0_bootloader_load_sos(struct psp_context *psp)return ret;/* Copy Secure OS binary to PSP memory */ -psp_copy_fw (psp, psp->sos.start_addr, psp->sos.size_bytes); + ret =psp_copy_fw (psp, psp->sos.start_addr, psp->sos.size_bytes); +if (ret) +return ret;/* Provide the PSP secure OS to bootloader */ WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_36,
drivers/gpu/drm/amd/amdgpu/psp_v13_0.c +6 -8
@@ -215,10 +215,9 @@ static int psp_v13_0_bootloader_load_component(struct psp_context *psp,if (ret)return ret; -memset (psp->fw_pri_buf,0 ,PSP_1_MEG ); - -/* Copy PSP KDB binary to memory */ -memcpy (psp->fw_pri_buf, bin_desc->start_addr, bin_desc->size_bytes); + ret =psp_copy_fw (psp, bin_desc->start_addr, bin_desc->size_bytes); +if (ret) +return ret;/* Provide the PSP KDB to bootloader */ WREG32_SOC15(MP0, 0, regMP0_SMN_C2PMSG_36,
@@ -284,10 +283,9 @@ static int psp_v13_0_bootloader_load_sos(struct psp_context *psp)if (ret)return ret; -memset (psp->fw_pri_buf,0 ,PSP_1_MEG ); - -/* Copy Secure OS binary to PSP memory */ -memcpy (psp->fw_pri_buf, psp->sos.start_addr, psp->sos.size_bytes); + ret =psp_copy_fw (psp, psp->sos.start_addr, psp->sos.size_bytes); +if (ret) +return ret;/* Provide the PSP secure OS to bootloader */ WREG32_SOC15(MP0, 0, regMP0_SMN_C2PMSG_36,
drivers/gpu/drm/amd/amdgpu/psp_v13_0_4.c +6 -8
@@ -107,10 +107,9 @@ static int psp_v13_0_4_bootloader_load_component(struct psp_context *psp,if (ret)return ret; -memset (psp->fw_pri_buf,0 ,PSP_1_MEG ); - -/* Copy PSP KDB binary to memory */ -memcpy (psp->fw_pri_buf, bin_desc->start_addr, bin_desc->size_bytes); + ret =psp_copy_fw (psp, bin_desc->start_addr, bin_desc->size_bytes); +if (ret) +return ret;/* Provide the PSP KDB to bootloader */ WREG32_SOC15(MP0, 0, regMP0_SMN_C2PMSG_36,
@@ -170,10 +169,9 @@ static int psp_v13_0_4_bootloader_load_sos(struct psp_context *psp)if (ret)return ret; -memset (psp->fw_pri_buf,0 ,PSP_1_MEG ); - -/* Copy Secure OS binary to PSP memory */ -memcpy (psp->fw_pri_buf, psp->sos.start_addr, psp->sos.size_bytes); + ret =psp_copy_fw (psp, psp->sos.start_addr, psp->sos.size_bytes); +if (ret) +return ret;/* Provide the PSP secure OS to bootloader */ WREG32_SOC15(MP0, 0, regMP0_SMN_C2PMSG_36,
drivers/gpu/drm/amd/amdgpu/psp_v3_1.c +6 -2
@@ -96,7 +96,9 @@ static int psp_v3_1_bootloader_load_sysdrv(struct psp_context *psp)return ret;/* Copy PSP System Driver binary to memory */ -psp_copy_fw (psp, psp->sys.start_addr, psp->sys.size_bytes); + ret =psp_copy_fw (psp, psp->sys.start_addr, psp->sys.size_bytes); +if (ret) +return ret;/* Provide the sys driver to bootloader */ WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_36,
@@ -135,7 +137,9 @@ static int psp_v3_1_bootloader_load_sos(struct psp_context *psp)return ret;/* Copy Secure OS binary to PSP memory */ -psp_copy_fw (psp, psp->sos.start_addr, psp->sos.size_bytes); + ret =psp_copy_fw (psp, psp->sos.start_addr, psp->sos.size_bytes); +if (ret) +return ret;/* Provide the PSP secure OS to bootloader */ WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_36,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1543/1674 pinctrl: mediatek: paris: bypass pinctrl GPIO layer in set GPIO direction
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chen-Yu Tsai <[email protected]>
[ Upstream commit c87c9046c4e00d599454e033a477176c4d73ac2a ]
pinctrl_gpio_direction_input() / pinctrl_gpio_direction_output() take the pinctrl mutex. This causes a gpiochip operations to need to sleep. Worse yet, the .can_sleep field in the gpiochip is not set. This causes the shared GPIO proxy to trip over, as it uses gpiod_cansleep() to check whether it can use a spinlock or needs a mutex. In this case, it ends up taking a spinlock, then calls pinctrl_gpio_direction_output(), which takes a mutex. This causes a huge warning.
While this class of Mediatek hardware does not have separate clear/set registers, the pinctrl context has a spinlock that is taken whenever a register read-modify-write is done. Also, once the GPIO function is selected / muxed in, further GPIO operations do not involve pinctrl operations or state. The GPIO direction and level values do not require toggling the pinmux or any other pin config options.
Switch to directly calling mtk_pinmux_gpio_set_direction() in the GPIO set direction callbacks to avoid taking the pinctrl mutex. Drop the .gpio_set_direction field in mtk_pmxops to signal we are no longer using the pinctrl GPIO layer for setting the direction.
--- drivers/pinctrl/mediatek/pinctrl-paris.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/pinctrl/mediatek/pinctrl-paris.c +2 -3
@@ -775,7 +775,6 @@ static const struct pinmux_ops mtk_pmxops = { .get_function_name = mtk_pmx_get_func_name, .get_function_groups = mtk_pmx_get_func_groups, .set_mux = mtk_pmx_set_mux, - .gpio_set_direction = mtk_pinmux_gpio_set_direction, .gpio_request_enable = mtk_pinmux_gpio_request_enable, };
@@ -904,7 +903,7 @@ static int mtk_gpio_direction_input(struct gpio_chip *chip, unsigned int gpio)if (gpio >= hw->soc->npins)return -EINVAL ; -return pinctrl_gpio_direction_input (chip, gpio); +return mtk_pinmux_gpio_set_direction (hw->pctrl,NULL , gpio, true); } static int mtk_gpio_direction_output(struct gpio_chip *chip, unsigned int gpio,
@@ -917,7 +916,7 @@ static int mtk_gpio_direction_output(struct gpio_chip *chip, unsigned int gpio,mtk_gpio_set (chip, gpio, value); -return pinctrl_gpio_direction_output (chip, gpio); +return mtk_pinmux_gpio_set_direction (hw->pctrl,NULL , gpio, false); }static int mtk_gpio_to_irq (struct gpio_chip *chip,unsigned int offset)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1544/1674 genirq/proc: Size interrupt directory names for 10-digit interrupt numbers
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit c2c7983c93f5d86962318be7e7298f1bc3feb1a6 ]
/proc/irq/<n>/ directory names are built in char name[10] buffers with sprintf(name, "%u", irq).
Ten-digit IRQ numbers already need 11 bytes including the trailing NUL, and current sparse-IRQ configurations allow interrupt numbers in that range.
Size the temporary name buffer for the current decimal form and switch to bounded formatting when creating or removing the proc entry.
--- kernel/irq/proc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
kernel/irq/proc.c +4 -3
@@ -10,6 +10,7 @@#include <linux/proc_fs.h> #include <linux/seq_file.h> #include <linux/interrupt.h> +#include <linux/kernel.h> #include <linux/kernel_stat.h> #include <linux/mutex.h>
@@ -333,7 +334,7 @@ void register_handler_proc(unsigned int irq, struct irqaction *action)#undef MAX_NAMELEN -#define MAX_NAMELEN 10 +#define MAX_NAMELEN 11void register_irq_proc (unsigned int irq,struct irq_desc *desc) {
@@ -354,7 +355,7 @@ void register_irq_proc(unsigned int irq, struct irq_desc *desc)if (desc->dir) goto out_unlock; -sprintf (name,"%d" , irq); +snprintf (name,MAX_NAMELEN ,"%u" , irq);/* create /proc/irq/1234 */ desc->dir =proc_mkdir (name, root_irq_dir);
@@ -408,7 +409,7 @@ void unregister_irq_proc(unsigned int irq, struct irq_desc *desc)#endif remove_proc_entry ("spurious" , desc->dir); -sprintf (name,"%u" , irq); +snprintf (name,MAX_NAMELEN ,"%u" , irq);remove_proc_entry (name, root_irq_dir); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1545/1674 PCI/sysfs: Demacrofy pci_dev_resource_resize_attr(n) functions
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ilpo Järvinen <[email protected]>
[ Upstream commit f6c73999837820f98519bf0146df44e58f20f89c ]
pci_dev_resource_resize_attr(n) macro is invoked for six resources, creating a large footprint function for each resource.
Rework the macro to only create a function that calls a helper function so the compiler can decide if it warrants to inline the function or not.
With x86_64 defconfig, this saves roughly 2.5kB:
$ scripts/bloat-o-meter drivers/pci/pci-sysfs.o{.old,.new}
add/remove: 1/0 grow/shrink: 0/6 up/down: 512/-2934 (-2422)
Function old new delta
__resource_resize_store - 512 +512
resource5_resize_store 503 14 -489
resource4_resize_store 503 14 -489
resource3_resize_store 503 14 -489
resource2_resize_store 503 14 -489
resource1_resize_store 503 14 -489
resource0_resize_store 500 11 -489
Total: Before=13399, After=10977, chg -18.08%(The compiler seemingly chose to still inline __resource_resize_show() which is fine, those functions are not very complex/large.)
Adapt the helper to this tree's existing resize logic: keep the four-argument pci_resize_resource() call and omit the loop that releases same-flag BARs, which is not present here.
Stable-dep-of: 25ec7f57dece ("PCI/sysfs: Add CAP_SYS_ADMIN check to __resource_resize_store()")
--- drivers/pci/pci-sysfs.c | 122 ++++++++++++++++++++++------------------ 1 file changed, 66 insertions(+), 56 deletions(-)
drivers/pci/pci-sysfs.c +66 -56
@@ -1409,71 +1409,81 @@ static const struct attribute_group pci_dev_reset_attr_group = { .is_visible = pci_dev_reset_attr_is_visible, }; +static ssize_t __resource_resize_show (struct device *dev,int n,char *buf) +{ +struct pci_dev *pdev =to_pci_dev (dev); +ssize_t ret; + +pci_config_pm_runtime_get (pdev); + + ret =sysfs_emit (buf,"%016llx\n" , + (u64 )pci_rebar_get_possible_sizes (pdev, n)); + +pci_config_pm_runtime_put (pdev); + +return ret; +} + +static ssize_t __resource_resize_store (struct device *dev,int n, +const char *buf,size_t count) +{ +struct pci_dev *pdev =to_pci_dev (dev); +unsigned long size; +int ret; +u16 cmd; + +if (kstrtoul (buf,0 , &size) <0 ) +return -EINVAL ; + +device_lock (dev); +if (dev->driver) { + ret = -EBUSY ; + goto unlock; + } + +pci_config_pm_runtime_get (pdev); + +if ((pdev->class >>8 ) ==PCI_CLASS_DISPLAY_VGA ) { + ret =aperture_remove_conflicting_pci_devices (pdev, +"resourceN_resize" ); +if (ret) + goto pm_put; + } + +pci_read_config_word (pdev,PCI_COMMAND , &cmd); +pci_write_config_word (pdev,PCI_COMMAND , + cmd & ~PCI_COMMAND_MEMORY ); + +pci_remove_resource_files (pdev); + + ret =pci_resize_resource (pdev, n, size,0 ); + +pci_assign_unassigned_bus_resources (pdev->bus); + +if (pci_create_resource_files (pdev)) +pci_warn (pdev,"Failed to recreate resource files after BAR resizing\n" ); + +pci_write_config_word (pdev,PCI_COMMAND , cmd); +pm_put: +pci_config_pm_runtime_put (pdev); +unlock: +device_unlock (dev); + +return ret ? ret : count; +} +#define pci_dev_resource_resize_attr (n) \ static ssize_t resource##n##_resize_show(struct device *dev, \ struct device_attribute *attr, \ - char * buf) \ + char *buf) \ { \ - struct pci_dev *pdev = to_pci_dev(dev); \ - ssize_t ret; \ - \ - pci_config_pm_runtime_get(pdev); \ - \ - ret = sysfs_emit(buf, "%016llx\n", \ - (u64)pci_rebar_get_possible_sizes(pdev, n)); \ - \ - pci_config_pm_runtime_put(pdev); \ - \ - return ret; \ + return __resource_resize_show(dev, n, buf); \ } \ - \ static ssize_t resource##n##_resize_store(struct device *dev, \ struct device_attribute *attr,\ const char *buf, size_t count)\ { \ - struct pci_dev *pdev = to_pci_dev(dev); \ - unsigned long size; \ - int ret; \ - u16 cmd; \ - \ - if (kstrtoul(buf, 0, &size) < 0) \ - return -EINVAL; \ - \ - device_lock(dev); \ - if (dev->driver) { \ - ret = -EBUSY; \ - goto unlock; \ - } \ - \ - pci_config_pm_runtime_get(pdev); \ - \ - if ((pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA) { \ - ret = aperture_remove_conflicting_pci_devices(pdev, \ - "resourceN_resize"); \ - if (ret) \ - goto pm_put; \ - } \ - \ - pci_read_config_word(pdev, PCI_COMMAND, &cmd); \ - pci_write_config_word(pdev, PCI_COMMAND, \ - cmd & ~PCI_COMMAND_MEMORY); \ - \ - pci_remove_resource_files(pdev); \ - \ - ret = pci_resize_resource(pdev, n, size, 0); \ - \ - pci_assign_unassigned_bus_resources(pdev->bus); \ - \ - if (pci_create_resource_files(pdev)) \ - pci_warn(pdev, "Failed to recreate resource files after BAR resizing\n");\ - \ - pci_write_config_word(pdev, PCI_COMMAND, cmd); \ -pm_put: \ - pci_config_pm_runtime_put(pdev); \ -unlock: \ - device_unlock(dev); \ - \ - return ret ? ret : count; \ + return __resource_resize_store(dev, n, buf, count); \ } \ static DEVICE_ATTR_RW(resource##n##_resize)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1546/1674 PCI/sysfs: Add CAP_SYS_ADMIN check to __resource_resize_store()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Krzysztof Wilczyński <[email protected]>
[ Upstream commit 25ec7f57deceec633f27bc93b615f951e2ade814 ]
Currently, the __resource_resize_store() allows writing to the resourceN_resize sysfs attribute to change a BAR's size without checking for capabilities, currently relying only on the file access check.
Resizing a BAR modifies PCI device configuration and can disrupt active drivers. After the upcoming conversion to static attributes, it will also trigger resource file updates via sysfs_update_groups().
Add a CAP_SYS_ADMIN check to prevent unprivileged users from performing BAR resize operations.
--- drivers/pci/pci-sysfs.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/pci/pci-sysfs.c +3 -0
@@ -1432,6 +1432,9 @@ static ssize_t __resource_resize_store(struct device *dev, int n,int ret;u16 cmd; +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; +if (kstrtoul (buf,0 , &size) <0 )return -EINVAL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1547/1674 bpf: Mark raw_tp arguments with PTR_MAYBE_NULL
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kumar Kartikeya Dwivedi <[email protected]>
[ Upstream commit cb4158ce8ec8a5bb528cc1693356a5eb8058094d ]
Arguments to a raw tracepoint are tagged as trusted, which carries the semantics that the pointer will be non-NULL. However, in certain cases, a raw tracepoint argument may end up being NULL. More context about this issue is available in [0].
Thus, there is a discrepancy between the reality, that raw_tp arguments can actually be NULL, and the verifier's knowledge, that they are never NULL, causing explicit NULL checks to be deleted, and accesses to such pointers potentially crashing the kernel.
To fix this, mark raw_tp arguments as PTR_MAYBE_NULL, and then special case the dereference and pointer arithmetic to permit it, and allow passing them into helpers/kfuncs; these exceptions are made for raw_tp programs only. Ensure that we don't do this when ref_obj_id > 0, as in that case this is an acquired object and doesn't need such adjustment.
The reason we do mask_raw_tp_trusted_reg logic is because other will recheck in places whether the register is a trusted_reg, and then consider our register as untrusted when detecting the presence of the PTR_MAYBE_NULL flag.
To allow safe dereference, we enable PROBE_MEM marking when we see loads into trusted pointers with PTR_MAYBE_NULL.
While trusted raw_tp arguments can also be passed into helpers or kfuncs where such broken assumption may cause issues, a future patch set will tackle their case separately, as PTR_TO_BTF_ID (without PTR_TRUSTED) can already be passed into helpers and causes similar problems. Thus, they are left alone for now.
It is possible that these checks also permit passing non-raw_tp args that are trusted PTR_TO_BTF_ID with null marking. In such a case, allowing dereference when pointer is NULL expands allowed behavior, so won't regress existing programs, and the case of passing these into helpers is the same as above and will be dealt with later.
Also update the failure case in tp_btf_nullable selftest to capture the new behavior, as the verifier will no longer cause an error when directly dereference a raw tracepoint argument marked as __nullable.
[0]: https://lore.kernel.org/bpf/[email protected]
--- include/linux/bpf.h | 6 ++++ kernel/bpf/btf.c | 4 +++ kernel/bpf/verifier.c | 77 ++++++++++++++++++++++++++++++++++++++----- 3 files changed, 79 insertions(+), 8 deletions(-)
include/linux/bpf.h +6 -0
@@ -3278,4 +3278,10 @@ static inline gfp_t bpf_memcg_flags(gfp_t flags) return flags; } +static inline bool bpf_prog_is_raw_tp (const struct bpf_prog *prog) +{ +return prog->type ==BPF_PROG_TYPE_TRACING && + prog->expected_attach_type ==BPF_TRACE_RAW_TP ; +} +#endif /* _LINUX_BPF_H */
kernel/bpf/btf.c +4 -0
@@ -6107,6 +6107,10 @@ bool btf_ctx_access(int off, int size, enum bpf_access_type type,if (prog_args_trusted (prog)) info->reg_type |=PTR_TRUSTED ; +/* Raw tracepoint arguments always get marked as maybe NULL */ +if (bpf_prog_is_raw_tp (prog)) + info->reg_type |=PTR_MAYBE_NULL ; +if (tgt_prog) {enum bpf_prog_type tgt_type;
kernel/bpf/verifier.c +69 -8
206 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1548/1674 scsi: ufs: exynos: Disable iocc if dma-coherent property isnt set
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Griffin <[email protected]>
[ Upstream commit f92bb7436802f8eb7ee72dc911a33c8897fde366 ]
If dma-coherent property isn't set then descriptors are non-cacheable and the iocc shareability bits should be disabled. Without this UFS can end up in an incompatible configuration and suffer from random cache related stability issues.
--- drivers/ufs/host/ufs-exynos.c | 17 +++++++++++++---- drivers/ufs/host/ufs-exynos.h | 3 ++- 2 files changed, 15 insertions(+), 5 deletions(-)
drivers/ufs/host/ufs-exynos.c +13 -4
@@ -200,8 +200,8 @@ static int exynosauto_ufs_drv_init(struct device *dev, struct exynos_ufs *ufs)/* IO Coherency setting */ if (ufs->sysreg) {return regmap_update_bits (ufs->sysreg, - ufs->shareability_reg_offset, -UFS_SHARABLE ,UFS_SHARABLE ); + ufs->iocc_offset, +UFS_SHARABLE , ufs->iocc_val); } attr->tx_dif_p_nsec =3200000 ;
@@ -1102,12 +1102,21 @@ static int exynos_ufs_parse_dt(struct device *dev, struct exynos_ufs *ufs) ufs->sysreg =NULL ; else {if (of_property_read_u32_index (np,"samsung,sysreg" ,1 , - &ufs->shareability_reg_offset)) { + &ufs->iocc_offset)) {dev_warn (dev,"can't get an offset from sysreg. Set to default value\n" ); - ufs->shareability_reg_offset =UFS_SHAREABILITY_OFFSET ; + ufs->iocc_offset =UFS_SHAREABILITY_OFFSET ; } } +/* +* no 'dma-coherent' property means the descriptors are +* non-cacheable so iocc shareability should be disabled. +*/ +if (of_dma_is_coherent (dev->of_node)) + ufs->iocc_val =UFS_SHARABLE ; +else + ufs->iocc_val =0 ; + ufs->pclk_avail_min =PCLK_AVAIL_MIN ; ufs->pclk_avail_max =PCLK_AVAIL_MAX ;
drivers/ufs/host/ufs-exynos.h +2 -1
@@ -212,7 +212,8 @@ struct exynos_ufs {ktime_t entry_hibern8_t;const struct exynos_ufs_drv_data *drv_data;struct regmap *sysreg; -u32 shareability_reg_offset; +u32 iocc_offset; +u32 iocc_val;u32 opts;#define EXYNOS_UFS_OPT_HAS_APB_CLK_CTRL BIT(0)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1549/1674 net: dsa: b53: do not enable EEE on bcm63xx
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jonas Gorski <[email protected]>
[ Upstream commit 1237c2d4a8db79dfd4369bff6930b0e385ed7d5c ]
BCM63xx internal switches do not support EEE, but provide multiple RGMII ports where external PHYs may be connected. If one of these PHYs are EEE capable, we may try to enable EEE for the MACs, which then hangs the system on access of the (non-existent) EEE registers.
Fix this by checking if the switch actually supports EEE before attempting to configure it.
--- drivers/net/dsa/b53/b53_common.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/dsa/b53/b53_common.c +6 -2
@@ -2268,8 +2268,12 @@ EXPORT_SYMBOL(b53_eee_enable_set);*/ int b53_eee_init (struct dsa_switch *ds,int port,struct phy_device *phy) { +struct b53_device *dev = ds->priv;int ret; +if (is5325 (dev) ||is5365 (dev) ||is63xx (dev)) +return 0 ; + ret =phy_init_eee (phy, false);if (ret)return 0 ;
@@ -2286,7 +2290,7 @@ int b53_get_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e)struct ethtool_eee *p = &dev->ports[port].eee;u16 reg; -if (is5325 (dev) ||is5365 (dev)) +if (is5325 (dev) ||is5365 (dev) ||is63xx (dev))return -EOPNOTSUPP ;b53_read16 (dev,B53_EEE_PAGE ,B53_EEE_LPI_INDICATE , ®);
@@ -2302,7 +2306,7 @@ int b53_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e)struct b53_device *dev = ds->priv;struct ethtool_eee *p = &dev->ports[port].eee; -if (is5325 (dev) ||is5365 (dev)) +if (is5325 (dev) ||is5365 (dev) ||is63xx (dev))return -EOPNOTSUPP ; p->eee_enabled = e->eee_enabled;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1550/1674 HID: nintendo: avoid bluetooth suspend/resume stalls
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel J. Ogorchock <[email protected]>
[ Upstream commit 4a0381080397e77792a5168069f174d3e56175ff ]
Ensure we don't stall or panic the kernel when using bluetooth-connected controllers. This was reported as an issue on android devices using kernel 6.6 due to the resume hook which had been added for usb joycons.
First, set a new state value to JOYCON_CTLR_STATE_SUSPENDED in a newly-added nintendo_hid_suspend. This makes sure we will not stall out the kernel waiting for input reports during led classdev suspend. The stalls could happen if connectivity is unreliable or lost to the controller prior to suspend.
Second, since we lose connectivity during suspend, do not try joycon_init() for bluetooth controllers in the nintendo_hid_resume path.
Tested via multiple suspend/resume flows when using the controller both in USB and bluetooth modes.
--- drivers/hid/hid-nintendo.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-)
drivers/hid/hid-nintendo.c +36 -2
@@ -301,6 +301,7 @@ enum joycon_ctlr_state {JOYCON_CTLR_STATE_INIT ,JOYCON_CTLR_STATE_READ ,JOYCON_CTLR_STATE_REMOVED , + JOYCON_CTLR_STATE_SUSPENDED, };/* Controller type received as part of device info */
@@ -2418,14 +2419,46 @@ static void nintendo_hid_remove(struct hid_device *hdev)static int nintendo_hid_resume (struct hid_device *hdev) { -int ret =joycon_init (hdev); +struct joycon_ctlr *ctlr =hid_get_drvdata (hdev); +int ret; + +hid_dbg (hdev,"resume\n" ); +if (ctlr->hdev->bus !=BUS_USB ) { +hid_dbg (hdev,"no-op resume for bt ctlr\n" ); + ctlr->ctlr_state =JOYCON_CTLR_STATE_READ ; +return 0 ; + } + ret =joycon_init (hdev);if (ret) -hid_err (hdev,"Failed to restore controller after resume" ); +hid_err (hdev, +"Failed to restore controller after resume: %d\n" , + ret); +else + ctlr->ctlr_state =JOYCON_CTLR_STATE_READ ;return ret; } +static int nintendo_hid_suspend (struct hid_device *hdev,pm_message_t message) +{ +struct joycon_ctlr *ctlr =hid_get_drvdata (hdev); + +hid_dbg (hdev,"suspend: %d\n" , message.event); +/* +* Avoid any blocking loops in suspend/resume transitions. +* +* joycon_enforce_subcmd_rate() can result in repeated retries if for +* whatever reason the controller stops providing input reports. +* +* This has been observed with bluetooth controllers which lose +* connectivity prior to suspend (but not long enough to result in +* complete disconnection). +*/ + ctlr->ctlr_state =JOYCON_CTLR_STATE_SUSPENDED ; +return 0 ; +} +#endif static const struct hid_device_id nintendo_hid_devices[] = {
@@ -2452,6 +2485,7 @@ static struct hid_driver nintendo_hid_driver = {#ifdef CONFIG_PM .resume = nintendo_hid_resume, + .suspend = nintendo_hid_suspend,#endif };module_hid_driver (nintendo_hid_driver);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1551/1674 xen: fix UAF in dmabuf_exp_from_pages()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Al Viro <[email protected]>
[ Upstream commit 532c8b51b3a8676cbf533a291f8156774f30ea87 ]
[dma_buf_fd() fixes; no preferences regarding the tree it goes through - up to xen folks]
As soon as we'd inserted a file reference into descriptor table, another thread could close it. That's fine for the case when all we are doing is returning that descriptor to userland (it's a race, but it's a userland race and there's nothing the kernel can do about it). However, if we follow fd_install() with any kind of access to objects that would be destroyed on close (be it the struct file itself or anything destroyed by its ->release()), we have a UAF.
dma_buf_fd() is a combination of reserving a descriptor and fd_install(). gntdev dmabuf_exp_from_pages() calls it and then proceeds to access the objects destroyed on close - starting with gntdev_dmabuf itself.
Fix that by doing reserving descriptor before anything else and do fd_install() only when everything had been set up.
Message-ID: <20250712050916.GY1880847@ZenIV>
--- drivers/xen/gntdev-dmabuf.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-)
drivers/xen/gntdev-dmabuf.c +13 -18
@@ -357,8 +357,12 @@ struct gntdev_dmabuf_export_args {static int dmabuf_exp_from_pages (struct gntdev_dmabuf_export_args *args) {DEFINE_DMA_BUF_EXPORT_INFO (exp_info); -struct gntdev_dmabuf *gntdev_dmabuf; -int ret; + struct gntdev_dmabuf *gntdev_dmabuf __free(kfree) = NULL; +CLASS (get_unused_fd, ret)(O_CLOEXEC ); +int fd; + +if (ret <0 ) +return ret; gntdev_dmabuf =kzalloc (sizeof (*gntdev_dmabuf),GFP_KERNEL );if (!gntdev_dmabuf)
@@ -383,32 +387,23 @@ static int dmabuf_exp_from_pages(struct gntdev_dmabuf_export_args *args) exp_info.priv = gntdev_dmabuf; gntdev_dmabuf->dmabuf =dma_buf_export (&exp_info); -if (IS_ERR (gntdev_dmabuf->dmabuf)) { - ret =PTR_ERR (gntdev_dmabuf->dmabuf); - gntdev_dmabuf->dmabuf =NULL ; - goto fail; - } - - ret =dma_buf_fd (gntdev_dmabuf->dmabuf,O_CLOEXEC ); -if (ret <0 ) - goto fail; +if (IS_ERR (gntdev_dmabuf->dmabuf)) +return PTR_ERR (gntdev_dmabuf->dmabuf); gntdev_dmabuf->fd = ret; args->fd = ret;pr_debug ("Exporting DMA buffer with fd %d\n" , ret); +get_file (gntdev_dmabuf->priv->filp);mutex_lock (&args->dmabuf_priv->lock);list_add (&gntdev_dmabuf->next, &args->dmabuf_priv->exp_list);mutex_unlock (&args->dmabuf_priv->lock); -get_file (gntdev_dmabuf->priv->filp); -return 0 ; -fail: -if (gntdev_dmabuf->dmabuf) -dma_buf_put (gntdev_dmabuf->dmabuf); -kfree (gntdev_dmabuf); -return ret; + fd = ret; + ret = -EBADF ; +fd_install (fd,no_free_ptr (gntdev_dmabuf)->dmabuf->file); +return 0 ; } static struct gntdev_grant_map *
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1552/1674 net: mscc: ocelot: Fix use-after-free caused by cyclic delayed work
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Duoming Zhou <[email protected]>
[ Upstream commit bc9ea787079671cb19a8b25ff9f02be5ef6bfcf5 ]
The origin code calls cancel_delayed_work() in ocelot_stats_deinit() to cancel the cyclic delayed work item ocelot->stats_work. However, cancel_delayed_work() may fail to cancel the work item if it is already executing. While destroy_workqueue() does wait for all pending work items in the work queue to complete before destroying the work queue, it cannot prevent the delayed work item from being rescheduled within the ocelot_check_stats_work() function. This limitation exists because the delayed work item is only enqueued into the work queue after its timer expires. Before the timer expiration, destroy_workqueue() has no visibility of this pending work item. Once the work queue appears empty, destroy_workqueue() proceeds with destruction. When the timer eventually expires, the delayed work item gets queued again, leading to the following warning:
workqueue: cannot queue ocelot_check_stats_work on wq ocelot-switch-stats
WARNING: CPU: 2 PID: 0 at kernel/workqueue.c:2255 __queue_work+0x875/0xaf0 ... RIP: 0010:__queue_work+0x875/0xaf0 ... RSP: 0018:ffff88806d108b10 EFLAGS: 00010086 RAX: 0000000000000000 RBX: 0000000000000101 RCX: 0000000000000027 RDX: 0000000000000027 RSI: 0000000000000004 RDI: ffff88806d123e88 RBP: ffffffff813c3170 R08: 0000000000000000 R09: ffffed100da247d2 R10: ffffed100da247d1 R11: ffff88806d123e8b R12: ffff88800c00f000 R13: ffff88800d7285c0 R14: ffff88806d0a5580 R15: ffff88800d7285a0 FS: 0000000000000000(0000) GS:ffff8880e5725000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007fe18e45ea10 CR3: 0000000005e6c000 CR4: 00000000000006f0 Call Trace: <IRQ> ? kasan_report+0xc6/0xf0 ? __pfx_delayed_work_timer_fn+0x10/0x10 ? __pfx_delayed_work_timer_fn+0x10/0x10 call_timer_fn+0x25/0x1c0 __run_timer_base.part.0+0x3be/0x8c0 ? __pfx_delayed_work_timer_fn+0x10/0x10 ? rcu_sched_clock_irq+0xb06/0x27d0 ? __pfx___run_timer_base.part.0+0x10/0x10 ? try_to_wake_up+0xb15/0x1960 ? _raw_spin_lock_irq+0x80/0xe0 ? __pfx__raw_spin_lock_irq+0x10/0x10 tmigr_handle_remote_up+0x603/0x7e0 ? __pfx_tmigr_handle_remote_up+0x10/0x10 ? sched_balance_trigger+0x1c0/0x9f0 ? sched_tick+0x221/0x5a0 ? _raw_spin_lock_irq+0x80/0xe0 ? __pfx__raw_spin_lock_irq+0x10/0x10 ? tick_nohz_handler+0x339/0x440 ? __pfx_tmigr_handle_remote_up+0x10/0x10 __walk_groups.isra.0+0x42/0x150 tmigr_handle_remote+0x1f4/0x2e0 ? __pfx_tmigr_handle_remote+0x10/0x10 ? ktime_get+0x60/0x140 ? lapic_next_event+0x11/0x20 ? clockevents_program_event+0x1d4/0x2a0 ? hrtimer_interrupt+0x322/0x780 handle_softirqs+0x16a/0x550 irq_exit_rcu+0xaf/0xe0 sysvec_apic_timer_interrupt+0x70/0x80 </IRQ>
...
The following diagram reveals the cause of the above warning:
CPU 0 (remove) | CPU 1 (delayed work callback)
mscc_ocelot_remove() |
ocelot_deinit() | ocelot_check_stats_work()
ocelot_stats_deinit() |
cancel_delayed_work()| ...
| queue_delayed_work()
destroy_workqueue() | (wait a time)
| __queue_work() //UAFThe above scenario actually constitutes a UAF vulnerability.
The ocelot_stats_deinit() is only invoked when initialization failure or resource destruction, so we must ensure that any delayed work items cannot be rescheduled.
Replace cancel_delayed_work() with disable_delayed_work_sync() to guarantee proper cancellation of the delayed work item and ensure completion of any currently executing work before the workqueue is deallocated.
A deadlock concern was considered: ocelot_stats_deinit() is called in a process context and is not holding any locks that the delayed work item might also need. Therefore, the use of the _sync() variant is safe here.
This bug was identified through static analysis. To reproduce the issue and validate the fix, I simulated ocelot-switch device by writing a kernel module and prepared the necessary resources for the virtual ocelot-switch device's probe process. Then, removing the virtual device will trigger the mscc_ocelot_remove() function, which in turn destroys the workqueue.
--- drivers/net/ethernet/mscc/ocelot_stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mscc/ocelot_stats.c +1 -1
@@ -984,6 +984,6 @@ int ocelot_stats_init(struct ocelot *ocelot)void ocelot_stats_deinit (struct ocelot *ocelot) { -cancel_delayed_work (&ocelot->stats_work); +cancel_delayed_work_sync (&ocelot->stats_work);destroy_workqueue (ocelot->stats_queue); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1553/1674 ACPI: platform: Use acpi_bus_get_primary_device()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
[ Upstream commit a9ba4dd2f18bf3f439d9ef0d8f375f90360ba1bd ]
The acpi_get_first_physical_node() usage in acpi_platform_fill_resource() and acpi_create_platform_device() is generally unsafe because in theory the device returned by it may be freed at any time [1].
It is also inefficient because acpi_get_first_physical_node() is called multiple times for the same argument which can be avoided.
Address these issues by using acpi_bus_get_primary_device() instead of acpi_get_first_physical_node() and adjusting the code to call it just once at the beginning of and acpi_create_platform_device() and drop the device reference acquired by it upon the return from that function.
--- drivers/acpi/acpi_platform.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/acpi/acpi_platform.c +7 -9
@@ -71,18 +71,15 @@ static struct notifier_block acpi_platform_notifier = { .notifier_call = acpi_platform_device_remove_notify, }; -static void acpi_platform_fill_resource (struct acpi_device *adev, -const struct resource *src,struct resource *dest) +static void acpi_platform_fill_resource (struct device *parent, +const struct resource *src, +struct resource *dest) { -struct device *parent; - *dest = *src; -/* * If the device has parent we need to take its resources into * account as well because this device might consume part of those. */ - parent =acpi_get_first_physical_node (acpi_dev_parent (adev));if (parent &&dev_is_pci (parent)) dest->parent =pci_find_resource (to_pci_dev (parent), dest); }
@@ -110,7 +107,8 @@ static unsigned int acpi_platform_resource_count(struct acpi_resource *ares, voistruct platform_device *acpi_create_platform_device (struct acpi_device *adev,const struct property_entry *properties) { -struct acpi_device *parent =acpi_dev_parent (adev); +struct acpi_device *p =acpi_dev_parent (adev); + struct device *parent __free(put_device) = acpi_bus_get_primary_device(p);struct platform_device *pdev =NULL ;struct platform_device_info pdevinfo;const struct acpi_device_id *match;
@@ -149,7 +147,7 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev, } count =0 ;list_for_each_entry (rentry, &resource_list, node) -acpi_platform_fill_resource (adev, rentry->res, +acpi_platform_fill_resource (parent, rentry->res, &resources[count++]);acpi_dev_free_resource_list (&resource_list);
@@ -161,7 +159,7 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev,* attached to it, that physical device should be the parent of the * platform device we are about to create. */ - pdevinfo.parent = parent ?acpi_get_first_physical_node (parent) :NULL ; + pdevinfo.parent = parent; pdevinfo.name =dev_name (&adev->dev); pdevinfo.id =PLATFORM_DEVID_NONE ; pdevinfo.res = resources;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1554/1674 drm/msm: Recover HW before retire hung submit
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jie Zhang <[email protected]>
[ Upstream commit b303e1d52811de7d1bcf793560754d4df68d4a1c ]
During recovery, it is not safe to retire the hung submit before we recover the GPU. Retiring the submit triggers BO free and that can result in GPU pagefaults since the GPU may be actively accessing those BOs.
To fix this, retire the submits after gpu recovery is complete in recover_worker().
Patchwork: https://patchwork.freedesktop.org/patch/730655/
Message-ID: <[email protected]>
--- drivers/gpu/drm/msm/msm_gpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/msm/msm_gpu.c +2 -2
@@ -418,11 +418,11 @@ static void recover_worker(struct kthread_work *work)msm_update_fence (ring->fctx, fence); } + gpu->funcs->recover (gpu); +/* retire completed submits, plus the one that hung: */ retire_submits (gpu); - gpu->funcs->recover (gpu); -/* * Replay all remaining submits starting with highest priority * ring
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1555/1674 ip_tunnel: adapt iptunnel_xmit_stats() to NETDEV_PCPU_STAT_DSTATS
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 8431c602f551549f082bbfa67f3003f2d8e3e132 ]
Blamed commits forgot that vxlan/geneve use udp_tunnel[6]_xmit_skb() which call iptunnel_xmit_stats().
iptunnel_xmit_stats() was assuming tunnels were only using NETDEV_PCPU_STAT_TSTATS.
@syncp offset in pcpu_sw_netstats and pcpu_dstats is different.
32bit kernels would either have corruptions or freezes if the syncp sequence was overwritten.
This patch also moves pcpu_stat_type closer to dev->{t,d}stats to avoid a potential cache line miss since iptunnel_xmit_stats() needs to read it.
--- include/net/ip_tunnels.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
include/net/ip_tunnels.h +10 -0
@@ -542,6 +542,16 @@ static inline int iptunnel_pull_offloads(struct sk_buff *skb)static inline void iptunnel_xmit_stats (struct net_device *dev,int pkt_len) {if (pkt_len >0 ) { +if (dev->pcpu_stat_type ==NETDEV_PCPU_STAT_DSTATS ) { +struct pcpu_dstats *dstats =get_cpu_ptr (dev->dstats); + +u64_stats_update_begin (&dstats->syncp); +u64_stats_add (&dstats->tx_bytes, pkt_len); +u64_stats_inc (&dstats->tx_packets); +u64_stats_update_end (&dstats->syncp); +put_cpu_ptr (dstats); +return ; + }struct pcpu_sw_netstats *tstats =get_cpu_ptr (dev->tstats);u64_stats_update_begin (&tstats->syncp);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1556/1674 RDMA/efa: Fix use of completion ctx after free
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yonatan Nachum <[email protected]>
[ Upstream commit ef3b06742c8a201d0e83edc9a33a89a4fe3009f8 ]
On admin queue completion handling, if the admin command completed with error we print data from the completion context. The issue is that we already freed the completion context in polling/interrupts handler which means we print data from context in an unknown state (it might be already used again).
Change the admin submission flow so alloc/dealloc of the context will be symmetric and dealloc will be called after any potential use of the context.
--- drivers/infiniband/hw/efa/efa_com.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-)
drivers/infiniband/hw/efa/efa_com.c +10 -18
@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause /* -* Copyright 2018-2024 Amazon.com, Inc. or its affiliates. All rights reserved. +* Copyright 2018-2026 Amazon.com, Inc. or its affiliates. All rights reserved. */ #include "efa_com.h"
@@ -499,7 +499,6 @@ static int efa_com_wait_and_process_admin_cq_polling(struct efa_comp_ctx *comp_c {unsigned long timeout;unsigned long flags; -int err; timeout = jiffies +usecs_to_jiffies (aq->completion_timeout);
@@ -519,24 +518,20 @@ static int efa_com_wait_and_process_admin_cq_polling(struct efa_comp_ctx *comp_catomic64_inc (&aq->stats.no_completion);clear_bit (EFA_AQ_STATE_RUNNING_BIT , &aq->state); - err = -ETIME ; - goto out; +return -ETIME ; }msleep (aq->poll_interval); } - err =efa_com_comp_status_to_errno (comp_ctx->user_cqe->acq_common_descriptor.status); -out: -efa_com_put_comp_ctx (aq, comp_ctx); -return err; +return efa_com_comp_status_to_errno ( + comp_ctx->user_cqe->acq_common_descriptor.status); }static int efa_com_wait_and_process_admin_cq_interrupts (struct efa_comp_ctx *comp_ctx,struct efa_com_admin_queue *aq) {unsigned long flags; -int err;wait_for_completion_timeout (&comp_ctx->wait_event,usecs_to_jiffies (aq->completion_timeout));
@@ -570,14 +565,11 @@ static int efa_com_wait_and_process_admin_cq_interrupts(struct efa_comp_ctx *com comp_ctx, aq->sq.pc, aq->sq.cc, aq->cq.cc);clear_bit (EFA_AQ_STATE_RUNNING_BIT , &aq->state); - err = -ETIME ; - goto out; +return -ETIME ; } - err =efa_com_comp_status_to_errno (comp_ctx->user_cqe->acq_common_descriptor.status); -out: -efa_com_put_comp_ctx (aq, comp_ctx); -return err; +return efa_com_comp_status_to_errno ( + comp_ctx->user_cqe->acq_common_descriptor.status); }/*
@@ -644,13 +636,13 @@ int efa_com_cmd_exec(struct efa_com_admin_queue *aq,if (err) {ibdev_err_ratelimited ( aq->efa_dev, -"Failed to process command %s (opcode %u) comp_status %d err %d\n" , +"Failed to process command %s (opcode %u) err %d\n" ,efa_com_cmd_str (cmd->aq_common_descriptor.opcode), - cmd->aq_common_descriptor.opcode, - comp_ctx->user_cqe->acq_common_descriptor.status, err); + cmd->aq_common_descriptor.opcode, err);atomic64_inc (&aq->stats.cmd_err); } +efa_com_put_comp_ctx (aq, comp_ctx);up (&aq->avail_cmds);return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1557/1674 ASoC: qcom: q6asm: handle the responses after closing
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Srinivas Kandagatla <[email protected]>
[ Upstream commit a354f030dbce17ab3cf299660a38b162d97f7151 ]
For record path, multiple read requests are queued to dsp in advance. However when data stream is closed, the pending read requests are rejected by the dsp and a response is sent to the driver, this case is not handled in the driver resulting in errors like below
q6asm-dai ab00000.remoteproc:glink-edge:apr:service@7:dais: command[0x10dac] not expecting rsp q6asm-dai ab00000.remoteproc:glink-edge:apr:service@7:dais: command[0x10dac] not expecting rsp q6asm-dai ab00000.remoteproc:glink-edge:apr:service@7:dais: command[0x10dac] not expecting rsp
This is same for both write and eos.
Fix this by allowing ASM_DATA_CMD_READ_V2, ASM_DATA_CMD_EOS and ASM_DATA_CMD_WRITE_V2 as expected response.
Stable-dep-of: 8a066a81ee0c ("ASoC: qcom: q6asm: drop DSP responses for closed data streams")
--- sound/soc/qcom/qdsp6/q6asm.c | 5 +++++ 1 file changed, 5 insertions(+)
sound/soc/qcom/qdsp6/q6asm.c +5 -0
@@ -637,6 +637,7 @@ static int32_t q6asm_stream_callback(struct apr_device *adev, client_event =ASM_CLIENT_EVENT_CMD_OUT_FLUSH_DONE ;break ;case ASM_STREAM_CMD_OPEN_WRITE_V3 : +case ASM_DATA_CMD_WRITE_V2 :case ASM_STREAM_CMD_OPEN_READ_V3 :case ASM_STREAM_CMD_OPEN_READWRITE_V2 :case ASM_STREAM_CMD_SET_ENCDEC_PARAM :
@@ -653,6 +654,10 @@ static int32_t q6asm_stream_callback(struct apr_device *adev, goto done; }break ; +case ASM_DATA_CMD_EOS : +case ASM_DATA_CMD_READ_V2 : +/* response as result of close stream */ +break ;default :dev_err (ac->dev,"command[0x%x] not expecting rsp\n" , result->opcode);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1558/1674 ASoC: qcom: q6asm: drop DSP responses for closed data streams
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cédric Bellegarde <[email protected]>
[ Upstream commit 8a066a81ee0c1b6cdbd81393536c3b2d19ccef25 ]
'Commit a354f030dbce ("ASoC: qcom: q6asm: handle the responses after closing")' attempted to ignore DSP responses arriving after a stream had been closed.
However, those responses were still handled, causing lockups.
Fix this by unconditionally dropping all DSP responses associated with closed data streams.
--- sound/soc/qcom/qdsp6/q6asm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/soc/qcom/qdsp6/q6asm.c +2 -2
@@ -637,7 +637,6 @@ static int32_t q6asm_stream_callback(struct apr_device *adev, client_event =ASM_CLIENT_EVENT_CMD_OUT_FLUSH_DONE ;break ;case ASM_STREAM_CMD_OPEN_WRITE_V3 : -case ASM_DATA_CMD_WRITE_V2 :case ASM_STREAM_CMD_OPEN_READ_V3 :case ASM_STREAM_CMD_OPEN_READWRITE_V2 :case ASM_STREAM_CMD_SET_ENCDEC_PARAM :
@@ -656,8 +655,9 @@ static int32_t q6asm_stream_callback(struct apr_device *adev,break ;case ASM_DATA_CMD_EOS :case ASM_DATA_CMD_READ_V2 : +case ASM_DATA_CMD_WRITE_V2 :/* response as result of close stream */ -break ; + goto done;default :dev_err (ac->dev,"command[0x%x] not expecting rsp\n" , result->opcode);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1559/1674 media: hantro: Disable multicore support
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Reichel <[email protected]>
[ Upstream commit ccdeb8d57f7fb3e5c05d72cb7dfb9bc78f09f542 ]
Avoid exposing equal Hantro video codecs to userspace. Equal video codecs allow scheduling work between the cores. For that kernel support is required, which does not yet exist. Until that is implemented avoid exposing each core separately to userspace so that multicore can be added in the future without breaking userspace ABI.
This was written with Rockchip RK3588 in mind (which has 4 Hantro H1 cores), but applies to all SoCs.
Stable-dep-of: e0203ddf9af7 ("media: verisilicon: Avoid G2 bus error while decoding H.264 and HEVC")
--- .../media/platform/verisilicon/hantro_drv.c | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+)
drivers/media/platform/verisilicon/hantro_drv.c +47 -0
@@ -987,6 +987,49 @@ static const struct media_device_ops hantro_m2m_media_ops = { .req_queue = v4l2_m2m_request_queue, }; +/* +* Some SoCs, like RK3588 have multiple identical Hantro cores, but the +* kernel is currently missing support for multi-core handling. Exposing +* separate devices for each core to userspace is bad, since that does +* not allow scheduling tasks properly (and creates ABI). With this workaround +* the driver will only probe for the first core and early exit for the other +* cores. Once the driver gains multi-core support, the same technique +* for detecting the main core can be used to cluster all cores together. +*/ +static int hantro_disable_multicore (struct hantro_dev *vpu) +{ +struct device_node *node =NULL ; +const char *compatible; +bool is_main_core; +int ret; + +/* Intentionally ignores the fallback strings */ + ret =of_property_read_string (vpu->dev->of_node,"compatible" , &compatible); +if (ret) +return ret; + +/* The first compatible and available node found is considered the main core */ +do { + node =of_find_compatible_node (node,NULL , compatible); +if (of_device_is_available (node)) +break ; + }while (node); + +if (!node) +return -EINVAL ; + + is_main_core = (vpu->dev->of_node == node); + +of_node_put (node); + +if (!is_main_core) { +dev_info (vpu->dev,"missing multi-core support, ignoring this instance\n" ); +return -ENODEV ; + } + +return 0 ; +} +static int hantro_probe (struct platform_device *pdev) {const struct of_device_id *match;
@@ -1006,6 +1049,10 @@ static int hantro_probe(struct platform_device *pdev) match =of_match_node (of_hantro_match, pdev->dev.of_node); vpu->variant = match->data; + ret =hantro_disable_multicore (vpu); +if (ret) +return ret; +/* * Support for nxp,imx8mq-vpu is kept for backwards compatibility * but it's deprecated. Please update your DTS file to use
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1560/1674 media: v4l2-mem2mem: Add a kref to the v4l2_m2m_dev structure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolas Dufresne <[email protected]>
[ Upstream commit db6b97a4f8041e479be9ef4b8b07022636c96f50 ]
Adding a reference count to the v4l2_m2m_dev structure allow safely sharing it across multiple hardware nodes. This can be used to prevent running jobs concurrently on m2m cores that have some internal resource sharing.
Stable-dep-of: e0203ddf9af7 ("media: verisilicon: Avoid G2 bus error while decoding H.264 and HEVC")
--- drivers/media/v4l2-core/v4l2-mem2mem.c | 23 +++++++++++++++++++++++ include/media/v4l2-mem2mem.h | 21 +++++++++++++++++++++ 2 files changed, 44 insertions(+)
drivers/media/v4l2-core/v4l2-mem2mem.c +23 -0
@@ -90,6 +90,7 @@ static const char * const m2m_entity_name[] = {* @job_work: worker to run queued jobs. * @job_queue_flags: flags of the queue status, %QUEUE_PAUSED. * @m2m_ops: driver callbacks +* @kref: device reference count */ struct v4l2_m2m_dev {struct v4l2_m2m_ctx *curr_ctx;
@@ -109,6 +110,8 @@ struct v4l2_m2m_dev {unsigned long job_queue_flags;const struct v4l2_m2m_ops *m2m_ops; + +struct kref kref; }; static struct v4l2_m2m_queue_ctx *get_queue_ctx(struct v4l2_m2m_ctx *m2m_ctx,
@@ -1207,6 +1210,7 @@ struct v4l2_m2m_dev *v4l2_m2m_init(const struct v4l2_m2m_ops *m2m_ops)INIT_LIST_HEAD (&m2m_dev->job_queue);spin_lock_init (&m2m_dev->job_spinlock);INIT_WORK (&m2m_dev->job_work, v4l2_m2m_device_run_work); +kref_init (&m2m_dev->kref);return m2m_dev; }
@@ -1218,6 +1222,25 @@ void v4l2_m2m_release(struct v4l2_m2m_dev *m2m_dev) }EXPORT_SYMBOL_GPL (v4l2_m2m_release); +void v4l2_m2m_get (struct v4l2_m2m_dev *m2m_dev) +{ +kref_get (&m2m_dev->kref); +} +EXPORT_SYMBOL_GPL (v4l2_m2m_get); + +static void v4l2_m2m_release_from_kref (struct kref *kref) +{ + struct v4l2_m2m_dev *m2m_dev = container_of(kref, struct v4l2_m2m_dev, kref); + +v4l2_m2m_release (m2m_dev); +} + +void v4l2_m2m_put (struct v4l2_m2m_dev *m2m_dev) +{ +kref_put (&m2m_dev->kref, v4l2_m2m_release_from_kref); +} +EXPORT_SYMBOL_GPL (v4l2_m2m_put); +struct v4l2_m2m_ctx *v4l2_m2m_ctx_init (struct v4l2_m2m_dev *m2m_dev,void *drv_priv,int (*queue_init)(void *priv,struct vb2_queue *src_vq,struct vb2_queue *dst_vq))
include/media/v4l2-mem2mem.h +21 -0
@@ -537,6 +537,27 @@ v4l2_m2m_register_media_controller(struct v4l2_m2m_dev *m2m_dev,*/ void v4l2_m2m_release (struct v4l2_m2m_dev *m2m_dev); +/** +* v4l2_m2m_get() - take a reference to the m2m_dev structure +* +* @m2m_dev: opaque pointer to the internal data to handle M2M context +* +* This is used to share the M2M device across multiple devices. This +* can be used to avoid scheduling two hardware nodes concurrently. +*/ +void v4l2_m2m_get (struct v4l2_m2m_dev *m2m_dev); + +/** +* v4l2_m2m_put() - remove a reference to the m2m_dev structure +* +* @m2m_dev: opaque pointer to the internal data to handle M2M context +* +* Once the M2M device has no more references, v4l2_m2m_release() will be +* called automatically. Users of this method should never call +* v4l2_m2m_release() directly. See v4l2_m2m_get() for more details. +*/ +void v4l2_m2m_put (struct v4l2_m2m_dev *m2m_dev); +/** * v4l2_m2m_ctx_init() - allocate and initialize a m2m context *
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1561/1674 media: verisilicon: Avoid G2 bus error while decoding H.264 and HEVC
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ming Qian <[email protected]>
[ Upstream commit e0203ddf9af7c8e170e1e99ce83b4dc07f0cd765 ]
For the i.MX8MQ platform, there is a hardware limitation: the g1 VPU and g2 VPU cannot decode simultaneously; otherwise, it will cause below bus error and produce corrupted pictures, even potentially lead to system hang.
[ 110.527986] hantro-vpu 38310000.video-codec: frame decode timed out. [ 110.583517] hantro-vpu 38310000.video-codec: bus error detected.
Therefore, it is necessary to ensure that g1 and g2 operate alternately. This allows for successful multi-instance decoding of H.264 and HEVC.
To achieve this, g1 and g2 share the same v4l2_m2m_dev, and then the v4l2_m2m_dev can handle the scheduling.
--- drivers/media/platform/verisilicon/hantro.h | 2 + .../media/platform/verisilicon/hantro_drv.c | 42 +++++++++++++++++-- .../media/platform/verisilicon/imx8m_vpu_hw.c | 8 ++++ 3 files changed, 49 insertions(+), 3 deletions(-)
drivers/media/platform/verisilicon/hantro.h +2 -0
@@ -77,6 +77,7 @@ struct hantro_irq {* @double_buffer: core needs double buffering * @legacy_regs: core uses legacy register set * @late_postproc: postproc must be set up at the end of the job +* @shared_devices: an array of device ids that cannot run concurrently */ struct hantro_variant {unsigned int enc_offset;
@@ -101,6 +102,7 @@ struct hantro_variant { unsigned int double_buffer : 1; unsigned int legacy_regs : 1; unsigned int late_postproc : 1; +const struct of_device_id *shared_devices; };/**
drivers/media/platform/verisilicon/hantro_drv.c +39 -3
72 lines not on this page · raw message
drivers/media/platform/verisilicon/imx8m_vpu_hw.c +8 -0
@@ -361,6 +361,12 @@ const struct hantro_variant imx8mq_vpu_variant = { .num_regs = ARRAY_SIZE(imx8mq_reg_names) }; +static const struct of_device_id imx8mq_vpu_shared_resources[]__initconst = { + { .compatible ="nxp,imx8mq-vpu-g1" , }, + { .compatible ="nxp,imx8mq-vpu-g2" , }, + {/* sentinel */ } +}; +const struct hantro_variant imx8mq_vpu_g1_variant = { .dec_fmts = imx8m_vpu_dec_fmts, .num_dec_fmts =ARRAY_SIZE (imx8m_vpu_dec_fmts),
@@ -374,6 +380,7 @@ const struct hantro_variant imx8mq_vpu_g1_variant = { .num_irqs = ARRAY_SIZE(imx8mq_irqs), .clk_names = imx8mq_g1_clk_names, .num_clocks = ARRAY_SIZE(imx8mq_g1_clk_names), + .shared_devices = imx8mq_vpu_shared_resources, };const struct hantro_variant imx8mq_vpu_g2_variant = {
@@ -389,6 +396,7 @@ const struct hantro_variant imx8mq_vpu_g2_variant = { .num_irqs = ARRAY_SIZE(imx8mq_g2_irqs), .clk_names = imx8mq_g2_clk_names, .num_clocks = ARRAY_SIZE(imx8mq_g2_clk_names), + .shared_devices = imx8mq_vpu_shared_resources, };const struct hantro_variant imx8mm_vpu_g1_variant = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1562/1674 netfilter: nfnetlink_queue: do shared-unconfirmed check before segmentation
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit 207b3ebacb6113acaaec0d171d5307032c690004 ]
Ulrich reports a regression with nfqueue:
If an application did not set the 'F_GSO' capability flag and a gso packet with an unconfirmed nf_conn entry is received all packets are now dropped instead of queued, because the check happens after skb_gso_segment(). In that case, we did have exclusive ownership of the skb and its associated conntrack entry. The elevated use count is due to skb_clone happening via skb_gso_segment().
Move the check so that its peformed vs. the aggregated packet.
Then, annotate the individual segments except the first one so we can do a 2nd check at reinject time.
For the normal case, where userspace does in-order reinjects, this avoids packet drops: first reinjected segment continues traversal and confirms entry, remaining segments observe the confirmed entry.
While at it, simplify nf_ct_drop_unconfirmed(): We only care about unconfirmed entries with a refcnt > 1, there is no need to special-case dying entries.
This only happens with UDP. With TCP, the only unconfirmed packet will be the TCP SYN, those aren't aggregated by GRO.
Next patch adds a udpgro test case to cover this scenario.
--- include/net/netfilter/nf_queue.h | 1 + net/netfilter/nfnetlink_queue.c | 122 +++++++++++++++++++------------ 2 files changed, 75 insertions(+), 48 deletions(-)
include/net/netfilter/nf_queue.h +1 -0
@@ -21,6 +21,7 @@ struct nf_queue_entry {struct net_device *physout;#endif struct nf_hook_state state; +bool nf_ct_is_unconfirmed;u16 size;/* sizeof(entry) + saved route keys */ /* extra space to store route keys */
net/netfilter/nfnetlink_queue.c +74 -48
166 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1563/1674 hwrng: core - use RCU and work_struct to fix race condition
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lianjie Wang <[email protected]>
[ Upstream commit cc2f39d6ac48e6e3cb2d6240bc0d6df839dd0828 ]
Currently, hwrng_fill is not cleared until the hwrng_fillfn() thread exits. Since hwrng_unregister() reads hwrng_fill outside the rng_mutex lock, a concurrent hwrng_unregister() may call kthread_stop() again on the same task.
Additionally, if hwrng_unregister() is called immediately after hwrng_register(), the stopped thread may have never been executed. Thus, hwrng_fill remains dirty even after hwrng_unregister() returns. In this case, subsequent calls to hwrng_register() will fail to start new threads, and hwrng_unregister() will call kthread_stop() on the same freed task. In both cases, a use-after-free occurs:
refcount_t: addition on 0; use-after-free.
WARNING: ... at lib/refcount.c:25 refcount_warn_saturate+0xec/0x1c0
Call Trace: kthread_stop+0x181/0x360 hwrng_unregister+0x288/0x380 virtrng_remove+0xe3/0x200
This patch fixes the race by protecting the global hwrng_fill pointer inside the rng_mutex lock, so that hwrng_fillfn() thread is stopped only once, and calls to kthread_run() and kthread_stop() are serialized with the lock held.
To avoid deadlock in hwrng_fillfn() while being stopped with the lock held, we convert current_rng to RCU, so that get_current_rng() can read current_rng without holding the lock. To remove the lock from put_rng(), we also delay the actual cleanup into a work_struct.
Since get_current_rng() no longer returns ERR_PTR values, the IS_ERR() checks are removed from its callers.
With hwrng_fill protected by the rng_mutex lock, hwrng_fillfn() can no longer clear hwrng_fill itself. Therefore, if hwrng_fillfn() returns directly after current_rng is dropped, kthread_stop() would be called on a freed task_struct later. To fix this, hwrng_fillfn() calls schedule() now to keep the task alive until being stopped. The kthread_stop() call is also moved from hwrng_unregister() to drop_current_rng(), ensuring kthread_stop() is called on all possible paths where current_rng becomes NULL, so that the thread would not wait forever.
--- drivers/char/hw_random/core.c | 148 ++++++++++++++++++++++------------ include/linux/hw_random.h | 2 + 2 files changed, 99 insertions(+), 51 deletions(-)
drivers/char/hw_random/core.c +97 -51
@@ -20,23 +20,25 @@#include <linux/miscdevice.h> #include <linux/module.h> #include <linux/random.h> +#include <linux/rcupdate.h> #include <linux/sched.h> #include <linux/sched/signal.h> #include <linux/slab.h> #include <linux/string.h> #include <linux/uaccess.h> +#include <linux/workqueue.h> #define RNG_MODULE_NAME "hw_random"#define RNG_BUFFER_SIZE (SMP_CACHE_BYTES < 32 ? 32 : SMP_CACHE_BYTES) -static struct hwrng *current_rng; +static struct hwrng __rcu *current_rng;/* the current rng has been explicitly chosen by user via sysfs */ static int cur_rng_set_by_user;static struct task_struct *hwrng_fill;/* list of registered rngs */ static LIST_HEAD (rng_list); -/* Protects rng_list and current_rng */ +/* Protects rng_list, hwrng_fill and updating on current_rng */ static DEFINE_MUTEX (rng_mutex);/* Protects rng read functions, data_avail, rng_buffer and rng_fillbuf */ static DEFINE_MUTEX (reading_mutex);
@@ -77,18 +79,39 @@ static void add_early_randomness(struct hwrng *rng) } } -static inline void cleanup_rng (struct kref *kref) +static void cleanup_rng_work (struct work_struct *work) { - struct hwrng *rng = container_of(kref, struct hwrng, ref); + struct hwrng *rng = container_of(work, struct hwrng, cleanup_work); + +/* +* Hold rng_mutex here so we serialize in case they set_current_rng +* on rng again immediately. +*/ +mutex_lock (&rng_mutex); + +/* Skip if rng has been reinitialized. */ +if (kref_read (&rng->ref)) { +mutex_unlock (&rng_mutex); +return ; + }if (rng->cleanup) rng->cleanup (rng);complete (&rng->cleanup_done); +mutex_unlock (&rng_mutex); +} + +static inline void cleanup_rng (struct kref *kref) +{ + struct hwrng *rng = container_of(kref, struct hwrng, ref); + +schedule_work (&rng->cleanup_work); }static int set_current_rng (struct hwrng *rng) { +struct hwrng *old_rng;int err;BUG_ON (!mutex_is_locked (&rng_mutex));
@@ -97,8 +120,14 @@ static int set_current_rng(struct hwrng *rng)if (err)return err; -drop_current_rng (); - current_rng = rng; + old_rng =rcu_dereference_protected (current_rng, +lockdep_is_held (&rng_mutex)); +rcu_assign_pointer (current_rng, rng); + +if (old_rng) { +synchronize_rcu (); +kref_put (&old_rng->ref, cleanup_rng); + }/* if necessary, start hwrng thread */ if (!hwrng_fill) {
@@ -114,47 +143,56 @@ static int set_current_rng(struct hwrng *rng)static void drop_current_rng (void ) { -BUG_ON (!mutex_is_locked (&rng_mutex)); -if (!current_rng) +struct hwrng *rng; + + rng =rcu_dereference_protected (current_rng, +lockdep_is_held (&rng_mutex)); +if (!rng)return ; +RCU_INIT_POINTER (current_rng,NULL ); +synchronize_rcu (); + +if (hwrng_fill) { +kthread_stop (hwrng_fill); + hwrng_fill =NULL ; + } +/* decrease last reference for triggering the cleanup */ -kref_put (¤t_rng->ref, cleanup_rng); - current_rng =NULL ; +kref_put (&rng->ref, cleanup_rng); } -/* Returns ERR_PTR(), NULL or refcounted hwrng */ +/* Returns NULL or refcounted hwrng */ static struct hwrng *get_current_rng_nolock (void ) { -if (current_rng) -kref_get (¤t_rng->ref); +struct hwrng *rng; + + rng =rcu_dereference_protected (current_rng, +lockdep_is_held (&rng_mutex)); +if (rng) +kref_get (&rng->ref); -return current_rng; +return rng; }static struct hwrng *get_current_rng (void ) {struct hwrng *rng; -if (mutex_lock_interruptible (&rng_mutex)) -return ERR_PTR (-ERESTARTSYS ); +rcu_read_lock (); + rng =rcu_dereference (current_rng); +if (rng) +kref_get (&rng->ref); - rng =get_current_rng_nolock (); +rcu_read_unlock (); -mutex_unlock (&rng_mutex);return rng; }static void put_rng (struct hwrng *rng) { -/* -* Hold rng_mutex here so we serialize in case they set_current_rng -* on rng again immediately. -*/ -mutex_lock (&rng_mutex);if (rng)kref_put (&rng->ref, cleanup_rng); -mutex_unlock (&rng_mutex); }static int hwrng_init (struct hwrng *rng)
@@ -219,10 +257,6 @@ static ssize_t rng_dev_read(struct file *filp, char __user *buf,while (size) { rng =get_current_rng (); -if (IS_ERR (rng)) { - err =PTR_ERR (rng); - goto out; - }if (!rng) { err = -ENODEV ; goto out;
@@ -309,7 +343,7 @@ static struct miscdevice rng_miscdev = {static int enable_best_rng (void ) { -struct hwrng *rng, *new_rng =NULL ; +struct hwrng *rng, *cur_rng, *new_rng =NULL ;int ret = -ENODEV ;BUG_ON (!mutex_is_locked (&rng_mutex));
@@ -327,7 +361,9 @@ static int enable_best_rng(void) new_rng = rng; } - ret = ((new_rng == current_rng) ?0 :set_current_rng (new_rng)); + cur_rng =rcu_dereference_protected (current_rng, +lockdep_is_held (&rng_mutex)); + ret = ((new_rng == cur_rng) ?0 :set_current_rng (new_rng));if (!ret) cur_rng_set_by_user =0 ;
@@ -345,7 +381,8 @@ static ssize_t rng_current_store(struct device *dev,if (err)return -ERESTARTSYS ; - old_rng = current_rng; + old_rng =rcu_dereference_protected (current_rng, +lockdep_is_held (&rng_mutex));if (sysfs_streq (buf,"" )) { err =enable_best_rng (); }else {
@@ -378,8 +415,6 @@ static ssize_t rng_current_show(struct device *dev,struct hwrng *rng; rng =get_current_rng (); -if (IS_ERR (rng)) -return PTR_ERR (rng); ret =snprintf (buf,PAGE_SIZE ,"%s\n" , rng ? rng->name :"none" );put_rng (rng);
@@ -423,8 +458,6 @@ static ssize_t rng_quality_show(struct device *dev,struct hwrng *rng; rng =get_current_rng (); -if (IS_ERR (rng)) -return PTR_ERR (rng);if (!rng)/* no need to put_rng */ return -ENODEV ;
@@ -439,6 +472,7 @@ static ssize_t rng_quality_store(struct device *dev,struct device_attribute *attr, const char *buf, size_t len) { + struct hwrng *rng;u16 quality;int ret = -EINVAL ;
@@ -455,12 +489,13 @@ static ssize_t rng_quality_store(struct device *dev, goto out; } -if (!current_rng) { + rng =rcu_dereference_protected (current_rng,lockdep_is_held (&rng_mutex)); +if (!rng) { ret = -ENODEV ; goto out; } - current_rng->quality = quality; + rng->quality = quality; current_quality = quality;/* obsolete */ /* the best available RNG may have changed */
@@ -506,8 +541,20 @@ static int hwrng_fillfn(void *unused)struct hwrng *rng; rng =get_current_rng (); -if (IS_ERR (rng) || !rng) +if (!rng) { +/* +* Keep the task_struct alive until kthread_stop() +* is called to avoid UAF in drop_current_rng(). +*/ +while (!kthread_should_stop ()) { +set_current_state (TASK_INTERRUPTIBLE ); +if (!kthread_should_stop ()) +schedule (); + } +set_current_state (TASK_RUNNING );break ; + } +mutex_lock (&reading_mutex); rc =rng_get_data (rng, rng_fillbuf,rng_buffer_size (),1 );
@@ -535,14 +582,13 @@ static int hwrng_fillfn(void *unused)add_hwgenerator_randomness ((void *)rng_fillbuf, rc, entropy >>10 , true); } - hwrng_fill =NULL ;return 0 ; }int hwrng_register (struct hwrng *rng) {int err = -EINVAL ; -struct hwrng *tmp; +struct hwrng *cur_rng, *tmp;bool is_new_current = false;if (!rng->name || (!rng->data_read && !rng->read))
@@ -558,6 +604,7 @@ int hwrng_register(struct hwrng *rng) }list_add_tail (&rng->list, &rng_list); +INIT_WORK (&rng->cleanup_work, cleanup_rng_work);init_completion (&rng->cleanup_done);complete (&rng->cleanup_done);init_completion (&rng->dying);
@@ -565,8 +612,10 @@ int hwrng_register(struct hwrng *rng)/* Adjust quality field to always have a proper value */ rng->quality =min_t (u16,min_t (u16, default_quality,1024 ), rng->quality ?:1024 ); -if (!current_rng || - (!cur_rng_set_by_user && rng->quality > current_rng->quality)) { + cur_rng =rcu_dereference_protected (current_rng, +lockdep_is_held (&rng_mutex)); +if (!cur_rng || + (!cur_rng_set_by_user && rng->quality > cur_rng->quality)) {/* * Set new rng as current as the new rng source * provides better entropy quality and was not
@@ -611,10 +660,12 @@ void hwrng_unregister(struct hwrng *rng)mutex_lock (&rng_mutex); - old_rng = current_rng; + old_rng =rcu_dereference_protected (current_rng, +lockdep_is_held (&rng_mutex));list_del (&rng->list);complete_all (&rng->dying); -if (current_rng == rng) { + +if (old_rng == rng) { err =enable_best_rng ();if (err) {drop_current_rng ();
@@ -623,12 +674,7 @@ void hwrng_unregister(struct hwrng *rng) } new_rng =get_current_rng_nolock (); -if (list_empty (&rng_list)) { -mutex_unlock (&rng_mutex); -if (hwrng_fill) -kthread_stop (hwrng_fill); - }else -mutex_unlock (&rng_mutex); +mutex_unlock (&rng_mutex);if (new_rng) {if (old_rng != new_rng)
@@ -723,7 +769,7 @@ static int __init hwrng_modinit(void) static void __exit hwrng_modexit(void) {mutex_lock (&rng_mutex); -BUG_ON (current_rng); +WARN_ON (rcu_access_pointer (current_rng));kfree (rng_buffer);kfree (rng_fillbuf);mutex_unlock (&rng_mutex);
include/linux/hw_random.h +2 -0
@@ -16,6 +16,7 @@#include <linux/types.h> #include <linux/list.h> #include <linux/kref.h> +#include <linux/workqueue.h> /** * struct hwrng - Hardware Random Number Generator driver
@@ -49,6 +50,7 @@ struct hwrng {/* internal. */ struct list_head list;struct kref ref; +struct work_struct cleanup_work;struct completion cleanup_done;struct completion dying; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1564/1674 KVM: SVM: Add missing save/restore handling of LBR MSRs
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yosry Ahmed <[email protected]>
[ Upstream commit 3700f0788da6acf73b2df56690f4b201aa4aefd2 ]
MSR_IA32_DEBUGCTLMSR and LBR MSRs are currently not enumerated by KVM_GET_MSR_INDEX_LIST, and LBR MSRs cannot be set with KVM_SET_MSRS. So save/restore is completely broken.
Fix it by adding the MSRs to msrs_to_save_base, and allowing writes to LBR MSRs from userspace only (as they are read-only MSRs) if LBR virtualization is enabled. Additionally, to correctly restore L1's LBRs while L2 is running, make sure the LBRs are copied from the captured VMCB01 save area in svm_copy_vmrun_state().
Note, for VMX, this also fixes a flaw where MSR_IA32_DEBUGCTLMSR isn't reported as an MSR to save/restore.
Note #2, over-reporting MSR_IA32_LASTxxx on Intel is ok, as KVM already handles unsupported reads and writes thanks to commit b5e2fec0ebc3 ("KVM:
Ignore DEBUGCTL MSRs with no effect") (kvm_do_msr_access() will morph the unsupported userspace write into a nop).
--- arch/x86/kvm/svm/nested.c | 9 +++++++++ arch/x86/kvm/svm/svm.c | 42 ++++++++++++++++++++++++++++++++++----- arch/x86/kvm/x86.c | 13 ++++++++++++ 3 files changed, 59 insertions(+), 5 deletions(-)
arch/x86/kvm/svm/nested.c +9 -0
@@ -973,6 +973,15 @@ void svm_copy_vmrun_state(struct vmcb_save_area *to_save, to_save->rsp = from_save->rsp; to_save->rip = from_save->rip; to_save->cpl =0 ; + +if (kvm_cpu_cap_has (X86_FEATURE_LBRV )) { + to_save->dbgctl = from_save->dbgctl; + to_save->br_from = from_save->br_from; + to_save->br_to = from_save->br_to; + to_save->last_excp_from = from_save->last_excp_from; + to_save->last_excp_to = from_save->last_excp_to; + to_save->dbgctl &= ~DEBUGCTL_RESERVED_BITS ; + } }void svm_copy_vmloadsave_state (struct vmcb *to_vmcb,struct vmcb *from_vmcb)
arch/x86/kvm/svm/svm.c +37 -5
62 lines not on this page · raw message
arch/x86/kvm/x86.c +13 -0
@@ -1473,6 +1473,9 @@ static const u32 msrs_to_save_base[] = {MSR_IA32_UMWAIT_CONTROL ,MSR_IA32_XFD ,MSR_IA32_XFD_ERR , +MSR_IA32_DEBUGCTLMSR , +MSR_IA32_LASTBRANCHFROMIP ,MSR_IA32_LASTBRANCHTOIP , + MSR_IA32_LASTINTFROMIP, MSR_IA32_LASTINTTOIP, }; static const u32 msrs_to_save_pmu[] = {
@@ -1914,6 +1917,16 @@ static int kvm_set_msr_ignored_check(struct kvm_vcpu *vcpu, {int ret =__kvm_set_msr (vcpu, index, data, host_initiated); +if (ret ==KVM_MSR_RET_UNSUPPORTED && host_initiated && !data) { +switch (index) { +case MSR_IA32_LASTBRANCHFROMIP : +case MSR_IA32_LASTBRANCHTOIP : +case MSR_IA32_LASTINTFROMIP : +case MSR_IA32_LASTINTTOIP : +return 0 ; + } + } +if (ret ==KVM_MSR_RET_UNSUPPORTED )if (kvm_msr_ignored_check (index, data, true)) ret =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1565/1674 ceph: fix num_ops off-by-one when crypto allocation fails
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sam Edwards <[email protected]>
[ Upstream commit a0d9555bf9eaeba34fe6b6bb86f442fe08ba3842 ]
move_dirty_folio_in_page_array() may fail if the file is encrypted, the dirty folio is not the first in the batch, and it fails to allocate a bounce buffer to hold the ciphertext. When that happens, ceph_process_folio_batch() simply redirties the folio and flushes the current batch -- it can retry that folio in a future batch.
However, if this failed folio is not contiguous with the last folio that did make it into the batch, then ceph_process_folio_batch() has already incremented ceph_wbc->num_ops; because it doesn't follow through and add the discontiguous folio to the array, ceph_submit_write() -- which expects that ceph_wbc->num_ops accurately reflects the number of contiguous ranges (and therefore the required number of "write extent" ops) in the writeback -- will panic the kernel:
BUG_ON(ceph_wbc->op_idx + 1 != req->r_num_ops);
This issue can be reproduced on affected kernels by writing to fscrypt-enabled CephFS file(s) with a 4KiB-written/4KiB-skipped/repeat pattern (total filesize should not matter) and gradually increasing the system's memory pressure until a bounce buffer allocation fails.
Fix this crash by decrementing ceph_wbc->num_ops back to the correct value when move_dirty_folio_in_page_array() fails, but the folio already started counting a new (i.e. still-empty) extent.
The defect corrected by this patch has existed since 2022 (see first Fixes:), but another bug blocked multi-folio encrypted writeback until recently (see second Fixes:). The second commit made it into 6.18.16, 6.19.6, and 7.0-rc1, unmasking the panic in those versions. This patch therefore fixes a regression (panic) introduced by cac190c7674f.
--- fs/ceph/addr.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/ceph/addr.c +4 -0
@@ -1160,6 +1160,10 @@ static int ceph_writepages_start(struct address_space *mapping,/* better not fail on first page! */ BUG_ON (locked_pages ==0 ); pages[locked_pages] =NULL ; +/* Did we just begin a new contiguous op? Nevermind! */ +if (len ==0 ) + num_ops--; +redirty_page_for_writepage (wbc, page);unlock_page (page);break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1566/1674 greybus: raw: fix use-after-free if write is called after disconnect
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Damien Riégel <[email protected]>
[ Upstream commit 84265cbd96b97058ef67e3f8be3933667a000835 ]
If a user writes to the chardev after disconnect has been called, the kernel panics with the following trace (with CONFIG_INIT_ON_FREE_DEFAULT_ON=y):
BUG: kernel NULL pointer dereference, address: 0000000000000218
...
Call Trace:
<TASK>
gb_operation_create_common+0x61/0x180
gb_operation_create_flags+0x28/0xa0
gb_operation_sync_timeout+0x6f/0x100
raw_write+0x7b/0xc7 [gb_raw]
vfs_write+0xcf/0x420
? task_mm_cid_work+0x136/0x220
ksys_write+0x63/0xe0
do_syscall_64+0xa4/0x290
entry_SYSCALL_64_after_hwframe+0x77/0x7fDisconnect calls gb_connection_destroy, which ends up freeing the connection object. When gb_operation_sync is called in the write file operations, its gets a freed connection as parameter and the kernel panics.
The gb_connection_destroy cannot be moved out of the disconnect function, as the Greybus subsystem expect all connections belonging to a bundle to be destroyed when disconnect returns.
To prevent this bug, use a rw lock to synchronize access between write and disconnect. This guarantees that the write function doesn't try to use a disconnected connection.
--- drivers/staging/greybus/raw.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
drivers/staging/greybus/raw.c +21 -2
@@ -21,6 +21,8 @@ struct gb_raw {struct list_head list;int list_data;struct mutex list_lock; +struct rw_semaphore disconnect_lock; +bool disconnected;struct cdev cdev;struct device dev; };
@@ -197,6 +199,7 @@ static int gb_raw_probe(struct gb_bundle *bundle,INIT_LIST_HEAD (&raw->list);mutex_init (&raw->list_lock); +init_rwsem (&raw->disconnect_lock); raw->connection = connection;greybus_set_drvdata (bundle, raw);
@@ -232,6 +235,11 @@ static void gb_raw_disconnect(struct gb_bundle *bundle)struct raw_data *temp;cdev_device_del (&raw->cdev, &raw->dev); + +down_write (&raw->disconnect_lock); + raw->disconnected = true; +up_write (&raw->disconnect_lock); +gb_connection_disable (connection);gb_connection_destroy (connection);
@@ -274,11 +282,22 @@ static ssize_t raw_write(struct file *file, const char __user *buf,if (count >MAX_PACKET_SIZE )return -E2BIG ; +down_read (&raw->disconnect_lock); + +if (raw->disconnected) { + retval = -ENODEV ; + goto exit; + } + retval =gb_raw_send (raw, count, buf);if (retval) -return retval; + goto exit; -return count; + retval = count; +exit: +up_read (&raw->disconnect_lock); + +return retval; } static ssize_t raw_read(struct file *file, char __user *buf, size_t count,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1567/1674 netfilter: revalidate bridge ports
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit ccb9fd4b87538ccf19ccff78ee26700526d94867 ]
ebt_redirect_tg() dereferences br_port_get_rcu() return without a NULL check, causing a kernel panic when the bridge port has been removed between the original hook invocation and an NFQUEUE reinject.
A mere NULL check isn't sufficient, however. As sashiko review points out userspace can not only remove the port from the bridge, it could also place the device in a different virtual device, e.g. macvlan.
If this happens, we must drop the packet, there is no way for us to reinject it into the bridge path.
Switch to _upper API, we don't need the bridge port structure. Also, this fix keeps another bug intact:
Both nfnetlink_log and nfnetlink_queue use CONFIG_BRIDGE_NETFILTER too aggressive, which prevents certain logging features when queueing in bridge family: NETFILTER_FAMILY_BRIDGE can be enabled while the old CONFIG_BRIDGE_NETFILTER cruft is off.
Fixes tag is a common ancestor, this was always broken.
--- net/bridge/netfilter/ebt_dnat.c | 4 +- net/bridge/netfilter/ebt_redirect.c | 16 +++++--- net/netfilter/nfnetlink_log.c | 23 +++++++++-- net/netfilter/nfnetlink_queue.c | 64 +++++++++++++++++++++++++---- 4 files changed, 89 insertions(+), 18 deletions(-)
net/bridge/netfilter/ebt_dnat.c +3 -1
@@ -39,7 +39,9 @@ ebt_dnat_tg(struct sk_buff *skb, const struct xt_action_param *par) dev =xt_in (par);break ;case NF_BR_PRE_ROUTING : - dev =br_port_get_rcu (xt_in (par))->br->dev; + dev =netdev_master_upper_dev_get_rcu (xt_in (par)); +if (!dev)/* bridge port removed? */ +return EBT_DROP ;break ;default : dev =NULL ;
net/bridge/netfilter/ebt_redirect.c +11 -5
@@ -24,12 +24,18 @@ ebt_redirect_tg(struct sk_buff *skb, const struct xt_action_param *par)if (skb_ensure_writable (skb,0 ))return EBT_DROP ; -if (xt_hooknum (par) !=NF_BR_BROUTING ) -/* rcu_read_lock()ed by nf_hook_thresh */ -ether_addr_copy (eth_hdr (skb)->h_dest, -br_port_get_rcu (xt_in (par))->br->dev->dev_addr); -else +if (xt_hooknum (par) !=NF_BR_BROUTING ) { +const struct net_device *dev; + + dev =netdev_master_upper_dev_get_rcu (xt_in (par)); +if (!dev) +return EBT_DROP ; + +ether_addr_copy (eth_hdr (skb)->h_dest, dev->dev_addr); + }else {ether_addr_copy (eth_hdr (skb)->h_dest,xt_in (par)->dev_addr); + } + skb->pkt_type =PACKET_HOST ;return info->target; }
net/netfilter/nfnetlink_log.c +19 -4
@@ -455,6 +455,23 @@ static int nfulnl_put_bridge(struct nfulnl_instance *inst, const struct sk_buffreturn -1 ; } +#if IS_ENABLED (CONFIG_BRIDGE_NETFILTER ) +static int nflog_put_master_ifindex (struct sk_buff *nlskb,int attr, +const struct net_device *dev) +{ +const struct net_device *upper; + +if (dev && !netif_is_bridge_port (dev)) +return 0 ; + + upper =netdev_master_upper_dev_get_rcu ((struct net_device *)dev); +if (upper &&nla_put_be32 (nlskb, attr,htonl (upper->ifindex))) +return -EMSGSIZE ; + +return 0 ; +} +#endif +/* This is an inline function, we don't really care about a long * list of arguments */ static inline int
@@ -509,8 +526,7 @@ __build_packet_message(struct nfnl_log_net *log,/* rcu_read_lock()ed by nf_hook_thresh or * nf_log_packet. */ - nla_put_be32(inst->skb, NFULA_IFINDEX_INDEV, - htonl(br_port_get_rcu(indev)->br->dev->ifindex))) + nflog_put_master_ifindex(inst->skb, NFULA_IFINDEX_INDEV, indev)) goto nla_put_failure; }else {int physinif;
@@ -546,8 +562,7 @@ __build_packet_message(struct nfnl_log_net *log,/* rcu_read_lock()ed by nf_hook_thresh or * nf_log_packet. */ - nla_put_be32(inst->skb, NFULA_IFINDEX_OUTDEV, - htonl(br_port_get_rcu(outdev)->br->dev->ifindex))) + nflog_put_master_ifindex(inst->skb, NFULA_IFINDEX_OUTDEV, outdev)) goto nla_put_failure; }else {struct net_device *physoutdev;
net/netfilter/nfnetlink_queue.c +56 -8
93 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1568/1674 erofs: fix use-after-free on sbi->sync_decompress
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gao Xiang <[email protected]>
[ Upstream commit 1aee05e814d292064bf5fa15733741040cdc48ba ]
z_erofs_decompress_kickoff() can race with filesystem unmount, causing a use-after-free on sbi->sync_decompress.
When I/O completes, z_erofs_endio() calls z_erofs_decompress_kickoff() to queue z_erofs_decompressqueue_work() asynchronously. Then, after all folios are unlocked, unmount workflow can proceed and sbi will be freed before accessing to sbi->sync_decompress.
Thread (unmount) I/O completion kworker
queue_work
z_erofs_decompressqueue_work
(all folios are unlocked)cleanup_mnt
..
erofs_kill_sb
erofs_sb_free
kfree(sbi)
access sbi->sync_decompress // UAF!!
--- fs/erofs/zdata.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/erofs/zdata.c +3 -3
@@ -1430,6 +1430,9 @@ static void z_erofs_decompress_kickoff(struct z_erofs_decompressqueue *io,if (atomic_add_return (bios, &io->pending_bios))return ;if (z_erofs_in_atomic ()) { +/* See `sync_decompress` in sysfs-fs-erofs for more details */ +if (sbi->opt.sync_decompress ==EROFS_SYNC_DECOMPRESS_AUTO ) + sbi->opt.sync_decompress =EROFS_SYNC_DECOMPRESS_FORCE_ON ;#ifdef CONFIG_EROFS_FS_PCPU_KTHREAD struct kthread_worker *worker;
@@ -1446,9 +1449,6 @@ static void z_erofs_decompress_kickoff(struct z_erofs_decompressqueue *io,#else queue_work (z_erofs_workqueue, &io->u.work);#endif -/* enable sync decompression for readahead */ -if (sbi->opt.sync_decompress ==EROFS_SYNC_DECOMPRESS_AUTO ) - sbi->opt.sync_decompress =EROFS_SYNC_DECOMPRESS_FORCE_ON ;return ; } gfp_flag =memalloc_noio_save ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1569/1674 net/handshake: hand off the pinned file reference to accept_doit
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit f4251190e58b209999c1ba9e6d2976136a1be055 ]
handshake_req_next() removes the request from the per-net pending list and drops hn_lock before handshake_nl_accept_doit() reads req->hr_sk->sk_socket and dereferences sock->file (once in FD_PREPARE() and again in get_file()). In that window a consumer running tls_handshake_cancel() followed by sockfd_put() (svc_sock_free) or __fput_sync() (xs_reset_transport) releases sock->file. sock_release() then runs sock_orphan(), zeroing sk_socket, and frees the struct socket. The accept-side code either reads NULL through sk_socket or chases freed memory.
The submit-side sock_hold() does not prevent this. sk_refcnt protects struct sock, but struct socket and sock->file are independently refcounted via the file descriptor the consumer owns. Pinning sk leaves sock and sock->file unprotected.
Retarget the accept-side dereferences at req->hr_file, which was pinned at submit time, instead of req->hr_sk->sk_socket->file. Pinning on its own is not sufficient: a consumer that cancels between handshake_req_next() returning and accept_doit reaching FD_PREPARE() takes the !remove_pending() branch in handshake_req_cancel() and drops hr_file before the accept side takes its own reference. Hand off an additional file reference inside handshake_req_next(), under hn_lock, so the accept side operates on a reference that no concurrent handshake_req_cancel() can revoke. FD_PREPARE() consumes that handed-off reference, either by transferring it to the new fd in fd_publish() or by dropping it in the cleanup destructor on error; the explicit get_file() that previously balanced FD_PREPARE() is therefore redundant and goes away.
Update handshake_req_cancel_test2 and _test3 to simulate the FD_PREPARE() consumption with an fput() so the kunit file-count assertions stay balanced.
--- net/handshake/handshake-test.c | 8 ++++++++ net/handshake/netlink.c | 6 +++--- net/handshake/request.c | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-)
net/handshake/handshake-test.c +8 -0
@@ -375,6 +375,10 @@ static void handshake_req_cancel_test2(struct kunit *test)/* Pretend to accept this request */ next =handshake_req_next (hn,HANDSHAKE_HANDLER_CLASS_TLSHD );KUNIT_ASSERT_PTR_EQ (test, req, next); +/* Simulate FD_PREPARE() consuming the file reference handed +* off by handshake_req_next(); see handshake_nl_accept_doit(). +*/ +fput (filp);/* Act */ result =handshake_req_cancel (sock->sk);
@@ -417,6 +421,10 @@ static void handshake_req_cancel_test3(struct kunit *test)/* Pretend to accept this request */ next =handshake_req_next (hn,HANDSHAKE_HANDLER_CLASS_TLSHD );KUNIT_ASSERT_PTR_EQ (test, req, next); +/* Simulate FD_PREPARE() consuming the file reference handed +* off by handshake_req_next(); see handshake_nl_accept_doit(). +*/ +fput (filp);/* Pretend to complete this request */ handshake_complete (next, -ETIMEDOUT ,NULL );
net/handshake/netlink.c +3 -3
@@ -92,7 +92,6 @@ int handshake_nl_accept_doit(struct sk_buff *skb, struct genl_info *info)struct net *net =sock_net (skb->sk);struct handshake_net *hn =handshake_pernet (net);struct handshake_req *req =NULL ; -struct socket *sock;int class, fd, err; err = -EOPNOTSUPP ;
@@ -109,9 +108,9 @@ int handshake_nl_accept_doit(struct sk_buff *skb, struct genl_info *info)if (!req) goto out_status; - sock = req->hr_sk->sk_socket; fd =get_unused_fd_flags (O_CLOEXEC );if (fd <0 ) { +fput (req->hr_file);/* drop ref from handshake_req_next() */ err = fd; goto out_complete; }
@@ -119,10 +118,11 @@ int handshake_nl_accept_doit(struct sk_buff *skb, struct genl_info *info) err = req->hr_proto->hp_accept (req, info, fd);if (err) {put_unused_fd (fd); +fput (req->hr_file);/* drop ref from handshake_req_next() */ goto out_complete; } -fd_install (fd,get_file (sock->file)); +fd_install (fd, req->hr_file);trace_handshake_cmd_accept (net, req, req->hr_sk, fd);return 0 ;
net/handshake/request.c +18 -0
@@ -182,6 +182,17 @@ static bool remove_pending(struct handshake_net *hn, struct handshake_req *req)return ret; } +/** +* handshake_req_next - Return the next queued handshake request +* @hn: per-net handshake state +* @class: handler class to match +* +* On a non-NULL return, the caller owns an extra reference +* on @req->hr_file. FD_PREPARE() consumes it on success; on +* the FD_PREPARE() failure path the caller must fput() it. +* +* Return: pointer to a removed handshake_req, or NULL. +*/ struct handshake_req *handshake_req_next (struct handshake_net *hn,int class) {struct handshake_req *req, *pos;
@@ -192,6 +203,13 @@ struct handshake_req *handshake_req_next(struct handshake_net *hn, int class)if (pos->hr_proto->hp_handler_class != class)continue ;__remove_pending_locked (hn, pos); +/* Hand off a file reference to the accept side under +* hn_lock. A concurrent handshake_req_cancel() can drop +* hr_file before accept reaches FD_PREPARE(); this extra +* reference keeps the file alive until FD_PREPARE() takes +* ownership. +*/ +get_file (pos->hr_file); req = pos;break ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1570/1674 cxl/region: Resolve region deletion races
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dan Williams <[email protected]>
[ Upstream commit 4dd86ca99ffcc413cbf79063fd9956ef54e0ca91 ]
Sungwoo noticed that the sysfs trigger to delete a region may try to delete a region multiple times. It also has no exclusion relative to the kernel releasing the region via CXL root device teardown.
Instead of installing new cxl root devres actions per region, use the existing root decoder unregistration event to remove all remaining regions. An xarray of regions replaces a devres list of regions.
This handles 3 separate issues with the old approach:
1/ sysfs users racing to delete the same region: no longer possible now
that the regions_lock is held over the lookup and deletion.
2/ multiple actions triggering deletion of the same region: solved by
erasing regions while holding @regions_lock, and only proceeding on successful erasure.
3/ userspace racing devres_release_all() to trigger the devres not found
warning: solved by sysfs unregistration not requiring a release action
--- drivers/cxl/core/core.h | 2 ++ drivers/cxl/core/port.c | 5 +++ drivers/cxl/core/region.c | 65 ++++++++++++++++++++++----------------- drivers/cxl/cxl.h | 4 +++ 4 files changed, 48 insertions(+), 28 deletions(-)
drivers/cxl/core/core.h +2 -0
@@ -28,6 +28,7 @@ int cxl_region_init(void);void cxl_region_exit (void );int cxl_get_poison_by_endpoint (struct cxl_port *port);struct cxl_region *cxl_dpa_to_region (const struct cxl_memdev *cxlmd,u64 dpa); +void kill_regions (struct cxl_root_decoder *cxlrd);#else static inline
@@ -42,6 +43,7 @@ static inline int cxl_get_poison_by_endpoint(struct cxl_port *port)static inline void cxl_decoder_kill_region (struct cxl_endpoint_decoder *cxled) { } +static inline void kill_regions (struct cxl_root_decoder *cxlrd) { };static inline int cxl_region_init (void ) {return 0 ;
drivers/cxl/core/port.c +5 -0
@@ -433,6 +433,8 @@ static void cxl_root_decoder_release(struct device *dev)if (atomic_read (&cxlrd->region_id) >=0 )memregion_free (atomic_read (&cxlrd->region_id)); +mutex_destroy (&cxlrd->regions_lock); +xa_destroy (&cxlrd->regions);__cxl_decoder_release (&cxlrd->cxlsd.cxld);kfree (cxlrd); }
@@ -1708,6 +1710,7 @@ struct cxl_root_decoder *cxl_root_decoder_alloc(struct cxl_port *port, cxlrd->calc_hb = calc_hb;mutex_init (&cxlrd->regions_lock); +xa_init (&cxlrd->regions); cxld = &cxlsd->cxld; cxld->dev.type = &cxl_decoder_root_type;
@@ -1894,6 +1897,8 @@ static void cxld_unregister(void *dev) cxled =to_cxl_endpoint_decoder (dev);cxl_decoder_kill_region (cxled); } +if (is_root_decoder (dev)) +kill_regions (to_cxl_root_decoder (dev));device_unregister (dev); }
drivers/cxl/core/region.c +37 -28
132 lines not on this page · raw message
drivers/cxl/cxl.h +4 -0
@@ -442,6 +442,8 @@ typedef struct cxl_dport *(*cxl_calc_hb_fn)(struct cxl_root_decoder *cxlrd,* @calc_hb: which host bridge covers the n'th position by granularity * @platform_data: platform specific configuration data * @regions_lock: sync region discovery, construction, and deletion +* @regions: regions to remove at root decoder destruct time +* @dead: root decoder dead to region creation * @cxlsd: base cxl switch decoder */ struct cxl_root_decoder {
@@ -450,6 +452,8 @@ struct cxl_root_decoder {cxl_calc_hb_fn calc_hb;void *platform_data;struct mutex regions_lock; +struct xarray regions; +bool dead;struct cxl_switch_decoder cxlsd; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1571/1674 Bluetooth: hci_core: Fix UAF in hci_unregister_dev()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jordan Walters <[email protected]>
[ Upstream commit 5edcc018fa6e80b2c478454a4a8229c23d67c181 ]
hci_unregister_dev() does not disable cmd_timer and ncmd_timer before the hci_dev structure is freed. If a timeout fires during device teardown, the callback dereferences freed memory (including the hdev->reset function pointer), leading to a use-after-free.
Add disable_delayed_work_sync() calls alongside the existing disable_work_sync() calls to ensure both timers are fully quiesced before teardown proceeds.
--- net/bluetooth/hci_core.c | 2 ++ 1 file changed, 2 insertions(+)
net/bluetooth/hci_core.c +2 -0
@@ -2713,6 +2713,8 @@ void hci_unregister_dev(struct hci_dev *hdev)cancel_work_sync (&hdev->tx_work);cancel_work_sync (&hdev->power_on);cancel_work_sync (&hdev->error_reset); +cancel_delayed_work_sync (&hdev->cmd_timer); +cancel_delayed_work_sync (&hdev->ncmd_timer);hci_cmd_sync_clear (hdev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1572/1674 btrfs: fix deadlock cloning inline extent when using flushoncommit
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Filipe Manana <[email protected]>
[ Upstream commit 532085d00eb54c074bdeae648b194765239f4d11 ]
In commit b48c980b6a7e ("btrfs: fix deadlock between reflink and transaction commit when using flushoncommit") a deadlock was fixed between reflinks and transaction commits when the fs is mounted with the flushoncommit option. This happened when we had to copy an inline extent's data to the destination file. However the issue was fixed only for the case where the destination offset is 0, it missed the case when the offset is greater than zero.
Fix this by ensuring we get i_size update whenever we copied an inline extent's data into the destination file.
Syzbot reported this with the following trace:
INFO: task kworker/u8:3:57 blocked for more than 143 seconds.
Not tainted syzkaller #0
"echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
task:kworker/u8:3 state:D stack:21600 pid:57 tgid:57 ppid:2 task_flags:0x4208160 flags:0x00080000
Workqueue: writeback wb_workfn (flush-btrfs-129)
Call Trace:
<TASK>
context_switch kernel/sched/core.c:5402 [inline]
__schedule+0x16f9/0x5500 kernel/sched/core.c:7204
__schedule_loop kernel/sched/core.c:7283 [inline]
schedule+0x164/0x360 kernel/sched/core.c:7298
wait_extent_bit fs/btrfs/extent-io-tree.c:905 [inline]
btrfs_lock_extent_bits+0x59c/0x700 fs/btrfs/extent-io-tree.c:2008
btrfs_lock_extent fs/btrfs/extent-io-tree.h:152 [inline]
btrfs_invalidate_folio+0x440/0xc00 fs/btrfs/inode.c:7718
extent_writepage fs/btrfs/extent_io.c:1848 [inline]
extent_write_cache_pages fs/btrfs/extent_io.c:2552 [inline]
btrfs_writepages+0x12f3/0x2410 fs/btrfs/extent_io.c:2684
do_writepages+0x32e/0x550 mm/page-writeback.c:2571
__writeback_single_inode+0x133/0x10e0 fs/fs-writeback.c:1764
writeback_sb_inodes+0x97f/0x1980 fs/fs-writeback.c:2056
wb_writeback+0x445/0xb00 fs/fs-writeback.c:2241
wb_do_writeback fs/fs-writeback.c:2388 [inline]
wb_workfn+0x3fd/0xf20 fs/fs-writeback.c:2428
process_one_work+0x98b/0x1630 kernel/workqueue.c:3318
process_scheduled_works kernel/workqueue.c:3401 [inline]
worker_thread+0xb49/0x1140 kernel/workqueue.c:3482
kthread+0x388/0x470 kernel/kthread.c:436
ret_from_fork+0x514/0xb70 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
</TASK>
INFO: task syz.0.145:8523 blocked for more than 143 seconds.
Not tainted syzkaller #0
"echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
task:syz.0.145 state:D stack:22752 pid:8523 tgid:8522 ppid:5850 task_flags:0x400140 flags:0x00080002
Call Trace:
<TASK>
context_switch kernel/sched/core.c:5402 [inline]
__schedule+0x16f9/0x5500 kernel/sched/core.c:7204
__schedule_loop kernel/sched/core.c:7283 [inline]
schedule+0x164/0x360 kernel/sched/core.c:7298
wb_wait_for_completion+0x3e8/0x790 fs/fs-writeback.c:227
__writeback_inodes_sb_nr+0x24c/0x2d0 fs/fs-writeback.c:2847
try_to_writeback_inodes_sb+0x9a/0xc0 fs/fs-writeback.c:2895
btrfs_start_delalloc_flush fs/btrfs/transaction.c:2182 [inline]
btrfs_commit_transaction+0x813/0x2fc0 fs/btrfs/transaction.c:2371
btrfs_sync_file+0xdf4/0x1230 fs/btrfs/file.c:1822
generic_write_sync include/linux/fs.h:2663 [inline]
btrfs_do_write_iter+0x6a9/0x840 fs/btrfs/file.c:1473
new_sync_write fs/read_write.c:595 [inline]
vfs_write+0x629/0xba0 fs/read_write.c:688
ksys_write+0x156/0x270 fs/read_write.c:740
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x15f/0x560 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f5a0bdece59
RSP: 002b:00007f5a0b446028 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00007f5a0c065fa0 RCX: 00007f5a0bdece59
RDX: 000000000000029f RSI: 0000200000000200 RDI: 0000000000000004
RBP: 00007f5a0be82d6f R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f5a0c066038 R14: 00007f5a0c065fa0 R15: 00007ffe149206b8
</TASK>
INFO: task syz.0.145:8539 blocked for more than 143 seconds.
Not tainted syzkaller #0
"echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
task:syz.0.145 state:D stack:23704 pid:8539 tgid:8522 ppid:5850 task_flags:0x400140 flags:0x00080002
Call Trace:
<TASK>
context_switch kernel/sched/core.c:5402 [inline]
__schedule+0x16f9/0x5500 kernel/sched/core.c:7204
__schedule_loop kernel/sched/core.c:7283 [inline]
schedule+0x164/0x360 kernel/sched/core.c:7298
wait_current_trans+0x39f/0x590 fs/btrfs/transaction.c:536
start_transaction+0xbd8/0x1820 fs/btrfs/transaction.c:716
clone_copy_inline_extent fs/btrfs/reflink.c:299 [inline]
btrfs_clone+0x1316/0x2540 fs/btrfs/reflink.c:574
btrfs_clone_files+0x271/0x3f0 fs/btrfs/reflink.c:795
btrfs_remap_file_range+0x76b/0x1320 fs/btrfs/reflink.c:948
vfs_clone_file_range+0x435/0x7b0 fs/remap_range.c:403
ioctl_file_clone fs/ioctl.c:239 [inline]
ioctl_file_clone_range fs/ioctl.c:257 [inline]
do_vfs_ioctl+0xe15/0x1540 fs/ioctl.c:544
__do_sys_ioctl fs/ioctl.c:595 [inline]
__se_sys_ioctl+0x82/0x170 fs/ioctl.c:583
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x15f/0x560 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f5a0bdece59
RSP: 002b:00007f5a0b425028 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 00007f5a0c066090 RCX: 00007f5a0bdece59
RDX: 00002000000000c0 RSI: 000000004020940d RDI: 0000000000000004
RBP: 00007f5a0be82d6f R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f5a0c066128 R14: 00007f5a0c066090 R15: 00007ffe149206b8
</TASK>--- fs/btrfs/reflink.c | 100 +++++++++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 44 deletions(-)
fs/btrfs/reflink.c +56 -44
@@ -179,6 +179,7 @@ static int clone_copy_inline_extent(struct inode *dst,struct btrfs_drop_extents_args drop_args = {0 };int ret;struct btrfs_key key; +bool copied_inline_to_page = false;if (new_key->offset >0 ) goto copy_to_page;
@@ -279,6 +280,60 @@ static int clone_copy_inline_extent(struct inode *dst, ret =btrfs_inode_set_file_extent_range (BTRFS_I (dst),0 , aligned_end); out:if (!ret && !trans) { +if (copied_inline_to_page && + new_key->offset + datal >i_size_read (dst)) { +/* +* If we copied the inline extent data to a page/folio +* beyond the i_size of the destination inode, then we +* need to increase the i_size before we start a +* transaction to update the inode item. This is to +* prevent a deadlock when the flushoncommit mount +* option is used, which happens like this: +* +* 1) Task A clones an inline extent from inode X to an +* offset of inode Y that is beyond Y's current +* i_size. This means we copied the inline extent's +* data to a folio of inode Y that is beyond its EOF, +* using the call above to copy_inline_to_page(); +* +* 2) Task B starts a transaction commit and calls +* btrfs_start_delalloc_flush() to flush delalloc; +* +* 3) The delalloc flushing sees the new dirty folio of +* inode Y and when it attempts to flush it, it ends +* up at extent_writepage() and sees that the offset +* of the folio is beyond the i_size of inode Y, so +* it attempts to invalidate the folio by calling +* folio_invalidate(), which ends up at btrfs' folio +* invalidate callback - btrfs_invalidate_folio(). +* There it tries to lock the folio's range in inode +* Y's extent io tree, but it blocks since it's +* currently locked by task A - during reflink we +* lock the inodes and the source and destination +* ranges after flushing all delalloc and waiting for +* ordered extent completion - after that we don't +* expect to have dirty folios in the ranges, the +* exception is if we have to copy an inline extent's +* data (because the destination offset is not zero); +* +* 4) Task A then does the 'goto out' below and attempts +* to start a transaction to update the inode item, +* and then it's blocked since the current +* transaction is in the TRANS_STATE_COMMIT_START +* state. Therefore task A has to wait for the +* current transaction to become unblocked (its +* state >= TRANS_STATE_UNBLOCKED). +* +* This leads to a deadlock - the task committing the +* transaction waiting for the delalloc flushing which +* is blocked during folio invalidation on the inode's +* extent lock and the reflink task waiting for the +* current transaction to be unblocked so that it can +* start a new one to update the inode item (while +* holding the extent lock). +*/ +i_size_write (dst, new_key->offset + datal); + }/* * No transaction here means we copied the inline extent into a * page of the destination inode.
@@ -313,50 +368,7 @@ static int clone_copy_inline_extent(struct inode *dst, ret =copy_inline_to_page (BTRFS_I (dst), new_key->offset, inline_data, size, datal, comp_type); - -/* -* If we copied the inline extent data to a page/folio beyond the i_size -* of the destination inode, then we need to increase the i_size before -* we start a transaction to update the inode item. This is to prevent a -* deadlock when the flushoncommit mount option is used, which happens -* like this: -* -* 1) Task A clones an inline extent from inode X to an offset of inode -* Y that is beyond Y's current i_size. This means we copied the -* inline extent's data to a folio of inode Y that is beyond its EOF, -* using the call above to copy_inline_to_page(); -* -* 2) Task B starts a transaction commit and calls -* btrfs_start_delalloc_flush() to flush delalloc; -* -* 3) The delalloc flushing sees the new dirty folio of inode Y and when -* it attempts to flush it, it ends up at extent_writepage() and sees -* that the offset of the folio is beyond the i_size of inode Y, so -* it attempts to invalidate the folio by calling folio_invalidate(), -* which ends up at btrfs' folio invalidate callback - -* btrfs_invalidate_folio(). There it tries to lock the folio's range -* in inode Y's extent io tree, but it blocks since it's currently -* locked by task A - during reflink we lock the inodes and the -* source and destination ranges after flushing all delalloc and -* waiting for ordered extent completion - after that we don't expect -* to have dirty folios in the ranges, the exception is if we have to -* copy an inline extent's data (because the destination offset is -* not zero); -* -* 4) Task A then does the 'goto out' below and attempts to start a -* transaction to update the inode item, and then it's blocked since -* the current transaction is in the TRANS_STATE_COMMIT_START state. -* Therefore task A has to wait for the current transaction to become -* unblocked (its state >= TRANS_STATE_UNBLOCKED). -* -* This leads to a deadlock - the task committing the transaction -* waiting for the delalloc flushing which is blocked during folio -* invalidation on the inode's extent lock and the reflink task waiting -* for the current transaction to be unblocked so that it can start a -* a new one to update the inode item (while holding the extent lock). -*/ -if (ret ==0 && new_key->offset + datal >i_size_read (dst)) -i_size_write (dst, new_key->offset + datal); + copied_inline_to_page = (ret ==0 ); goto out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1573/1674 md/raid1,raid10: fix bio accounting for split md cloned bios
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abd-Alrhman Masalkhi <[email protected]>
[ Upstream commit ba976e3501111d11c550848b3b7341a73035f582 ]
Use md_cloned_bio() to control bio accounting instead of relying on r1bio_existed in raid1 or the io_accounting flag in raid10.
The previous logic does not reliably reflect whether a bio is an md cloned bio. When a failed bio is split and resubmitted via bio_submit_split_bioset() on the error path, this can lead to either double accounting for md cloned bios, or missing accounting for bios returned from bio_submit_split_bioset()
Fix this by using md_cloned_bio() to detect md cloned bios and skip accounting accordingly.
--- drivers/md/raid1.c | 2 +- drivers/md/raid10.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/md/raid1.c +1 -1
@@ -1307,7 +1307,7 @@ static void raid1_read_request(struct mddev *mddev, struct bio *bio, } r1_bio->read_disk = rdisk; -if (!r1bio_existed) { +if (likely (!md_cloned_bio (mddev, bio))) {md_account_bio (mddev, &bio); r1_bio->master_bio = bio; }
drivers/md/raid10.c +4 -4
@@ -1164,7 +1164,7 @@ static bool regular_request_wait(struct mddev *mddev, struct r10conf *conf, }static void raid10_read_request (struct mddev *mddev,struct bio *bio, -struct r10bio *r10_bio,bool io_accounting) +struct r10bio *r10_bio) {struct r10conf *conf = mddev->private;struct bio *read_bio;
@@ -1241,7 +1241,7 @@ static void raid10_read_request(struct mddev *mddev, struct bio *bio, } slot = r10_bio->read_slot; -if (io_accounting) { +if (likely (!md_cloned_bio (mddev, bio))) {md_account_bio (mddev, &bio); r10_bio->master_bio = bio; }
@@ -1604,7 +1604,7 @@ static bool __make_request(struct mddev *mddev, struct bio *bio, int sectors) ret = true;if (bio_data_dir (bio) ==READ ) -raid10_read_request (mddev, bio, r10_bio, true); +raid10_read_request (mddev, bio, r10_bio);else ret =raid10_write_request (mddev, bio, r10_bio);
@@ -3027,7 +3027,7 @@ static void handle_read_error(struct mddev *mddev, struct r10bio *r10_bio)rdev_dec_pending (rdev, mddev); r10_bio->state =0 ; -raid10_read_request (mddev, r10_bio->master_bio, r10_bio, false); +raid10_read_request (mddev, r10_bio->master_bio, r10_bio);/* * allow_barrier after re-submit to ensure no sync io * can be issued while regular io pending.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1574/1674 md/raid1,raid10: fix error-path detection with md_cloned_bio()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abd-Alrhman Masalkhi <[email protected]>
[ Upstream commit 811545e0926d02a6a0b1a1258bb5544777c164d4 ]
Detect the error path using md_cloned_bio() instead of relying on r1_bio in raid1 or r10_bio->read_slot in raid10, which may be NULL or -1 after splitting and resubmitting a failed bio.
As a result, the error path may not be recognized and memory allocations can incorrectly use GFP_NOIO instead of (GFP_NOIO | __GFP_HIGH), which can lead to a deadlock under memory pressure.
--- drivers/md/raid1.c | 13 ++++++++++--- drivers/md/raid10.c | 20 ++++++++++++++------ 2 files changed, 24 insertions(+), 9 deletions(-)
drivers/md/raid1.c +10 -3
@@ -1220,11 +1220,18 @@ static void raid1_read_request(struct mddev *mddev, struct bio *bio,char b[BDEVNAME_SIZE ];/* -* If r1_bio is set, we are blocking the raid1d thread -* so there is a tiny risk of deadlock. So ask for +* An md cloned bio indicates we are in the error path. +* This is more reliable than checking r1_bio, which might +* be NULL even in the error path if a failed bio was split. +*/ +bool err_path =md_cloned_bio (mddev, bio); + +/* +* If we are in the error path, we are blocking the raid1d +* thread so there is a tiny risk of deadlock. So ask for * emergency memory if needed. */ -gfp_t gfp = r1_bio ? (GFP_NOIO | __GFP_HIGH) :GFP_NOIO ; +gfp_t gfp = err_path ? (GFP_NOIO | __GFP_HIGH) :GFP_NOIO ;if (r1bio_existed) {/* Need to get the block device name carefully */
drivers/md/raid10.c +14 -6
@@ -1173,7 +1173,20 @@ static void raid10_read_request(struct mddev *mddev, struct bio *bio,char b[BDEVNAME_SIZE ];int slot = r10_bio->read_slot;struct md_rdev *err_rdev =NULL ; -gfp_t gfp =GFP_NOIO ; + +/* +* An md cloned bio indicates we are in the error path. +* This is more reliable than checking slot, which might +* be -1 even in the error path if a failed bio was split. +*/ +bool err_path =md_cloned_bio (mddev, bio); + +/* +* If we are in the error path, we are blocking the raid10d +* thread so there is a tiny risk of deadlock. So ask for +* emergency memory if needed. +*/ +gfp_t gfp = err_path ? (GFP_NOIO | __GFP_HIGH) :GFP_NOIO ;int error;if (slot >=0 && r10_bio->devs[slot].rdev) {
@@ -1185,11 +1198,6 @@ static void raid10_read_request(struct mddev *mddev, struct bio *bio,* we lose the device name in error messages. */ int disk; -/* -* As we are blocking raid10, it is a little safer to -* use __GFP_HIGH. -*/ - gfp =GFP_NOIO | __GFP_HIGH;rcu_read_lock (); disk = r10_bio->devs[slot].devnum;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1575/1674 iommu: Pass domain to remove_dev_pasid() op
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yi Liu <[email protected]>
[ Upstream commit d2f85a263883b679f87ed8f911746105658e9c47 ]
Existing remove_dev_pasid() callbacks of the underlying iommu drivers get the attached domain from the group->pasid_array. However, the domain stored in group->pasid_array is not always correct in all scenarios. A wrong domain may result in failure in remove_dev_pasid() callback. To avoid such problems, it is more reliable to pass the domain to the remove_dev_pasid() op.
Stable-dep-of: 530f8f9c3546 ("iommu/sva: Set handle->dev before the SVA handle is visible")
--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 9 ++------- drivers/iommu/intel/iommu.c | 11 +++-------- drivers/iommu/iommu.c | 9 +++++---- include/linux/iommu.h | 3 ++- 4 files changed, 12 insertions(+), 20 deletions(-)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +2 -7
@@ -2864,14 +2864,9 @@ static int arm_smmu_def_domain_type(struct device *dev)return 0 ; } -static void arm_smmu_remove_dev_pasid (struct device *dev,ioasid_t pasid) +static void arm_smmu_remove_dev_pasid (struct device *dev,ioasid_t pasid, +struct iommu_domain *domain) { -struct iommu_domain *domain; - - domain =iommu_get_domain_for_dev_pasid (dev, pasid,IOMMU_DOMAIN_SVA ); -if (WARN_ON (IS_ERR (domain)) || !domain) -return ; -arm_smmu_sva_remove_dev_pasid (domain, dev, pasid); }
drivers/iommu/intel/iommu.c +3 -8
@@ -4722,18 +4722,14 @@ static void intel_iommu_iotlb_sync_map(struct iommu_domain *domain,__mapping_notify_one (info->iommu, dmar_domain, pfn, pages); } -static void intel_iommu_remove_dev_pasid (struct device *dev,ioasid_t pasid) +static void intel_iommu_remove_dev_pasid (struct device *dev,ioasid_t pasid, +struct iommu_domain *domain) {struct intel_iommu *iommu =device_to_iommu (dev,NULL ,NULL ); +struct dmar_domain *dmar_domain =to_dmar_domain (domain);struct dev_pasid_info *curr, *dev_pasid =NULL ; -struct dmar_domain *dmar_domain; -struct iommu_domain *domain;unsigned long flags; - domain =iommu_get_domain_for_dev_pasid (dev, pasid,0 ); -if (WARN_ON_ONCE (!domain)) - goto out_tear_down; -/* * The SVA implementation needs to handle its own stuffs like the mm * notification. Before consolidating that code into iommu core, let
@@ -4744,7 +4740,6 @@ static void intel_iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid) goto out_tear_down; } - dmar_domain =to_dmar_domain (domain);spin_lock_irqsave (&dmar_domain->lock, flags);list_for_each_entry (curr, &dmar_domain->dev_pasids, link_domain) {if (curr->dev == dev && curr->pasid == pasid) {
drivers/iommu/iommu.c +5 -4
@@ -3407,20 +3407,21 @@ static int __iommu_set_group_pasid(struct iommu_domain *domain,if (device == last_gdev)break ; - ops->remove_dev_pasid (device->dev, pasid); + ops->remove_dev_pasid (device->dev, pasid, domain); }return ret; }static void __iommu_remove_group_pasid (struct iommu_group *group, -ioasid_t pasid) +ioasid_t pasid, +struct iommu_domain *domain) {struct group_device *device;const struct iommu_ops *ops;for_each_group_device (group, device) { ops =dev_iommu_ops (device->dev); - ops->remove_dev_pasid (device->dev, pasid); + ops->remove_dev_pasid (device->dev, pasid, domain); } }
@@ -3479,7 +3480,7 @@ void iommu_detach_device_pasid(struct iommu_domain *domain, struct device *dev,struct iommu_group *group =iommu_group_get (dev);mutex_lock (&group->mutex); -__iommu_remove_group_pasid (group, pasid); +__iommu_remove_group_pasid (group, pasid, domain);WARN_ON (xa_erase (&group->pasid_array, pasid) != domain);mutex_unlock (&group->mutex);
include/linux/iommu.h +2 -1
@@ -289,7 +289,8 @@ struct iommu_ops { struct iommu_page_response *msg);int (*def_domain_type)(struct device *dev); -void (*remove_dev_pasid)(struct device *dev,ioasid_t pasid); +void (*remove_dev_pasid)(struct device *dev,ioasid_t pasid, +struct iommu_domain *domain);const struct iommu_domain_ops *default_domain_ops;unsigned long pgsize_bitmap;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1576/1674 iommu/sva: Set handle->dev before the SVA handle is visible
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuai Xue <[email protected]>
[ Upstream commit 530f8f9c3546cb3ebee1b135375aaee08a073ebb ]
iommu_attach_device_pasid() installs the new SVA attach handle in the group PASID lookup before iommu_sva_bind_device() returns. A concurrent bind can therefore find and reuse the same handle after iommu_sva_lock is dropped.
handle->dev was initialized after dropping iommu_sva_lock. This leaves a window where a racing bind can return a handle whose dev pointer is still NULL. A subsequent iommu_sva_unbind_device() can then dereference it via handle->dev->iommu_group.
Initialize handle->dev before releasing iommu_sva_lock so any visible SVA handle is fully initialized.
--- drivers/iommu/iommu-sva.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/iommu/iommu-sva.c +1 -2
@@ -100,10 +100,9 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm goto out_free_domain; domain->users =1 ; out: -mutex_unlock (&iommu_sva_lock); handle->dev = dev; handle->domain = domain; - +mutex_unlock (&iommu_sva_lock);return handle; out_free_domain:
Signature · 1 line
2.53.0