5.10.253-rc1 review
Subsystems (9)
Greg Kroah-Hartman
maintainerPATCH 422/491 mm/hugetlb: fix two comments related to huge_pmd_unshare()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Red Hat) <[email protected]>
Ever since we stopped using the page count to detect shared PMD page tables, these comments are outdated.
The only reason we have to flush the TLB early is because once we drop the i_mmap_rwsem, the previously shared page table could get freed (to then get reallocated and used for other purpose). So we really have to flush the TLB before that could happen.
So let's simplify the comments a bit.
The "If we unshared PMDs, the TLB flush was not recorded in mmu_gather." part introduced as in commit a4a118f2eead ("hugetlbfs: flush TLBs correctly after huge_pmd_unshare") was confusing: sure it is recorded in the mmu_gather, otherwise tlb_flush_mmu_tlbonly() wouldn't do anything. So let's drop that comment while at it as well.
We'll centralize these comments in a single helper as we rework the code next.
--- mm/hugetlb.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-)
mm/hugetlb.c +8 -16
@@ -4027,17 +4027,10 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,tlb_end_vma (tlb, vma);/* -* If we unshared PMDs, the TLB flush was not recorded in mmu_gather. We -* could defer the flush until now, since by holding i_mmap_rwsem we -* guaranteed that the last refernece would not be dropped. But we must -* do the flushing before we return, as otherwise i_mmap_rwsem will be -* dropped and the last reference to the shared PMDs page might be -* dropped as well. -* -* In theory we could defer the freeing of the PMD pages as well, but -* huge_pmd_unshare() relies on the exact page_count for the PMD page to -* detect sharing, so we cannot defer the release of the page either. -* Instead, do flush now. +* There is nothing protecting a previously-shared page table that we +* unshared through huge_pmd_unshare() from getting freed after we +* release i_mmap_rwsem, so flush the TLB now. If huge_pmd_unshare() +* succeeded, flush the range corresponding to the pud. */ if (force_flush)tlb_flush_mmu_tlbonly (tlb);
@@ -5113,11 +5106,10 @@ unsigned long hugetlb_change_protection(struct vm_area_struct *vma,cond_resched (); }/* -* Must flush TLB before releasing i_mmap_rwsem: x86's huge_pmd_unshare -* may have cleared our pud entry and done put_page on the page table: -* once we release i_mmap_rwsem, another task can do the final put_page -* and that page table be reused and filled with junk. If we actually -* did unshare a page of pmds, flush the range corresponding to the pud. +* There is nothing protecting a previously-shared page table that we +* unshared through huge_pmd_unshare() from getting freed after we +* release i_mmap_rwsem, so flush the TLB now. If huge_pmd_unshare() +* succeeded, flush the range corresponding to the pud. */ if (shared_pmd)flush_hugetlb_tlb_range (vma, range.start, range.end);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 423/491 mm/rmap: fix two comments related to huge_pmd_unshare()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Red Hat) <[email protected]>
PMD page table unsharing no longer touches the refcount of a PMD page table. Also, it is not about dropping the refcount of a "PMD page" but the "PMD page table".
Let's just simplify by saying that the PMD page table was unmapped, consequently also unmapping the folio that was mapped into this page.
This code should be deduplicated in the future.
[ David: We don't have 40549ba8f8e0 ("hugetlb: use new vma_lock
for pmd sharing synchronization") and a98a2f0c8ce1 ("mm/rmap: split migration into its own so changes in mm/rmap.c looks quite different. ]
--- mm/rmap.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
mm/rmap.c +2 -7
@@ -1490,13 +1490,8 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, range.end);/* -* The ref count of the PMD page was dropped -* which is part of the way map counting -* is done for shared PMDs. Return 'true' -* here. When there is no other sharing, -* huge_pmd_unshare returns false and we will -* unmap the actual page and drop map count -* to zero. +* The PMD table was unmapped, +* consequently unmapping the folio. */ page_vma_mapped_walk_done (&pvmw);break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 424/491 mm/hugetlb: fix excessive IPI broadcasts when unsharing PMD tables using mmu_gather
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Red Hat) <[email protected]>
commit 8ce720d5bd91e9dc16db3604aa4b1bf76770a9a1 upstream.
As reported, ever since commit 1013af4f585f ("mm/hugetlb: fix huge_pmd_unshare() vs GUP-fast race") we can end up in some situations where we perform so many IPI broadcasts when unsharing hugetlb PMD page tables that it severely regresses some workloads.
In particular, when we fork()+exit(), or when we munmap() a large area backed by many shared PMD tables, we perform one IPI broadcast per unshared PMD table.
There are two optimizations to be had:
(1) When we process (unshare) multiple such PMD tables, such as during exit(), it is sufficient to send a single IPI broadcast (as long as we respect locking rules) instead of one per PMD table.
Locking prevents that any of these PMD tables could get reused before we drop the lock.
(2) When we are not the last sharer (> 2 users including us), there is no need to send the IPI broadcast. The shared PMD tables cannot become exclusive (fully unshared) before an IPI will be broadcasted by the last sharer.
Concurrent GUP-fast could walk into a PMD table just before we unshared it. It could then succeed in grabbing a page from the shared page table even after munmap() etc succeeded (and supressed an IPI). But there is not difference compared to GUP-fast just sleeping for a while after grabbing the page and re-enabling IRQs.
Most importantly, GUP-fast will never walk into page tables that are no-longer shared, because the last sharer will issue an IPI broadcast.
(if ever required, checking whether the PUD changed in GUP-fast
after grabbing the page like we do in the PTE case could handle this)
So let's rework PMD sharing TLB flushing + IPI sync to use the mmu_gather infrastructure so we can implement these optimizations and demystify the code at least a bit. Extend the mmu_gather infrastructure to be able to deal with our special hugetlb PMD table sharing implementation.
To make initialization of the mmu_gather easier when working on a single VMA (in particular, when dealing with hugetlb), provide tlb_gather_mmu_vma().
We'll consolidate the handling for (full) unsharing of PMD tables in tlb_unshare_pmd_ptdesc() and tlb_flush_unshared_tables(), and track in "struct mmu_gather" whether we had (full) unsharing of PMD tables.
Because locking is very special (concurrent unsharing+reuse must be prevented), we disallow deferring flushing to tlb_finish_mmu() and instead require an explicit earlier call to tlb_flush_unshared_tables().
Quoted 1 line
From hugetlb code, we call
huge_pmd_unshare_flush()where we make sure
that the expected lock protecting us from concurrent unsharing+reuse is still held.
Check with a VM_WARN_ON_ONCE() in tlb_finish_mmu() that tlb_flush_unshared_tables() was properly called earlier.
Document it all properly.
Notes about tlb_remove_table_sync_one() interaction with unsharing:
There are two fairly tricky things:
(1) tlb_remove_table_sync_one() is a NOP on architectures without CONFIG_MMU_GATHER_RCU_TABLE_FREE.
Here, the assumption is that the previous TLB flush would send an IPI to all relevant CPUs. Careful: some architectures like x86 only send IPIs to all relevant CPUs when tlb->freed_tables is set.
The relevant architectures should be selecting MMU_GATHER_RCU_TABLE_FREE, but x86 might not do that in stable kernels and it might have been problematic before this patch.
Also, the arch flushing behavior (independent of IPIs) is different when tlb->freed_tables is set. Do we have to enlighten them to also take care of tlb->unshared_tables? So far we didn't care, so hopefully we are fine. Of course, we could be setting tlb->freed_tables as well, but that might then unnecessarily flush too much, because the semantics of tlb->freed_tables are a bit fuzzy.
This patch changes nothing in this regard.
(2) tlb_remove_table_sync_one() is not a NOP on architectures with CONFIG_MMU_GATHER_RCU_TABLE_FREE that actually don't need a sync.
Take x86 as an example: in the common case (!pv, !X86_FEATURE_INVLPGB) we still issue IPIs during TLB flushes and don't actually need the second tlb_remove_table_sync_one().
This optimized can be implemented on top of this, by checking e.g., in tlb_remove_table_sync_one() whether we really need IPIs. But as described in (1), it really must honor tlb->freed_tables then to send IPIs to all relevant CPUs.
Notes on TLB flushing changes:
(1) Flushing for non-shared PMD tables
We're converting from flush_hugetlb_tlb_range() to tlb_remove_huge_tlb_entry(). Given that we properly initialize the MMU gather in tlb_gather_mmu_vma() to be hugetlb aware, similar to __unmap_hugepage_range(), that should be fine.
(2) Flushing for shared PMD tables
We're converting from various things (flush_hugetlb_tlb_range(), tlb_flush_pmd_range(), flush_tlb_range()) to tlb_flush_pmd_range().
tlb_flush_pmd_range() achieves the same that tlb_remove_huge_tlb_entry() would achieve in these scenarios. Note that tlb_remove_huge_tlb_entry() also calls __tlb_remove_tlb_entry(), however that is only implemented on powerpc, which does not support PMD table sharing.
Similar to (1), tlb_gather_mmu_vma() should make sure that TLB flushing keeps on working as expected.
Further, note that the ptdesc_pmd_pts_dec() in huge_pmd_share() is not a concern, as we are holding the i_mmap_lock the whole time, preventing concurrent unsharing. That ptdesc_pmd_pts_dec() usage will be removed separately as a cleanup later.
There are plenty more cleanups to be had, but they have to wait until this is fixed.
[ David: We don't have ptdesc and the wrappers, so work directly on
page->pt_share_count and pass "struct page" instead of "struct ptdesc". CONFIG_HUGETLB_PMD_PAGE_TABLE_SHARING is still called CONFIG_ARCH_WANT_HUGE_PMD_SHARE and is set even without CONFIG_HUGETLB_PAGE. We don't have 550a7d60bd5e ("mm, hugepages: add mremap() support for hugepage backed vma"), so move_hugetlb_page_tables() does not exist. We don't have 40549ba8f8e0 ("hugetlb: use new vma_lock for pmd sharing synchronization") and a98a2f0c8ce1 ("mm/rmap: split migration into its own so changes in mm/rmap.c looks quite different. We don't have 4ddb4d91b82f ("hugetlb: do not update address
in huge_pmd_unshare"), so huge_pmd_unshare() still gets a pointer to an address. tlb_gather_mmu() + tlb_finish_mmu() still consume ranges, so also teach tlb_gather_mmu_vma() to forward ranges. Some smaller contextual stuff, in particular, around tlb_gather_mmu_full(). ]
--- include/asm-generic/tlb.h | 77 ++++++++++++++++++++++++++- include/linux/hugetlb.h | 15 ++++-- include/linux/mm_types.h | 2 + mm/hugetlb.c | 108 ++++++++++++++++++++++---------------- mm/mmu_gather.c | 36 +++++++++++++ mm/rmap.c | 11 ++-- 6 files changed, 195 insertions(+), 54 deletions(-)
include/asm-generic/tlb.h +75 -2
@@ -46,7 +46,8 @@* * The mmu_gather API consists of: * -* - tlb_gather_mmu() / tlb_finish_mmu(); start and finish a mmu_gather +* - tlb_gather_mmu() / tlb_gather_mmu_vma() / tlb_finish_mmu(); start and +* finish a mmu_gather * * Finish in particular will issue a (final) TLB invalidate and free * all (remaining) queued pages.
@@ -291,6 +292,20 @@ struct mmu_gather { unsigned int vma_exec : 1; unsigned int vma_huge : 1; +/* +* Did we unshare (unmap) any shared page tables? For now only +* used for hugetlb PMD table sharing. +*/ + unsigned int unshared_tables : 1; + +/* +* Did we unshare any page tables such that they are now exclusive +* and could get reused+modified by the new owner? When setting this +* flag, "unshared_tables" will be set as well. For now only used +* for hugetlb PMD table sharing. +*/ + unsigned int fully_unshared_tables : 1; +unsigned int batch_count;#ifndef CONFIG_MMU_GATHER_NO_GATHER
@@ -327,6 +342,7 @@ static inline void __tlb_reset_range(struct mmu_gather *tlb) tlb->cleared_pmds =0 ; tlb->cleared_puds =0 ; tlb->cleared_p4ds =0 ; + tlb->unshared_tables =0 ;/* * Do not reset mmu_gather::vma_* fields here, we do not * call into tlb_start_vma() again to set them if there is an
@@ -422,7 +438,7 @@ static inline void tlb_flush_mmu_tlbonly(struct mmu_gather *tlb)* these bits. */ if (!(tlb->freed_tables || tlb->cleared_ptes || tlb->cleared_pmds || - tlb->cleared_puds || tlb->cleared_p4ds)) + tlb->cleared_puds || tlb->cleared_p4ds || tlb->unshared_tables))return ;tlb_flush (tlb);
@@ -660,6 +676,63 @@ static inline void tlb_flush_p4d_range(struct mmu_gather *tlb, } while (0)#endif +#if defined(CONFIG_ARCH_WANT_HUGE_PMD_SHARE ) && defined(CONFIG_HUGETLB_PAGE ) +static inline void tlb_unshare_pmd_ptdesc (struct mmu_gather *tlb,struct page *pt, +unsigned long addr) +{ +/* +* The caller must make sure that concurrent unsharing + exclusive +* reuse is impossible until tlb_flush_unshared_tables() was called. +*/ +VM_WARN_ON_ONCE (!atomic_read (&pt->pt_share_count)); +atomic_dec (&pt->pt_share_count); + +/* Clearing a PUD pointing at a PMD table with PMD leaves. */ +tlb_flush_pmd_range (tlb, addr &PUD_MASK ,PUD_SIZE ); + +/* +* If the page table is now exclusively owned, we fully unshared +* a page table. +*/ +if (!atomic_read (&pt->pt_share_count)) + tlb->fully_unshared_tables = true; + tlb->unshared_tables = true; +} + +static inline void tlb_flush_unshared_tables (struct mmu_gather *tlb) +{ +/* +* As soon as the caller drops locks to allow for reuse of +* previously-shared tables, these tables could get modified and +* even reused outside of hugetlb context, so we have to make sure that +* any page table walkers (incl. TLB, GUP-fast) are aware of that +* change. +* +* Even if we are not fully unsharing a PMD table, we must +* flush the TLB for the unsharer now. +*/ +if (tlb->unshared_tables) +tlb_flush_mmu_tlbonly (tlb); + +/* +* Similarly, we must make sure that concurrent GUP-fast will not +* walk previously-shared page tables that are getting modified+reused +* elsewhere. So broadcast an IPI to wait for any concurrent GUP-fast. +* +* We only perform this when we are the last sharer of a page table, +* as the IPI will reach all CPUs: any GUP-fast. +* +* Note that on configs where tlb_remove_table_sync_one() is a NOP, +* the expectation is that the tlb_flush_mmu_tlbonly() would have issued +* required IPIs already for us. +*/ +if (tlb->fully_unshared_tables) { +tlb_remove_table_sync_one (); + tlb->fully_unshared_tables = false; + } +} +#endif +#endif /* CONFIG_MMU */ #endif /* _ASM_GENERIC__TLB_H */
include/linux/hugetlb.h +10 -5
@@ -166,8 +166,9 @@ pte_t *huge_pte_alloc(struct mm_struct *mm, unsigned long addr, unsigned long sz);pte_t *huge_pte_offset (struct mm_struct *mm,unsigned long addr,unsigned long sz); -int huge_pmd_unshare (struct mm_struct *mm,struct vm_area_struct *vma, -unsigned long *addr,pte_t *ptep); +int huge_pmd_unshare (struct mmu_gather *tlb,struct vm_area_struct *vma, +unsigned long *addr,pte_t *ptep); +void huge_pmd_unshare_flush (struct mmu_gather *tlb,struct vm_area_struct *vma);void adjust_range_if_pmd_sharing_possible (struct vm_area_struct *vma,unsigned long *start,unsigned long *end); struct page *follow_huge_addr(struct mm_struct *mm, unsigned long address,
@@ -208,13 +209,17 @@ static inline struct address_space *hugetlb_page_mapping_lock_write(return NULL ; } -static inline int huge_pmd_unshare (struct mm_struct *mm, -struct vm_area_struct *vma, -unsigned long *addr,pte_t *ptep) +static inline int huge_pmd_unshare (struct mmu_gather *tlb, +struct vm_area_struct *vma,unsigned long *addr,pte_t *ptep) {return 0 ; } +static inline void huge_pmd_unshare_flush (struct mmu_gather *tlb, +struct vm_area_struct *vma) +{ +} +static inline void adjust_range_if_pmd_sharing_possible (struct vm_area_struct *vma,unsigned long *start,unsigned long *end)
include/linux/mm_types.h +2 -0
@@ -610,6 +610,8 @@ static inline cpumask_t *mm_cpumask(struct mm_struct *mm)struct mmu_gather ;extern void tlb_gather_mmu (struct mmu_gather *tlb,struct mm_struct *mm,unsigned long start,unsigned long end); +void tlb_gather_mmu_vma (struct mmu_gather *tlb,struct vm_area_struct *vma, +unsigned long start,unsigned long end);extern void tlb_finish_mmu (struct mmu_gather *tlb,unsigned long start,unsigned long end);
mm/hugetlb.c +64 -44
224 lines not on this page · raw message
mm/mmu_gather.c +36 -0
@@ -7,6 +7,7 @@#include <linux/rcupdate.h> #include <linux/smp.h> #include <linux/swap.h> +#include <linux/hugetlb.h> #include <asm/pgalloc.h> #include <asm/tlb.h>
@@ -281,10 +282,39 @@ void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, tlb->page_size =0 ;#endif + tlb->fully_unshared_tables =0 ;__tlb_reset_range (tlb);inc_tlb_flush_pending (tlb->mm); } +/** +* tlb_gather_mmu_vma - initialize an mmu_gather structure for operating on a +* single VMA +* @tlb: the mmu_gather structure to initialize +* @vma: the vm_area_struct +* @start: start of the region that will be removed from the page-table +* @end: end of the region that will be removed from the page-table +* +* Called to initialize an (on-stack) mmu_gather structure for operating on +* a single VMA. In contrast to tlb_gather_mmu(), calling this function will +* not require another call to tlb_start_vma(). In contrast to tlb_start_vma(), +* this function will *not* call flush_cache_range(). +* +* For hugetlb VMAs, this function will also initialize the mmu_gather +* page_size accordingly, not requiring a separate call to +* tlb_change_page_size(). +* +*/ +void tlb_gather_mmu_vma (struct mmu_gather *tlb,struct vm_area_struct *vma, +unsigned long start,unsigned long end) +{ +tlb_gather_mmu (tlb, vma->vm_mm, start, end); +tlb_update_vma_flags (tlb, vma); +if (is_vm_hugetlb_page (vma)) +/* All entries have the same size. */ +tlb_change_page_size (tlb,huge_page_size (hstate_vma (vma))); +} +/** * tlb_finish_mmu - finish an mmu_gather structure * @tlb: the mmu_gather structure to finish
@@ -297,6 +327,12 @@ void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm,void tlb_finish_mmu (struct mmu_gather *tlb,unsigned long start,unsigned long end) { +/* +* We expect an earlier huge_pmd_unshare_flush() call to sort this out, +* due to complicated locking requirements with page table unsharing. +*/ +VM_WARN_ON_ONCE (tlb->fully_unshared_tables); +/* * If there are parallel threads are doing PTE changes on same range * under non-exclusive lock (e.g., mmap_lock read-side) but defer TLB
mm/rmap.c +8 -3
@@ -73,7 +73,7 @@#include <linux/memremap.h> #include <linux/userfaultfd_k.h> -#include <asm/tlbflush.h> +#include <asm/tlb.h> #include <trace/events/tlb.h>
@@ -1470,13 +1470,16 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, address = pvmw.address;if (PageHuge (page) && !PageAnon (page)) { +struct mmu_gather tlb; +/* * To call huge_pmd_unshare, i_mmap_rwsem must be * held in write mode. Caller needs to explicitly * do this outside rmap routines. */ VM_BUG_ON (!(flags &TTU_RMAP_LOCKED )); -if (huge_pmd_unshare (mm, vma, &address, pvmw.pte)) { +tlb_gather_mmu_vma (&tlb, vma, range.start, range.end); +if (huge_pmd_unshare (&tlb, vma, &address, pvmw.pte)) {/* * huge_pmd_unshare unmapped an entire PMD * page. There is no way of knowing exactly
@@ -1485,9 +1488,10 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,* already adjusted above to cover this range. */ flush_cache_range (vma, range.start, range.end); -flush_tlb_range (vma, range.start, range.end); +huge_pmd_unshare_flush (&tlb, vma);mmu_notifier_invalidate_range (mm, range.start, range.end); +tlb_finish_mmu (&tlb, range.start, range.end);/* * The PMD table was unmapped,
@@ -1496,6 +1500,7 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,page_vma_mapped_walk_done (&pvmw);break ; } +tlb_finish_mmu (&tlb, range.start, range.end); } if (IS_ENABLED(CONFIG_MIGRATION) &&
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 425/491 media: uvcvideo: Move guid to entity
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ricardo Ribalda <[email protected]>
[ Upstream commit 351509c604dcb065305a165d7552058c2cbc447d ]
Instead of having multiple copies of the entity guid on the code, move it to the entity structure.
Stable-dep-of: 0e2ee70291e6 ("media: uvcvideo: Mark invalid entities with id UVC_INVALID_ENTITY_ID")
--- drivers/media/usb/uvc/uvc_ctrl.c | 30 ++++-------------------------- drivers/media/usb/uvc/uvc_driver.c | 25 +++++++++++++++++++++++-- drivers/media/usb/uvc/uvcvideo.h | 2 +- 3 files changed, 28 insertions(+), 29 deletions(-)
drivers/media/usb/uvc/uvc_ctrl.c +4 -26
@@ -827,31 +827,10 @@ static void uvc_set_le_value(struct uvc_control_mapping *mapping,* Terminal and unit management */ -static const u8 uvc_processing_guid[16 ] =UVC_GUID_UVC_PROCESSING ; -static const u8 uvc_camera_guid[16 ] =UVC_GUID_UVC_CAMERA ; -static const u8 uvc_media_transport_input_guid[16 ] = -UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT ; -static int uvc_entity_match_guid (const struct uvc_entity *entity, -const u8 guid[16 ]) +const u8 guid[16 ]) { -switch (UVC_ENTITY_TYPE (entity)) { -case UVC_ITT_CAMERA : -return memcmp (uvc_camera_guid, guid,16 ) ==0 ; - -case UVC_ITT_MEDIA_TRANSPORT_INPUT : -return memcmp (uvc_media_transport_input_guid, guid,16 ) ==0 ; - -case UVC_VC_PROCESSING_UNIT : -return memcmp (uvc_processing_guid, guid,16 ) ==0 ; - -case UVC_VC_EXTENSION_UNIT : -return memcmp (entity->extension.guidExtensionCode, - guid,16 ) ==0 ; - -default : -return 0 ; - } +return memcmp (entity->guid, guid,sizeof (entity->guid)) ==0 ; }/* ------------------------------------------------------------------------
@@ -1882,8 +1861,7 @@ static int uvc_ctrl_fill_xu_info(struct uvc_device *dev,if (data ==NULL )return -ENOMEM ; -memcpy (info->entity, ctrl->entity->extension.guidExtensionCode, -sizeof (info->entity)); +memcpy (info->entity, ctrl->entity->guid,sizeof (info->entity)); info->index = ctrl->index; info->selector = ctrl->index +1 ;
@@ -1989,7 +1967,7 @@ int uvc_xu_ctrl_query(struct uvc_video_chain *chain,if (!found) {uvc_trace (UVC_TRACE_CONTROL ,"Control %pUl/%u not found.\n" , - entity->extension.guidExtensionCode, xqry->selector); + entity->guid, xqry->selector);return -ENOENT ; }
drivers/media/usb/uvc/uvc_driver.c +23 -2
@@ -1032,6 +1032,11 @@ static int uvc_parse_streaming(struct uvc_device *dev,return ret; } +static const u8 uvc_camera_guid[16 ] =UVC_GUID_UVC_CAMERA ; +static const u8 uvc_media_transport_input_guid[16 ] = +UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT ; +static const u8 uvc_processing_guid[16 ] =UVC_GUID_UVC_PROCESSING ; +static struct uvc_entity *uvc_alloc_entity (u16 type,u8 id,unsigned int num_pads,unsigned int extra_size) {
@@ -1054,6 +1059,22 @@ static struct uvc_entity *uvc_alloc_entity(u16 type, u8 id, entity->id = id; entity->type = type; +/* +* Set the GUID for standard entity types. For extension units, the GUID +* is initialized by the caller. +*/ +switch (type) { +case UVC_ITT_CAMERA : +memcpy (entity->guid, uvc_camera_guid,16 ); +break ; +case UVC_ITT_MEDIA_TRANSPORT_INPUT : +memcpy (entity->guid, uvc_media_transport_input_guid,16 ); +break ; +case UVC_VC_PROCESSING_UNIT : +memcpy (entity->guid, uvc_processing_guid,16 ); +break ; + } + entity->num_links =0 ; entity->num_pads = num_pads; entity->pads = ((void *)(entity +1 )) + extra_size;
@@ -1125,7 +1146,7 @@ static int uvc_parse_vendor_control(struct uvc_device *dev,if (unit ==NULL )return -ENOMEM ; -memcpy (unit->extension.guidExtensionCode, &buffer[4 ],16 ); +memcpy (unit->guid, &buffer[4 ],16 ); unit->extension.bNumControls = buffer[20 ];memcpy (unit->baSourceID, &buffer[22 ], p); unit->extension.bControlSize = buffer[22 +p];
@@ -1376,7 +1397,7 @@ static int uvc_parse_standard_control(struct uvc_device *dev,if (unit ==NULL )return -ENOMEM ; -memcpy (unit->extension.guidExtensionCode, &buffer[4 ],16 ); +memcpy (unit->guid, &buffer[4 ],16 ); unit->extension.bNumControls = buffer[20 ];memcpy (unit->baSourceID, &buffer[22 ], p); unit->extension.bControlSize = buffer[22 +p];
drivers/media/usb/uvc/uvcvideo.h +1 -1
@@ -305,6 +305,7 @@ struct uvc_entity {u8 id;u16 type;char name[64 ]; +u8 guid[16 ];/* Media controller-related fields. */ struct video_device *vdev;
@@ -343,7 +344,6 @@ struct uvc_entity { } selector;struct { -u8 guidExtensionCode[16 ];u8 bNumControls;u8 bControlSize;u8 *bmControls;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 426/491 media: uvcvideo: Allow extra entities
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ricardo Ribalda <[email protected]>
[ Upstream commit cae79e50d1222010fde8c522410c315f74d35c40 ]
Increase the size of the id, to avoid collisions with entities implemented by the driver that are not part of the UVC device.
Entities exposed by the UVC device use IDs 0-255, extra entities implemented by the driver (such as the GPIO entity) use IDs 256 and up.
Stable-dep-of: 0e2ee70291e6 ("media: uvcvideo: Mark invalid entities with id UVC_INVALID_ENTITY_ID")
--- drivers/media/usb/uvc/uvc_driver.c | 2 +- drivers/media/usb/uvc/uvcvideo.h | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-)
drivers/media/usb/uvc/uvc_driver.c +1 -1
@@ -1037,7 +1037,7 @@ static const u8 uvc_media_transport_input_guid[16] =UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT ;static const u8 uvc_processing_guid[16 ] =UVC_GUID_UVC_PROCESSING ; -static struct uvc_entity *uvc_alloc_entity (u16 type,u8 id, +static struct uvc_entity *uvc_alloc_entity (u16 type,u16 id,unsigned int num_pads,unsigned int extra_size) {struct uvc_entity *entity;
drivers/media/usb/uvc/uvcvideo.h +6 -1
@@ -302,7 +302,12 @@ struct uvc_entity {* chain. */ unsigned int flags; -u8 id; +/* +* Entities exposed by the UVC device use IDs 0-255, extra entities +* implemented by the driver (such as the GPIO entity) use IDs 256 and +* up. +*/ +u16 id;u16 type;char name[64 ];u8 guid[16 ];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 427/491 media: uvcvideo: Implement UVC_EXT_GPIO_UNIT
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ricardo Ribalda <[email protected]>
[ Upstream commit 2886477ff98740cc3333cf785e4de0b1ff3d7a28 ]
Some devices can implement a physical switch to disable the input of the camera on demand. Think of it like an elegant privacy sticker.
The system can read the status of the privacy switch via a GPIO.
It is important to know the status of the switch, e.g. to notify the user when the camera will produce black frames and a videochat application is used.
In some systems, the GPIO is connected to the main SoC instead of the camera controller, with the connection reported by the system firmware (ACPI or DT). In that case, the UVC device isn't aware of the GPIO. We need to implement a virtual entity to handle the GPIO fully on the driver side.
For example, for ACPI-based systems, the GPIO is reported in the USB device object:
Scope (\_SB.PCI0.XHCI.RHUB.HS07)
{ /.../
Name (_CRS, ResourceTemplate () // _CRS: Current Resource Settings
{
GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly,
"\\_SB.PCI0.GPIO", 0x00, ResourceConsumer, ,
)
{ // Pin list
0x0064
}
})
Name (_DSD, Package (0x02) // _DSD: Device-Specific Data
{
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301") /* Device Properties for _DSD */,
Package (0x01)
{
Package (0x02)
{
"privacy-gpio",
Package (0x04)
{
\_SB.PCI0.XHCI.RHUB.HS07,
Zero,
Zero,
One
}
}
}
})}
Stable-dep-of: 0e2ee70291e6 ("media: uvcvideo: Mark invalid entities with id UVC_INVALID_ENTITY_ID")
--- drivers/media/usb/uvc/uvc_ctrl.c | 3 + drivers/media/usb/uvc/uvc_driver.c | 127 +++++++++++++++++++++++++++++ drivers/media/usb/uvc/uvc_entity.c | 1 + drivers/media/usb/uvc/uvcvideo.h | 16 ++++ 4 files changed, 147 insertions(+)
drivers/media/usb/uvc/uvc_ctrl.c +3 -0
@@ -2378,6 +2378,9 @@ int uvc_ctrl_init_device(struct uvc_device *dev) }else if (UVC_ENTITY_TYPE (entity) ==UVC_ITT_CAMERA ) { bmControls = entity->camera.bmControls; bControlSize = entity->camera.bControlSize; + }else if (UVC_ENTITY_TYPE (entity) ==UVC_EXT_GPIO_UNIT ) { + bmControls = entity->gpio.bmControls; + bControlSize = entity->gpio.bControlSize; }/* Remove bogus/blacklisted controls */
drivers/media/usb/uvc/uvc_driver.c +127 -0
169 lines not on this page · raw message
drivers/media/usb/uvc/uvc_entity.c +1 -0
@@ -105,6 +105,7 @@ static int uvc_mc_init_entity(struct uvc_video_chain *chain,case UVC_OTT_DISPLAY :case UVC_OTT_MEDIA_TRANSPORT_OUTPUT :case UVC_EXTERNAL_VENDOR_SPECIFIC : +case UVC_EXT_GPIO_UNIT :default : function =MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN ;break ;
drivers/media/usb/uvc/uvcvideo.h +16 -0
@@ -6,6 +6,7 @@#error "The uvcvideo.h header is deprecated, use linux/uvcvideo.h instead."#endif /* __KERNEL__ */ +#include <linux/atomic.h> #include <linux/kernel.h> #include <linux/poll.h> #include <linux/usb.h>
@@ -37,6 +38,8 @@ (UVC_ENTITY_IS_TERM (entity) && \ ((entity)->type & 0x8000) == UVC_TERM_OUTPUT) +#define UVC_EXT_GPIO_UNIT 0x7ffe +#define UVC_EXT_GPIO_UNIT_ID 0x100/* ------------------------------------------------------------------------ * GUIDs
@@ -56,6 +59,9 @@#define UVC_GUID_UVC_SELECTOR \ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02} +#define UVC_GUID_EXT_GPIO_CONTROLLER \ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03}#define UVC_GUID_FORMAT_MJPEG \ { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \
@@ -213,6 +219,7 @@* Structures. */ +struct gpio_desc ;struct uvc_device ;/* TODO: Put the most frequently accessed fields at the beginning of
@@ -354,6 +361,13 @@ struct uvc_entity {u8 *bmControls;u8 *bmControlsType; } extension; + +struct { +u8 bControlSize; +u8 *bmControls; +struct gpio_desc *gpio_privacy; +int irq; + } gpio; };u8 bNrInPins;
@@ -696,6 +710,8 @@ struct uvc_device {struct uvc_control *ctrl;const void *data; } async_ctrl; + +struct uvc_entity *gpio_unit; };enum uvc_handle_state {
Signature · 1 line
2.53.0
Re: [PATCH 5.10 427/491] media: uvcvideo: Implement UVC_EXT_GPIO_UNIT
Quoted 7 lines · Greg Kroah-Hartman
5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ricardo Ribalda <[email protected]>
[ Upstream commit
2886477ff98740cc3333cf785e4de0b1ff3d7a28]
This is a new feature, not obviously suitable for stable.
If it really is needed for 5.10 then there are a number of bug fixes that also need to follow: 387e89393071 ["media: uvcvideo: Fix deferred probing error"), a9ea1a3d88b7 ("media: uvcvideo: Fix crash during unbind if gpio unit is in use"), and f0f078457f18 ("media: uvcvideo: Fix memory leak in uvc_gpio_parse").
Ben.
Quoted 332 lines
Some devices can implement a physical switch to disable the input of the camera on demand. Think of it like an elegant privacy sticker.
The system can read the status of the privacy switch via a GPIO.
It is important to know the status of the switch, e.g. to notify the user when the camera will produce black frames and a videochat application is used.
In some systems, the GPIO is connected to the main SoC instead of the camera controller, with the connection reported by the system firmware (ACPI or DT). In that case, the UVC device isn't aware of the GPIO. We need to implement a virtual entity to handle the GPIO fully on the driver side.
For example, for ACPI-based systems, the GPIO is reported in the USB device object:
Scope (\_SB.PCI0.XHCI.RHUB.HS07) {/.../ Name (_CRS, ResourceTemplate () // _CRS: Current Resource Settings { GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly, "\\_SB.PCI0.GPIO", 0x00, ResourceConsumer, , ) { // Pin list 0x0064 } }) Name (_DSD, Package (0x02) // _DSD: Device-Specific Data { ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301") /* Device Properties for _DSD */, Package (0x01) { Package (0x02) { "privacy-gpio", Package (0x04) { \_SB.PCI0.XHCI.RHUB.HS07, Zero, Zero, One } } } })}
Signed-off-by Ricardo Ribalda <[email protected]>Signed-off-by Laurent Pinchart <[email protected]>Signed-off-by Mauro Carvalho Chehab <[email protected]>Stable-dep-of:
0e2ee70291e6("media: uvcvideo: Mark invalid entities with idUVC_INVALID_ENTITY_ID")Signed-off-by Sasha Levin <[email protected]>--- drivers/media/usb/uvc/uvc_ctrl.c | 3 + drivers/media/usb/uvc/uvc_driver.c | 127 +++++++++++++++++++++++++++++ drivers/media/usb/uvc/uvc_entity.c | 1 + drivers/media/usb/uvc/uvcvideo.h | 16 ++++ 4 files changed, 147 insertions(+)drivers/media/usb/uvc/uvc_ctrl.c +3
-0@@ -2378,6 +2378,9 @@ int uvc_ctrl_init_device(struct uvc_device *dev) }else if (UVC_ENTITY_TYPE (entity) ==UVC_ITT_CAMERA ) { bmControls = entity->camera.bmControls; bControlSize = entity->camera.bControlSize; + }else if (UVC_ENTITY_TYPE (entity) ==UVC_EXT_GPIO_UNIT ) { + bmControls = entity->gpio.bmControls; + bControlSize = entity->gpio.bControlSize; }/* Remove bogus/blacklisted controls */ drivers/media/usb/uvc/uvc_driver.c +127
-0@@ -7,6 +7,7 @@*/ #include <linux/atomic.h> +#include <linux/gpio/consumer.h> #include <linux/kernel.h> #include <linux/list.h> #include <linux/module.h> @@ -1033,6 +1034,7 @@ static int uvc_parse_streaming(struct uvc_device *dev, }static const u8 uvc_camera_guid[16 ] =UVC_GUID_UVC_CAMERA ; +static const u8 uvc_gpio_guid[16 ] =UVC_GUID_EXT_GPIO_CONTROLLER ;static const u8 uvc_media_transport_input_guid[16 ] =UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT ;static const u8 uvc_processing_guid[16 ] =UVC_GUID_UVC_PROCESSING ;@@ -1064,6 +1066,9 @@ static struct uvc_entity *uvc_alloc_entity(u16 type, u16 id,* is initialized by the caller. */ switch (type) { +case UVC_EXT_GPIO_UNIT : +memcpy (entity->guid, uvc_gpio_guid,16 ); +break ;case UVC_ITT_CAMERA :memcpy (entity->guid, uvc_camera_guid,16 );break ;@@ -1467,6 +1472,108 @@ static int uvc_parse_control(struct uvc_device *dev)return 0 ; } +/* ----------------------------------------------------------------------------- +* Privacy GPIO +*/ + +static void uvc_gpio_event (struct uvc_device *dev) +{ +struct uvc_entity *unit = dev->gpio_unit; +struct uvc_video_chain *chain; +u8 new_val; + +if (!unit) +return ; + + new_val =gpiod_get_value_cansleep (unit->gpio.gpio_privacy); + +/* GPIO entities are always on the first chain. */ + chain = list_first_entry(&dev->chains, struct uvc_video_chain, list); +uvc_ctrl_status_event (chain, unit->controls, &new_val); +} + +static int uvc_gpio_get_cur (struct uvc_device *dev,struct uvc_entity *entity, +u8 cs,void *data,u16 size) +{ +if (cs !=UVC_CT_PRIVACY_CONTROL || size <1 ) +return -EINVAL ; + + *(u8 *)data =gpiod_get_value_cansleep (entity->gpio.gpio_privacy); + +return 0 ; +} + +static int uvc_gpio_get_info (struct uvc_device *dev,struct uvc_entity *entity, +u8 cs,u8 *caps) +{ +if (cs !=UVC_CT_PRIVACY_CONTROL ) +return -EINVAL ; + + *caps =UVC_CONTROL_CAP_GET |UVC_CONTROL_CAP_AUTOUPDATE ; +return 0 ; +} + +static irqreturn_t uvc_gpio_irq (int irq,void *data) +{ +struct uvc_device *dev = data; + +uvc_gpio_event (dev); +return IRQ_HANDLED ; +} + +static int uvc_gpio_parse (struct uvc_device *dev) +{ +struct uvc_entity *unit; +struct gpio_desc *gpio_privacy; +int irq; + + gpio_privacy =devm_gpiod_get_optional (&dev->udev->dev,"privacy" , +GPIOD_IN ); +if (IS_ERR_OR_NULL (gpio_privacy)) +return PTR_ERR_OR_ZERO (gpio_privacy); + + unit =uvc_alloc_entity (UVC_EXT_GPIO_UNIT ,UVC_EXT_GPIO_UNIT_ID ,0 ,1 ); +if (!unit) +return -ENOMEM ; + + irq =gpiod_to_irq (gpio_privacy); +if (irq <0 ) { +if (irq !=EPROBE_DEFER ) +dev_err (&dev->udev->dev, +"No IRQ for privacy GPIO (%d)\n" , irq); +return irq; + } + + unit->gpio.gpio_privacy = gpio_privacy; + unit->gpio.irq = irq; + unit->gpio.bControlSize =1 ; + unit->gpio.bmControls = (u8 *)unit +sizeof (*unit); + unit->gpio.bmControls[0 ] =1 ; + unit->get_cur = uvc_gpio_get_cur; + unit->get_info = uvc_gpio_get_info; +strncpy (unit->name,"GPIO" ,sizeof (unit->name) -1 ); + +list_add_tail (&unit->list, &dev->entities); + + dev->gpio_unit = unit; + +return 0 ; +} + +static int uvc_gpio_init_irq (struct uvc_device *dev) +{ +struct uvc_entity *unit = dev->gpio_unit; + +if (!unit || unit->gpio.irq <0 ) +return 0 ; + +return devm_request_threaded_irq (&dev->udev->dev, unit->gpio.irq,NULL , + uvc_gpio_irq, +IRQF_ONESHOT |IRQF_TRIGGER_FALLING | +IRQF_TRIGGER_RISING , +"uvc_privacy_gpio" , dev); +} +/* ------------------------------------------------------------------------ * UVC device scan */ @@ -1988,6 +2095,13 @@ static int uvc_scan_device(struct uvc_device *dev)return -1 ; } +/* Add GPIO entity to the first chain. */ +if (dev->gpio_unit) { + chain =list_first_entry (&dev->chains, + struct uvc_video_chain, list); +list_add_tail (&dev->gpio_unit->chain, &chain->entities); + } +return 0 ; }@@ -2350,6 +2464,12 @@ static int uvc_probe(struct usb_interface *intf, goto error; } +/* Parse the associated GPIOs. */ +if (uvc_gpio_parse (dev) <0 ) { +uvc_trace (UVC_TRACE_PROBE ,"Unable to parse UVC GPIOs\n" ); + goto error; + } + uvc_printk(KERN_INFO, "Found UVC %u.%02x device %s (%04x:%04x)\n", dev->uvc_version >> 8, dev->uvc_version & 0xff, udev->product ? udev->product : "<unnamed>",@@ -2394,6 +2514,13 @@ static int uvc_probe(struct usb_interface *intf, "supported.\n", ret); } + ret =uvc_gpio_init_irq (dev); +if (ret <0 ) { +dev_err (&dev->udev->dev, +"Unable to request privacy GPIO IRQ (%d)\n" , ret); + goto error; + } +uvc_trace (UVC_TRACE_PROBE ,"UVC device initialized.\n" );usb_enable_autosuspend (udev);return 0 ;drivers/media/usb/uvc/uvc_entity.c +1
-0@@ -105,6 +105,7 @@ static int uvc_mc_init_entity(struct uvc_video_chain *chain,case UVC_OTT_DISPLAY :case UVC_OTT_MEDIA_TRANSPORT_OUTPUT :case UVC_EXTERNAL_VENDOR_SPECIFIC : +case UVC_EXT_GPIO_UNIT :default : function =MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN ;break ;drivers/media/usb/uvc/uvcvideo.h +16
-0@@ -6,6 +6,7 @@#error "The uvcvideo.h header is deprecated, use linux/uvcvideo.h instead."#endif /* __KERNEL__ */ +#include <linux/atomic.h> #include <linux/kernel.h> #include <linux/poll.h> #include <linux/usb.h> @@ -37,6 +38,8 @@ (UVC_ENTITY_IS_TERM (entity) && \ ((entity)->type & 0x8000) == UVC_TERM_OUTPUT) +#define UVC_EXT_GPIO_UNIT 0x7ffe +#define UVC_EXT_GPIO_UNIT_ID 0x100/* ------------------------------------------------------------------------ * GUIDs @@ -56,6 +59,9 @@#define UVC_GUID_UVC_SELECTOR \ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02} +#define UVC_GUID_EXT_GPIO_CONTROLLER \ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03}#define UVC_GUID_FORMAT_MJPEG \ { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \@@ -213,6 +219,7 @@* Structures. */ +struct gpio_desc ;struct uvc_device ;/* TODO: Put the most frequently accessed fields at the beginning of @@ -354,6 +361,13 @@ struct uvc_entity {u8 *bmControls;u8 *bmControlsType; } extension; + +struct { +u8 bControlSize; +u8 *bmControls; +struct gpio_desc *gpio_privacy; +int irq; + } gpio; };u8 bNrInPins;@@ -696,6 +710,8 @@ struct uvc_device {struct uvc_control *ctrl;const void *data; } async_ctrl; + +struct uvc_entity *gpio_unit; };enum uvc_handle_state {
Signature · 2 lines
Ben Hutchings When in doubt, use brute force. - Ken Thompson
Re: [PATCH 5.10 427/491] media: uvcvideo: Implement UVC_EXT_GPIO_UNIT
Quoted 11 lines · Ben Hutchings
Quoted 7 lines · Greg Kroah-Hartman
5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ricardo Ribalda <[email protected]>
[ Upstream commit
2886477ff98740cc3333cf785e4de0b1ff3d7a28]This is a new feature, not obviously suitable for stable.
Agree with Ben here.
if the reason for this patch is to get "media: uvcvideo: Use heuristic to find stream entity" in 5.10 I can work on a backport that only adds this feature without GPIO it should be pretty easy.
Quoted 345 lines
If it really is needed for 5.10 then there are a number of bug fixes that also need to follow:
387e89393071["media: uvcvideo: Fix deferred probing error"),a9ea1a3d88b7("media: uvcvideo: Fix crash during unbind if gpio unit is in use"), andf0f078457f18("media: uvcvideo: Fix memory leak inuvc_gpio_parse").Ben.
Quoted 324 lines
Some devices can implement a physical switch to disable the input of the camera on demand. Think of it like an elegant privacy sticker.
The system can read the status of the privacy switch via a GPIO.
It is important to know the status of the switch, e.g. to notify the user when the camera will produce black frames and a videochat application is used.
In some systems, the GPIO is connected to the main SoC instead of the camera controller, with the connection reported by the system firmware (ACPI or DT). In that case, the UVC device isn't aware of the GPIO. We need to implement a virtual entity to handle the GPIO fully on the driver side.
For example, for ACPI-based systems, the GPIO is reported in the USB device object:
Scope (\_SB.PCI0.XHCI.RHUB.HS07) {/.../ Name (_CRS, ResourceTemplate () // _CRS: Current Resource Settings { GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly, "\\_SB.PCI0.GPIO", 0x00, ResourceConsumer, , ) { // Pin list 0x0064 } }) Name (_DSD, Package (0x02) // _DSD: Device-Specific Data { ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301") /* Device Properties for _DSD */, Package (0x01) { Package (0x02) { "privacy-gpio", Package (0x04) { \_SB.PCI0.XHCI.RHUB.HS07, Zero, Zero, One } } } })}
Signed-off-by Ricardo Ribalda <[email protected]>Signed-off-by Laurent Pinchart <[email protected]>Signed-off-by Mauro Carvalho Chehab <[email protected]>Stable-dep-of:
0e2ee70291e6("media: uvcvideo: Mark invalid entities with idUVC_INVALID_ENTITY_ID")Signed-off-by Sasha Levin <[email protected]>--- drivers/media/usb/uvc/uvc_ctrl.c | 3 + drivers/media/usb/uvc/uvc_driver.c | 127 +++++++++++++++++++++++++++++ drivers/media/usb/uvc/uvc_entity.c | 1 + drivers/media/usb/uvc/uvcvideo.h | 16 ++++ 4 files changed, 147 insertions(+)drivers/media/usb/uvc/uvc_ctrl.c +3
-0@@ -2378,6 +2378,9 @@ int uvc_ctrl_init_device(struct uvc_device *dev) }else if (UVC_ENTITY_TYPE (entity) ==UVC_ITT_CAMERA ) { bmControls = entity->camera.bmControls; bControlSize = entity->camera.bControlSize; + }else if (UVC_ENTITY_TYPE (entity) ==UVC_EXT_GPIO_UNIT ) { + bmControls = entity->gpio.bmControls; + bControlSize = entity->gpio.bControlSize; }/* Remove bogus/blacklisted controls */ drivers/media/usb/uvc/uvc_driver.c +127
-0@@ -7,6 +7,7 @@*/ #include <linux/atomic.h> +#include <linux/gpio/consumer.h> #include <linux/kernel.h> #include <linux/list.h> #include <linux/module.h> @@ -1033,6 +1034,7 @@ static int uvc_parse_streaming(struct uvc_device *dev, }static const u8 uvc_camera_guid[16 ] =UVC_GUID_UVC_CAMERA ; +static const u8 uvc_gpio_guid[16 ] =UVC_GUID_EXT_GPIO_CONTROLLER ;static const u8 uvc_media_transport_input_guid[16 ] =UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT ;static const u8 uvc_processing_guid[16 ] =UVC_GUID_UVC_PROCESSING ;@@ -1064,6 +1066,9 @@ static struct uvc_entity *uvc_alloc_entity(u16 type, u16 id,* is initialized by the caller. */ switch (type) { +case UVC_EXT_GPIO_UNIT : +memcpy (entity->guid, uvc_gpio_guid,16 ); +break ;case UVC_ITT_CAMERA :memcpy (entity->guid, uvc_camera_guid,16 );break ;@@ -1467,6 +1472,108 @@ static int uvc_parse_control(struct uvc_device *dev)return 0 ; } +/* ----------------------------------------------------------------------------- +* Privacy GPIO +*/ + +static void uvc_gpio_event (struct uvc_device *dev) +{ +struct uvc_entity *unit = dev->gpio_unit; +struct uvc_video_chain *chain; +u8 new_val; + +if (!unit) +return ; + + new_val =gpiod_get_value_cansleep (unit->gpio.gpio_privacy); + +/* GPIO entities are always on the first chain. */ + chain = list_first_entry(&dev->chains, struct uvc_video_chain, list); +uvc_ctrl_status_event (chain, unit->controls, &new_val); +} + +static int uvc_gpio_get_cur (struct uvc_device *dev,struct uvc_entity *entity, +u8 cs,void *data,u16 size) +{ +if (cs !=UVC_CT_PRIVACY_CONTROL || size <1 ) +return -EINVAL ; + + *(u8 *)data =gpiod_get_value_cansleep (entity->gpio.gpio_privacy); + +return 0 ; +} + +static int uvc_gpio_get_info (struct uvc_device *dev,struct uvc_entity *entity, +u8 cs,u8 *caps) +{ +if (cs !=UVC_CT_PRIVACY_CONTROL ) +return -EINVAL ; + + *caps =UVC_CONTROL_CAP_GET |UVC_CONTROL_CAP_AUTOUPDATE ; +return 0 ; +} + +static irqreturn_t uvc_gpio_irq (int irq,void *data) +{ +struct uvc_device *dev = data; + +uvc_gpio_event (dev); +return IRQ_HANDLED ; +} + +static int uvc_gpio_parse (struct uvc_device *dev) +{ +struct uvc_entity *unit; +struct gpio_desc *gpio_privacy; +int irq; + + gpio_privacy =devm_gpiod_get_optional (&dev->udev->dev,"privacy" , +GPIOD_IN ); +if (IS_ERR_OR_NULL (gpio_privacy)) +return PTR_ERR_OR_ZERO (gpio_privacy); + + unit =uvc_alloc_entity (UVC_EXT_GPIO_UNIT ,UVC_EXT_GPIO_UNIT_ID ,0 ,1 ); +if (!unit) +return -ENOMEM ; + + irq =gpiod_to_irq (gpio_privacy); +if (irq <0 ) { +if (irq !=EPROBE_DEFER ) +dev_err (&dev->udev->dev, +"No IRQ for privacy GPIO (%d)\n" , irq); +return irq; + } + + unit->gpio.gpio_privacy = gpio_privacy; + unit->gpio.irq = irq; + unit->gpio.bControlSize =1 ; + unit->gpio.bmControls = (u8 *)unit +sizeof (*unit); + unit->gpio.bmControls[0 ] =1 ; + unit->get_cur = uvc_gpio_get_cur; + unit->get_info = uvc_gpio_get_info; +strncpy (unit->name,"GPIO" ,sizeof (unit->name) -1 ); + +list_add_tail (&unit->list, &dev->entities); + + dev->gpio_unit = unit; + +return 0 ; +} + +static int uvc_gpio_init_irq (struct uvc_device *dev) +{ +struct uvc_entity *unit = dev->gpio_unit; + +if (!unit || unit->gpio.irq <0 ) +return 0 ; + +return devm_request_threaded_irq (&dev->udev->dev, unit->gpio.irq,NULL , + uvc_gpio_irq, +IRQF_ONESHOT |IRQF_TRIGGER_FALLING | +IRQF_TRIGGER_RISING , +"uvc_privacy_gpio" , dev); +} +/* ------------------------------------------------------------------------ * UVC device scan */ @@ -1988,6 +2095,13 @@ static int uvc_scan_device(struct uvc_device *dev)return -1 ; } +/* Add GPIO entity to the first chain. */ +if (dev->gpio_unit) { + chain =list_first_entry (&dev->chains, + struct uvc_video_chain, list); +list_add_tail (&dev->gpio_unit->chain, &chain->entities); + } +return 0 ; }@@ -2350,6 +2464,12 @@ static int uvc_probe(struct usb_interface *intf, goto error; } +/* Parse the associated GPIOs. */ +if (uvc_gpio_parse (dev) <0 ) { +uvc_trace (UVC_TRACE_PROBE ,"Unable to parse UVC GPIOs\n" ); + goto error; + } + uvc_printk(KERN_INFO, "Found UVC %u.%02x device %s (%04x:%04x)\n", dev->uvc_version >> 8, dev->uvc_version & 0xff, udev->product ? udev->product : "<unnamed>",@@ -2394,6 +2514,13 @@ static int uvc_probe(struct usb_interface *intf, "supported.\n", ret); } + ret =uvc_gpio_init_irq (dev); +if (ret <0 ) { +dev_err (&dev->udev->dev, +"Unable to request privacy GPIO IRQ (%d)\n" , ret); + goto error; + } +uvc_trace (UVC_TRACE_PROBE ,"UVC device initialized.\n" );usb_enable_autosuspend (udev);return 0 ;drivers/media/usb/uvc/uvc_entity.c +1
-0@@ -105,6 +105,7 @@ static int uvc_mc_init_entity(struct uvc_video_chain *chain,case UVC_OTT_DISPLAY :case UVC_OTT_MEDIA_TRANSPORT_OUTPUT :case UVC_EXTERNAL_VENDOR_SPECIFIC : +case UVC_EXT_GPIO_UNIT :default : function =MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN ;break ;drivers/media/usb/uvc/uvcvideo.h +14
-0@@ -6,6 +6,7 @@#error "The uvcvideo.h header is deprecated, use linux/uvcvideo.h instead."#endif /* __KERNEL__ */ +#include <linux/atomic.h> #include <linux/kernel.h> #include <linux/poll.h> #include <linux/usb.h> @@ -37,6 +38,8 @@ (UVC_ENTITY_IS_TERM (entity) && \ ((entity)->type & 0x8000) == UVC_TERM_OUTPUT) +#define UVC_EXT_GPIO_UNIT 0x7ffe +#define UVC_EXT_GPIO_UNIT_ID 0x100/* ------------------------------------------------------------------------ * GUIDs @@ -56,6 +59,9 @@#define UVC_GUID_UVC_SELECTOR \ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02} +#define UVC_GUID_EXT_GPIO_CONTROLLER \ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03}#define UVC_GUID_FORMAT_MJPEG \ { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \@@ -213,6 +219,7 @@* Structures. */ +struct gpio_desc ;struct uvc_device ;/* TODO: Put the most frequently accessed fields at the beginning of @@ -354,6 +361,13 @@ struct uvc_entity {u8 *bmControls;u8 *bmControlsType; } extension; + +struct { +u8 bControlSize; +u8 *bmControls; +struct gpio_desc *gpio_privacy; +int irq; + } gpio; };u8 bNrInPins;drivers/media/usb/uvc/uvcvideo.h struct uvc_device { · line 717
Quoted 8 lines
drivers/media/usb/uvc/uvcvideo.h +2
-0@@ -696,6 +710,8 @@ struct uvc_device {struct uvc_control *ctrl;const void *data; } async_ctrl; + +struct uvc_entity *gpio_unit; };enum uvc_handle_state {--
Ben Hutchings
When in doubt, use brute force. - Ken Thompson
Signature · 1 line
Ricardo Ribalda
Sasha Levin
maintainerRe: [PATCH 5.10 427/491] media: uvcvideo: Implement UVC_EXT_GPIO_UNIT
Quoted 5 lines · Ricardo Ribalda
Agree with Ben here.
if the reason for this patch is to get "media: uvcvideo: Use heuristic to find stream entity" in 5.10 I can work on a backport that only adds this feature without GPIO it should be pretty easy.
Dropped all 5 uvcvideo patches from the 5.10 queue (move-guid-to-entity, allow-extra-entities, implement-uvc_ext_gpio_unit, mark-invalid-entities, use-heuristic-to-find-stream-entity).
An alternative backport without the GPIO code would be welcome, thanks.
PATCH 1/3 media: uvcvideo: Allow extra entities
[ Upstream commit cae79e50d1222010fde8c522410c315f74d35c40 ]
Increase the size of the id, to avoid collisions with entities implemented by the driver that are not part of the UVC device.
Entities exposed by the UVC device use IDs 0-255, extra entities implemented by the driver (such as the GPIO entity) use IDs 256 and up.
--- drivers/media/usb/uvc/uvc_driver.c | 2 +- drivers/media/usb/uvc/uvcvideo.h | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-)
drivers/media/usb/uvc/uvc_driver.c +1 -1
@@ -1032,7 +1032,7 @@ static int uvc_parse_streaming(struct uvc_device *dev,return ret; } -static struct uvc_entity *uvc_alloc_entity (u16 type,u8 id, +static struct uvc_entity *uvc_alloc_entity (u16 type,u16 id,unsigned int num_pads,unsigned int extra_size) {struct uvc_entity *entity;
drivers/media/usb/uvc/uvcvideo.h +6 -1
@@ -302,7 +302,12 @@ struct uvc_entity {* chain. */ unsigned int flags; -u8 id; +/* +* Entities exposed by the UVC device use IDs 0-255, extra entities +* implemented by the driver (such as the GPIO entity) use IDs 256 and +* up. +*/ +u16 id;u16 type;char name[64 ];
Signature · 1 line
2.54.0.rc0.605.g598a273b03-goog
PATCH 2/3 media: uvcvideo: Mark invalid entities with id UVC_INVALID_ENTITY_ID
From: Thadeu Lima de Souza Cascardo <[email protected]>
[ Upstream commit 0e2ee70291e64a30fe36960c85294726d34a103e ]
Per UVC 1.1+ specification 3.7.2, units and terminals must have a non-zero unique ID.
``` Each Unit and Terminal within the video function is assigned a unique identification number, the Unit ID (UID) or Terminal ID (TID), contained in the bUnitID or bTerminalID field of the descriptor. The value 0x00 is reserved for undefined ID, ```
If we add a new entity with id 0 or a duplicated ID, it will be marked as UVC_INVALID_ENTITY_ID.
In a previous attempt commit 3dd075fe8ebb ("media: uvcvideo: Require entities to have a non-zero unique ID"), we ignored all the invalid units, this broke a lot of non-compatible cameras. Hopefully we are more lucky this time.
This also prevents some syzkaller reproducers from triggering warnings due to a chain of entities referring to themselves. In one particular case, an Output Unit is connected to an Input Unit, both with the same ID of 1. But when looking up for the source ID of the Output Unit, that same entity is found instead of the input entity, which leads to such warnings.
In another case, a backward chain was considered finished as the source ID was 0. Later on, that entity was found, but its pads were not valid.
Here is a sample stack trace for one of those cases.
[ 20.650953] usb 1-1: new high-speed USB device number 2 using dummy_hcd [ 20.830206] usb 1-1: Using ep0 maxpacket: 8 [ 20.833501] usb 1-1: config 0 descriptor?? [ 21.038518] usb 1-1: string descriptor 0 read error: -71 [ 21.038893] usb 1-1: Found UVC 0.00 device <unnamed> (2833:0201) [ 21.039299] uvcvideo 1-1:0.0: Entity type for entity Output 1 was not initialized! [ 21.041583] uvcvideo 1-1:0.0: Entity type for entity Input 1 was not initialized! [ 21.042218] ------------[ cut here ]------------ [ 21.042536] WARNING: CPU: 0 PID: 9 at drivers/media/mc/mc-entity.c:1147 media_create_pad_link+0x2c4/0x2e0 [ 21.043195] Modules linked in: [ 21.043535] CPU: 0 UID: 0 PID: 9 Comm: kworker/0:1 Not tainted 6.11.0-rc7-00030-g3480e43aeccf #444 [ 21.044101] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.15.0-1 04/01/2014 [ 21.044639] Workqueue: usb_hub_wq hub_event [ 21.045100] RIP: 0010:media_create_pad_link+0x2c4/0x2e0 [ 21.045508] Code: fe e8 20 01 00 00 b8 f4 ff ff ff 48 83 c4 30 5b 41 5c 41 5d 41 5e 41 5f 5d c3 cc cc cc cc 0f 0b eb e9 0f 0b eb 0a 0f 0b eb 06 <0f> 0b eb 02 0f 0b b8 ea ff ff ff eb d4 66 2e 0f 1f 84 00 00 00 00 [ 21.046801] RSP: 0018:ffffc9000004b318 EFLAGS: 00010246 [ 21.047227] RAX: ffff888004e5d458 RBX: 0000000000000000 RCX: ffffffff818fccf1 [ 21.047719] RDX: 000000000000007b RSI: 0000000000000000 RDI: ffff888004313290 [ 21.048241] RBP: ffff888004313290 R08: 0001ffffffffffff R09: 0000000000000000 [ 21.048701] R10: 0000000000000013 R11: 0001888004313290 R12: 0000000000000003 [ 21.049138] R13: ffff888004313080 R14: ffff888004313080 R15: 0000000000000000 [ 21.049648] FS: 0000000000000000(0000) GS:ffff88803ec00000(0000) knlGS:0000000000000000 [ 21.050271] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 21.050688] CR2: 0000592cc27635b0 CR3: 000000000431c000 CR4: 0000000000750ef0 [ 21.051136] PKRU: 55555554 [ 21.051331] Call Trace: [ 21.051480] <TASK> [ 21.051611] ? __warn+0xc4/0x210 [ 21.051861] ? media_create_pad_link+0x2c4/0x2e0 [ 21.052252] ? report_bug+0x11b/0x1a0 [ 21.052540] ? trace_hardirqs_on+0x31/0x40 [ 21.052901] ? handle_bug+0x3d/0x70 [ 21.053197] ? exc_invalid_op+0x1a/0x50 [ 21.053511] ? asm_exc_invalid_op+0x1a/0x20 [ 21.053924] ? media_create_pad_link+0x91/0x2e0 [ 21.054364] ? media_create_pad_link+0x2c4/0x2e0 [ 21.054834] ? media_create_pad_link+0x91/0x2e0 [ 21.055131] ? _raw_spin_unlock+0x1e/0x40 [ 21.055441] ? __v4l2_device_register_subdev+0x202/0x210 [ 21.055837] uvc_mc_register_entities+0x358/0x400 [ 21.056144] uvc_register_chains+0x1fd/0x290 [ 21.056413] uvc_probe+0x380e/0x3dc0 [ 21.056676] ? __lock_acquire+0x5aa/0x26e0 [ 21.056946] ? find_held_lock+0x33/0xa0 [ 21.057196] ? kernfs_activate+0x70/0x80 [ 21.057533] ? usb_match_dynamic_id+0x1b/0x70 [ 21.057811] ? find_held_lock+0x33/0xa0 [ 21.058047] ? usb_match_dynamic_id+0x55/0x70 [ 21.058330] ? lock_release+0x124/0x260 [ 21.058657] ? usb_match_one_id_intf+0xa2/0x100 [ 21.058997] usb_probe_interface+0x1ba/0x330 [ 21.059399] really_probe+0x1ba/0x4c0 [ 21.059662] __driver_probe_device+0xb2/0x180 [ 21.059944] driver_probe_device+0x5a/0x100 [ 21.060170] __device_attach_driver+0xe9/0x160 [ 21.060427] ? __pfx___device_attach_driver+0x10/0x10 [ 21.060872] bus_for_each_drv+0xa9/0x100 [ 21.061312] __device_attach+0xed/0x190 [ 21.061812] device_initial_probe+0xe/0x20 [ 21.062229] bus_probe_device+0x4d/0xd0 [ 21.062590] device_add+0x308/0x590 [ 21.062912] usb_set_configuration+0x7b6/0xaf0 [ 21.063403] usb_generic_driver_probe+0x36/0x80 [ 21.063714] usb_probe_device+0x7b/0x130 [ 21.063936] really_probe+0x1ba/0x4c0 [ 21.064111] __driver_probe_device+0xb2/0x180 [ 21.064577] driver_probe_device+0x5a/0x100 [ 21.065019] __device_attach_driver+0xe9/0x160 [ 21.065403] ? __pfx___device_attach_driver+0x10/0x10 [ 21.065820] bus_for_each_drv+0xa9/0x100 [ 21.066094] __device_attach+0xed/0x190 [ 21.066535] device_initial_probe+0xe/0x20 [ 21.066992] bus_probe_device+0x4d/0xd0 [ 21.067250] device_add+0x308/0x590 [ 21.067501] usb_new_device+0x347/0x610 [ 21.067817] hub_event+0x156b/0x1e30 [ 21.068060] ? process_scheduled_works+0x48b/0xaf0 [ 21.068337] process_scheduled_works+0x5a3/0xaf0 [ 21.068668] worker_thread+0x3cf/0x560 [ 21.068932] ? kthread+0x109/0x1b0 [ 21.069133] kthread+0x197/0x1b0 [ 21.069343] ? __pfx_worker_thread+0x10/0x10 [ 21.069598] ? __pfx_kthread+0x10/0x10 [ 21.069908] ret_from_fork+0x32/0x40 [ 21.070169] ? __pfx_kthread+0x10/0x10 [ 21.070424] ret_from_fork_asm+0x1a/0x30 [ 21.070737] </TASK>
--- drivers/media/usb/uvc/uvc_driver.c | 66 +++++++++++++++++++----------- drivers/media/usb/uvc/uvcvideo.h | 2 + 2 files changed, 44 insertions(+), 24 deletions(-)
drivers/media/usb/uvc/uvc_driver.c +42 -24
@@ -412,6 +412,9 @@ struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id) {struct uvc_entity *entity; +if (id ==UVC_INVALID_ENTITY_ID ) +return NULL ; +list_for_each_entry (entity, &dev->entities, list) {if (entity->id == id)return entity;
@@ -1032,14 +1035,27 @@ static int uvc_parse_streaming(struct uvc_device *dev,return ret; } -static struct uvc_entity *uvc_alloc_entity (u16 type,u16 id, -unsigned int num_pads,unsigned int extra_size) +static struct uvc_entity *uvc_alloc_new_entity (struct uvc_device *dev,u16 type, +u16 id,unsigned int num_pads, +unsigned int extra_size) {struct uvc_entity *entity;unsigned int num_inputs;unsigned int size;unsigned int i; +/* Per UVC 1.1+ spec 3.7.2, the ID should be non-zero. */ +if (id ==0 ) { +dev_err (&dev->intf->dev,"Found Unit with invalid ID 0\n" ); + id =UVC_INVALID_ENTITY_ID ; + } + +/* Per UVC 1.1+ spec 3.7.2, the ID is unique. */ +if (uvc_entity_by_id (dev, id)) { +dev_err (&dev->intf->dev,"Found multiple Units with ID %u\n" , id); + id =UVC_INVALID_ENTITY_ID ; + } + extra_size =roundup (extra_size,sizeof (*entity->pads));if (num_pads) num_inputs = type &UVC_TERM_OUTPUT ? num_pads : num_pads -1 ;
@@ -1049,7 +1065,7 @@ static struct uvc_entity *uvc_alloc_entity(u16 type, u16 id, + num_inputs; entity =kzalloc (size,GFP_KERNEL );if (entity ==NULL ) -return NULL ; +return ERR_PTR (-ENOMEM ); entity->id = id; entity->type = type;
@@ -1120,10 +1136,10 @@ static int uvc_parse_vendor_control(struct uvc_device *dev,break ; } - unit =uvc_alloc_entity (UVC_VC_EXTENSION_UNIT , buffer[3 ], - p +1 ,2 *n); -if (unit ==NULL ) -return -ENOMEM ; + unit =uvc_alloc_new_entity (dev,UVC_VC_EXTENSION_UNIT , + buffer[3 ], p +1 ,2 * n); +if (IS_ERR (unit)) +return PTR_ERR (unit);memcpy (unit->extension.guidExtensionCode, &buffer[4 ],16 ); unit->extension.bNumControls = buffer[20 ];
@@ -1234,10 +1250,10 @@ static int uvc_parse_standard_control(struct uvc_device *dev,return -EINVAL ; } - term =uvc_alloc_entity (type |UVC_TERM_INPUT , buffer[3 ], -1 , n + p); -if (term ==NULL ) -return -ENOMEM ; + term =uvc_alloc_new_entity (dev, type |UVC_TERM_INPUT , + buffer[3 ],1 , n + p); +if (IS_ERR (term)) +return PTR_ERR (term);if (UVC_ENTITY_TYPE (term) ==UVC_ITT_CAMERA ) { term->camera.bControlSize = n;
@@ -1293,10 +1309,10 @@ static int uvc_parse_standard_control(struct uvc_device *dev,return 0 ; } - term =uvc_alloc_entity (type |UVC_TERM_OUTPUT , buffer[3 ], -1 ,0 ); -if (term ==NULL ) -return -ENOMEM ; + term =uvc_alloc_new_entity (dev, type |UVC_TERM_OUTPUT , + buffer[3 ],1 ,0 ); +if (IS_ERR (term)) +return PTR_ERR (term);memcpy (term->baSourceID, &buffer[7 ],1 );
@@ -1317,9 +1333,10 @@ static int uvc_parse_standard_control(struct uvc_device *dev,return -EINVAL ; } - unit =uvc_alloc_entity (buffer[2 ], buffer[3 ], p +1 ,0 ); -if (unit ==NULL ) -return -ENOMEM ; + unit =uvc_alloc_new_entity (dev, buffer[2 ], buffer[3 ], + p +1 ,0 ); +if (IS_ERR (unit)) +return PTR_ERR (unit);memcpy (unit->baSourceID, &buffer[5 ], p);
@@ -1341,9 +1358,9 @@ static int uvc_parse_standard_control(struct uvc_device *dev,return -EINVAL ; } - unit =uvc_alloc_entity (buffer[2 ], buffer[3 ],2 , n); -if (unit ==NULL ) -return -ENOMEM ; + unit =uvc_alloc_new_entity (dev, buffer[2 ], buffer[3 ],2 , n); +if (IS_ERR (unit)) +return PTR_ERR (unit);memcpy (unit->baSourceID, &buffer[4 ],1 ); unit->processing.wMaxMultiplier =
@@ -1372,9 +1389,10 @@ static int uvc_parse_standard_control(struct uvc_device *dev,return -EINVAL ; } - unit =uvc_alloc_entity (buffer[2 ], buffer[3 ], p +1 , n); -if (unit ==NULL ) -return -ENOMEM ; + unit =uvc_alloc_new_entity (dev, buffer[2 ], buffer[3 ], + p +1 , n); +if (IS_ERR (unit)) +return PTR_ERR (unit);memcpy (unit->extension.guidExtensionCode, &buffer[4 ],16 ); unit->extension.bNumControls = buffer[20 ];
drivers/media/usb/uvc/uvcvideo.h +2 -0
@@ -170,6 +170,8 @@ 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} +#define UVC_INVALID_ENTITY_ID 0xffff +/* ------------------------------------------------------------------------ * Driver specific constants. */
Signature · 1 line
2.54.0.rc0.605.g598a273b03-goog
PATCH 3/3 media: uvcvideo: Use heuristic to find stream entity
In reply to Ricardo Ribalda[ Upstream commit 758dbc756aad429da11c569c0d067f7fd032bcf7 ]
Some devices, like the Grandstream GUV3100 webcam, have an invalid UVC descriptor where multiple entities share the same ID, this is invalid and makes it impossible to make a proper entity tree without heuristics.
We have recently introduced a change in the way that we handle invalid entities that has caused a regression on broken devices.
Implement a new heuristic to handle these devices properly.
--- drivers/media/usb/uvc/uvc_driver.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/media/usb/uvc/uvc_driver.c +14 -1
@@ -442,13 +442,26 @@ static struct uvc_entity *uvc_entity_by_reference(struct uvc_device *dev,static struct uvc_streaming *uvc_stream_by_id (struct uvc_device *dev,int id) { -struct uvc_streaming *stream; +struct uvc_streaming *stream, *last_stream; +unsigned int count =0 ;list_for_each_entry (stream, &dev->streams, list) { + count +=1 ; + last_stream = stream;if (stream->header.bTerminalLink == id)return stream; } +/* +* If the streaming entity is referenced by an invalid ID, notify the +* user and use heuristics to guess the correct entity. +*/ +if (count ==1 && id ==UVC_INVALID_ENTITY_ID ) { +dev_warn (&dev->intf->dev, +"UVC non compliance: Invalid USB header. The streaming entity has an invalid ID, guessing the correct one." ); +return last_stream; + } +return NULL ; }
Signature · 1 line
2.54.0.rc0.605.g598a273b03-goog
Re: [PATCH 5.10.y 0/3] media: uvcvideo: Allow extra entities / Mark invalid entities / heuristic
In reply to Ricardo RibaldaQuoted 5 lines · Ricardo Ribalda
Backport to 5.10.y:
cae79e50d122media: uvcvideo: Allow extra entities0e2ee70291e6media: uvcvideo: Mark invalid entities with id
UVC_INVALID_ENTITY_ID
758dbc756aadmedia: uvcvideo: Use heuristic to find stream entity
Queued for 5.10, thanks.
--
Thanks,
Sasha
Greg Kroah-Hartman
maintainerPATCH 428/491 media: uvcvideo: Mark invalid entities with id UVC_INVALID_ENTITY_ID
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thadeu Lima de Souza Cascardo <[email protected]>
[ Upstream commit 0e2ee70291e64a30fe36960c85294726d34a103e ]
Per UVC 1.1+ specification 3.7.2, units and terminals must have a non-zero unique ID.
``` Each Unit and Terminal within the video function is assigned a unique identification number, the Unit ID (UID) or Terminal ID (TID), contained in the bUnitID or bTerminalID field of the descriptor. The value 0x00 is reserved for undefined ID, ```
If we add a new entity with id 0 or a duplicated ID, it will be marked as UVC_INVALID_ENTITY_ID.
In a previous attempt commit 3dd075fe8ebb ("media: uvcvideo: Require entities to have a non-zero unique ID"), we ignored all the invalid units, this broke a lot of non-compatible cameras. Hopefully we are more lucky this time.
This also prevents some syzkaller reproducers from triggering warnings due to a chain of entities referring to themselves. In one particular case, an Output Unit is connected to an Input Unit, both with the same ID of 1. But when looking up for the source ID of the Output Unit, that same entity is found instead of the input entity, which leads to such warnings.
In another case, a backward chain was considered finished as the source ID was 0. Later on, that entity was found, but its pads were not valid.
Here is a sample stack trace for one of those cases.
[ 20.650953] usb 1-1: new high-speed USB device number 2 using dummy_hcd [ 20.830206] usb 1-1: Using ep0 maxpacket: 8 [ 20.833501] usb 1-1: config 0 descriptor?? [ 21.038518] usb 1-1: string descriptor 0 read error: -71 [ 21.038893] usb 1-1: Found UVC 0.00 device <unnamed> (2833:0201) [ 21.039299] uvcvideo 1-1:0.0: Entity type for entity Output 1 was not initialized! [ 21.041583] uvcvideo 1-1:0.0: Entity type for entity Input 1 was not initialized! [ 21.042218] ------------[ cut here ]------------ [ 21.042536] WARNING: CPU: 0 PID: 9 at drivers/media/mc/mc-entity.c:1147 media_create_pad_link+0x2c4/0x2e0 [ 21.043195] Modules linked in: [ 21.043535] CPU: 0 UID: 0 PID: 9 Comm: kworker/0:1 Not tainted 6.11.0-rc7-00030-g3480e43aeccf #444 [ 21.044101] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.15.0-1 04/01/2014 [ 21.044639] Workqueue: usb_hub_wq hub_event [ 21.045100] RIP: 0010:media_create_pad_link+0x2c4/0x2e0 [ 21.045508] Code: fe e8 20 01 00 00 b8 f4 ff ff ff 48 83 c4 30 5b 41 5c 41 5d 41 5e 41 5f 5d c3 cc cc cc cc 0f 0b eb e9 0f 0b eb 0a 0f 0b eb 06 <0f> 0b eb 02 0f 0b b8 ea ff ff ff eb d4 66 2e 0f 1f 84 00 00 00 00 [ 21.046801] RSP: 0018:ffffc9000004b318 EFLAGS: 00010246 [ 21.047227] RAX: ffff888004e5d458 RBX: 0000000000000000 RCX: ffffffff818fccf1 [ 21.047719] RDX: 000000000000007b RSI: 0000000000000000 RDI: ffff888004313290 [ 21.048241] RBP: ffff888004313290 R08: 0001ffffffffffff R09: 0000000000000000 [ 21.048701] R10: 0000000000000013 R11: 0001888004313290 R12: 0000000000000003 [ 21.049138] R13: ffff888004313080 R14: ffff888004313080 R15: 0000000000000000 [ 21.049648] FS: 0000000000000000(0000) GS:ffff88803ec00000(0000) knlGS:0000000000000000 [ 21.050271] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 21.050688] CR2: 0000592cc27635b0 CR3: 000000000431c000 CR4: 0000000000750ef0 [ 21.051136] PKRU: 55555554 [ 21.051331] Call Trace: [ 21.051480] <TASK> [ 21.051611] ? __warn+0xc4/0x210 [ 21.051861] ? media_create_pad_link+0x2c4/0x2e0 [ 21.052252] ? report_bug+0x11b/0x1a0 [ 21.052540] ? trace_hardirqs_on+0x31/0x40 [ 21.052901] ? handle_bug+0x3d/0x70 [ 21.053197] ? exc_invalid_op+0x1a/0x50 [ 21.053511] ? asm_exc_invalid_op+0x1a/0x20 [ 21.053924] ? media_create_pad_link+0x91/0x2e0 [ 21.054364] ? media_create_pad_link+0x2c4/0x2e0 [ 21.054834] ? media_create_pad_link+0x91/0x2e0 [ 21.055131] ? _raw_spin_unlock+0x1e/0x40 [ 21.055441] ? __v4l2_device_register_subdev+0x202/0x210 [ 21.055837] uvc_mc_register_entities+0x358/0x400 [ 21.056144] uvc_register_chains+0x1fd/0x290 [ 21.056413] uvc_probe+0x380e/0x3dc0 [ 21.056676] ? __lock_acquire+0x5aa/0x26e0 [ 21.056946] ? find_held_lock+0x33/0xa0 [ 21.057196] ? kernfs_activate+0x70/0x80 [ 21.057533] ? usb_match_dynamic_id+0x1b/0x70 [ 21.057811] ? find_held_lock+0x33/0xa0 [ 21.058047] ? usb_match_dynamic_id+0x55/0x70 [ 21.058330] ? lock_release+0x124/0x260 [ 21.058657] ? usb_match_one_id_intf+0xa2/0x100 [ 21.058997] usb_probe_interface+0x1ba/0x330 [ 21.059399] really_probe+0x1ba/0x4c0 [ 21.059662] __driver_probe_device+0xb2/0x180 [ 21.059944] driver_probe_device+0x5a/0x100 [ 21.060170] __device_attach_driver+0xe9/0x160 [ 21.060427] ? __pfx___device_attach_driver+0x10/0x10 [ 21.060872] bus_for_each_drv+0xa9/0x100 [ 21.061312] __device_attach+0xed/0x190 [ 21.061812] device_initial_probe+0xe/0x20 [ 21.062229] bus_probe_device+0x4d/0xd0 [ 21.062590] device_add+0x308/0x590 [ 21.062912] usb_set_configuration+0x7b6/0xaf0 [ 21.063403] usb_generic_driver_probe+0x36/0x80 [ 21.063714] usb_probe_device+0x7b/0x130 [ 21.063936] really_probe+0x1ba/0x4c0 [ 21.064111] __driver_probe_device+0xb2/0x180 [ 21.064577] driver_probe_device+0x5a/0x100 [ 21.065019] __device_attach_driver+0xe9/0x160 [ 21.065403] ? __pfx___device_attach_driver+0x10/0x10 [ 21.065820] bus_for_each_drv+0xa9/0x100 [ 21.066094] __device_attach+0xed/0x190 [ 21.066535] device_initial_probe+0xe/0x20 [ 21.066992] bus_probe_device+0x4d/0xd0 [ 21.067250] device_add+0x308/0x590 [ 21.067501] usb_new_device+0x347/0x610 [ 21.067817] hub_event+0x156b/0x1e30 [ 21.068060] ? process_scheduled_works+0x48b/0xaf0 [ 21.068337] process_scheduled_works+0x5a3/0xaf0 [ 21.068668] worker_thread+0x3cf/0x560 [ 21.068932] ? kthread+0x109/0x1b0 [ 21.069133] kthread+0x197/0x1b0 [ 21.069343] ? __pfx_worker_thread+0x10/0x10 [ 21.069598] ? __pfx_kthread+0x10/0x10 [ 21.069908] ret_from_fork+0x32/0x40 [ 21.070169] ? __pfx_kthread+0x10/0x10 [ 21.070424] ret_from_fork_asm+0x1a/0x30 [ 21.070737] </TASK>
--- drivers/media/usb/uvc/uvc_driver.c | 73 +++++++++++++++++++----------- drivers/media/usb/uvc/uvcvideo.h | 2 + 2 files changed, 48 insertions(+), 27 deletions(-)
drivers/media/usb/uvc/uvc_driver.c +46 -27
@@ -413,6 +413,9 @@ struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id) {struct uvc_entity *entity; +if (id ==UVC_INVALID_ENTITY_ID ) +return NULL ; +list_for_each_entry (entity, &dev->entities, list) {if (entity->id == id)return entity;
@@ -1039,14 +1042,27 @@ static const u8 uvc_media_transport_input_guid[16] =UVC_GUID_UVC_MEDIA_TRANSPORT_INPUT ;static const u8 uvc_processing_guid[16 ] =UVC_GUID_UVC_PROCESSING ; -static struct uvc_entity *uvc_alloc_entity (u16 type,u16 id, -unsigned int num_pads,unsigned int extra_size) +static struct uvc_entity *uvc_alloc_new_entity (struct uvc_device *dev,u16 type, +u16 id,unsigned int num_pads, +unsigned int extra_size) {struct uvc_entity *entity;unsigned int num_inputs;unsigned int size;unsigned int i; +/* Per UVC 1.1+ spec 3.7.2, the ID should be non-zero. */ +if (id ==0 ) { +dev_err (&dev->intf->dev,"Found Unit with invalid ID 0\n" ); + id =UVC_INVALID_ENTITY_ID ; + } + +/* Per UVC 1.1+ spec 3.7.2, the ID is unique. */ +if (uvc_entity_by_id (dev, id)) { +dev_err (&dev->intf->dev,"Found multiple Units with ID %u\n" , id); + id =UVC_INVALID_ENTITY_ID ; + } + extra_size =roundup (extra_size,sizeof (*entity->pads));if (num_pads) num_inputs = type &UVC_TERM_OUTPUT ? num_pads : num_pads -1 ;
@@ -1056,7 +1072,7 @@ static struct uvc_entity *uvc_alloc_entity(u16 type, u16 id, + num_inputs; entity =kzalloc (size,GFP_KERNEL );if (entity ==NULL ) -return NULL ; +return ERR_PTR (-ENOMEM ); entity->id = id; entity->type = type;
@@ -1146,10 +1162,10 @@ static int uvc_parse_vendor_control(struct uvc_device *dev,break ; } - unit =uvc_alloc_entity (UVC_VC_EXTENSION_UNIT , buffer[3 ], - p +1 ,2 *n); -if (unit ==NULL ) -return -ENOMEM ; + unit =uvc_alloc_new_entity (dev,UVC_VC_EXTENSION_UNIT , + buffer[3 ], p +1 ,2 * n); +if (IS_ERR (unit)) +return PTR_ERR (unit);memcpy (unit->guid, &buffer[4 ],16 ); unit->extension.bNumControls = buffer[20 ];
@@ -1260,10 +1276,10 @@ static int uvc_parse_standard_control(struct uvc_device *dev,return -EINVAL ; } - term =uvc_alloc_entity (type |UVC_TERM_INPUT , buffer[3 ], -1 , n + p); -if (term ==NULL ) -return -ENOMEM ; + term =uvc_alloc_new_entity (dev, type |UVC_TERM_INPUT , + buffer[3 ],1 , n + p); +if (IS_ERR (term)) +return PTR_ERR (term);if (UVC_ENTITY_TYPE (term) ==UVC_ITT_CAMERA ) { term->camera.bControlSize = n;
@@ -1319,10 +1335,10 @@ static int uvc_parse_standard_control(struct uvc_device *dev,return 0 ; } - term =uvc_alloc_entity (type |UVC_TERM_OUTPUT , buffer[3 ], -1 ,0 ); -if (term ==NULL ) -return -ENOMEM ; + term =uvc_alloc_new_entity (dev, type |UVC_TERM_OUTPUT , + buffer[3 ],1 ,0 ); +if (IS_ERR (term)) +return PTR_ERR (term);memcpy (term->baSourceID, &buffer[7 ],1 );
@@ -1343,9 +1359,10 @@ static int uvc_parse_standard_control(struct uvc_device *dev,return -EINVAL ; } - unit =uvc_alloc_entity (buffer[2 ], buffer[3 ], p +1 ,0 ); -if (unit ==NULL ) -return -ENOMEM ; + unit =uvc_alloc_new_entity (dev, buffer[2 ], buffer[3 ], + p +1 ,0 ); +if (IS_ERR (unit)) +return PTR_ERR (unit);memcpy (unit->baSourceID, &buffer[5 ], p);
@@ -1367,9 +1384,9 @@ static int uvc_parse_standard_control(struct uvc_device *dev,return -EINVAL ; } - unit =uvc_alloc_entity (buffer[2 ], buffer[3 ],2 , n); -if (unit ==NULL ) -return -ENOMEM ; + unit =uvc_alloc_new_entity (dev, buffer[2 ], buffer[3 ],2 , n); +if (IS_ERR (unit)) +return PTR_ERR (unit);memcpy (unit->baSourceID, &buffer[4 ],1 ); unit->processing.wMaxMultiplier =
@@ -1398,9 +1415,10 @@ static int uvc_parse_standard_control(struct uvc_device *dev,return -EINVAL ; } - unit =uvc_alloc_entity (buffer[2 ], buffer[3 ], p +1 , n); -if (unit ==NULL ) -return -ENOMEM ; + unit =uvc_alloc_new_entity (dev, buffer[2 ], buffer[3 ], + p +1 , n); +if (IS_ERR (unit)) +return PTR_ERR (unit);memcpy (unit->guid, &buffer[4 ],16 ); unit->extension.bNumControls = buffer[20 ];
@@ -1532,9 +1550,10 @@ static int uvc_gpio_parse(struct uvc_device *dev)if (IS_ERR_OR_NULL (gpio_privacy))return PTR_ERR_OR_ZERO (gpio_privacy); - unit =uvc_alloc_entity (UVC_EXT_GPIO_UNIT ,UVC_EXT_GPIO_UNIT_ID ,0 ,1 ); -if (!unit) -return -ENOMEM ; + unit =uvc_alloc_new_entity (dev,UVC_EXT_GPIO_UNIT , +UVC_EXT_GPIO_UNIT_ID ,0 ,1 ); +if (IS_ERR (unit)) +return PTR_ERR (unit); irq =gpiod_to_irq (gpio_privacy);if (irq <0 ) {
drivers/media/usb/uvc/uvcvideo.h +2 -0
@@ -41,6 +41,8 @@#define UVC_EXT_GPIO_UNIT 0x7ffe#define UVC_EXT_GPIO_UNIT_ID 0x100 +#define UVC_INVALID_ENTITY_ID 0xffff +/* ------------------------------------------------------------------------ * GUIDs */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 429/491 media: uvcvideo: Use heuristic to find stream entity
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ricardo Ribalda <[email protected]>
[ Upstream commit 758dbc756aad429da11c569c0d067f7fd032bcf7 ]
Some devices, like the Grandstream GUV3100 webcam, have an invalid UVC descriptor where multiple entities share the same ID, this is invalid and makes it impossible to make a proper entity tree without heuristics.
We have recently introduced a change in the way that we handle invalid entities that has caused a regression on broken devices.
Implement a new heuristic to handle these devices properly.
--- drivers/media/usb/uvc/uvc_driver.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/media/usb/uvc/uvc_driver.c +14 -1
@@ -443,13 +443,26 @@ static struct uvc_entity *uvc_entity_by_reference(struct uvc_device *dev,static struct uvc_streaming *uvc_stream_by_id (struct uvc_device *dev,int id) { -struct uvc_streaming *stream; +struct uvc_streaming *stream, *last_stream; +unsigned int count =0 ;list_for_each_entry (stream, &dev->streams, list) { + count +=1 ; + last_stream = stream;if (stream->header.bTerminalLink == id)return stream; } +/* +* If the streaming entity is referenced by an invalid ID, notify the +* user and use heuristics to guess the correct entity. +*/ +if (count ==1 && id ==UVC_INVALID_ENTITY_ID ) { +dev_warn (&dev->intf->dev, +"UVC non compliance: Invalid USB header. The streaming entity has an invalid ID, guessing the correct one." ); +return last_stream; + } +return NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 430/491 apparmor: validate DFA start states are in bounds in unpack_pdb
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Massimiliano Pellizzer <[email protected]>
commit 9063d7e2615f4a7ab321de6b520e23d370e58816 upstream.
Backport for conflicts caused by
ad596ea74e74 ("apparmor: group dfa policydb unpacking")
- rearrange and consolidated the unpack.
b11e51dd7094 ("apparmor: test: make static symbols visible during kunit testing")
- rename function and make it visible to kunit tests
Start states are read from untrusted data and used as indexes into the DFA state tables. The aa_dfa_next() function call in unpack_pdb() will access dfa->tables[YYTD_ID_BASE][start], and if the start state exceeds the number of states in the DFA, this results in an out-of-bound read.
==================================================================
BUG: KASAN: slab-out-of-bounds in aa_dfa_next+0x2a1/0x360 Read of size 4 at addr ffff88811956fb90 by task su/1097 ...
Reject policies with out-of-bounds start states during unpacking to prevent the issue.
--- security/apparmor/policy_unpack.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)
security/apparmor/policy_unpack.c +19 -2
@@ -841,9 +841,18 @@ static struct aa_profile *unpack_profile error = -EPROTO ; goto fail; } -if (!unpack_u32 (e, &profile->policy.start[0 ],"start" )) +if (!unpack_u32 (e, &profile->policy.start[0 ],"start" )) {/* default start state */ profile->policy.start[0 ] =DFA_START ; + }else { +size_t state_count = profile->policy.dfa->tables[YYTD_ID_BASE ]->td_lolen; + +if (profile->policy.start[0 ] >= state_count) { + info ="invalid dfa start state" ; + goto fail; + } + } +/* setup class index */ for (i =AA_CLASS_FILE ; i <=AA_CLASS_LAST ; i++) { profile->policy.start[i] =
@@ -864,9 +873,17 @@ static struct aa_profile *unpack_profile info ="failed to unpack profile file rules" ; goto fail; }else if (profile->file.dfa) { -if (!unpack_u32 (e, &profile->file.start,"dfa_start" )) +if (!unpack_u32 (e, &profile->file.start,"dfa_start" )) {/* default start state */ profile->file.start =DFA_START ; + }else { +size_t state_count = profile->file.dfa->tables[YYTD_ID_BASE ]->td_lolen; + +if (profile->file.start >= state_count) { + info ="invalid dfa start state" ; + goto fail; + } + } }else if (profile->policy.dfa && profile->policy.start[AA_CLASS_FILE ]) { profile->file.dfa =aa_get_dfa (profile->policy.dfa);
Re: [PATCH 5.10 430/491] apparmor: validate DFA start states are in bounds in unpack_pdb
Quoted 48 lines · Greg Kroah-Hartman
5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Massimiliano Pellizzer <[email protected]>
commit
9063d7e2615f4a7ab321de6b520e23d370e58816upstream.Backport for conflicts caused by
ad596ea74e74("apparmor: group dfa policydb unpacking")
- rearrange and consolidated the unpack.
b11e51dd7094("apparmor: test: make static symbols visible during kunit testing")
- rename function and make it visible to kunit testsStart states are read from untrusted data and used as indexes into the DFA state tables. The
aa_dfa_next()function call inunpack_pdb()will access dfa->tables[YYTD_ID_BASE][start], and if the start state exceeds the number of states in the DFA, this results in an out-of-bound read.==================================================================
BUG: KASAN: slab-out-of-bounds in aa_dfa_next+0x2a1/0x360 Read of size 4 at addr ffff88811956fb90 by task su/1097 ...Reject policies with out-of-bounds start states during unpacking to prevent the issue.
Fixes ad5ff3db53c6 ("AppArmor: Add ability to load extended policy")Reported-by Qualys Security Advisory <[email protected]>Tested-by Salvatore Bonaccorso <[email protected]>Reviewed-by Georgia Garcia <[email protected]>Reviewed-by Cengiz Can <[email protected]>Signed-off-by Massimiliano Pellizzer <[email protected]>Signed-off-by John Johansen <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- security/apparmor/policy_unpack.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)security/apparmor/policy_unpack.c +1
-1@@ -841,9 +841,18 @@ static struct aa_profile *unpack_profile error = -EPROTO ; goto fail; } -if (!unpack_u32 (e, &profile->policy.start[0 ],"start" )) +if (!unpack_u32 (e, &profile->policy.start[0 ],"start" )) {
security/apparmor/policy_unpack.c static struct aa_profile *unpack_profile · line 854
Quoted 10 lines
security/apparmor/policy_unpack.c +8
-0/* default start state */ profile->policy.start[0 ] =DFA_START ; + }else { +size_t state_count = profile->policy.dfa->tables[YYTD_ID_BASE ]->td_lolen; + +if (profile->policy.start[0 ] >= state_count) { + info ="invalid dfa start state" ; + goto fail; + } + }
[...]
Isn't this range check needed even if we use the default start state? unpack_table() only checks that td_tolen > 0, so we could end up with profile->policy.start[0] = DFA_START == 1 and profile->policy.dfa->tables[YYTD_ID_BASE]->td_lolen == 1.
(This is specific to the backport as the upstream version didn't put this check in an else-block.)
Ben.
Signature · 3 lines
Ben Hutchings Any smoothly functioning technology is indistinguishable from a rigged demo.
Re: [PATCH 5.10 430/491] apparmor: validate DFA start states are in bounds in unpack_pdb
Quoted 61 lines · Ben Hutchings
Quoted 58 lines · Greg Kroah-Hartman
5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Massimiliano Pellizzer <[email protected]>
commit
9063d7e2615f4a7ab321de6b520e23d370e58816upstream.Backport for conflicts caused by
ad596ea74e74("apparmor: group dfa policydb unpacking")
- rearrange and consolidated the unpack.
b11e51dd7094("apparmor: test: make static symbols visible during kunit testing")
- rename function and make it visible to kunit testsStart states are read from untrusted data and used as indexes into the DFA state tables. The
aa_dfa_next()function call inunpack_pdb()will access dfa->tables[YYTD_ID_BASE][start], and if the start state exceeds the number of states in the DFA, this results in an out-of-bound read.==================================================================
BUG: KASAN: slab-out-of-bounds in aa_dfa_next+0x2a1/0x360 Read of size 4 at addr ffff88811956fb90 by task su/1097 ...Reject policies with out-of-bounds start states during unpacking to prevent the issue.
Fixes ad5ff3db53c6 ("AppArmor: Add ability to load extended policy")Reported-by Qualys Security Advisory <[email protected]>Tested-by Salvatore Bonaccorso <[email protected]>Reviewed-by Georgia Garcia <[email protected]>Reviewed-by Cengiz Can <[email protected]>Signed-off-by Massimiliano Pellizzer <[email protected]>Signed-off-by John Johansen <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- security/apparmor/policy_unpack.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)security/apparmor/policy_unpack.c +9
-1@@ -841,9 +841,18 @@ static struct aa_profile *unpack_profile error = -EPROTO ; goto fail; } -if (!unpack_u32 (e, &profile->policy.start[0 ],"start" )) +if (!unpack_u32 (e, &profile->policy.start[0 ],"start" )) {/* default start state */ profile->policy.start[0 ] =DFA_START ; + }else { +size_t state_count = profile->policy.dfa->tables[YYTD_ID_BASE ]->td_lolen; + +if (profile->policy.start[0 ] >= state_count) { + info ="invalid dfa start state" ; + goto fail; + } + }[...]
Quoted 8 lines
Isn't this range check needed even if we use the default start state?
unpack_table()only checks thattd_tolen> 0, so we could end up with profile->policy.start[0] =DFA_START== 1 and profile->policy.dfa->tables[YYTD_ID_BASE]->td_lolen == 1.(This is specific to the backport as the upstream version didn't put this check in an else-block.)
Hey Ben,
I specifically chose not to make that alteration to the patches sent to stable after reviewing the submission rules. That would be a non-backport related change from what landed upstream and we were referencing as the upstream patch. Instead I am sending Linus a 2nd patch that addresses the issue by ensure the loaded dfa has at least two states. It will has a fixes tag and will get pulled back.
Re: [PATCH 5.10 430/491] apparmor: validate DFA start states are in bounds in unpack_pdb
Quoted 71 lines · John Johansen
Quoted 61 lines · Ben Hutchings
Quoted 58 lines · Greg Kroah-Hartman
5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Massimiliano Pellizzer <[email protected]>
commit
9063d7e2615f4a7ab321de6b520e23d370e58816upstream.Backport for conflicts caused by
ad596ea74e74("apparmor: group dfa policydb unpacking")
- rearrange and consolidated the unpack.
b11e51dd7094("apparmor: test: make static symbols visible during kunit testing")
- rename function and make it visible to kunit testsStart states are read from untrusted data and used as indexes into the DFA state tables. The
aa_dfa_next()function call inunpack_pdb()will access dfa->tables[YYTD_ID_BASE][start], and if the start state exceeds the number of states in the DFA, this results in an out-of-bound read.==================================================================
BUG: KASAN: slab-out-of-bounds in aa_dfa_next+0x2a1/0x360 Read of size 4 at addr ffff88811956fb90 by task su/1097 ...Reject policies with out-of-bounds start states during unpacking to prevent the issue.
Fixes ad5ff3db53c6 ("AppArmor: Add ability to load extended policy")Reported-by Qualys Security Advisory <[email protected]>Tested-by Salvatore Bonaccorso <[email protected]>Reviewed-by Georgia Garcia <[email protected]>Reviewed-by Cengiz Can <[email protected]>Signed-off-by Massimiliano Pellizzer <[email protected]>Signed-off-by John Johansen <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- security/apparmor/policy_unpack.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)security/apparmor/policy_unpack.c +9
-1@@ -841,9 +841,18 @@ static struct aa_profile *unpack_profile error = -EPROTO ; goto fail; } -if (!unpack_u32 (e, &profile->policy.start[0 ],"start" )) +if (!unpack_u32 (e, &profile->policy.start[0 ],"start" )) {/* default start state */ profile->policy.start[0 ] =DFA_START ; + }else { +size_t state_count = profile->policy.dfa->tables[YYTD_ID_BASE ]->td_lolen; + +if (profile->policy.start[0 ] >= state_count) { + info ="invalid dfa start state" ; + goto fail; + } + }[...]
Quoted 8 lines
Isn't this range check needed even if we use the default start state?
unpack_table()only checks thattd_tolen> 0, so we could end up with profile->policy.start[0] =DFA_START== 1 and profile->policy.dfa->tables[YYTD_ID_BASE]->td_lolen == 1.(This is specific to the backport as the upstream version didn't put this check in an else-block.)
Quoted 5 lines
Hey Ben,
I specifically chose not to make that alteration to the patches sent to stable after reviewing the submission rules. That would be a non-backport related change from what landed upstream and we were referencing as the upstream patch.
But the upstream patch didn't have this problem! The range check was not conditional so it would catch this case.
Quoted 3 lines
Instead I am sending Linus a 2nd patch that addresses
the issue by ensure the loaded dfa has at least two states. It will has a fixes tag and will get pulled back.
I think you are talking about adding a check in unpack_table(). I am talking about the later check in unpack_profile() (or in unpack_pdb() upstream).
Ben.
Signature · 3 lines
Ben Hutchings Nothing is ever a complete failure; it can always serve as a bad example.
PATCH 1/1 apparmor: validate default DFA states are in bounds
In reply to Ben HutchingsSome backports of commit 9063d7e2615f ("apparmor: validate DFA start states are in bounds in unpack_pdb") limited the bounds checks on DFA start states to the case where the start state was explicit in the policy. However, the default DFA start state (DFA_START = 1) could also be out-of-bounds.
Move these checks out of the else-branches so that they are applied regardless of how the start state was initialised.
--- security/apparmor/policy_unpack.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-)
security/apparmor/policy_unpack.c +15 -12
@@ -829,6 +829,8 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name) }if (aa_unpack_nameX (e,AA_STRUCT ,"policydb" )) { +size_t state_count; +/* generic policy dfa - optional and may be NULL */ info ="failed to unpack policydb" ; profile->policy.dfa =unpack_dfa (e);
@@ -843,13 +845,12 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name)if (!aa_unpack_u32 (e, &profile->policy.start[0 ],"start" )) {/* default start state */ profile->policy.start[0 ] =DFA_START ; - }else { -size_t state_count = profile->policy.dfa->tables[YYTD_ID_BASE ]->td_lolen; + } -if (profile->policy.start[0 ] >= state_count) { - info ="invalid dfa start state" ; - goto fail; - } + state_count = profile->policy.dfa->tables[YYTD_ID_BASE ]->td_lolen; +if (profile->policy.start[0 ] >= state_count) { + info ="invalid dfa start state" ; + goto fail; }/* setup class index */
@@ -872,16 +873,18 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name) info ="failed to unpack profile file rules" ; goto fail; }else if (profile->file.dfa) { +size_t state_count; +if (!aa_unpack_u32 (e, &profile->file.start,"dfa_start" )) {/* default start state */ profile->file.start =DFA_START ; - }else { -size_t state_count = profile->file.dfa->tables[YYTD_ID_BASE ]->td_lolen; + } -if (profile->file.start >= state_count) { - info ="invalid dfa start state" ; - goto fail; - } + state_count = profile->file.dfa->tables[YYTD_ID_BASE ]->td_lolen; + +if (profile->file.start >= state_count) { + info ="invalid dfa start state" ; + goto fail; } }else if (profile->policy.dfa && profile->policy.start[AA_CLASS_FILE ]) {
PATCH 1/1 apparmor: validate default DFA states are in bounds
In reply to Ben HutchingsSome backports of commit 9063d7e2615f ("apparmor: validate DFA start states are in bounds in unpack_pdb") limited the bounds checks on DFA start states to the case where the start state was explicit in the policy. However, the default DFA start state (DFA_START = 1) could also be out-of-bounds.
Move these checks out of the else-branches so that they are applied regardless of how the start state was initialised.
--- security/apparmor/policy_unpack.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-)
security/apparmor/policy_unpack.c +15 -12
@@ -846,6 +846,8 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name) }if (unpack_nameX (e,AA_STRUCT ,"policydb" )) { +size_t state_count; +/* generic policy dfa - optional and may be NULL */ info ="failed to unpack policydb" ; profile->policy.dfa =unpack_dfa (e);
@@ -860,13 +862,12 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name)if (!unpack_u32 (e, &profile->policy.start[0 ],"start" )) {/* default start state */ profile->policy.start[0 ] =DFA_START ; - }else { -size_t state_count = profile->policy.dfa->tables[YYTD_ID_BASE ]->td_lolen; + } -if (profile->policy.start[0 ] >= state_count) { - info ="invalid dfa start state" ; - goto fail; - } + state_count = profile->policy.dfa->tables[YYTD_ID_BASE ]->td_lolen; +if (profile->policy.start[0 ] >= state_count) { + info ="invalid dfa start state" ; + goto fail; }/* setup class index */
@@ -889,16 +890,18 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name) info ="failed to unpack profile file rules" ; goto fail; }else if (profile->file.dfa) { +size_t state_count; +if (!unpack_u32 (e, &profile->file.start,"dfa_start" )) {/* default start state */ profile->file.start =DFA_START ; - }else { -size_t state_count = profile->file.dfa->tables[YYTD_ID_BASE ]->td_lolen; + } -if (profile->file.start >= state_count) { - info ="invalid dfa start state" ; - goto fail; - } + state_count = profile->file.dfa->tables[YYTD_ID_BASE ]->td_lolen; + +if (profile->file.start >= state_count) { + info ="invalid dfa start state" ; + goto fail; } }else if (profile->policy.dfa && profile->policy.start[AA_CLASS_FILE ]) {
Greg Kroah-Hartman
maintainerPATCH 431/491 apparmor: fix memory leak in verify_header
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Massimiliano Pellizzer <[email protected]>
commit e38c55d9f834e5b848bfed0f5c586aaf45acb825 upstream.
The function sets *ns = NULL on every call, leaking the namespace string allocated in previous iterations when multiple profiles are unpacked. This also breaks namespace consistency checking since *ns is always NULL when the comparison is made.
Remove the incorrect assignment.
The caller (aa_unpack) initializes *ns to NULL once before the loop, which is sufficient.
--- security/apparmor/policy_unpack.c | 1 - 1 file changed, 1 deletion(-)
security/apparmor/policy_unpack.c +0 -1
@@ -976,7 +976,6 @@ static int verify_header(struct aa_ext * {int error = -EPROTONOSUPPORT ;const char *name =NULL ; - *ns =NULL ;/* get the interface version */ if (!unpack_u32 (e, &e->version,"version" )) {
Greg Kroah-Hartman
maintainerPATCH 432/491 apparmor: replace recursive profile removal with iterative approach
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Massimiliano Pellizzer <[email protected]>
commit ab09264660f9de5d05d1ef4e225aa447c63a8747 upstream.
The profile removal code uses recursion when removing nested profiles, which can lead to kernel stack exhaustion and system crashes.
Reproducer:
$ pf='a'; for ((i=0; i<1024; i++)); do
echo -e "profile $pf { \n }" | apparmor_parser -K -a;
pf="$pf//x";
done
$ echo -n a > /sys/kernel/security/apparmor/.removeReplace the recursive __aa_profile_list_release() approach with an iterative approach in __remove_profile(). The function repeatedly finds and removes leaf profiles until the entire subtree is removed, maintaining the same removal semantic without recursion.
--- security/apparmor/policy.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-)
security/apparmor/policy.c +27 -3
@@ -146,19 +146,43 @@ static void __list_remove_profile(struct }/** -* __remove_profile - remove old profile, and children -* @profile: profile to be replaced (NOT NULL) +* __remove_profile - remove profile, and children +* @profile: profile to be removed (NOT NULL) * * Requires: namespace list lock be held, or list not be shared */ static void __remove_profile (struct aa_profile *profile) { +struct aa_profile *curr, *to_remove; +AA_BUG (!profile);AA_BUG (!profile->ns);AA_BUG (!mutex_is_locked (&profile->ns->lock));/* release any children lists first */ -__aa_profile_list_release (&profile->base.profiles); +if (!list_empty (&profile->base.profiles)) { + curr = list_first_entry(&profile->base.profiles, struct aa_profile, base.list); + +while (curr != profile) { + +while (!list_empty (&curr->base.profiles)) + curr =list_first_entry (&curr->base.profiles, + struct aa_profile, base.list); + + to_remove = curr; +if (!list_is_last (&to_remove->base.list, + &aa_deref_parent (curr)->base.profiles)) + curr =list_next_entry (to_remove, base.list); +else + curr =aa_deref_parent (curr); + +/* released by free_profile */ +aa_label_remove (&to_remove->label); +__aafs_profile_rmdir (to_remove); +__list_remove_profile (to_remove); + } + } +/* released by free_profile */ aa_label_remove (&profile->label);__aafs_profile_rmdir (profile);
Greg Kroah-Hartman
maintainerPATCH 433/491 apparmor: fix: limit the number of levels of policy namespaces
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Johansen <[email protected]>
commit 306039414932c80f8420695a24d4fe10c84ccfb2 upstream.
Currently the number of policy namespaces is not bounded relying on the user namespace limit. However policy namespaces aren't strictly tied to user namespaces and it is possible to create them and nest them arbitrarily deep which can be used to exhaust system resource.
Hard cap policy namespaces to the same depth as user namespaces.
--- security/apparmor/include/policy_ns.h | 2 ++ security/apparmor/policy_ns.c | 2 ++ 2 files changed, 4 insertions(+)
security/apparmor/include/policy_ns.h +2 -0
@@ -18,6 +18,8 @@#include "label.h" #include "policy.h" +/* Match max depth of user namespaces */ +#define MAX_NS_DEPTH 32/* struct aa_ns_acct - accounting of profiles in namespace * @max_size: maximum space allowed for all profiles in namespace
security/apparmor/policy_ns.c +2 -0
@@ -249,6 +249,8 @@ static struct aa_ns *__aa_create_ns(struAA_BUG (!name);AA_BUG (!mutex_is_locked (&parent->lock)); +if (parent->level >MAX_NS_DEPTH ) +return ERR_PTR (-ENOSPC ); ns =alloc_ns (parent->base.hname, name);if (!ns)return ERR_PTR (-ENOMEM );
Greg Kroah-Hartman
maintainerPATCH 434/491 apparmor: fix side-effect bug in match_char() macro usage
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Massimiliano Pellizzer <[email protected]>
commit 8756b68edae37ff546c02091989a4ceab3f20abd upstream.
The match_char() macro evaluates its character parameter multiple times when traversing differential encoding chains. When invoked with *str++, the string pointer advances on each iteration of the inner do-while loop, causing the DFA to check different characters at each iteration and therefore skip input characters. This results in out-of-bounds reads when the pointer advances past the input buffer boundary.
[ 94.984676] ================================================================== [ 94.985301] BUG: KASAN: slab-out-of-bounds in aa_dfa_match+0x5ae/0x760 [ 94.985655] Read of size 1 at addr ffff888100342000 by task file/976
[ 94.986319] CPU: 7 UID: 1000 PID: 976 Comm: file Not tainted 6.19.0-rc7-next-20260127 #1 PREEMPT(lazy) [ 94.986322] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 [ 94.986329] Call Trace: [ 94.986341] <TASK> [ 94.986347] dump_stack_lvl+0x5e/0x80 [ 94.986374] print_report+0xc8/0x270 [ 94.986384] ? aa_dfa_match+0x5ae/0x760 [ 94.986388] kasan_report+0x118/0x150 [ 94.986401] ? aa_dfa_match+0x5ae/0x760 [ 94.986405] aa_dfa_match+0x5ae/0x760 [ 94.986408] __aa_path_perm+0x131/0x400 [ 94.986418] aa_path_perm+0x219/0x2f0 [ 94.986424] apparmor_file_open+0x345/0x570 [ 94.986431] security_file_open+0x5c/0x140 [ 94.986442] do_dentry_open+0x2f6/0x1120 [ 94.986450] vfs_open+0x38/0x2b0 [ 94.986453] ? may_open+0x1e2/0x2b0 [ 94.986466] path_openat+0x231b/0x2b30 [ 94.986469] ? __x64_sys_openat+0xf8/0x130 [ 94.986477] do_file_open+0x19d/0x360 [ 94.986487] do_sys_openat2+0x98/0x100 [ 94.986491] __x64_sys_openat+0xf8/0x130 [ 94.986499] do_syscall_64+0x8e/0x660 [ 94.986515] ? count_memcg_events+0x15f/0x3c0 [ 94.986526] ? srso_alias_return_thunk+0x5/0xfbef5 [ 94.986540] ? handle_mm_fault+0x1639/0x1ef0 [ 94.986551] ? vma_start_read+0xf0/0x320 [ 94.986558] ? srso_alias_return_thunk+0x5/0xfbef5 [ 94.986561] ? srso_alias_return_thunk+0x5/0xfbef5 [ 94.986563] ? fpregs_assert_state_consistent+0x50/0xe0 [ 94.986572] ? srso_alias_return_thunk+0x5/0xfbef5 [ 94.986574] ? arch_exit_to_user_mode_prepare+0x9/0xb0 [ 94.986587] ? srso_alias_return_thunk+0x5/0xfbef5 [ 94.986588] ? irqentry_exit+0x3c/0x590 [ 94.986595] entry_SYSCALL_64_after_hwframe+0x76/0x7e [ 94.986597] RIP: 0033:0x7fda4a79c3ea
Fix by extracting the character value before invoking match_char, ensuring single evaluation per outer loop.
--- security/apparmor/match.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-)
security/apparmor/match.c +20 -10
@@ -452,13 +452,18 @@ unsigned int aa_dfa_match_len(struct aa_if (dfa->tables[YYTD_ID_EC ]) {/* Equivalence class table defined */ u8 *equiv =EQUIV_TABLE (dfa); -for (; len; len--) -match_char (state, def, base, next, check, - equiv[(u8) *str++]); +for (; len; len--) { +u8 c = equiv[(u8) *str]; + +match_char (state, def, base, next, check, c); + str++; + } }else {/* default is direct to next state */ -for (; len; len--) -match_char (state, def, base, next, check, (u8) *str++); +for (; len; len--) { +match_char (state, def, base, next, check, (u8) *str); + str++; + } }return state;
@@ -493,13 +498,18 @@ unsigned int aa_dfa_match(struct aa_dfa/* Equivalence class table defined */ u8 *equiv =EQUIV_TABLE (dfa);/* default is direct to next state */ -while (*str) -match_char (state, def, base, next, check, - equiv[(u8) *str++]); +while (*str) { +u8 c = equiv[(u8) *str]; + +match_char (state, def, base, next, check, c); + str++; + } }else {/* default is direct to next state */ -while (*str) -match_char (state, def, base, next, check, (u8) *str++); +while (*str) { +match_char (state, def, base, next, check, (u8) *str); + str++; + } }return state;
Greg Kroah-Hartman
maintainerPATCH 435/491 apparmor: fix missing bounds check on DEFAULT table in verify_dfa()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Massimiliano Pellizzer <[email protected]>
commit d352873bbefa7eb39995239d0b44ccdf8aaa79a4 upstream.
The verify_dfa() function only checks DEFAULT_TABLE bounds when the state is not differentially encoded.
When the verification loop traverses the differential encoding chain, it reads k = DEFAULT_TABLE[j] and uses k as an array index without validation. A malformed DFA with DEFAULT_TABLE[j] >= state_count, therefore, causes both out-of-bounds reads and writes.
[ 57.179855] ================================================================== [ 57.180549] BUG: KASAN: slab-out-of-bounds in verify_dfa+0x59a/0x660 [ 57.180904] Read of size 4 at addr ffff888100eadec4 by task su/993
[ 57.181554] CPU: 1 UID: 0 PID: 993 Comm: su Not tainted 6.19.0-rc7-next-20260127 #1 PREEMPT(lazy) [ 57.181558] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 [ 57.181563] Call Trace: [ 57.181572] <TASK> [ 57.181577] dump_stack_lvl+0x5e/0x80 [ 57.181596] print_report+0xc8/0x270 [ 57.181605] ? verify_dfa+0x59a/0x660 [ 57.181608] kasan_report+0x118/0x150 [ 57.181620] ? verify_dfa+0x59a/0x660 [ 57.181623] verify_dfa+0x59a/0x660 [ 57.181627] aa_dfa_unpack+0x1610/0x1740 [ 57.181629] ? __kmalloc_cache_noprof+0x1d0/0x470 [ 57.181640] unpack_pdb+0x86d/0x46b0 [ 57.181647] ? srso_alias_return_thunk+0x5/0xfbef5 [ 57.181653] ? srso_alias_return_thunk+0x5/0xfbef5 [ 57.181656] ? aa_unpack_nameX+0x1a8/0x300 [ 57.181659] aa_unpack+0x20b0/0x4c30 [ 57.181662] ? srso_alias_return_thunk+0x5/0xfbef5 [ 57.181664] ? stack_depot_save_flags+0x33/0x700 [ 57.181681] ? kasan_save_track+0x4f/0x80 [ 57.181683] ? kasan_save_track+0x3e/0x80 [ 57.181686] ? __kasan_kmalloc+0x93/0xb0 [ 57.181688] ? __kvmalloc_node_noprof+0x44a/0x780 [ 57.181693] ? aa_simple_write_to_buffer+0x54/0x130 [ 57.181697] ? policy_update+0x154/0x330 [ 57.181704] aa_replace_profiles+0x15a/0x1dd0 [ 57.181707] ? srso_alias_return_thunk+0x5/0xfbef5 [ 57.181710] ? __kvmalloc_node_noprof+0x44a/0x780 [ 57.181712] ? aa_loaddata_alloc+0x77/0x140 [ 57.181715] ? srso_alias_return_thunk+0x5/0xfbef5 [ 57.181717] ? _copy_from_user+0x2a/0x70 [ 57.181730] policy_update+0x17a/0x330 [ 57.181733] profile_replace+0x153/0x1a0 [ 57.181735] ? rw_verify_area+0x93/0x2d0 [ 57.181740] vfs_write+0x235/0xab0 [ 57.181745] ksys_write+0xb0/0x170 [ 57.181748] do_syscall_64+0x8e/0x660 [ 57.181762] entry_SYSCALL_64_after_hwframe+0x76/0x7e [ 57.181765] RIP: 0033:0x7f6192792eb2
Remove the MATCH_FLAG_DIFF_ENCODE condition to validate all DEFAULT_TABLE entries unconditionally.
--- security/apparmor/match.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
security/apparmor/match.c +3 -2
@@ -204,9 +204,10 @@ static int verify_dfa(struct aa_dfa *dfaif (state_count ==0 ) goto out;for (i =0 ; i < state_count; i++) { -if (!(BASE_TABLE (dfa)[i] &MATCH_FLAG_DIFF_ENCODE ) && - (DEFAULT_TABLE (dfa)[i] >= state_count)) +if (DEFAULT_TABLE (dfa)[i] >= state_count) { +pr_err ("AppArmor DFA default state out of bounds" ); goto out; + }if (BASE_TABLE (dfa)[i] &MATCH_FLAGS_INVALID ) {pr_err ("AppArmor DFA state with invalid match flags" ); goto out;
Greg Kroah-Hartman
maintainerPATCH 436/491 apparmor: Fix double free of ns_name in aa_replace_profiles()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Johansen <[email protected]>
commit 5df0c44e8f5f619d3beb871207aded7c78414502 upstream.
if ns_name is NULL after
1071 error = aa_unpack(udata, &lh, &ns_name);
and if ent->ns_name contains an ns_name in
1089 } else if (ent->ns_name) {
then ns_name is assigned the ent->ns_name
1095 ns_name = ent->ns_name;
however ent->ns_name is freed at
1262 aa_load_ent_free(ent);
and then again when freeing ns_name at
1270 kfree(ns_name);
Fix this by NULLing out ent->ns_name after it is transferred to ns_name
")
--- security/apparmor/policy.c | 1 + 1 file changed, 1 insertion(+)
security/apparmor/policy.c +1 -0
@@ -917,6 +917,7 @@ ssize_t aa_replace_profiles(struct aa_ns goto fail; } ns_name = ent->ns_name; + ent->ns_name =NULL ; }else count++; }
Greg Kroah-Hartman
maintainerPATCH 437/491 apparmor: fix unprivileged local user can do privileged policy management
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Johansen <[email protected]>
commit 6601e13e82841879406bf9f369032656f441a425 upstream.
Backport for api changes introduced in
- 90c436a64a6e ("apparmor: pass cred through to audit info.")
- 92de220a7f33 ("apparmor: update policy capable checks to use a label")
An unprivileged local user can load, replace, and remove profiles by opening the apparmorfs interfaces, via a confused deputy attack, by passing the opened fd to a privileged process, and getting the privileged process to write to the interface.
This does require a privileged target that can be manipulated to do the write for the unprivileged process, but once such access is achieved full policy management is possible and all the possible implications that implies: removing confinement, DoS of system or target applications by denying all execution, by-passing the unprivileged user namespace restriction, to exploiting kernel bugs for a local privilege escalation.
The policy management interface can not have its permissions simply changed from 0666 to 0600 because non-root processes need to be able to load policy to different policy namespaces.
Instead ensure the task writing the interface has privileges that are a subset of the task that opened the interface. This is already done via policy for confined processes, but unconfined can delegate access to the opened fd, by-passing the usual policy check.
--- security/apparmor/apparmorfs.c | 19 +++++++++++------- security/apparmor/include/policy.h | 5 ++-- security/apparmor/policy.c | 39 +++++++++++++++++++++++++++++++++++-- 3 files changed, 52 insertions(+), 11 deletions(-)
security/apparmor/apparmorfs.c +12 -7
@@ -409,7 +409,8 @@ static struct aa_loaddata *aa_simple_wri }static ssize_t policy_update (u32 mask,const char __user *buf,size_t size, -loff_t *pos,struct aa_ns *ns) +loff_t *pos,struct aa_ns *ns, +const struct cred *ocred) {struct aa_loaddata *data;struct aa_label *label;
@@ -420,7 +421,7 @@ static ssize_t policy_update(u32 mask, c/* high level check about policy management - fine grained in * below after unpack */ - error =aa_may_manage_policy (label, ns, mask); + error =aa_may_manage_policy (current_cred (), label, ns, ocred, mask);if (error) goto end_section;
@@ -441,7 +442,8 @@ static ssize_t profile_load(struct file loff_t *pos) {struct aa_ns *ns =aa_get_ns (f->f_inode->i_private); -int error =policy_update (AA_MAY_LOAD_POLICY , buf, size, pos, ns); +int error =policy_update (AA_MAY_LOAD_POLICY , buf, size, pos, ns, + f->f_cred);aa_put_ns (ns);
@@ -459,7 +461,7 @@ static ssize_t profile_replace(struct fi {struct aa_ns *ns =aa_get_ns (f->f_inode->i_private);int error =policy_update (AA_MAY_LOAD_POLICY |AA_MAY_REPLACE_POLICY , - buf, size, pos, ns); + buf, size, pos, ns, f->f_cred);aa_put_ns (ns);return error;
@@ -483,7 +485,8 @@ static ssize_t profile_remove(struct fil/* high level check about policy management - fine grained in * below after unpack */ - error =aa_may_manage_policy (label, ns,AA_MAY_REMOVE_POLICY ); + error =aa_may_manage_policy (current_cred (), label, ns, + f->f_cred,AA_MAY_REMOVE_POLICY );if (error) goto out;
@@ -1796,7 +1799,8 @@ static int ns_mkdir_op(struct inode *dirint error; label =begin_current_label_crit_section (); - error =aa_may_manage_policy (label,NULL ,AA_MAY_LOAD_POLICY ); + error =aa_may_manage_policy (current_cred (), label,NULL ,NULL , +AA_MAY_LOAD_POLICY );end_current_label_crit_section (label);if (error)return error;
@@ -1845,7 +1849,8 @@ static int ns_rmdir_op(struct inode *dirint error; label =begin_current_label_crit_section (); - error =aa_may_manage_policy (label,NULL ,AA_MAY_LOAD_POLICY ); + error =aa_may_manage_policy (current_cred (), label,NULL ,NULL , +AA_MAY_LOAD_POLICY );end_current_label_crit_section (label);if (error)return error;
security/apparmor/include/policy.h +3 -2
@@ -303,7 +303,8 @@ static inline int AUDIT_MODE(struct aa_pbool policy_view_capable (struct aa_ns *ns);bool policy_admin_capable (struct aa_ns *ns); -int aa_may_manage_policy (struct aa_label *label,struct aa_ns *ns, -u32 mask); +int aa_may_manage_policy (const struct cred *subj_cred, +struct aa_label *label,struct aa_ns *ns, +const struct cred *ocred,u32 mask);#endif /* __AA_POLICY_H */
security/apparmor/policy.c +37 -2
@@ -695,14 +695,44 @@ bool policy_admin_capable(struct aa_ns *return policy_view_capable (ns) && capable && !aa_g_lock_policy; } +static bool is_subset_of_obj_privilege (const struct cred *cred, +struct aa_label *label, +const struct cred *ocred) +{ +if (cred == ocred) +return true; + +if (!aa_label_is_subset (label,cred_label (ocred))) +return false; +/* don't allow crossing userns for now */ +if (cred->user_ns != ocred->user_ns) +return false; +if (!cap_issubset (cred->cap_inheritable, ocred->cap_inheritable)) +return false; +if (!cap_issubset (cred->cap_permitted, ocred->cap_permitted)) +return false; +if (!cap_issubset (cred->cap_effective, ocred->cap_effective)) +return false; +if (!cap_issubset (cred->cap_bset, ocred->cap_bset)) +return false; +if (!cap_issubset (cred->cap_ambient, ocred->cap_ambient)) +return false; +return true; +} + +/** * aa_may_manage_policy - can the current task manage policy +* @subj_cred; subjects cred * @label: label to check if it can manage policy -* @op: the policy manipulation operation being done +* @ns: namespace being managed by @label (may be NULL if @label's ns) +* @ocred: object cred if request is coming from an open object +* @mask: contains the policy manipulation operation being done * * Returns: 0 if the task is allowed to manipulate policy else error */ -int aa_may_manage_policy (struct aa_label *label,struct aa_ns *ns,u32 mask) +int aa_may_manage_policy (const struct cred *subj_cred,struct aa_label *label, +struct aa_ns *ns,const struct cred *ocred,u32 mask) {const char *op;
@@ -718,6 +748,11 @@ int aa_may_manage_policy(struct aa_labelreturn audit_policy (label, op,NULL ,NULL ,"policy_locked" , -EACCES ); +if (ocred && !is_subset_of_obj_privilege (subj_cred, label, ocred)) +return audit_policy (label, op,NULL ,NULL , +"not privileged for target profile" , + -EACCES ); +if (!policy_admin_capable (ns))return audit_policy (label, op,NULL ,NULL ,"not policy admin" , -EACCES );
Greg Kroah-Hartman
maintainerPATCH 438/491 apparmor: fix differential encoding verification
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Johansen <[email protected]>
commit 39440b137546a3aa383cfdabc605fb73811b6093 upstream.
Differential encoding allows loops to be created if it is abused. To prevent this the unpack should verify that a diff-encode chain terminates.
Unfortunately the differential encode verification had two bugs.
1. it conflated states that had gone through check and already been marked, with states that were currently being checked and marked. This means that loops in the current chain being verified are treated as a chain that has already been verified.
2. the order bailout on already checked states compared current chain check iterators j,k instead of using the outer loop iterator i. Meaning a step backwards in states in the current chain verification was being mistaken for moving to an already verified state.
Move to a double mark scheme where already verified states get a different mark, than the current chain being kept. This enables us to also drop the backwards verification check that was the cause of the second error as any already verified state is already marked.
--- security/apparmor/include/match.h | 1 + security/apparmor/match.c | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-)
security/apparmor/include/match.h +1 -0
@@ -190,6 +190,7 @@ static inline void aa_put_dfa(struct aa_#define MATCH_FLAG_DIFF_ENCODE 0x80000000#define MARK_DIFF_ENCODE 0x40000000#define MATCH_FLAG_OOB_TRANSITION 0x20000000 +#define MARK_DIFF_ENCODE_VERIFIED 0x10000000#define MATCH_FLAGS_MASK 0xff000000#define MATCH_FLAGS_VALID (MATCH_FLAG_DIFF_ENCODE | MATCH_FLAG_OOB_TRANSITION)#define MATCH_FLAGS_INVALID (MATCH_FLAGS_MASK & ~MATCH_FLAGS_VALID)
security/apparmor/match.c +19 -4
@@ -246,16 +246,31 @@ static int verify_dfa(struct aa_dfa *dfasize_t j, k;for (j = i; - (BASE_TABLE (dfa)[j] &MATCH_FLAG_DIFF_ENCODE ) && - !(BASE_TABLE (dfa)[j] &MARK_DIFF_ENCODE ); + ((BASE_TABLE (dfa)[j] &MATCH_FLAG_DIFF_ENCODE ) && + !(BASE_TABLE (dfa)[j] &MARK_DIFF_ENCODE_VERIFIED )); j = k) { +if (BASE_TABLE (dfa)[j] &MARK_DIFF_ENCODE ) +/* loop in current chain */ + goto out; k =DEFAULT_TABLE (dfa)[j];if (j == k) +/* self loop */ goto out; -if (k < j) -break ;/* already verified */ BASE_TABLE (dfa)[j] |=MARK_DIFF_ENCODE ; } +/* move mark to verified */ +for (j = i; + (BASE_TABLE (dfa)[j] &MATCH_FLAG_DIFF_ENCODE ); + j = k) { + k =DEFAULT_TABLE (dfa)[j]; +if (j < i) +/* jumps to state/chain that has been +* verified +*/ +break ; +BASE_TABLE (dfa)[j] &= ~MARK_DIFF_ENCODE ; +BASE_TABLE (dfa)[j] |=MARK_DIFF_ENCODE_VERIFIED ; + } } error =0 ;
Greg Kroah-Hartman
maintainerPATCH 439/491 apparmor: fix race on rawdata dereference
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Johansen <[email protected]>
commit a0b7091c4de45a7325c8780e6934a894f92ac86b upstream.
Backport for conflicts introdued by
d61c57fde819 ("apparmor: make export of raw binary profile to userspace optional") which nests the conflicting code inside an if condition
There is a race condition that leads to a use-after-free situation:
because the rawdata inodes are not refcounted, an attacker can start open()ing one of the rawdata files, and at the same time remove the last reference to this rawdata (by removing the corresponding profile, for example), which frees its struct aa_loaddata; as a result, when seq_rawdata_open() is reached, i_private is a dangling pointer and freed memory is accessed.
The rawdata inodes weren't refcounted to avoid a circular refcount and were supposed to be held by the profile rawdata reference. However during profile removal there is a window where the vfs and profile destruction race, resulting in the use after free.
Fix this by moving to a double refcount scheme. Where the profile refcount on rawdata is used to break the circular dependency. Allowing for freeing of the rawdata once all inode references to the rawdata are put.
--- security/apparmor/apparmorfs.c | 36 +++++++++------ security/apparmor/include/policy_unpack.h | 71 ++++++++++++++++++------------ security/apparmor/policy.c | 12 ++--- security/apparmor/policy_unpack.c | 32 +++++++++---- 4 files changed, 94 insertions(+), 57 deletions(-)
security/apparmor/apparmorfs.c +22 -14
@@ -77,7 +77,7 @@ static void rawdata_f_data_free(struct rif (!private)return ; -aa_put_loaddata (private->loaddata); +aa_put_i_loaddata (private->loaddata);kvfree (private); }
@@ -401,7 +401,9 @@ static struct aa_loaddata *aa_simple_wri data->size = copy_size;if (copy_from_user (data->data, userbuf, copy_size)) { -aa_put_loaddata (data); +/* trigger free - don't need to put pcount */ +aa_put_i_loaddata (data); +return ERR_PTR (-EFAULT ); }
@@ -429,7 +431,10 @@ static ssize_t policy_update(u32 mask, c error =PTR_ERR (data);if (!IS_ERR (data)) { error =aa_replace_profiles (ns, label, mask, data); -aa_put_loaddata (data); +/* put pcount, which will put count and free if no +* profiles referencing it. +*/ +aa_put_profile_loaddata (data); } end_section:end_current_label_crit_section (label);
@@ -500,7 +505,7 @@ static ssize_t profile_remove(struct filif (!IS_ERR (data)) { data->data[size] =0 ; error =aa_remove_profiles (ns, label, data->data, size); -aa_put_loaddata (data); +aa_put_profile_loaddata (data); } out:end_current_label_crit_section (label);
@@ -1225,18 +1230,17 @@ static const struct file_operations seq_static int seq_rawdata_open (struct inode *inode,struct file *file,int (*show)(struct seq_file *,void *)) { -struct aa_loaddata *data =__aa_get_loaddata (inode->i_private); +struct aa_loaddata *data =aa_get_i_loaddata (inode->i_private);int error;if (!data) -/* lost race this ent is being reaped */ return -ENOENT ; error =single_open (file, show, data);if (error) {AA_BUG (file->private_data && ((struct seq_file *)file->private_data)->private); -aa_put_loaddata (data); +aa_put_i_loaddata (data); }return error;
@@ -1247,7 +1251,7 @@ static int seq_rawdata_release(struct instruct seq_file *seq = (struct seq_file *) file->private_data;if (seq) -aa_put_loaddata (seq->private); +aa_put_i_loaddata (seq->private);return single_release (inode, file); }
@@ -1366,9 +1370,8 @@ static int rawdata_open(struct inode *inif (!policy_view_capable (NULL ))return -EACCES ; - loaddata =__aa_get_loaddata (inode->i_private); + loaddata =aa_get_i_loaddata (inode->i_private);if (!loaddata) -/* lost race: this entry is being reaped */ return -ENOENT ; private =rawdata_f_data_alloc (loaddata->size);
@@ -1393,7 +1396,7 @@ fail_decompress:return error; fail_private_alloc: -aa_put_loaddata (loaddata); +aa_put_i_loaddata (loaddata);return error; }
@@ -1410,9 +1413,9 @@ static void remove_rawdata_dents(structfor (i =0 ; i <AAFS_LOADDATA_NDENTS ; i++) {if (!IS_ERR_OR_NULL (rawdata->dents[i])) { -/* no refcounts on i_private */ aafs_remove (rawdata->dents[i]); rawdata->dents[i] =NULL ; +aa_put_i_loaddata (rawdata); } } }
@@ -1451,18 +1454,21 @@ int __aa_fs_create_rawdata(struct aa_nsif (IS_ERR (dir))/* ->name freed when rawdata freed */ return PTR_ERR (dir); +aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_DIR ] = dir; dent =aafs_create_file ("abi" ,S_IFREG |0444 , dir, rawdata, &seq_rawdata_abi_fops);if (IS_ERR (dent)) goto fail; +aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_ABI ] = dent; dent =aafs_create_file ("revision" ,S_IFREG |0444 , dir, rawdata, &seq_rawdata_revision_fops);if (IS_ERR (dent)) goto fail; +aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_REVISION ] = dent;if (aa_g_hash_policy) {
@@ -1470,6 +1476,7 @@ int __aa_fs_create_rawdata(struct aa_ns rawdata, &seq_rawdata_hash_fops);if (IS_ERR (dent)) goto fail; +aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_HASH ] = dent; }
@@ -1478,24 +1485,25 @@ int __aa_fs_create_rawdata(struct aa_ns &seq_rawdata_compressed_size_fops);if (IS_ERR (dent)) goto fail; +aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_COMPRESSED_SIZE ] = dent; dent =aafs_create_file ("raw_data" ,S_IFREG |0444 , dir, rawdata, &rawdata_fops);if (IS_ERR (dent)) goto fail; +aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_DATA ] = dent;d_inode (dent)->i_size = rawdata->size; rawdata->ns =aa_get_ns (ns);list_add (&rawdata->list, &ns->rawdata_list); -/* no refcount on inode rawdata */ return 0 ; fail:remove_rawdata_dents (rawdata); - +aa_put_i_loaddata (rawdata);return PTR_ERR (dent); }
security/apparmor/include/policy_unpack.h +43 -28
110 lines not on this page · raw message
security/apparmor/policy.c +6 -6
@@ -265,7 +265,7 @@ void aa_free_profile(struct aa_profile * }kfree_sensitive (profile->hash); -aa_put_loaddata (profile->rawdata); +aa_put_profile_loaddata (profile->rawdata);aa_label_destroy (&profile->label);kfree_sensitive (profile);
@@ -925,7 +925,7 @@ ssize_t aa_replace_profiles(struct aa_nsLIST_HEAD (lh); op = mask &AA_MAY_REPLACE_POLICY ?OP_PROF_REPL :OP_PROF_LOAD ; -aa_get_loaddata (udata); +aa_get_profile_loaddata (udata);/* released below */ error =aa_unpack (udata, &lh, &ns_name);if (error)
@@ -976,10 +976,10 @@ ssize_t aa_replace_profiles(struct aa_nsif (aa_rawdata_eq (rawdata_ent, udata)) {struct aa_loaddata *tmp; - tmp =__aa_get_loaddata (rawdata_ent); + tmp =aa_get_profile_loaddata (rawdata_ent);/* check we didn't fail the race */ if (tmp) { -aa_put_loaddata (udata); +aa_put_profile_loaddata (udata); udata = tmp;break ; }
@@ -989,7 +989,7 @@ ssize_t aa_replace_profiles(struct aa_nslist_for_each_entry (ent, &lh, list) {struct aa_policy *policy; - ent->new->rawdata =aa_get_loaddata (udata); + ent->new->rawdata =aa_get_profile_loaddata (udata); error =__lookup_replace (ns, ent->new->base.hname, !(mask &AA_MAY_REPLACE_POLICY ), &ent->old, &info);
@@ -1103,7 +1103,7 @@ ssize_t aa_replace_profiles(struct aa_ns out:aa_put_ns (ns); -aa_put_loaddata (udata); +aa_put_profile_loaddata (udata);kfree (ns_name);if (error)
security/apparmor/policy_unpack.c +23 -9
@@ -147,34 +147,47 @@ bool aa_rawdata_eq(struct aa_loaddata *lreturn memcmp (l->data, r->data, r->compressed_size ?: r->size) ==0 ; } +static void do_loaddata_free (struct aa_loaddata *d) +{ +kfree_sensitive (d->hash); +kfree_sensitive (d->name); +kvfree (d->data); +kfree_sensitive (d); +} + +void aa_loaddata_kref (struct kref *kref) +{ + struct aa_loaddata *d = container_of(kref, struct aa_loaddata, count); + +do_loaddata_free (d); +} +/* * need to take the ns mutex lock which is NOT safe most places that * put_loaddata is called, so we have to delay freeing it */ -static void do_loaddata_free (struct work_struct *work) +static void do_ploaddata_rmfs (struct work_struct *work) { struct aa_loaddata *d = container_of(work, struct aa_loaddata, work);struct aa_ns *ns =aa_get_ns (d->ns);if (ns) {mutex_lock_nested (&ns->lock, ns->level); +/* remove fs ref to loaddata */ __aa_fs_remove_rawdata (d);mutex_unlock (&ns->lock);aa_put_ns (ns); } - -kfree_sensitive (d->hash); -kfree_sensitive (d->name); -kvfree (d->data); -kfree_sensitive (d); +/* called by dropping last pcount, so drop its associated icount */ +aa_put_i_loaddata (d); } -void aa_loaddata_kref (struct kref *kref) +void aa_ploaddata_kref (struct kref *kref) { - struct aa_loaddata *d = container_of(kref, struct aa_loaddata, count); + struct aa_loaddata *d = container_of(kref, struct aa_loaddata, pcount);if (d) { -INIT_WORK (&d->work, do_loaddata_free); +INIT_WORK (&d->work, do_ploaddata_rmfs);schedule_work (&d->work); } }
@@ -192,6 +205,7 @@ struct aa_loaddata *aa_loaddata_alloc(sireturn ERR_PTR (-ENOMEM ); }kref_init (&d->count); +kref_init (&d->pcount);INIT_LIST_HEAD (&d->list);return d;
Greg Kroah-Hartman
maintainerPATCH 440/491 apparmor: fix race between freeing data and fs accessing it
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Johansen <[email protected]>
commit 8e135b8aee5a06c52a4347a5a6d51223c6f36ba3 upstream.
Backport for conflicts introdued by
- conversion from sha1 to sha256 introduced in
e44a4dc4b36c ("apparmor: switch SECURITY_APPARMOR_HASH from sha1 to sha256
")
- adding of conditioanl that nests the conflicting code inside an if condition
d61c57fde819 ("apparmor: make export of raw binary profile to userspace optional")
AppArmor was putting the reference to i_private data on its end after removing the original entry from the file system. However the inode can and does live beyond that point and it is possible that some of the fs call back functions will be invoked after the reference has been put, which results in a race between freeing the data and accessing it through the fs.
While the rawdata/loaddata is the most likely candidate to fail the race, as it has the fewest references. If properly crafted it might be possible to trigger a race for the other types stored in i_private.
Fix this by moving the put of i_private referenced data to the correct place which is during inode eviction.
--- security/apparmor/apparmorfs.c | 193 +++++++++++++++++------------- security/apparmor/include/label.h | 16 +- security/apparmor/include/lib.h | 12 + security/apparmor/include/policy.h | 8 - security/apparmor/include/policy_unpack.h | 6 security/apparmor/label.c | 12 + security/apparmor/policy_unpack.c | 6 7 files changed, 152 insertions(+), 101 deletions(-)
security/apparmor/apparmorfs.c +113 -80
@@ -32,6 +32,7 @@#include "include/crypto.h" #include "include/ipc.h" #include "include/label.h" +#include "include/lib.h" #include "include/policy.h" #include "include/policy_ns.h" #include "include/resource.h"
@@ -61,6 +62,7 @@* securityfs and apparmorfs filesystems. */ +#define IREF_POISON 101/* * support fns
@@ -150,6 +152,71 @@ static int aafs_show_path(struct seq_filreturn 0 ; } +static struct aa_ns *get_ns_common_ref (struct aa_common_ref *ref) +{ +if (ref) { + struct aa_label *reflabel = container_of(ref, struct aa_label, + count); +return aa_get_ns (labels_ns (reflabel)); + } + +return NULL ; +} + +static struct aa_proxy *get_proxy_common_ref (struct aa_common_ref *ref) +{ +if (ref) + return aa_get_proxy(container_of(ref, struct aa_proxy, count)); + +return NULL ; +} + +static struct aa_loaddata *get_loaddata_common_ref (struct aa_common_ref *ref) +{ +if (ref) + return aa_get_i_loaddata(container_of(ref, struct aa_loaddata, + count)); +return NULL ; +} + +static void aa_put_common_ref (struct aa_common_ref *ref) +{ +if (!ref) +return ; + +switch (ref->reftype) { +case REF_RAWDATA : +aa_put_i_loaddata (container_of (ref ,struct aa_loaddata , +count )); +break ; +case REF_PROXY : +aa_put_proxy (container_of (ref ,struct aa_proxy , +count )); +break ; +case REF_NS : +/* ns count is held on its unconfined label */ +aa_put_ns (labels_ns (container_of (ref ,struct aa_label ,count ))); +break ; +default : +AA_BUG (true,"unknown refcount type" ); +break ; + } +} + +static void aa_get_common_ref (struct aa_common_ref *ref) +{ +kref_get (&ref->count); +} + +static void aafs_evict (struct inode *inode) +{ +struct aa_common_ref *ref = inode->i_private; + +clear_inode (inode); +aa_put_common_ref (ref); + inode->i_private = (void *)IREF_POISON ; +} +static void aafs_free_inode (struct inode *inode) {if (S_ISLNK (inode->i_mode))
@@ -159,6 +226,7 @@ static void aafs_free_inode(struct inodestatic const struct super_operations aafs_super_ops = { .statfs = simple_statfs, + .evict_inode = aafs_evict, .free_inode = aafs_free_inode, .show_path = aafs_show_path, };
@@ -259,7 +327,8 @@ static int __aafs_setup_d_inode(struct i* aafs_remove(). Will return ERR_PTR on failure. */ static struct dentry *aafs_create (const char *name,umode_t mode, -struct dentry *parent,void *data,void *link, +struct dentry *parent, +struct aa_common_ref *data,void *link,const struct file_operations *fops,const struct inode_operations *iops) {
@@ -296,6 +365,9 @@ static struct dentry *aafs_create(const goto fail_dentry;inode_unlock (dir); +if (data) +aa_get_common_ref (data); +return dentry; fail_dentry:
@@ -320,7 +392,8 @@ fail_lock:* see aafs_create */ static struct dentry *aafs_create_file (const char *name,umode_t mode, -struct dentry *parent,void *data, +struct dentry *parent, +struct aa_common_ref *data,const struct file_operations *fops) {return aafs_create (name, mode, parent, data,NULL , fops,NULL );
@@ -446,7 +519,7 @@ end_section:static ssize_t profile_load (struct file *f,const char __user *buf,size_t size,loff_t *pos) { -struct aa_ns *ns =aa_get_ns (f->f_inode->i_private); +struct aa_ns *ns =get_ns_common_ref (f->f_inode->i_private);int error =policy_update (AA_MAY_LOAD_POLICY , buf, size, pos, ns, f->f_cred);
@@ -464,7 +537,7 @@ static const struct file_operations aa_fstatic ssize_t profile_replace (struct file *f,const char __user *buf,size_t size,loff_t *pos) { -struct aa_ns *ns =aa_get_ns (f->f_inode->i_private); +struct aa_ns *ns =get_ns_common_ref (f->f_inode->i_private);int error =policy_update (AA_MAY_LOAD_POLICY |AA_MAY_REPLACE_POLICY , buf, size, pos, ns, f->f_cred);aa_put_ns (ns);
@@ -484,7 +557,7 @@ static ssize_t profile_remove(struct filstruct aa_loaddata *data;struct aa_label *label;ssize_t error; -struct aa_ns *ns =aa_get_ns (f->f_inode->i_private); +struct aa_ns *ns =get_ns_common_ref (f->f_inode->i_private); label =begin_current_label_crit_section ();/* high level check about policy management - fine grained in
@@ -574,7 +647,7 @@ static int ns_revision_open(struct inodeif (!rev)return -ENOMEM ; - rev->ns =aa_get_ns (inode->i_private); + rev->ns =get_ns_common_ref (inode->i_private);if (!rev->ns) rev->ns =aa_get_current_ns (); file->private_data = rev;
@@ -1052,7 +1125,7 @@ static const struct file_operations seq_static int seq_profile_open (struct inode *inode,struct file *file,int (*show)(struct seq_file *,void *)) { -struct aa_proxy *proxy =aa_get_proxy (inode->i_private); +struct aa_proxy *proxy =get_proxy_common_ref (inode->i_private);int error =single_open (file, show, proxy);if (error) {
@@ -1230,7 +1303,7 @@ static const struct file_operations seq_static int seq_rawdata_open (struct inode *inode,struct file *file,int (*show)(struct seq_file *,void *)) { -struct aa_loaddata *data =aa_get_i_loaddata (inode->i_private); +struct aa_loaddata *data =get_loaddata_common_ref (inode->i_private);int error;if (!data)
@@ -1370,7 +1443,7 @@ static int rawdata_open(struct inode *inif (!policy_view_capable (NULL ))return -EACCES ; - loaddata =aa_get_i_loaddata (inode->i_private); + loaddata =get_loaddata_common_ref (inode->i_private);if (!loaddata)return -ENOENT ;
@@ -1415,7 +1488,6 @@ static void remove_rawdata_dents(structif (!IS_ERR_OR_NULL (rawdata->dents[i])) {aafs_remove (rawdata->dents[i]); rawdata->dents[i] =NULL ; -aa_put_i_loaddata (rawdata); } } }
@@ -1454,45 +1526,41 @@ int __aa_fs_create_rawdata(struct aa_nsif (IS_ERR (dir))/* ->name freed when rawdata freed */ return PTR_ERR (dir); -aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_DIR ] = dir; - dent =aafs_create_file ("abi" ,S_IFREG |0444 , dir, rawdata, + dent =aafs_create_file ("abi" ,S_IFREG |0444 , dir, &rawdata->count, &seq_rawdata_abi_fops);if (IS_ERR (dent)) goto fail; -aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_ABI ] = dent; - dent =aafs_create_file ("revision" ,S_IFREG |0444 , dir, rawdata, - &seq_rawdata_revision_fops); + dent =aafs_create_file ("revision" ,S_IFREG |0444 , dir, + &rawdata->count, + &seq_rawdata_revision_fops);if (IS_ERR (dent)) goto fail; -aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_REVISION ] = dent;if (aa_g_hash_policy) { dent =aafs_create_file ("sha1" ,S_IFREG |0444 , dir, - rawdata, &seq_rawdata_hash_fops); + &rawdata->count, + &seq_rawdata_hash_fops);if (IS_ERR (dent)) goto fail; -aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_HASH ] = dent; } dent =aafs_create_file ("compressed_size" ,S_IFREG |0444 , dir, - rawdata, + &rawdata->count, &seq_rawdata_compressed_size_fops);if (IS_ERR (dent)) goto fail; -aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_COMPRESSED_SIZE ] = dent; - dent =aafs_create_file ("raw_data" ,S_IFREG |0444 , - dir, rawdata, &rawdata_fops); + dent =aafs_create_file ("raw_data" ,S_IFREG |0444 , dir, + &rawdata->count, &rawdata_fops);if (IS_ERR (dent)) goto fail; -aa_get_i_loaddata (rawdata); rawdata->dents[AAFS_LOADDATA_DATA ] = dent;d_inode (dent)->i_size = rawdata->size;
@@ -1503,7 +1571,6 @@ int __aa_fs_create_rawdata(struct aa_ns fail:remove_rawdata_dents (rawdata); -aa_put_i_loaddata (rawdata);return PTR_ERR (dent); }
@@ -1525,13 +1592,10 @@ void __aafs_profile_rmdir(struct aa_prof__aafs_profile_rmdir (child);for (i =AAFS_PROF_SIZEOF -1 ; i >=0 ; --i) { -struct aa_proxy *proxy;if (!profile->dents[i])continue ; - proxy =d_inode (profile->dents[i])->i_private;aafs_remove (profile->dents[i]); -aa_put_proxy (proxy); profile->dents[i] =NULL ; } }
@@ -1561,14 +1625,7 @@ static struct dentry *create_profile_filstruct aa_profile *profile, const struct file_operations *fops) { - struct aa_proxy *proxy = aa_get_proxy(profile->label.proxy); -struct dentry *dent; - - dent =aafs_create_file (name,S_IFREG |0444 , dir, proxy, fops); -if (IS_ERR (dent)) -aa_put_proxy (proxy); - -return dent; + return aafs_create_file(name, S_IFREG | 0444, dir, &profile->label.proxy->count, fops); }static int profile_depth (struct aa_profile *profile)
@@ -1618,7 +1675,8 @@ static const char *rawdata_get_link_basestruct delayed_call *done, const char *name) { - struct aa_proxy *proxy = inode->i_private; + struct aa_common_ref *ref = inode->i_private; + struct aa_proxy *proxy = container_of(ref, struct aa_proxy, count);struct aa_label *label;struct aa_profile *profile;char *target;
@@ -1758,27 +1816,23 @@ int __aafs_profile_mkdir(struct aa_profiif (profile->rawdata) { dent =aafs_create ("raw_sha1" ,S_IFLNK |0444 , dir, - profile->label.proxy,NULL ,NULL , + &profile->label.proxy->count,NULL ,NULL , &rawdata_link_sha1_iops);if (IS_ERR (dent)) goto fail; -aa_get_proxy (profile->label.proxy); profile->dents[AAFS_PROF_RAW_HASH ] = dent; - dent =aafs_create ("raw_abi" ,S_IFLNK |0444 , dir, - profile->label.proxy,NULL ,NULL , + &profile->label.proxy->count,NULL ,NULL , &rawdata_link_abi_iops);if (IS_ERR (dent)) goto fail; -aa_get_proxy (profile->label.proxy); profile->dents[AAFS_PROF_RAW_ABI ] = dent; dent =aafs_create ("raw_data" ,S_IFLNK |0444 , dir, - profile->label.proxy,NULL ,NULL , + &profile->label.proxy->count,NULL ,NULL , &rawdata_link_data_iops);if (IS_ERR (dent)) goto fail; -aa_get_proxy (profile->label.proxy); profile->dents[AAFS_PROF_RAW_DATA ] = dent; }
@@ -1813,7 +1867,7 @@ static int ns_mkdir_op(struct inode *dirif (error)return error; - parent =aa_get_ns (dir->i_private); + parent =get_ns_common_ref (dir->i_private);AA_BUG (d_inode (ns_subns_dir (parent)) != dir);/* we have to unlock and then relock to get locking order right
@@ -1863,7 +1917,7 @@ static int ns_rmdir_op(struct inode *dirif (error)return error; - parent =aa_get_ns (dir->i_private); + parent =get_ns_common_ref (dir->i_private);/* rmdir calls the generic securityfs functions to remove files * from the apparmor dir. It is up to the apparmor ns locking * to avoid races.
@@ -1933,27 +1987,6 @@ void __aafs_ns_rmdir(struct aa_ns *ns)__aa_fs_list_remove_rawdata (ns); -if (ns_subns_dir (ns)) { - sub =d_inode (ns_subns_dir (ns))->i_private; -aa_put_ns (sub); - } -if (ns_subload (ns)) { - sub =d_inode (ns_subload (ns))->i_private; -aa_put_ns (sub); - } -if (ns_subreplace (ns)) { - sub =d_inode (ns_subreplace (ns))->i_private; -aa_put_ns (sub); - } -if (ns_subremove (ns)) { - sub =d_inode (ns_subremove (ns))->i_private; -aa_put_ns (sub); - } -if (ns_subrevision (ns)) { - sub =d_inode (ns_subrevision (ns))->i_private; -aa_put_ns (sub); - } -for (i =AAFS_NS_SIZEOF -1 ; i >=0 ; --i) {aafs_remove (ns->dents[i]); ns->dents[i] =NULL ;
@@ -1978,40 +2011,40 @@ static int __aafs_ns_mkdir_entries(strucreturn PTR_ERR (dent);ns_subdata_dir (ns) = dent; - dent =aafs_create_file ("revision" ,0444 , dir, ns, + dent =aafs_create_file ("revision" ,0444 , dir, + &ns->unconfined->label.count, &aa_fs_ns_revision_fops);if (IS_ERR (dent))return PTR_ERR (dent); -aa_get_ns (ns);ns_subrevision (ns) = dent; - dent =aafs_create_file (".load" ,0640 , dir, ns, - &aa_fs_profile_load); + dent =aafs_create_file (".load" ,0640 , dir, + &ns->unconfined->label.count, + &aa_fs_profile_load);if (IS_ERR (dent))return PTR_ERR (dent); -aa_get_ns (ns);ns_subload (ns) = dent; - dent =aafs_create_file (".replace" ,0640 , dir, ns, - &aa_fs_profile_replace); + dent =aafs_create_file (".replace" ,0640 , dir, + &ns->unconfined->label.count, + &aa_fs_profile_replace);if (IS_ERR (dent))return PTR_ERR (dent); -aa_get_ns (ns);ns_subreplace (ns) = dent; - dent =aafs_create_file (".remove" ,0640 , dir, ns, - &aa_fs_profile_remove); + dent =aafs_create_file (".remove" ,0640 , dir, + &ns->unconfined->label.count, + &aa_fs_profile_remove);if (IS_ERR (dent))return PTR_ERR (dent); -aa_get_ns (ns);ns_subremove (ns) = dent;/* use create_dentry so we can supply private data */ - dent =aafs_create ("namespaces" ,S_IFDIR |0755 , dir, ns,NULL ,NULL , - &ns_dir_inode_operations); + dent =aafs_create ("namespaces" ,S_IFDIR |0755 , dir, + &ns->unconfined->label.count, +NULL ,NULL , &ns_dir_inode_operations);if (IS_ERR (dent))return PTR_ERR (dent); -aa_get_ns (ns);ns_subns_dir (ns) = dent;return 0 ;
security/apparmor/include/label.h +8 -8
@@ -103,7 +103,7 @@ enum label_flags {struct aa_label ;struct aa_proxy { -struct kref count; +struct aa_common_ref count;struct aa_label __rcu *label; };
@@ -123,7 +123,7 @@ struct label_it {* @ent: set of profiles for label, actual size determined by @size */ struct aa_label { -struct kref count; +struct aa_common_ref count;struct rb_node node;struct rcu_head rcu;struct aa_proxy *proxy;
@@ -373,7 +373,7 @@ int aa_label_match(struct aa_profile *pr*/ static inline struct aa_label *__aa_get_label (struct aa_label *l) { -if (l &&kref_get_unless_zero (&l->count)) +if (l &&kref_get_unless_zero (&l->count.count))return l;return NULL ;
@@ -382,7 +382,7 @@ static inline struct aa_label *__aa_get_static inline struct aa_label *aa_get_label (struct aa_label *l) {if (l) -kref_get (&(l->count)); +kref_get (&(l->count.count));return l; }
@@ -402,7 +402,7 @@ static inline struct aa_label *aa_get_larcu_read_lock ();do { c =rcu_dereference (*l); - }while (c && !kref_get_unless_zero (&c->count)); + }while (c && !kref_get_unless_zero (&c->count.count));rcu_read_unlock ();return c;
@@ -442,7 +442,7 @@ static inline struct aa_label *aa_get_nestatic inline void aa_put_label (struct aa_label *l) {if (l) -kref_put (&l->count, aa_label_kref); +kref_put (&l->count.count, aa_label_kref); }
@@ -452,7 +452,7 @@ void aa_proxy_kref(struct kref *kref);static inline struct aa_proxy *aa_get_proxy (struct aa_proxy *proxy) {if (proxy) -kref_get (&(proxy->count)); +kref_get (&(proxy->count.count));return proxy; }
@@ -460,7 +460,7 @@ static inline struct aa_proxy *aa_get_prstatic inline void aa_put_proxy (struct aa_proxy *proxy) {if (proxy) -kref_put (&proxy->count, aa_proxy_kref); +kref_put (&proxy->count.count, aa_proxy_kref); }void __aa_proxy_redirect (struct aa_label *orig,struct aa_label *new);
security/apparmor/include/lib.h +12 -0
@@ -60,6 +60,18 @@ void aa_info_message(const char *str);/* Security blob offsets */ extern struct lsm_blob_sizes apparmor_blob_sizes; +enum reftype { +REF_NS , +REF_PROXY , +REF_RAWDATA , +}; + +/* common reference count used by data the shows up in aafs */ +struct aa_common_ref { +struct kref count; +enum reftype reftype; +}; +/** * aa_strneq - compare null terminated @str to a non null terminated substring * @str: a null terminated string
security/apparmor/include/policy.h +4 -4
@@ -243,7 +243,7 @@ static inline unsigned int PROFILE_MEDIAstatic inline struct aa_profile *aa_get_profile (struct aa_profile *p) {if (p) -kref_get (&(p->label.count)); +kref_get (&(p->label.count.count));return p; }
@@ -257,7 +257,7 @@ static inline struct aa_profile *aa_get_*/ static inline struct aa_profile *aa_get_profile_not0 (struct aa_profile *p) { -if (p &&kref_get_unless_zero (&p->label.count)) +if (p &&kref_get_unless_zero (&p->label.count.count))return p;return NULL ;
@@ -277,7 +277,7 @@ static inline struct aa_profile *aa_get_rcu_read_lock ();do { c =rcu_dereference (*p); - }while (c && !kref_get_unless_zero (&c->label.count)); + }while (c && !kref_get_unless_zero (&c->label.count.count));rcu_read_unlock ();return c;
@@ -290,7 +290,7 @@ static inline struct aa_profile *aa_get_static inline void aa_put_profile (struct aa_profile *p) {if (p) -kref_put (&p->label.count, aa_label_kref); +kref_put (&p->label.count.count, aa_label_kref); }static inline int AUDIT_MODE (struct aa_profile *profile)
security/apparmor/include/policy_unpack.h +3 -3
@@ -67,7 +67,7 @@ enum {* fs entries and drops the associated @count ref. */ struct aa_loaddata { -struct kref count; +struct aa_common_ref count;struct kref pcount;struct list_head list;struct work_struct work;
@@ -102,7 +102,7 @@ aa_get_i_loaddata(struct aa_loaddata *da {if (data) -kref_get (&(data->count)); +kref_get (&(data->count.count));return data; }
@@ -130,7 +130,7 @@ struct aa_loaddata *aa_loaddata_alloc(sistatic inline void aa_put_i_loaddata (struct aa_loaddata *data) {if (data) -kref_put (&data->count, aa_loaddata_kref); +kref_put (&data->count.count, aa_loaddata_kref); }static inline void aa_put_profile_loaddata (struct aa_loaddata *data)
security/apparmor/label.c +8 -4
@@ -52,7 +52,8 @@ static void free_proxy(struct aa_proxy *void aa_proxy_kref (struct kref *kref) { - struct aa_proxy *proxy = container_of(kref, struct aa_proxy, count); + struct aa_proxy *proxy = container_of(kref, struct aa_proxy, + count.count);free_proxy (proxy); }
@@ -63,7 +64,8 @@ struct aa_proxy *aa_alloc_proxy(struct a new =kzalloc (sizeof (struct aa_proxy ), gfp);if (new) { -kref_init (&new->count); +kref_init (&new->count.count); + new->count.reftype =REF_PROXY ;rcu_assign_pointer (new->label,aa_get_label (label)); }return new;
@@ -366,7 +368,8 @@ static void label_free_rcu(struct rcu_hevoid aa_label_kref (struct kref *kref) { - struct aa_label *label = container_of(kref, struct aa_label, count); + struct aa_label *label = container_of(kref, struct aa_label, + count.count);struct aa_ns *ns =labels_ns (label);if (!ns) {
@@ -403,7 +406,8 @@ bool aa_label_init(struct aa_label *labe label->size = size;/* doesn't include null */ label->vec[size] =NULL ;/* null terminate */ -kref_init (&label->count); +kref_init (&label->count.count); + label->count.reftype =REF_NS ;/* for aafs purposes */ RB_CLEAR_NODE (&label->node);return true;
security/apparmor/policy_unpack.c +4 -2
@@ -157,7 +157,8 @@ static void do_loaddata_free(struct aa_lvoid aa_loaddata_kref (struct kref *kref) { - struct aa_loaddata *d = container_of(kref, struct aa_loaddata, count); + struct aa_loaddata *d = container_of(kref, struct aa_loaddata, + count.count);do_loaddata_free (d); }
@@ -204,7 +205,8 @@ struct aa_loaddata *aa_loaddata_alloc(sikfree (d);return ERR_PTR (-ENOMEM ); } -kref_init (&d->count); +kref_init (&d->count.count); + d->count.reftype =REF_RAWDATA ;kref_init (&d->pcount);INIT_LIST_HEAD (&d->list);
Greg Kroah-Hartman
maintainerPATCH 441/491 netfilter: nft_ct: fix use-after-free in timeout object destroy
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tuan Do <[email protected]>
commit f8dca15a1b190787bbd03285304b569631160eda upstream.
nft_ct_timeout_obj_destroy() frees the timeout object with kfree() immediately after nf_ct_untimeout(), without waiting for an RCU grace period. Concurrent packet processing on other CPUs may still hold RCU-protected references to the timeout object obtained via rcu_dereference() in nf_ct_timeout_data().
Add an rcu_head to struct nf_ct_timeout and use kfree_rcu() to defer freeing until after an RCU grace period, matching the approach already used in nfnetlink_cttimeout.c.
KASAN report:
BUG: KASAN: slab-use-after-free in nf_conntrack_tcp_packet+0x1381/0x29d0 Read of size 4 at addr ffff8881035fe19c by task exploit/80 Call Trace: nf_conntrack_tcp_packet+0x1381/0x29d0 nf_conntrack_in+0x612/0x8b0 nf_hook_slow+0x70/0x100 __ip_local_out+0x1b2/0x210 tcp_sendmsg_locked+0x722/0x1580 __sys_sendto+0x2d8/0x320 Allocated by task 75: nft_ct_timeout_obj_init+0xf6/0x290 nft_obj_init+0x107/0x1b0 nf_tables_newobj+0x680/0x9c0 nfnetlink_rcv_batch+0xc29/0xe00 Freed by task 26: nft_obj_destroy+0x3f/0xa0 nf_tables_trans_destroy_work+0x51c/0x5c0 process_one_work+0x2c4/0x5a0
--- include/net/netfilter/nf_conntrack_timeout.h | 1 + net/netfilter/nft_ct.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
include/net/netfilter/nf_conntrack_timeout.h +1 -0
@@ -14,6 +14,7 @@struct nf_ct_timeout {__u16 l3num;const struct nf_conntrack_l4proto *l4proto; +struct rcu_head rcu;char data[]; };
net/netfilter/nft_ct.c +1 -1
@@ -935,7 +935,7 @@ static void nft_ct_timeout_obj_destroy(cnf_queue_nf_hook_drop (ctx->net);nf_ct_untimeout (ctx->net, timeout);nf_ct_netns_put (ctx->net, ctx->family); -kfree (priv->timeout); +kfree_rcu (priv->timeout, rcu); } static int nft_ct_timeout_obj_dump(struct sk_buff *skb,
Greg Kroah-Hartman
maintainerPATCH 442/491 tipc: fix bc_ackers underflow on duplicate GRP_ACK_MSG
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oleh Konko <[email protected]>
commit 48a5fe38772b6f039522469ee6131a67838221a8 upstream.
The GRP_ACK_MSG handler in tipc_group_proto_rcv() currently decrements bc_ackers on every inbound group ACK, even when the same member has already acknowledged the current broadcast round.
Because bc_ackers is a u16, a duplicate ACK received after the last legitimate ACK wraps the counter to 65535. Once wrapped, tipc_group_bc_cong() keeps reporting congestion and later group broadcasts on the affected socket stay blocked until the group is recreated.
Fix this by ignoring duplicate or stale ACKs before touching bc_acked or bc_ackers. This makes repeated GRP_ACK_MSG handling idempotent and prevents the underflow path.
--- net/tipc/group.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/tipc/group.c +5 -1
@@ -745,6 +745,7 @@ void tipc_group_proto_rcv(struct tipc_gru32 port =msg_origport (hdr);struct tipc_member *m, *pm;u16 remitted, in_flight; +u16 acked;if (!grp)return ;
@@ -797,7 +798,10 @@ void tipc_group_proto_rcv(struct tipc_grcase GRP_ACK_MSG :if (!m)return ; - m->bc_acked =msg_grp_bc_acked (hdr); + acked =msg_grp_bc_acked (hdr); +if (less_eq (acked, m->bc_acked)) +return ; + m->bc_acked = acked;if (--grp->bc_ackers)return ;list_del_init (&m->small_win);
Greg Kroah-Hartman
maintainerPATCH 443/491 wifi: brcmsmac: Fix dma_free_coherent() size
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Fourier <[email protected]>
commit 12cd7632757a54ce586e36040210b1a738a0fc53 upstream.
dma_alloc_consistent() may change the size to align it. The new size is saved in alloced.
Change the free size to match the allocation size.
--- drivers/net/wireless/broadcom/brcm80211/brcmsmac/dma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/broadcom/brcm80211/brcmsmac/dma.c +1 -1
@@ -483,7 +483,7 @@ static void *dma_ringalloc(struct dma_inif (((desc_strtaddr + size -1 ) & boundary) != (desc_strtaddr & boundary)) { *alignbits =dma_align_sizetobits (size); -dma_free_coherent (di->dmadev, size, va, *descpa); +dma_free_coherent (di->dmadev, *alloced, va, *descpa); va =dma_alloc_consistent (di, size, *alignbits, alloced, descpa); }
Greg Kroah-Hartman
maintainerPATCH 444/491 arm64: dts: hisilicon: poplar: Correct PCIe reset GPIO polarity
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shawn Guo <[email protected]>
commit c1f2b0f2b5e37b2c27540a175aea2755a3799433 upstream.
The PCIe reset GPIO on Poplar is actually active low. The active high worked before because kernel driver didn't respect the setting from DT. This is changed since commit 1d26a55fbeb9 ("PCI: histb: Switch to using gpiod API"), and thus PCIe on Poplar got brken since then.
Fix the problem by correcting the polarity.
--- arch/arm64/boot/dts/hisilicon/hi3798cv200-poplar.dts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/hisilicon/hi3798cv200-poplar.dts +1 -1
@@ -179,7 +179,7 @@ }; &pcie { - reset-gpios = <&gpio4 4 GPIO_ACTIVE_HIGH>; + reset-gpios = <&gpio4 4 GPIO_ACTIVE_LOW>; vpcie-supply = <®_pcie>; status = "okay"; };
Greg Kroah-Hartman
maintainerPATCH 445/491 arm64: dts: hisilicon: hi3798cv200: Add missing dma-ranges
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shawn Guo <[email protected]>
commit 1af997cad473d505248df6d9577183bb91f69670 upstream.
Reboot starts failing on Poplar since commit 8424ecdde7df ("arm64: mm:
Set ZONE_DMA size based on devicetree's dma-ranges"), which effectively changes zone_dma_bits from 30 to 32 for arm64 platforms that do not properly define dma-ranges in device tree. It's unclear how Poplar reboot gets broken by this change exactly, but a dma-ranges limiting zone_dma to the first 1 GB fixes the regression.
--- arch/arm64/boot/dts/hisilicon/hi3798cv200.dtsi | 1 + 1 file changed, 1 insertion(+)
arch/arm64/boot/dts/hisilicon/hi3798cv200.dtsi +1 -0
@@ -81,6 +81,7 @@ #address-cells = <1>; #size-cells = <1>; ranges = <0x0 0x0 0xf0000000 0x10000000>; + dma-ranges = <0x0 0x0 0x0 0x40000000>; crg: clock-reset-controller@8a22000 { compatible = "hisilicon,hi3798cv200-crg", "syscon", "simple-mfd";
Greg Kroah-Hartman
maintainerPATCH 446/491 nfc: pn533: allocate rx skb before consuming bytes
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
commit c71ba669b570c7b3f86ec875be222ea11dacb352 upstream.
pn532_receive_buf() reports the number of accepted bytes to the serdev core. The current code consumes bytes into recv_skb and may already hand a complete frame to pn533_recv_frame() before allocating a fresh receive buffer.
If that alloc_skb() fails, the callback returns 0 even though it has already consumed bytes, and it leaves recv_skb as NULL for the next receive callback. That breaks the receive_buf() accounting contract and can also lead to a NULL dereference on the next skb_put_u8().
Allocate the receive skb lazily before consuming the next byte instead. If allocation fails, return the number of bytes already accepted.
--- drivers/nfc/pn533/uart.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/nfc/pn533/uart.c +8 -3
@@ -211,6 +211,13 @@ static int pn532_receive_buf(struct serddel_timer (&dev->cmd_timeout);for (i =0 ; i < count; i++) { +if (!dev->recv_skb) { + dev->recv_skb =alloc_skb (PN532_UART_SKB_BUFF_LEN , +GFP_KERNEL ); +if (!dev->recv_skb) +return i; + } +if (unlikely (!skb_tailroom (dev->recv_skb)))skb_trim (dev->recv_skb,0 );
@@ -219,9 +226,7 @@ static int pn532_receive_buf(struct serdcontinue ;pn533_recv_frame (dev->priv, dev->recv_skb,0 ); - dev->recv_skb =alloc_skb (PN532_UART_SKB_BUFF_LEN ,GFP_KERNEL ); -if (!dev->recv_skb) -return 0 ; + dev->recv_skb =NULL ; }return i;
Greg Kroah-Hartman
maintainerPATCH 447/491 batman-adv: reject oversized global TT response buffers
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruide Cao <[email protected]>
commit 3a359bf5c61d52e7f09754108309d637532164a6 upstream.
batadv_tt_prepare_tvlv_global_data() builds the allocation length for a global TT response in 16-bit temporaries. When a remote originator advertises a large enough global TT, the TT payload length plus the VLAN header offset can exceed 65535 and wrap before kmalloc().
The full-table response path still uses the original TT payload length when it fills tt_change, so the wrapped allocation is too small and batadv_tt_prepare_tvlv_global_data() writes past the end of the heap object before the later packet-size check runs.
Fix this by rejecting TT responses whose TVLV value length cannot fit in the 16-bit TVLV payload length field.
--- net/batman-adv/translation-table.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
net/batman-adv/translation-table.c +7 -2
@@ -849,8 +849,8 @@ batadv_tt_prepare_tvlv_global_data(struc {u16 num_vlan =0 ;u16 num_entries =0 ; -u16 change_offset; -u16 tvlv_len; +u16 tvlv_len =0 ; +unsigned int change_offset;struct batadv_tvlv_tt_vlan_data *tt_vlan;struct batadv_orig_node_vlan *vlan;u8 *tt_change_ptr;
@@ -868,6 +868,11 @@ batadv_tt_prepare_tvlv_global_data(strucif (*tt_len <0 ) *tt_len =batadv_tt_len (num_entries); +if (change_offset >U16_MAX || *tt_len >U16_MAX - change_offset) { + *tt_len =0 ; + goto out; + } + tvlv_len = *tt_len; tvlv_len += change_offset;
Greg Kroah-Hartman
maintainerPATCH 448/491 net: altera-tse: fix skb leak on DMA mapping error in tse_start_xmit()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Carlier <[email protected]>
commit 6dede3967619b5944003227a5d09fdc21ed57d10 upstream.
When dma_map_single() fails in tse_start_xmit(), the function returns NETDEV_TX_OK without freeing the skb. Since NETDEV_TX_OK tells the stack the packet was consumed, the skb is never freed, leaking memory on every DMA mapping failure.
Add dev_kfree_skb_any() before returning to properly free the skb.
--- drivers/net/ethernet/altera/altera_tse_main.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/altera/altera_tse_main.c +1 -0
@@ -591,6 +591,7 @@ static netdev_tx_t tse_start_xmit(struct DMA_TO_DEVICE);if (dma_mapping_error (priv->device, dma_addr)) {netdev_err (priv->dev,"%s: DMA mapping error\n" , __func__); +dev_kfree_skb_any (skb); ret =NETDEV_TX_OK ; goto out; }
Greg Kroah-Hartman
maintainerPATCH 449/491 mmc: vub300: fix NULL-deref on disconnect
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit dff34ef879c5e73298443956a8b391311ba78d57 upstream.
Make sure to deregister the controller before dropping the reference to the driver data on disconnect to avoid NULL-pointer dereferences or use-after-free.
--- drivers/mmc/host/vub300.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/host/vub300.c +1 -1
@@ -2371,8 +2371,8 @@ static void vub300_disconnect(struct usbusb_set_intfdata (interface,NULL );/* prevent more I/O from starting */ vub300->interface =NULL ; -kref_put (&vub300->kref, vub300_delete);mmc_remove_host (mmc); +kref_put (&vub300->kref, vub300_delete);pr_info ("USB vub300 remote SDIO host controller[%d]" " now disconnected" , ifnum);return ;
Greg Kroah-Hartman
maintainerPATCH 450/491 net: qualcomm: qca_uart: report the consumed byte on RX skb allocation failure
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
commit b76254c55dc8f23edc089027dd3f8792554c69fb upstream.
qca_tty_receive() consumes each input byte before checking whether a completed frame needs a fresh receive skb. When the current byte completes a frame, the driver delivers that frame and then allocates a new skb for the next one.
If that allocation fails, the current code returns i even though data[i] has already been consumed and may already have completed the delivered frame. Since serdev interprets the return value as the number of accepted bytes, this under-reports progress by one byte and can replay the final byte of the completed frame into a fresh parser state on the next call.
Return i + 1 in that failure path so the accepted-byte count matches the actual receive-state progress.
--- drivers/net/ethernet/qualcomm/qca_uart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/qualcomm/qca_uart.c +1 -1
@@ -115,7 +115,7 @@ qca_tty_receive(struct serdev_device *seif (!qca->rx_skb) {netdev_dbg (netdev,"recv: out of RX resources\n" ); n_stats->rx_errors++; -return i; +return i +1 ; } } }
Greg Kroah-Hartman
maintainerPATCH 451/491 net: stmmac: fix integer underflow in chain mode
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tyllis Xu <[email protected]>
commit 51f4e090b9f87b40c21b6daadb5c06e6c0a07b67 upstream.
The jumbo_frm() chain-mode implementation unconditionally computes
len = nopaged_len - bmax;
where nopaged_len = skb_headlen(skb) (linear bytes only) and bmax is BUF_SIZE_8KiB or BUF_SIZE_2KiB. However, the caller stmmac_xmit() decides to invoke jumbo_frm() based on skb->len (total length including page fragments):
is_jumbo = stmmac_is_jumbo_frm(priv, skb->len, enh_desc);
When a packet has a small linear portion (nopaged_len <= bmax) but a large total length due to page fragments (skb->len > bmax), the subtraction wraps as an unsigned integer, producing a huge len value (~0xFFFFxxxx). This causes the while (len != 0) loop to execute hundreds of thousands of iterations, passing skb->data + bmax * i pointers far beyond the skb buffer to dma_map_single(). On IOMMU-less SoCs (the typical deployment for stmmac), this maps arbitrary kernel memory to the DMA engine, constituting a kernel memory disclosure and potential memory corruption from hardware.
Fix this by introducing a buf_len local variable clamped to min(nopaged_len, bmax). Computing len = nopaged_len - buf_len is then always safe: it is zero when the linear portion fits within a single descriptor, causing the while (len != 0) loop to be skipped naturally, and the fragment loop in stmmac_xmit() handles page fragments afterward.
--- drivers/net/ethernet/stmicro/stmmac/chain_mode.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/net/ethernet/stmicro/stmmac/chain_mode.c +6 -5
@@ -20,7 +20,7 @@ static int jumbo_frm(void *p, struct sk_unsigned int nopaged_len =skb_headlen (skb);struct stmmac_priv *priv = tx_q->priv_data;unsigned int entry = tx_q->cur_tx; -unsigned int bmax, des2; +unsigned int bmax, buf_len, des2;unsigned int i =1 , len;struct dma_desc *desc;
@@ -31,17 +31,18 @@ static int jumbo_frm(void *p, struct sk_else bmax = BUF_SIZE_2KiB; - len = nopaged_len - bmax; + buf_len = min_t(unsigned int, nopaged_len, bmax); + len = nopaged_len - buf_len; des2 =dma_map_single (priv->device, skb->data, - bmax,DMA_TO_DEVICE ); + buf_len,DMA_TO_DEVICE ); desc->des2 =cpu_to_le32 (des2);if (dma_mapping_error (priv->device, des2))return -1 ; tx_q->tx_skbuff_dma[entry].buf = des2; - tx_q->tx_skbuff_dma[entry].len = bmax; + tx_q->tx_skbuff_dma[entry].len = buf_len;/* do not close the descriptor and do not set own bit */ -stmmac_prepare_tx_desc (priv, desc,1 , bmax, csum,STMMAC_CHAIN_MODE , +stmmac_prepare_tx_desc (priv, desc,1 , buf_len, csum,STMMAC_CHAIN_MODE ,0 , false, skb->len);while (len !=0 ) {
Greg Kroah-Hartman
maintainerPATCH 452/491 rxrpc: Fix key/keyring checks in setsockopt(RXRPC_SECURITY_KEY/KEYRING)
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
commit 2afd86ccbb2082a3c4258aea8c07e5bb6267bc2f upstream.
An AF_RXRPC socket can be both client and server at the same time. When sending new calls (ie. it's acting as a client), it uses rx->key to set the security, and when accepting incoming calls (ie. it's acting as a server), it uses rx->securities.
setsockopt(RXRPC_SECURITY_KEY) sets rx->key to point to an rxrpc-type key and setsockopt(RXRPC_SECURITY_KEYRING) sets rx->securities to point to a keyring of rxrpc_s-type keys.
Now, it should be possible to use both rx->key and rx->securities on the same socket - but for userspace AF_RXRPC sockets rxrpc_setsockopt() prevents that.
Fix this by:
(1) Remove the incorrect check rxrpc_setsockopt(RXRPC_SECURITY_KEYRING)
makes on rx->key.
(2) Move the check that rxrpc_setsockopt(RXRPC_SECURITY_KEY) makes on
rx->key down into rxrpc_request_key().
(3) Remove rxrpc_request_key()'s check on rx->securities.
This (in combination with a previous patch) pushes the checks down into the functions that set those pointers and removes the cross-checks that prevent both key and keyring being set.
--- net/rxrpc/af_rxrpc.c | 6 ------ net/rxrpc/key.c | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-)
net/rxrpc/af_rxrpc.c +0 -6
@@ -614,9 +614,6 @@ static int rxrpc_setsockopt(struct socke goto success;case RXRPC_SECURITY_KEY : - ret = -EINVAL ; -if (rx->key) - goto error; ret = -EISCONN ;if (rx->sk.sk_state !=RXRPC_UNBOUND ) goto error;
@@ -624,9 +621,6 @@ static int rxrpc_setsockopt(struct socke goto error;case RXRPC_SECURITY_KEYRING : - ret = -EINVAL ; -if (rx->key) - goto error; ret = -EISCONN ;if (rx->sk.sk_state !=RXRPC_UNBOUND ) goto error;
net/rxrpc/key.c +1 -1
@@ -903,7 +903,7 @@ int rxrpc_request_key(struct rxrpc_sock_enter ("" ); -if (optlen <=0 || optlen >PAGE_SIZE -1 || rx->securities) +if (optlen <=0 || optlen >PAGE_SIZE -1 || rx->key)return -EINVAL ; description =memdup_sockptr_nul (optval, optlen);
Greg Kroah-Hartman
maintainerPATCH 453/491 xen/privcmd: unregister xenstore notifier on module exit
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: GuoHan Zhao <[email protected]>
commit cd7e1fef5a1ca1c4fcd232211962ac2395601636 upstream.
Commit 453b8fb68f36 ("xen/privcmd: restrict usage in unprivileged domU") added a xenstore notifier to defer setting the restriction target until Xenstore is ready.
XEN_PRIVCMD can be built as a module, but privcmd_exit() leaves that notifier behind. Balance the notifier lifecycle by unregistering it on module exit.
This is harmless even if xenstore was already ready at registration time and the notifier was never queued on the chain.
Message-ID: <[email protected]>
--- drivers/xen/privcmd.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/xen/privcmd.c +3 -0
@@ -1069,6 +1069,9 @@ static int __init privcmd_init(void) static void __exit privcmd_exit(void) { +if (!xen_initial_domain ()) +unregister_xenstore_notifier (&xenstore_notifier); +misc_deregister (&privcmd_dev);misc_deregister (&xen_privcmdbuf_dev); }
Greg Kroah-Hartman
maintainerPATCH 454/491 ASoC: soc-core: dont use discriminatory terms on snd_soc_runtime_get_dai_fmt()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuninori Morimoto <[email protected]>
commit 640eac4c849d6390f272862ba8db14f28d423670 upstream.
snd_soc_runtime_get_dai_fmt() is using discriminatory terms. This patch fixup it.
--- sound/soc/soc-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/soc/soc-core.c +2 -2
@@ -1209,8 +1209,8 @@ found: mask |=SND_SOC_DAIFMT_CLOCK_MASK ;if (!(dai_link->dai_fmt &SND_SOC_DAIFMT_INV_MASK )) mask |=SND_SOC_DAIFMT_INV_MASK ; -if (!(dai_link->dai_fmt &SND_SOC_DAIFMT_MASTER_MASK )) - mask |=SND_SOC_DAIFMT_MASTER_MASK ; +if (!(dai_link->dai_fmt &SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK )) + mask |=SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK ; dai_link->dai_fmt |= (dai_fmt & mask); }
Greg Kroah-Hartman
maintainerPATCH 455/491 ASoC: tegra: Fix Master Volume Control
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jon Hunter <[email protected]>
commit f9fd804aa0a36f15a35ca070ec4c52650876cc29 upstream.
Commit 3ed2b549b39f ("ALSA: pcm: fix wait_time calculations") corrected the PCM wait_time calculations and in doing so reduced the calculated wait_time. This exposed an issue with the Tegra Master Volume Control (MVC) device where the reduced wait_time caused the MVC to fail. For now fix this by setting the default wait_time for Tegra to be 500ms.
--- sound/soc/tegra/tegra_pcm.c | 3 +++ 1 file changed, 3 insertions(+)
sound/soc/tegra/tegra_pcm.c +3 -0
@@ -111,6 +111,9 @@ int tegra_pcm_open(struct snd_soc_componreturn ret; } +/* Set wait time to 500ms by default */ + substream->wait_time =500 ; +return 0 ; }EXPORT_SYMBOL_GPL (tegra_pcm_open);
Greg Kroah-Hartman
maintainerPATCH 456/491 netlink: add nla be16/32 types to minlen array
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
commit 9a0d18853c280f6a0ee99f91619f2442a17a323a upstream.
BUG: KMSAN: uninit-value in nla_validate_range_unsigned lib/nlattr.c:222 [inline] BUG: KMSAN: uninit-value in nla_validate_int_range lib/nlattr.c:336 [inline] BUG: KMSAN: uninit-value in validate_nla lib/nlattr.c:575 [inline] BUG: KMSAN: uninit-value in __nla_validate_parse+0x2e20/0x45c0 lib/nlattr.c:631 nla_validate_range_unsigned lib/nlattr.c:222 [inline] nla_validate_int_range lib/nlattr.c:336 [inline] validate_nla lib/nlattr.c:575 [inline]
...
The message in question matches this policy:
[NFTA_TARGET_REV] = NLA_POLICY_MAX(NLA_BE32, 255),
but because NLA_BE32 size in minlen array is 0, the validation code will read past the malformed (too small) attribute.
Note: Other attributes, e.g. BITFIELD32, SINT, UINT.. are also missing:
those likely should be added too.
--- lib/nlattr.c | 4 ++++ 1 file changed, 4 insertions(+)
lib/nlattr.c +4 -0
@@ -30,6 +30,8 @@ static const u8 nla_attr_len[NLA_TYPE_MA [NLA_S16] = sizeof(s16), [NLA_S32] = sizeof(s32), [NLA_S64] = sizeof(s64), + [NLA_BE16] = sizeof(__be16), + [NLA_BE32] = sizeof(__be32), };static const u8 nla_attr_minlen[NLA_TYPE_MAX +1 ] = {
@@ -43,6 +45,8 @@ static const u8 nla_attr_minlen[NLA_TYPE [NLA_S16] = sizeof(s16), [NLA_S32] = sizeof(s32), [NLA_S64] = sizeof(s64), + [NLA_BE16] = sizeof(__be16), + [NLA_BE32] = sizeof(__be32), };/*
Greg Kroah-Hartman
maintainerPATCH 457/491 cpufreq: governor: Free dbs_data directly when gov->init() fails
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Liao Chang <[email protected]>
[ Upstream commit 916f13884042f615cfbfc0b42cc68dadee826f2a ]
Due to the kobject embedded in the dbs_data doest not has a release() method yet, it needs to use kfree() to free dbs_data directly when governor fails to allocate the tunner field of dbs_data.
Stable-dep-of: 6dcf9d0064ce ("cpufreq: governor: fix double free in cpufreq_dbs_governor_init() error path")
--- drivers/cpufreq/cpufreq_governor.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/cpufreq/cpufreq_governor.c +3 -1
@@ -430,7 +430,7 @@ int cpufreq_dbs_governor_init(struct cpu ret = gov->init (dbs_data);if (ret) - goto free_policy_dbs_info; + goto free_dbs_data;/* * The sampling interval should not be less than the transition latency
@@ -464,6 +464,8 @@ int cpufreq_dbs_governor_init(struct cpuif (!have_governor_per_policy ()) gov->gdbs_data =NULL ; gov->exit (dbs_data); + +free_dbs_data:kfree (dbs_data); free_policy_dbs_info:
Greg Kroah-Hartman
maintainerPATCH 458/491 cpufreq: governor: fix double free in cpufreq_dbs_governor_init() error path
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit 6dcf9d0064ce2f3e3dfe5755f98b93abe6a98e1e ]
When kobject_init_and_add() fails, cpufreq_dbs_governor_init() calls kobject_put(&dbs_data->attr_set.kobj).
The kobject release callback cpufreq_dbs_data_release() calls gov->exit(dbs_data) and kfree(dbs_data), but the current error path then calls gov->exit(dbs_data) and kfree(dbs_data) again, causing a double free.
Keep the direct kfree(dbs_data) for the gov->init() failure path, but after kobject_init_and_add() has been called, let kobject_put() handle the cleanup through cpufreq_dbs_data_release().
--- drivers/cpufreq/cpufreq_governor.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/cpufreq/cpufreq_governor.c +3 -3
@@ -457,13 +457,13 @@ int cpufreq_dbs_governor_init(struct cpu/* Failure, so roll back. */ pr_err ("initialization failed (dbs_data kobject init error %d)\n" , ret); -kobject_put (&dbs_data->attr_set.kobj); - policy->governor_data =NULL ;if (!have_governor_per_policy ()) gov->gdbs_data =NULL ; - gov->exit (dbs_data); + +kobject_put (&dbs_data->attr_set.kobj); + goto free_policy_dbs_info; free_dbs_data:kfree (dbs_data);
Greg Kroah-Hartman
maintainerPATCH 459/491 seg6: separate dst_cache for input and output paths in seg6 lwtunnel
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrea Mayer <[email protected]>
[ Upstream commit c3812651b522fe8437ebb7063b75ddb95b571643 ]
The seg6 lwtunnel uses a single dst_cache per encap route, shared between seg6_input_core() and seg6_output_core(). These two paths can perform the post-encap SID lookup in different routing contexts (e.g., ip rules matching on the ingress interface, or VRF table separation). Whichever path runs first populates the cache, and the other reuses it blindly, bypassing its own lookup.
Fix this by splitting the cache into cache_input and cache_output, so each path maintains its own cached dst independently.
--- net/ipv6/seg6_iptunnel.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-)
net/ipv6/seg6_iptunnel.c +23 -11
@@ -45,7 +45,8 @@ static size_t seg6_lwt_headroom(struct s }struct seg6_lwt { -struct dst_cache cache; +struct dst_cache cache_input; +struct dst_cache cache_output;struct seg6_iptunnel_encap tuninfo[]; };
@@ -326,7 +327,7 @@ static int seg6_input(struct sk_buff *sk slwt =seg6_lwt_lwtunnel (orig_dst->lwtstate);local_bh_disable (); - dst =dst_cache_get (&slwt->cache); + dst =dst_cache_get (&slwt->cache_input);skb_dst_drop (skb);
@@ -334,7 +335,7 @@ static int seg6_input(struct sk_buff *skip6_route_input (skb); dst =skb_dst (skb);if (!dst->error) { -dst_cache_set_ip6 (&slwt->cache, dst, +dst_cache_set_ip6 (&slwt->cache_input, dst, &ipv6_hdr (skb)->saddr); } }else {
@@ -363,7 +364,7 @@ static int seg6_output(struct net *net, slwt =seg6_lwt_lwtunnel (orig_dst->lwtstate);local_bh_disable (); - dst =dst_cache_get (&slwt->cache); + dst =dst_cache_get (&slwt->cache_output);local_bh_enable ();if (unlikely (!dst)) {
@@ -384,7 +385,7 @@ static int seg6_output(struct net *net, }local_bh_disable (); -dst_cache_set_ip6 (&slwt->cache, dst, &fl6.saddr); +dst_cache_set_ip6 (&slwt->cache_output, dst, &fl6.saddr);local_bh_enable (); }
@@ -461,11 +462,13 @@ static int seg6_build_state(struct net * slwt =seg6_lwt_lwtunnel (newts); - err =dst_cache_init (&slwt->cache,GFP_ATOMIC ); -if (err) { -kfree (newts); -return err; - } + err =dst_cache_init (&slwt->cache_input,GFP_ATOMIC ); +if (err) + goto err_free_newts; + + err =dst_cache_init (&slwt->cache_output,GFP_ATOMIC ); +if (err) + goto err_destroy_input;memcpy (&slwt->tuninfo, tuninfo, tuninfo_len);
@@ -480,11 +483,20 @@ static int seg6_build_state(struct net * *ts = newts;return 0 ; + +err_destroy_input: +dst_cache_destroy (&slwt->cache_input); +err_free_newts: +kfree (newts); +return err; }static void seg6_destroy_state (struct lwtunnel_state *lwt) { -dst_cache_destroy (&seg6_lwt_lwtunnel (lwt)->cache); +struct seg6_lwt *slwt =seg6_lwt_lwtunnel (lwt); + +dst_cache_destroy (&slwt->cache_input); +dst_cache_destroy (&slwt->cache_output); } static int seg6_fill_encap_info(struct sk_buff *skb,
Greg Kroah-Hartman
maintainerPATCH 460/491 net: rfkill: prevent unlimited numbers of rfkill events from being created
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
[ Upstream commit ea245d78dec594372e27d8c79616baf49e98a4a1 ]
Userspace can create an unlimited number of rfkill events if the system is so configured, while not consuming them from the rfkill file descriptor, causing a potential out of memory situation. Prevent this from bounding the number of pending rfkill events at a "large" number (i.e. 1000) to prevent abuses like this.
--- net/rfkill/core.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-)
net/rfkill/core.c +27 -13
@@ -71,11 +71,14 @@ struct rfkill_int_event {struct rfkill_event ev; }; +/* Max rfkill events that can be "in-flight" for one data source */ +#define MAX_RFKILL_EVENT 1000struct rfkill_data {struct list_head list;struct list_head events;struct mutex mtx;wait_queue_head_t read_wait; +u32 event_count;bool input_handler; };
@@ -252,9 +255,12 @@ static void rfkill_global_led_trigger_un }#endif /* CONFIG_RFKILL_LEDS */ -static void rfkill_fill_event (struct rfkill_event *ev,struct rfkill *rfkill, -enum rfkill_operation op) +static int rfkill_fill_event (struct rfkill_int_event *int_ev, +struct rfkill *rfkill, +struct rfkill_data *data, +enum rfkill_operation op) { +struct rfkill_event *ev = &int_ev->ev;unsigned long flags; ev->idx = rfkill->idx;
@@ -266,6 +272,16 @@ static void rfkill_fill_event(struct rfk ev->soft = !!(rfkill->state & (RFKILL_BLOCK_SW |RFKILL_BLOCK_SW_PREV ));spin_unlock_irqrestore (&rfkill->lock, flags); + +mutex_lock (&data->mtx); +if (data->event_count++ >MAX_RFKILL_EVENT ) { + data->event_count--; +mutex_unlock (&data->mtx); +return -ENOSPC ; + } +list_add_tail (&int_ev->list, &data->events); +mutex_unlock (&data->mtx); +return 0 ; }static void rfkill_send_events (struct rfkill *rfkill,enum rfkill_operation op)
@@ -277,10 +293,10 @@ static void rfkill_send_events(struct rf ev =kzalloc (sizeof (*ev),GFP_KERNEL );if (!ev)continue ; -rfkill_fill_event (&ev->ev, rfkill, op); -mutex_lock (&data->mtx); -list_add_tail (&ev->list, &data->events); -mutex_unlock (&data->mtx); +if (rfkill_fill_event (ev, rfkill, data, op)) { +kfree (ev); +continue ; + }wake_up_interruptible (&data->read_wait); } }
@@ -1118,21 +1134,19 @@ static int rfkill_fop_open(struct inodeinit_waitqueue_head (&data->read_wait);mutex_lock (&rfkill_global_mutex); -mutex_lock (&data->mtx);/* -* start getting events from elsewhere but hold mtx to get -* startup events added first +* start getting events from elsewhere but hold rfkill_global_mutex +* to get startup events added first */ list_for_each_entry (rfkill, &rfkill_list, node) { ev =kzalloc (sizeof (*ev),GFP_KERNEL );if (!ev) goto free; -rfkill_fill_event (&ev->ev, rfkill,RFKILL_OP_ADD ); -list_add_tail (&ev->list, &data->events); +if (rfkill_fill_event (ev, rfkill, data,RFKILL_OP_ADD )) +kfree (ev); }list_add (&data->list, &rfkill_fds); -mutex_unlock (&data->mtx);mutex_unlock (&rfkill_global_mutex); file->private_data = data;
@@ -1140,7 +1154,6 @@ static int rfkill_fop_open(struct inodereturn stream_open (inode, file); free: -mutex_unlock (&data->mtx);mutex_unlock (&rfkill_global_mutex);mutex_destroy (&data->mtx);list_for_each_entry_safe (ev, tmp, &data->events, list)
@@ -1200,6 +1213,7 @@ static ssize_t rfkill_fop_read(struct fi ret = -EFAULT ;list_del (&ev->list); + data->event_count--;kfree (ev); out:mutex_unlock (&data->mtx);
Greg Kroah-Hartman
maintainerPATCH 461/491 usb: gadget: f_hid: move list and spinlock inits from bind to alloc
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Zimmermann <[email protected]>
[ Upstream commit 4e0a88254ad59f6c53a34bf5fa241884ec09e8b2 ]
There was an issue when you did the following:
- setup and bind an hid gadget
- open /dev/hidg0
- use the resulting fd in EPOLL_CTL_ADD
- unbind the UDC
- bind the UDC
- use the fd in EPOLL_CTL_DEL
When CONFIG_DEBUG_LIST was enabled, a list_del corruption was reported within remove_wait_queue (via ep_remove_wait_queue). After some debugging I found out that the queues, which f_hid registers via poll_wait were the problem. These were initialized using init_waitqueue_head inside hidg_bind. So effectively, the bind function re-initialized the queues while there were still items in them.
The solution is to move the initialization from hidg_bind to hidg_alloc to extend their lifetimes to the lifetime of the function instance.
Additionally, I found many other possibly problematic init calls in the bind function, which I moved as well.
--- drivers/usb/gadget/function/f_hid.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/usb/gadget/function/f_hid.c +6 -5
@@ -996,13 +996,8 @@ static int hidg_bind(struct usb_configurif (status) goto fail; -spin_lock_init (&hidg->write_spinlock); hidg->write_pending =1 ; hidg->req =NULL ; -spin_lock_init (&hidg->read_spinlock); -init_waitqueue_head (&hidg->write_queue); -init_waitqueue_head (&hidg->read_queue); -INIT_LIST_HEAD (&hidg->completed_out_req);/* create char device */ cdev_init (&hidg->cdev, &f_hidg_fops);
@@ -1272,6 +1267,12 @@ static struct usb_function *hidg_alloc(smutex_lock (&opts->lock); ++opts->refcnt; +spin_lock_init (&hidg->write_spinlock); +spin_lock_init (&hidg->read_spinlock); +init_waitqueue_head (&hidg->write_queue); +init_waitqueue_head (&hidg->read_queue); +INIT_LIST_HEAD (&hidg->completed_out_req); +device_initialize (&hidg->dev); hidg->dev.release = hidg_release; hidg->dev.class = hidg_class;
Greg Kroah-Hartman
maintainerPATCH 462/491 usb: gadget: u_ether: Fix race between gether_disconnect and eth_stop
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuen-Han Tsai <[email protected]>
[ Upstream commit e1eabb072c75681f78312c484ccfffb7430f206e ]
A race condition between gether_disconnect() and eth_stop() leads to a NULL pointer dereference. Specifically, if eth_stop() is triggered concurrently while gether_disconnect() is tearing down the endpoints, eth_stop() attempts to access the cleared endpoint descriptor, causing the following NPE:
Unable to handle kernel NULL pointer dereference Call trace: __dwc3_gadget_ep_enable+0x60/0x788 dwc3_gadget_ep_enable+0x70/0xe4 usb_ep_enable+0x60/0x15c eth_stop+0xb8/0x108
Because eth_stop() crashes while holding the dev->lock, the thread running gether_disconnect() fails to acquire the same lock and spins forever, resulting in a hardlockup:
Core - Debugging Information for Hardlockup core(7)
Call trace: queued_spin_lock_slowpath+0x94/0x488 _raw_spin_lock+0x64/0x6c gether_disconnect+0x19c/0x1e8 ncm_set_alt+0x68/0x1a0 composite_setup+0x6a0/0xc50
The root cause is that the clearing of dev->port_usb in gether_disconnect() is delayed until the end of the function.
Move the clearing of dev->port_usb to the very beginning of gether_disconnect() while holding dev->lock. This cuts off the link immediately, ensuring eth_stop() will see dev->port_usb as NULL and safely bail out.
--- drivers/usb/gadget/function/u_ether.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/usb/gadget/function/u_ether.c +4 -4
@@ -1141,6 +1141,10 @@ void gether_disconnect(struct gether *liDBG (dev,"%s\n" , __func__); +spin_lock (&dev->lock); + dev->port_usb =NULL ; +spin_unlock (&dev->lock); +netif_stop_queue (dev->net);netif_carrier_off (dev->net);
@@ -1178,10 +1182,6 @@ void gether_disconnect(struct gether *li dev->header_len =0 ; dev->unwrap =NULL ; dev->wrap =NULL ; - -spin_lock (&dev->lock); - dev->port_usb =NULL ; -spin_unlock (&dev->lock); }EXPORT_SYMBOL_GPL (gether_disconnect);
Greg Kroah-Hartman
maintainerPATCH 463/491 usb: gadget: uvc: fix NULL pointer dereference during unbind race
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jimmy Hu <[email protected]>
[ Upstream commit eba2936bbe6b752a31725a9eb5c674ecbf21ee7d ]
Commit b81ac4395bbe ("usb: gadget: uvc: allow for application to cleanly shutdown") introduced two stages of synchronization waits totaling 1500ms in uvc_function_unbind() to prevent several types of kernel panics. However, this timing-based approach is insufficient during power management (PM) transitions.
When the PM subsystem starts freezing user space processes, the wait_event_interruptible_timeout() is aborted early, which allows the unbind thread to proceed and nullify the gadget pointer (cdev->gadget = NULL):
[ 814.123447][ T947] configfs-gadget.g1 gadget.0: uvc: uvc_function_unbind() [ 814.178583][ T3173] PM: suspend entry (deep) [ 814.192487][ T3173] Freezing user space processes [ 814.197668][ T947] configfs-gadget.g1 gadget.0: uvc: uvc_function_unbind no clean disconnect, wait for release
When the PM subsystem resumes or aborts the suspend and tasks are restarted, the V4L2 release path is executed and attempts to access the already nullified gadget pointer, triggering a kernel panic:
[ 814.292597][ C0] PM: pm_system_irq_wakeup: 479 triggered dhdpcie_host_wake [ 814.386727][ T3173] Restarting tasks ... [ 814.403522][ T4558] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000030 [ 814.404021][ T4558] pc : usb_gadget_deactivate+0x14/0xf4 [ 814.404031][ T4558] lr : usb_function_deactivate+0x54/0x94 [ 814.404078][ T4558] Call trace: [ 814.404080][ T4558] usb_gadget_deactivate+0x14/0xf4 [ 814.404083][ T4558] usb_function_deactivate+0x54/0x94 [ 814.404087][ T4558] uvc_function_disconnect+0x1c/0x5c [ 814.404092][ T4558] uvc_v4l2_release+0x44/0xac [ 814.404095][ T4558] v4l2_release+0xcc/0x130
Address the race condition and NULL pointer dereference by:
1. State Synchronization (flag + mutex)
Introduce a 'func_unbound' flag in struct uvc_device. This allows uvc_function_disconnect() to safely skip accessing the nullified cdev->gadget pointer. As suggested by Alan Stern, this flag is protected by a new mutex (uvc->lock) to ensure proper memory ordering and prevent instruction reordering or speculative loads. This mutex is also used to protect 'func_connected' for consistent state management.
2. Explicit Synchronization (completion)
Use a completion to synchronize uvc_function_unbind() with the uvc_vdev_release() callback. This prevents Use-After-Free (UAF) by ensuring struct uvc_device is freed after all video device resources are released.
--- drivers/usb/gadget/function/f_uvc.c | 46 ++++++++++++++++++++++++++++++--- drivers/usb/gadget/function/uvc.h | 3 ++ drivers/usb/gadget/function/uvc_v4l2.c | 13 +++++++-- 3 files changed, 56 insertions(+), 6 deletions(-)
drivers/usb/gadget/function/f_uvc.c +42 -4
@@ -393,6 +393,14 @@ uvc_function_disconnect(struct uvc_devic {int ret; +mutex_lock (&uvc->lock); +if (uvc->func_unbound) { +dev_dbg (&uvc->vdev.dev,"skipping function deactivate (unbound)\n" ); +mutex_unlock (&uvc->lock); +return ; + } +mutex_unlock (&uvc->lock); +if ((ret =usb_function_deactivate (&uvc->func)) <0 )uvcg_info (&uvc->func,"UVC disconnect failed with %d\n" , ret); }
@@ -411,6 +419,15 @@ static ssize_t function_name_show(structstatic DEVICE_ATTR_RO (function_name); +static void uvc_vdev_release (struct video_device *vdev) +{ +struct uvc_device *uvc =video_get_drvdata (vdev); + +/* Signal uvc_function_unbind() that the video device has been released */ +if (uvc->vdev_release_done) +complete (uvc->vdev_release_done); +} +static int uvc_register_video (struct uvc_device *uvc) {
@@ -421,7 +438,7 @@ uvc_register_video(struct uvc_device *uv uvc->vdev.v4l2_dev = &uvc->v4l2_dev; uvc->vdev.fops = &uvc_v4l2_fops; uvc->vdev.ioctl_ops = &uvc_v4l2_ioctl_ops; - uvc->vdev.release = video_device_release_empty; + uvc->vdev.release = uvc_vdev_release; uvc->vdev.vfl_dir =VFL_DIR_TX ; uvc->vdev.lock = &uvc->video.mutex; uvc->vdev.device_caps =V4L2_CAP_VIDEO_OUTPUT |V4L2_CAP_STREAMING ;
@@ -595,6 +612,9 @@ uvc_function_bind(struct usb_configuratiint ret = -EINVAL ;uvcg_info (f,"%s()\n" , __func__); +mutex_lock (&uvc->lock); + uvc->func_unbound = false; +mutex_unlock (&uvc->lock); opts =fi_to_f_uvc_opts (f->fi);/* Sanity check the streaming endpoint module parameters.
@@ -887,18 +907,25 @@ static void uvc_free(struct usb_functionstatic void uvc_function_unbind (struct usb_configuration *c,struct usb_function *f) { +DECLARE_COMPLETION_ONSTACK (vdev_release_done);struct usb_composite_dev *cdev = c->cdev;struct uvc_device *uvc =to_uvc (f);long wait_ret =1 ; +bool connected;uvcg_info (f,"%s()\n" , __func__); +mutex_lock (&uvc->lock); + uvc->func_unbound = true; + uvc->vdev_release_done = &vdev_release_done; + connected = uvc->func_connected; +mutex_unlock (&uvc->lock);/* If we know we're connected via v4l2, then there should be a cleanup * of the device from userspace either via UVC_EVENT_DISCONNECT or * though the video device removal uevent. Allow some time for the * application to close out before things get deleted. */ -if (uvc->func_connected) { +if (connected) {uvcg_dbg (f,"waiting for clean disconnect\n" ); wait_ret =wait_event_interruptible_timeout (uvc->func_connected_queue, uvc->func_connected == false,msecs_to_jiffies (500 ));
@@ -909,8 +936,13 @@ static void uvc_function_unbind(struct uvideo_unregister_device (&uvc->vdev);v4l2_device_unregister (&uvc->v4l2_dev); -if (uvc->func_connected) { -/* Wait for the release to occur to ensure there are no longer any +mutex_lock (&uvc->lock); + connected = uvc->func_connected; +mutex_unlock (&uvc->lock); + +if (connected) { +/* +* Wait for the release to occur to ensure there are no longer any * pending operations that may cause panics when resources are cleaned * up. */
@@ -920,6 +952,10 @@ static void uvc_function_unbind(struct uuvcg_dbg (f,"done waiting for release with ret: %ld\n" , wait_ret); } +/* Wait for the video device to be released */ +wait_for_completion (&vdev_release_done); + uvc->vdev_release_done =NULL ; +usb_ep_free_request (cdev->gadget->ep0, uvc->control_req);kfree (uvc->control_buf);
@@ -937,6 +973,8 @@ static struct usb_function *uvc_alloc(streturn ERR_PTR (-ENOMEM );mutex_init (&uvc->video.mutex); +mutex_init (&uvc->lock); + uvc->func_unbound = true; uvc->state =UVC_STATE_DISCONNECTED ;init_waitqueue_head (&uvc->func_connected_queue); opts =fi_to_f_uvc_opts (fi);
drivers/usb/gadget/function/uvc.h +3 -0
@@ -118,6 +118,9 @@ struct uvc_device {enum uvc_state state;struct usb_function func;struct uvc_video video; +struct completion *vdev_release_done; +struct mutex lock;/* protects func_unbound and func_connected */ +bool func_unbound;bool func_connected;wait_queue_head_t func_connected_queue;
drivers/usb/gadget/function/uvc_v4l2.c +11 -2
@@ -234,12 +234,18 @@ uvc_v4l2_subscribe_event(struct v4l2_fhif (sub->type <UVC_EVENT_FIRST || sub->type >UVC_EVENT_LAST )return -EINVAL ; -if (sub->type ==UVC_EVENT_SETUP && uvc->func_connected) +mutex_lock (&uvc->lock); + +if (sub->type ==UVC_EVENT_SETUP && uvc->func_connected) { +mutex_unlock (&uvc->lock);return -EBUSY ; + } ret =v4l2_event_subscribe (fh, sub,2 ,NULL ); -if (ret <0 ) +if (ret <0 ) { +mutex_unlock (&uvc->lock);return ret; + }if (sub->type ==UVC_EVENT_SETUP ) { uvc->func_connected = true;
@@ -247,6 +253,7 @@ uvc_v4l2_subscribe_event(struct v4l2_fhuvc_function_connect (uvc); } +mutex_unlock (&uvc->lock);return 0 ; }
@@ -255,7 +262,9 @@ static void uvc_v4l2_disable(struct uvc_uvc_function_disconnect (uvc);uvcg_video_enable (&uvc->video,0 );uvcg_free_buffers (&uvc->video.queue); +mutex_lock (&uvc->lock); uvc->func_connected = false; +mutex_unlock (&uvc->lock);wake_up_interruptible (&uvc->func_connected_queue); }
Greg Kroah-Hartman
maintainerPATCH 464/491 net: macb: Move devm_{free,request}_irq() out of spin lock area
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kevin Hao <[email protected]>
[ Upstream commit 317e49358ebbf6390fa439ef3c142f9239dd25fb ]
The devm_free_irq() and devm_request_irq() functions should not be executed in an atomic context.
During device suspend, all userspace processes and most kernel threads are frozen. Additionally, we flush all tx/rx status, disable all macb interrupts, and halt rx operations. Therefore, it is safe to split the region protected by bp->lock into two independent sections, allowing devm_free_irq() and devm_request_irq() to run in a non-atomic context. This modification resolves the following lockdep warning:
BUG: sleeping function called from invalid context at kernel/locking/mutex.c:591
in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 501, name: rtcwake
preempt_count: 1, expected: 0
RCU nest depth: 1, expected: 0
7 locks held by rtcwake/501:
#0: ffff0008038c3408 (sb_writers#5){.+.+}-{0:0}, at: vfs_write+0xf8/0x368
#1: ffff0008049a5e88 (&of->mutex#2){+.+.}-{4:4}, at: kernfs_fop_write_iter+0xbc/0x1c8
#2: ffff00080098d588 (kn->active#70){.+.+}-{0:0}, at: kernfs_fop_write_iter+0xcc/0x1c8
#3: ffff800081c84888 (system_transition_mutex){+.+.}-{4:4}, at: pm_suspend+0x1ec/0x290
#4: ffff0008009ba0f8 (&dev->mutex){....}-{4:4}, at: device_suspend+0x118/0x4f0
#5: ffff800081d00458 (rcu_read_lock){....}-{1:3}, at: rcu_lock_acquire+0x4/0x48
#6: ffff0008031fb9e0 (&bp->lock){-.-.}-{3:3}, at: macb_suspend+0x144/0x558
irq event stamp: 8682
hardirqs last enabled at (8681): [<ffff8000813c7d7c>] _raw_spin_unlock_irqrestore+0x44/0x88
hardirqs last disabled at (8682): [<ffff8000813c7b58>] _raw_spin_lock_irqsave+0x38/0x98
softirqs last enabled at (7322): [<ffff8000800f1b4c>] handle_softirqs+0x52c/0x588
softirqs last disabled at (7317): [<ffff800080010310>] __do_softirq+0x20/0x2c
CPU: 1 UID: 0 PID: 501 Comm: rtcwake Not tainted 7.0.0-rc3-next-20260310-yocto-standard+ #125 PREEMPT
Hardware name: ZynqMP ZCU102 Rev1.1 (DT)
Call trace:
show_stack+0x24/0x38 (C)
__dump_stack+0x28/0x38
dump_stack_lvl+0x64/0x88
dump_stack+0x18/0x24
__might_resched+0x200/0x218
__might_sleep+0x38/0x98
__mutex_lock_common+0x7c/0x1378
mutex_lock_nested+0x38/0x50
free_irq+0x68/0x2b0
devm_irq_release+0x24/0x38
devres_release+0x40/0x80
devm_free_irq+0x48/0x88
macb_suspend+0x298/0x558
device_suspend+0x218/0x4f0
dpm_suspend+0x244/0x3a0
dpm_suspend_start+0x50/0x78
suspend_devices_and_enter+0xec/0x560
pm_suspend+0x194/0x290
state_store+0x110/0x158
kobj_attr_store+0x1c/0x30
sysfs_kf_write+0xa8/0xd0
kernfs_fop_write_iter+0x11c/0x1c8
vfs_write+0x248/0x368
ksys_write+0x7c/0xf8
__arm64_sys_write+0x28/0x40
invoke_syscall+0x4c/0xe8
el0_svc_common+0x98/0xf0
do_el0_svc+0x28/0x40
el0_svc+0x54/0x1e0
el0t_64_sync_handler+0x84/0x130
el0t_64_sync+0x198/0x1a0--- drivers/net/ethernet/cadence/macb_main.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/net/ethernet/cadence/macb_main.c +8 -5
@@ -4734,6 +4734,8 @@ static int __maybe_unused macb_suspend(sif (bp->caps &MACB_CAPS_ISR_CLEAR_ON_WRITE )queue_writel (queue,ISR ,-1 ); } +spin_unlock_irqrestore (&bp->lock, flags); +/* Change interrupt handler and * Enable WoL IRQ on queue 0 */
@@ -4745,11 +4747,12 @@ static int __maybe_unused macb_suspend(sdev_err (dev,"Unable to request IRQ %d (error %d)\n" , bp->queues[0 ].irq, err); -spin_unlock_irqrestore (&bp->lock, flags);return err; } +spin_lock_irqsave (&bp->lock, flags);queue_writel (bp->queues,IER ,GEM_BIT (WOL ));gem_writel (bp,WOL ,MACB_BIT (MAG )); +spin_unlock_irqrestore (&bp->lock, flags); }else { err =devm_request_irq (dev, bp->queues[0 ].irq, macb_wol_interrupt,IRQF_SHARED , netdev->name, bp->queues);
@@ -4757,13 +4760,13 @@ static int __maybe_unused macb_suspend(sdev_err (dev,"Unable to request IRQ %d (error %d)\n" , bp->queues[0 ].irq, err); -spin_unlock_irqrestore (&bp->lock, flags);return err; } +spin_lock_irqsave (&bp->lock, flags);queue_writel (bp->queues,IER ,MACB_BIT (WOL ));macb_writel (bp,WOL ,MACB_BIT (MAG )); +spin_unlock_irqrestore (&bp->lock, flags); } -spin_unlock_irqrestore (&bp->lock, flags);enable_irq_wake (bp->queues[0 ].irq); }
@@ -4825,6 +4828,8 @@ static int __maybe_unused macb_resume(stqueue_readl (bp->queues,ISR );if (bp->caps &MACB_CAPS_ISR_CLEAR_ON_WRITE )queue_writel (bp->queues,ISR ,-1 ); +spin_unlock_irqrestore (&bp->lock, flags); +/* Replace interrupt handler on queue 0 */ devm_free_irq (dev, bp->queues[0 ].irq, bp->queues); err = devm_request_irq(dev, bp->queues[0].irq, macb_interrupt,
@@ -4833,10 +4838,8 @@ static int __maybe_unused macb_resume(stdev_err (dev,"Unable to request IRQ %d (error %d)\n" , bp->queues[0 ].irq, err); -spin_unlock_irqrestore (&bp->lock, flags);return err; } -spin_unlock_irqrestore (&bp->lock, flags);disable_irq_wake (bp->queues[0 ].irq);
Greg Kroah-Hartman
maintainerPATCH 465/491 mm/huge_memory: fix folio isnt locked in softleaf_to_folio()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jinjiang Tu <[email protected]>
[ Upstream commit 4c5e7f0fcd592801c9cc18f29f80fbee84eb8669 ]
On arm64 server, we found folio that get from migration entry isn't locked in softleaf_to_folio(). This issue triggers when mTHP splitting and zap_nonpresent_ptes() races, and the root cause is lack of memory barrier in softleaf_to_folio(). The race is as follows:
CPU0 CPU1
deferred_split_scan() zap_nonpresent_ptes()
lock folio
split_folio()
unmap_folio()
change ptes to migration entries
__split_folio_to_order() softleaf_to_folio()
set flags(including PG_locked) for tail pages folio = pfn_folio(softleaf_to_pfn(entry))
smp_wmb() VM_WARN_ON_ONCE(!folio_test_locked(folio))
prep_compound_page() for tail pages
In __split_folio_to_order(), smp_wmb() guarantees page flags of tail pages are visible before the tail page becomes non-compound. smp_wmb() should be paired with smp_rmb() in softleaf_to_folio(), which is missed. As a result, if zap_nonpresent_ptes() accesses migration entry that stores tail pfn, softleaf_to_folio() may see the updated compound_head of tail page before page->flags.
This issue will trigger VM_WARN_ON_ONCE() in pfn_swap_entry_folio() because of the race between folio split and zap_nonpresent_ptes() leading to a folio incorrectly undergoing modification without a folio lock being held.
This is a BUG_ON() before commit 93976a20345b ("mm: eliminate further swapops predicates"), which in merged in v6.19-rc1.
To fix it, add missing smp_rmb() if the softleaf entry is migration entry in softleaf_to_folio() and softleaf_to_page().
--- include/linux/swapops.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/linux/swapops.h +6 -0
@@ -198,6 +198,12 @@ static inline struct page *migration_ent {struct page *p =pfn_to_page (swp_offset (entry));/* +* Ensure we do not race with split, which might alter tail pages +* into new folios and thus result in observing an unlocked page. +* This matches the write barrier in __split_huge_page_tail(). +*/ +smp_rmb (); +/* * Any use of migration entries may only occur while the * corresponding page is locked */
Greg Kroah-Hartman
maintainerPATCH 466/491 ext4: fix the might_sleep() warnings in kvfree()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zqiang <[email protected]>
[ Upstream commit 496bb99b7e66f48b178126626f47e9ba79e2d0fa ]
Use the kvfree() in the RCU read critical section can trigger the following warnings:
EXT4-fs (vdb): unmounting filesystem cd983e5b-3c83-4f5a-a136-17b00eb9d018.
WARNING: suspicious RCU usage
./include/linux/rcupdate.h:409 Illegal context switch in RCU read-side critical section!
other info that might help us debug this:
rcu_scheduler_active = 2, debug_locks = 1
Call Trace: <TASK> dump_stack_lvl+0xbb/0xd0 dump_stack+0x14/0x20 lockdep_rcu_suspicious+0x15a/0x1b0 __might_resched+0x375/0x4d0 ? put_object.part.0+0x2c/0x50 __might_sleep+0x108/0x160 vfree+0x58/0x910 ? ext4_group_desc_free+0x27/0x270 kvfree+0x23/0x40 ext4_group_desc_free+0x111/0x270 ext4_put_super+0x3c8/0xd40 generic_shutdown_super+0x14c/0x4a0 ? __pfx_shrinker_free+0x10/0x10 kill_block_super+0x40/0x90 ext4_kill_sb+0x6d/0xb0 deactivate_locked_super+0xb4/0x180 deactivate_super+0x7e/0xa0 cleanup_mnt+0x296/0x3e0 __cleanup_mnt+0x16/0x20 task_work_run+0x157/0x250 ? __pfx_task_work_run+0x10/0x10 ? exit_to_user_mode_loop+0x6a/0x550 exit_to_user_mode_loop+0x102/0x550 do_syscall_64+0x44a/0x500 entry_SYSCALL_64_after_hwframe+0x77/0x7f </TASK> BUG: sleeping function called from invalid context at mm/vmalloc.c:3441 in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 556, name: umount preempt_count: 1, expected: 0 CPU: 3 UID: 0 PID: 556 Comm: umount Call Trace: <TASK> dump_stack_lvl+0xbb/0xd0 dump_stack+0x14/0x20 __might_resched+0x275/0x4d0 ? put_object.part.0+0x2c/0x50 __might_sleep+0x108/0x160 vfree+0x58/0x910 ? ext4_group_desc_free+0x27/0x270 kvfree+0x23/0x40 ext4_group_desc_free+0x111/0x270 ext4_put_super+0x3c8/0xd40 generic_shutdown_super+0x14c/0x4a0 ? __pfx_shrinker_free+0x10/0x10 kill_block_super+0x40/0x90 ext4_kill_sb+0x6d/0xb0 deactivate_locked_super+0xb4/0x180 deactivate_super+0x7e/0xa0 cleanup_mnt+0x296/0x3e0 __cleanup_mnt+0x16/0x20 task_work_run+0x157/0x250 ? __pfx_task_work_run+0x10/0x10 ? exit_to_user_mode_loop+0x6a/0x550 exit_to_user_mode_loop+0x102/0x550 do_syscall_64+0x44a/0x500 entry_SYSCALL_64_after_hwframe+0x77/0x7f
The above scenarios occur in initialization failures and teardown paths, there are no parallel operations on the resources released by kvfree(), this commit therefore remove rcu_read_lock/unlock() and use rcu_access_pointer() instead of rcu_dereference() operations.
--- fs/ext4/mballoc.c | 10 +++------- fs/ext4/super.c | 6 ++---- 2 files changed, 5 insertions(+), 11 deletions(-)
fs/ext4/mballoc.c +3 -7
@@ -2894,9 +2894,7 @@ err_freebuddy:rcu_read_unlock ();iput (sbi->s_buddy_cache); err_freesgi: -rcu_read_lock (); -kvfree (rcu_dereference (sbi->s_group_info)); -rcu_read_unlock (); +kvfree (rcu_access_pointer (sbi->s_group_info));return -ENOMEM ; }
@@ -3088,7 +3086,8 @@ int ext4_mb_release(struct super_block *struct kmem_cache *cachep =get_groupinfo_cache (sb->s_blocksize_bits);int count; -if (sbi->s_group_info) { + group_info =rcu_access_pointer (sbi->s_group_info); +if (group_info) {for (i =0 ; i < ngroups; i++) {cond_resched (); grinfo =ext4_get_group_info (sb, i);
@@ -3106,12 +3105,9 @@ int ext4_mb_release(struct super_block * num_meta_group_infos = (ngroups +EXT4_DESC_PER_BLOCK (sb) -1 ) >>EXT4_DESC_PER_BLOCK_BITS (sb); -rcu_read_lock (); - group_info =rcu_dereference (sbi->s_group_info);for (i =0 ; i < num_meta_group_infos; i++)kfree (group_info[i]);kvfree (group_info); -rcu_read_unlock (); }kfree (sbi->s_mb_offsets);kfree (sbi->s_mb_maxs);
fs/ext4/super.c +2 -4
@@ -1207,18 +1207,16 @@ static void ext4_put_super(struct super_if (!sb_rdonly (sb))ext4_commit_super (sb,1 ); -rcu_read_lock (); - group_desc =rcu_dereference (sbi->s_group_desc); + group_desc =rcu_access_pointer (sbi->s_group_desc);for (i =0 ; i < sbi->s_gdb_count; i++)brelse (group_desc[i]);kvfree (group_desc); - flex_groups =rcu_dereference (sbi->s_flex_groups); + flex_groups =rcu_access_pointer (sbi->s_flex_groups);if (flex_groups) {for (i =0 ; i < sbi->s_flex_groups_allocated; i++)kvfree (flex_groups[i]);kvfree (flex_groups); } -rcu_read_unlock ();percpu_counter_destroy (&sbi->s_freeclusters_counter);percpu_counter_destroy (&sbi->s_freeinodes_counter);percpu_counter_destroy (&sbi->s_dirs_counter);
Greg Kroah-Hartman
maintainerPATCH 467/491 xfs: save ailp before dropping the AIL lock in push callbacks
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuto Ohnuki <[email protected]>
[ Upstream commit 394d70b86fae9fe865e7e6d9540b7696f73aa9b6 ]
In xfs_inode_item_push() and xfs_qm_dquot_logitem_push(), the AIL lock is dropped to perform buffer IO. Once the cluster buffer no longer protects the log item from reclaim, the log item may be freed by background reclaim or the dquot shrinker. The subsequent spin_lock() call dereferences lip->li_ailp, which is a use-after-free.
Fix this by saving the ailp pointer in a local variable while the AIL lock is held and the log item is guaranteed to be valid.
--- fs/xfs/xfs_dquot_item.c | 9 +++++++-- fs/xfs/xfs_inode_item.c | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-)
fs/xfs/xfs_dquot_item.c +7 -2
@@ -124,6 +124,7 @@ xfs_qm_dquot_logitem_push( {struct xfs_dquot *dqp =DQUOT_ITEM (lip)->qli_dquot;struct xfs_buf *bp = lip->li_buf; +struct xfs_ail *ailp = lip->li_ailp;uint rval =XFS_ITEM_SUCCESS ;int error;
@@ -152,7 +153,7 @@ xfs_qm_dquot_logitem_push( goto out_unlock; } -spin_unlock (&lip->li_ailp->ail_lock); +spin_unlock (&ailp->ail_lock); error =xfs_qm_dqflush (dqp, &bp);if (!error) {
@@ -162,7 +163,11 @@ xfs_qm_dquot_logitem_push( }else if (error == -EAGAIN ) rval =XFS_ITEM_LOCKED ; -spin_lock (&lip->li_ailp->ail_lock); +/* +* The buffer no longer protects the log item from reclaim, so +* do not reference lip after this point. +*/ +spin_lock (&ailp->ail_lock); out_unlock:xfs_dqunlock (dqp);return rval;
fs/xfs/xfs_inode_item.c +7 -2
@@ -514,6 +514,7 @@ xfs_inode_item_push(struct xfs_inode_log_item *iip =INODE_ITEM (lip);struct xfs_inode *ip = iip->ili_inode;struct xfs_buf *bp = lip->li_buf; +struct xfs_ail *ailp = lip->li_ailp;uint rval =XFS_ITEM_SUCCESS ;int error;
@@ -529,7 +530,7 @@ xfs_inode_item_push(if (!xfs_buf_trylock (bp))return XFS_ITEM_LOCKED ; -spin_unlock (&lip->li_ailp->ail_lock); +spin_unlock (&ailp->ail_lock);/* * We need to hold a reference for flushing the cluster buffer as it may
@@ -553,7 +554,11 @@ xfs_inode_item_push( rval =XFS_ITEM_LOCKED ; } -spin_lock (&lip->li_ailp->ail_lock); +/* +* The buffer no longer protects the log item from reclaim, so +* do not reference lip after this point. +*/ +spin_lock (&ailp->ail_lock);return rval; }
Greg Kroah-Hartman
maintainerPATCH 468/491 xfs: stop reclaim before pushing AIL during unmount
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuto Ohnuki <[email protected]>
[ Upstream commit 4f24a767e3d64a5f58c595b5c29b6063a201f1e3 ]
The unmount sequence in xfs_unmount_flush_inodes() pushed the AIL while background reclaim and inodegc are still running. This is broken independently of any use-after-free issues - background reclaim and inodegc should not be running while the AIL is being pushed during unmount, as inodegc can dirty and insert inodes into the AIL during the flush, and background reclaim can race to abort and free dirty inodes.
Reorder xfs_unmount_flush_inodes() to stop inodegc and cancel background reclaim before pushing the AIL. Stop inodegc before cancelling m_reclaim_work because the inodegc worker can re-queue m_reclaim_work via xfs_inodegc_set_reclaimable.
--- fs/xfs/xfs_mount.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/xfs/xfs_mount.c +4 -3
@@ -652,8 +652,9 @@ xfs_check_summary_counts(* have been retrying in the background. This will prevent never-ending * retries in AIL pushing from hanging the unmount. * -* Finally, we can push the AIL to clean all the remaining dirty objects, then -* reclaim the remaining inodes that are still in memory at this point in time. +* Stop inodegc and background reclaim before pushing the AIL so that they +* are not running while the AIL is being flushed. Then push the AIL to +* clean all the remaining dirty objects and reclaim the remaining inodes. */ static void xfs_unmount_flush_inodes(
@@ -665,8 +666,8 @@ xfs_unmount_flush_inodes( mp->m_flags |=XFS_MOUNT_UNMOUNTING ; -xfs_ail_push_all_sync (mp->m_ail);cancel_delayed_work_sync (&mp->m_reclaim_work); +xfs_ail_push_all_sync (mp->m_ail);xfs_reclaim_inodes (mp);xfs_health_unmount (mp); }
Greg Kroah-Hartman
maintainerPATCH 469/491 ext4: fix iloc.bh leak in ext4_fc_replay_inode() error paths
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Baokun Li <[email protected]>
[ Upstream commit ec0a7500d8eace5b4f305fa0c594dd148f0e8d29 ]
During code review, Joseph found that ext4_fc_replay_inode() calls ext4_get_fc_inode_loc() to get the inode location, which holds a reference to iloc.bh that must be released via brelse().
However, several error paths jump to the 'out' label without releasing iloc.bh:
- ext4_handle_dirty_metadata() failure
- sync_dirty_buffer() failure
- ext4_mark_inode_used() failure
- ext4_iget() failure
Fix this by introducing an 'out_brelse' label placed just before the existing 'out' label to ensure iloc.bh is always released.
Additionally, make ext4_fc_replay_inode() propagate errors properly instead of always returning 0.
--- fs/ext4/fast_commit.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
fs/ext4/fast_commit.c +8 -5
@@ -1480,19 +1480,21 @@ static int ext4_fc_replay_inode(struct s/* Immediately update the inode on disk. */ ret =ext4_handle_dirty_metadata (NULL ,NULL , iloc.bh);if (ret) - goto out; + goto out_brelse; ret =sync_dirty_buffer (iloc.bh);if (ret) - goto out; + goto out_brelse; ret =ext4_mark_inode_used (sb, ino);if (ret) - goto out; + goto out_brelse;/* Given that we just wrote the inode on disk, this SHOULD succeed. */ inode =ext4_iget (sb, ino,EXT4_IGET_NORMAL );if (IS_ERR (inode)) {jbd_debug (1 ,"Inode not found." ); -return -EFSCORRUPTED ; + inode =NULL ; + ret = -EFSCORRUPTED ; + goto out_brelse; }/*
@@ -1508,13 +1510,14 @@ static int ext4_fc_replay_inode(struct sext4_inode_csum_set (inode,ext4_raw_inode (&iloc),EXT4_I (inode)); ret =ext4_handle_dirty_metadata (NULL ,NULL , iloc.bh);sync_dirty_buffer (iloc.bh); +out_brelse:brelse (iloc.bh); out:iput (inode);if (!ret)blkdev_issue_flush (sb->s_bdev,GFP_KERNEL ); -return 0 ; +return ret; }/*
Greg Kroah-Hartman
maintainerPATCH 470/491 ext4: publish jinode after initialization
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li Chen <[email protected]>
[ Upstream commit 1aec30021edd410b986c156f195f3d23959a9d11 ]
ext4_inode_attach_jinode() publishes ei->jinode to concurrent users. It used to set ei->jinode before jbd2_journal_init_jbd_inode(), allowing a reader to observe a non-NULL jinode with i_vfs_inode still unset.
The fast commit flush path can then pass this jinode to jbd2_wait_inode_data(), which dereferences i_vfs_inode->i_mapping and may crash.
Below is the crash I observe:
``` BUG: unable to handle page fault for address: 000000010beb47f4 PGD 110e51067 P4D 110e51067 PUD 0 Oops: Oops: 0000 [#1] SMP NOPTI CPU: 1 UID: 0 PID: 4850 Comm: fc_fsync_bench_ Not tainted 6.18.0-00764-g795a690c06a5 #1 PREEMPT(voluntary) Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Arch Linux 1.17.0-2-2 04/01/2014 RIP: 0010:xas_find_marked+0x3d/0x2e0 Code: e0 03 48 83 f8 02 0f 84 f0 01 00 00 48 8b 47 08 48 89 c3 48 39 c6 0f 82 fd 01 00 00 48 85 c9 74 3d 48 83 f9 03 77 63 4c 8b 0f <49> 8b 71 08 48 c7 47 18 00 00 00 00 48 89 f1 83 e1 03 48 83 f9 02 RSP: 0018:ffffbbee806e7bf0 EFLAGS: 00010246 RAX: 000000000010beb4 RBX: 000000000010beb4 RCX: 0000000000000003 RDX: 0000000000000001 RSI: 0000002000300000 RDI: ffffbbee806e7c10 RBP: 0000000000000001 R08: 0000002000300000 R09: 000000010beb47ec R10: ffff9ea494590090 R11: 0000000000000000 R12: 0000002000300000 R13: ffffbbee806e7c90 R14: ffff9ea494513788 R15: ffffbbee806e7c88 FS: 00007fc2f9e3e6c0(0000) GS:ffff9ea6b1444000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 000000010beb47f4 CR3: 0000000119ac5000 CR4: 0000000000750ef0 PKRU: 55555554 Call Trace: <TASK> filemap_get_folios_tag+0x87/0x2a0 __filemap_fdatawait_range+0x5f/0xd0 ? srso_alias_return_thunk+0x5/0xfbef5 ? __schedule+0x3e7/0x10c0 ? srso_alias_return_thunk+0x5/0xfbef5 ? srso_alias_return_thunk+0x5/0xfbef5 ? srso_alias_return_thunk+0x5/0xfbef5 ? preempt_count_sub+0x5f/0x80 ? srso_alias_return_thunk+0x5/0xfbef5 ? cap_safe_nice+0x37/0x70 ? srso_alias_return_thunk+0x5/0xfbef5 ? preempt_count_sub+0x5f/0x80 ? srso_alias_return_thunk+0x5/0xfbef5 filemap_fdatawait_range_keep_errors+0x12/0x40 ext4_fc_commit+0x697/0x8b0 ? ext4_file_write_iter+0x64b/0x950 ? srso_alias_return_thunk+0x5/0xfbef5 ? preempt_count_sub+0x5f/0x80 ? srso_alias_return_thunk+0x5/0xfbef5 ? vfs_write+0x356/0x480 ? srso_alias_return_thunk+0x5/0xfbef5 ? preempt_count_sub+0x5f/0x80 ext4_sync_file+0xf7/0x370 do_fsync+0x3b/0x80 ? syscall_trace_enter+0x108/0x1d0 __x64_sys_fdatasync+0x16/0x20 do_syscall_64+0x62/0x2c0 entry_SYSCALL_64_after_hwframe+0x76/0x7e ... ```
Fix this by initializing the jbd2_inode first.
Use smp_wmb() and WRITE_ONCE() to publish ei->jinode after initialization. Readers use READ_ONCE() to fetch the pointer.
--- fs/ext4/fast_commit.c | 4 ++-- fs/ext4/inode.c | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-)
fs/ext4/fast_commit.c +2 -2
@@ -902,7 +902,7 @@ static int ext4_fc_submit_inode_data_allfinish_wait (&ei->i_fc_wait, &wait); }spin_unlock (&sbi->s_fc_lock); - ret =jbd2_submit_inode_data (ei->jinode); + ret =jbd2_submit_inode_data (READ_ONCE (ei->jinode));if (ret)return ret;spin_lock (&sbi->s_fc_lock);
@@ -927,7 +927,7 @@ static int ext4_fc_wait_inode_data_all(jcontinue ;spin_unlock (&sbi->s_fc_lock); - ret =jbd2_wait_inode_data (journal, pos->jinode); + ret =jbd2_wait_inode_data (journal,READ_ONCE (pos->jinode));if (ret)return ret;spin_lock (&sbi->s_fc_lock);
fs/ext4/inode.c +11 -4
@@ -121,6 +121,8 @@ void ext4_inode_csum_set(struct inode *istatic inline int ext4_begin_ordered_truncate (struct inode *inode,loff_t new_size) { +struct jbd2_inode *jinode =READ_ONCE (EXT4_I (inode)->jinode); +trace_ext4_begin_ordered_truncate (inode, new_size);/* * If jinode is zero, then we never opened the file for
@@ -128,10 +130,10 @@ static inline int ext4_begin_ordered_tru* jbd2_journal_begin_ordered_truncate() since there's no * outstanding writes we need to flush. */ -if (!EXT4_I (inode)->jinode) +if (!jinode)return 0 ;return jbd2_journal_begin_ordered_truncate (EXT4_JOURNAL (inode), -EXT4_I (inode)->jinode, + jinode, new_size); }
@@ -4231,8 +4233,13 @@ int ext4_inode_attach_jinode(struct inodspin_unlock (&inode->i_lock);return -ENOMEM ; } - ei->jinode = jinode; -jbd2_journal_init_jbd_inode (ei->jinode, inode); +jbd2_journal_init_jbd_inode (jinode, inode); +/* +* Publish ->jinode only after it is fully initialized so that +* readers never observe a partially initialized jbd2_inode. +*/ +smp_wmb (); +WRITE_ONCE (ei->jinode, jinode); jinode =NULL ; }spin_unlock (&inode->i_lock);
Greg Kroah-Hartman
maintainerPATCH 471/491 Bluetooth: L2CAP: Fix accepting multiple L2CAP_ECRED_CONN_REQ
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luiz Augusto von Dentz <[email protected]>
[ Upstream commit 5b3e2052334f2ff6d5200e952f4aa66994d09899 ]
Currently the code attempts to accept requests regardless of the command identifier which may cause multiple requests to be marked as pending (FLAG_DEFER_SETUP) which can cause more than L2CAP_ECRED_MAX_CID(5) to be allocated in l2cap_ecred_rsp_defer causing an overflow.
The spec is quite clear that the same identifier shall not be used on subsequent requests:
'Within each signaling channel a different Identifier shall be used for each successive request or indication.'
https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core-62/out/en/host/logical-link-control-and-adaptation-protocol-specification.html#UUID-32a25a06-4aa4-c6c7-77c5-dcfe3682355d
So this attempts to check if there are any channels pending with the same identifier and rejects if any are found.
--- net/bluetooth/l2cap_core.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
net/bluetooth/l2cap_core.c +9 -1
@@ -6053,7 +6053,7 @@ static inline int l2cap_ecred_conn_req(su16 mtu, mps;__le16 psm;u8 result, len =0 ; -int i, num_scid; +int i, num_scid =0 ;bool defer = false;if (!enable_ecred)
@@ -6063,6 +6063,14 @@ static inline int l2cap_ecred_conn_req(s result =L2CAP_CR_LE_INVALID_PARAMS ; goto response; } + +/* Check if there are no pending channels with the same ident */ +__l2cap_chan_list_id (conn, cmd->ident, l2cap_ecred_list_defer, + &num_scid); +if (num_scid) { + result =L2CAP_CR_LE_INVALID_PARAMS ; + goto response; + } cmd_len -=sizeof (*req); num_scid = cmd_len /sizeof (u16);
Greg Kroah-Hartman
maintainerPATCH 472/491 drm: Fix use-after-free on framebuffers and property blobs when calling drm_dev_unplug
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maarten Lankhorst <[email protected]>
[ Upstream commit 6bee098b91417654703e17eb5c1822c6dfd0c01d ]
When trying to do a rather aggressive test of igt's "xe_module_load --r reload" with a full desktop environment and game running I noticed a few OOPSes when dereferencing freed pointers, related to framebuffers and property blobs after the compositor exits.
Solve this by guarding the freeing in drm_file with drm_dev_enter/exit, and immediately put the references from struct drm_file objects during drm_dev_unplug().
Related warnings for framebuffers on the subtest:
[ 739.713076] ------------[ cut here ]------------
WARN_ON(!list_empty(&dev->mode_config.fb_list))
[ 739.713079] WARNING: drivers/gpu/drm/drm_mode_config.c:584 at drm_mode_config_cleanup+0x30b/0x320 [drm], CPU#12: xe_module_load/13145
....
[ 739.713328] Call Trace:
[ 739.713330] <TASK>
[ 739.713335] ? intel_pmdemand_destroy_state+0x11/0x20 [xe]
[ 739.713574] ? intel_atomic_global_obj_cleanup+0xe4/0x1a0 [xe]
[ 739.713794] intel_display_driver_remove_noirq+0x51/0xb0 [xe]
[ 739.714041] xe_display_fini_early+0x33/0x50 [xe]
[ 739.714284] devm_action_release+0xf/0x20
[ 739.714294] devres_release_all+0xad/0xf0
[ 739.714301] device_unbind_cleanup+0x12/0xa0
[ 739.714305] device_release_driver_internal+0x1b7/0x210
[ 739.714311] device_driver_detach+0x14/0x20
[ 739.714315] unbind_store+0xa6/0xb0
[ 739.714319] drv_attr_store+0x21/0x30
[ 739.714322] sysfs_kf_write+0x48/0x60
[ 739.714328] kernfs_fop_write_iter+0x16b/0x240
[ 739.714333] vfs_write+0x266/0x520
[ 739.714341] ksys_write+0x72/0xe0
[ 739.714345] __x64_sys_write+0x19/0x20
[ 739.714347] x64_sys_call+0xa15/0xa30
[ 739.714355] do_syscall_64+0xd8/0xab0
[ 739.714361] entry_SYSCALL_64_after_hwframe+0x4b/0x53and
[ 739.714459] ------------[ cut here ]------------ [ 739.714461] xe 0000:67:00.0: [drm] drm_WARN_ON(!list_empty(&fb->filp_head)) [ 739.714464] WARNING: drivers/gpu/drm/drm_framebuffer.c:833 at drm_framebuffer_free+0x6c/0x90 [drm], CPU#12: xe_module_load/13145 [ 739.714715] RIP: 0010:drm_framebuffer_free+0x7a/0x90 [drm] ... [ 739.714869] Call Trace: [ 739.714871] <TASK> [ 739.714876] drm_mode_config_cleanup+0x26a/0x320 [drm] [ 739.714998] ? __drm_printfn_seq_file+0x20/0x20 [drm] [ 739.715115] ? drm_mode_config_cleanup+0x207/0x320 [drm] [ 739.715235] intel_display_driver_remove_noirq+0x51/0xb0 [xe] [ 739.715576] xe_display_fini_early+0x33/0x50 [xe] [ 739.715821] devm_action_release+0xf/0x20 [ 739.715828] devres_release_all+0xad/0xf0 [ 739.715843] device_unbind_cleanup+0x12/0xa0 [ 739.715850] device_release_driver_internal+0x1b7/0x210 [ 739.715856] device_driver_detach+0x14/0x20 [ 739.715860] unbind_store+0xa6/0xb0 [ 739.715865] drv_attr_store+0x21/0x30 [ 739.715868] sysfs_kf_write+0x48/0x60 [ 739.715873] kernfs_fop_write_iter+0x16b/0x240 [ 739.715878] vfs_write+0x266/0x520 [ 739.715886] ksys_write+0x72/0xe0 [ 739.715890] __x64_sys_write+0x19/0x20 [ 739.715893] x64_sys_call+0xa15/0xa30 [ 739.715900] do_syscall_64+0xd8/0xab0 [ 739.715905] entry_SYSCALL_64_after_hwframe+0x4b/0x53
and then finally file close blows up:
[ 743.186530] Oops: general protection fault, probably for non-canonical address 0xdead000000000122: 0000 [#1] SMP
[ 743.186535] CPU: 3 UID: 1000 PID: 3453 Comm: kwin_wayland Tainted: G W 7.0.0-rc1-valkyria+ #110 PREEMPT_{RT,(lazy)}
[ 743.186537] Tainted: [W]=WARN
[ 743.186538] Hardware name: Gigabyte Technology Co., Ltd. X299 AORUS Gaming 3/X299 AORUS Gaming 3-CF, BIOS F8n 12/06/2021
[ 743.186539] RIP: 0010:drm_framebuffer_cleanup+0x55/0xc0 [drm]
[ 743.186588] Code: d8 72 73 0f b6 42 05 ff c3 39 c3 72 e8 49 8d bd 50 07 00 00 31 f6 e8 3a 80 d3 e1 49 8b 44 24 10 49 8d 7c 24 08 49 8b 54 24 08 <48> 3b 38 0f 85 95 7f 02 00 48 3b 7a 08 0f 85 8b 7f 02 00 48 89 42
[ 743.186589] RSP: 0018:ffffc900085e3cf8 EFLAGS: 00010202
[ 743.186591] RAX: dead000000000122 RBX: 0000000000000001 RCX: ffffffff8217ed03
[ 743.186592] RDX: dead000000000100 RSI: 0000000000000000 RDI: ffff88814675ba08
[ 743.186593] RBP: ffffc900085e3d10 R08: 0000000000000000 R09: 0000000000000000
[ 743.186593] R10: 0000000000000000 R11: 0000000000000000 R12: ffff88814675ba00
[ 743.186594] R13: ffff88810d778000 R14: ffff888119f6dca0 R15: ffff88810c660bb0
[ 743.186595] FS: 00007ff377d21280(0000) GS:ffff888cec3f8000(0000) knlGS:0000000000000000
[ 743.186596] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 743.186596] CR2: 000055690b55e000 CR3: 0000000113586003 CR4: 00000000003706f0
[ 743.186597] Call Trace:
[ 743.186598] <TASK>
[ 743.186603] intel_user_framebuffer_destroy+0x12/0x90 [xe]
[ 743.186722] drm_framebuffer_free+0x3a/0x90 [drm]
[ 743.186750] ? trace_hardirqs_on+0x5f/0x120
[ 743.186754] drm_mode_object_put+0x51/0x70 [drm]
[ 743.186786] drm_fb_release+0x105/0x190 [drm]
[ 743.186812] ? rt_mutex_slowunlock+0x3aa/0x410
[ 743.186817] ? rt_spin_lock+0xea/0x1b0
[ 743.186819] drm_file_free+0x1e0/0x2c0 [drm]
[ 743.186843] drm_release_noglobal+0x91/0xf0 [drm]
[ 743.186865] __fput+0x100/0x2e0
[ 743.186869] fput_close_sync+0x40/0xa0
[ 743.186870] __x64_sys_close+0x3e/0x80
[ 743.186873] x64_sys_call+0xa07/0xa30
[ 743.186879] do_syscall_64+0xd8/0xab0
[ 743.186881] entry_SYSCALL_64_after_hwframe+0x4b/0x53
[ 743.186882] RIP: 0033:0x7ff37e567732
[ 743.186884] Code: 08 0f 85 a1 38 ff ff 49 89 fb 48 89 f0 48 89 d7 48 89 ce 4c 89 c2 4d 89 ca 4c 8b 44 24 08 4c 8b 4c 24 10 4c 89 5c 24 08 0f 05 <c3> 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 00 f3 0f 1e fa 55 bf 01 00
[ 743.186885] RSP: 002b:00007ffc818169a8 EFLAGS: 00000246 ORIG_RAX: 0000000000000003
[ 743.186886] RAX: ffffffffffffffda RBX: 00007ffc81816a30 RCX: 00007ff37e567732
[ 743.186887] RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000012
[ 743.186888] RBP: 00007ffc818169d0 R08: 0000000000000000 R09: 0000000000000000
[ 743.186889] R10: 0000000000000000 R11: 0000000000000246 R12: 000055d60a7996e0
[ 743.186889] R13: 00007ffc81816a90 R14: 00007ffc81816a90 R15: 000055d60a782a30
[ 743.186892] </TASK>
[ 743.186893] Modules linked in: rfcomm snd_hrtimer xt_CHECKSUM xt_MASQUERADE xt_conntrack ipt_REJECT nf_reject_ipv4 xt_tcpudp xt_addrtype nft_compat x_tables nft_chain_nat nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 nf_tables overlay cfg80211 bnep mtd_intel_dg snd_hda_codec_intelhdmi mtd snd_hda_codec_hdmi nls_utf8 mxm_wmi intel_wmi_thunderbolt gigabyte_wmi wmi_bmof xe drm_gpuvm drm_gpusvm_helper i2c_algo_bit drm_buddy drm_ttm_helper ttm video drm_suballoc_helper gpu_sched drm_client_lib drm_exec drm_display_helper cec drm_kunit_helpers drm_kms_helper kunit x86_pkg_temp_thermal intel_powerclamp coretemp snd_hda_codec_alc882 snd_hda_codec_realtek_lib snd_hda_codec_generic snd_hda_intel snd_soc_avs snd_soc_hda_codec snd_hda_ext_core snd_hda_codec snd_hwdep snd_hda_core snd_intel_dspcfg snd_soc_core snd_compress ac97_bus snd_pcm snd_seq snd_seq_device snd_timer i2c_i801 i2c_mux snd i2c_smbus btusb btrtl btbcm btmtk btintel bluetooth ecdh_generic rfkill ecc mei_me mei ioatdma dca wmi nfsd drm i2c_dev fuse nfnetlink
[ 743.186938] ---[ end trace 0000000000000000 ]---And for property blobs:
void drm_mode_config_cleanup(struct drm_device *dev) {
...
list_for_each_entry_safe(blob, bt, &dev->mode_config.property_blob_list,
head_global) {
drm_property_blob_put(blob);
}Resulting in:
[ 371.072940] BUG: unable to handle page fault for address: 000001ffffffffff
[ 371.072944] #PF: supervisor read access in kernel mode
[ 371.072945] #PF: error_code(0x0000) - not-present page
[ 371.072947] PGD 0 P4D 0
[ 371.072950] Oops: Oops: 0000 [#1] SMP
[ 371.072953] CPU: 0 UID: 1000 PID: 3693 Comm: kwin_wayland Not tainted 7.0.0-rc1-valkyria+ #111 PREEMPT_{RT,(lazy)}
[ 371.072956] Hardware name: Gigabyte Technology Co., Ltd. X299 AORUS Gaming 3/X299 AORUS Gaming 3-CF, BIOS F8n 12/06/2021
[ 371.072957] RIP: 0010:drm_property_destroy_user_blobs+0x3b/0x90 [drm]
[ 371.073019] Code: 00 00 48 83 ec 10 48 8b 86 30 01 00 00 48 39 c3 74 59 48 89 c2 48 8d 48 c8 48 8b 00 4c 8d 60 c8 eb 04 4c 8d 60 c8 48 8b 71 40 <48> 39 16 0f 85 39 32 01 00 48 3b 50 08 0f 85 2f 32 01 00 48 89 70
[ 371.073021] RSP: 0018:ffffc90006a73de8 EFLAGS: 00010293
[ 371.073022] RAX: 000001ffffffffff RBX: ffff888118a1a930 RCX: ffff8881b92355c0
[ 371.073024] RDX: ffff8881b92355f8 RSI: 000001ffffffffff RDI: ffff888118be4000
[ 371.073025] RBP: ffffc90006a73e08 R08: ffff8881009b7300 R09: ffff888cecc5b000
[ 371.073026] R10: ffffc90006a73e90 R11: 0000000000000002 R12: 000001ffffffffc7
[ 371.073027] R13: ffff888118a1a980 R14: ffff88810b366d20 R15: ffff888118a1a970
[ 371.073028] FS: 00007f1faccbb280(0000) GS:ffff888cec2db000(0000) knlGS:0000000000000000
[ 371.073029] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 371.073030] CR2: 000001ffffffffff CR3: 000000010655c001 CR4: 00000000003706f0
[ 371.073031] Call Trace:
[ 371.073033] <TASK>
[ 371.073036] drm_file_free+0x1df/0x2a0 [drm]
[ 371.073077] drm_release_noglobal+0x7a/0xe0 [drm]
[ 371.073113] __fput+0xe2/0x2b0
[ 371.073118] fput_close_sync+0x40/0xa0
[ 371.073119] __x64_sys_close+0x3e/0x80
[ 371.073122] x64_sys_call+0xa07/0xa30
[ 371.073126] do_syscall_64+0xc0/0x840
[ 371.073130] entry_SYSCALL_64_after_hwframe+0x4b/0x53
[ 371.073132] RIP: 0033:0x7f1fb3501732
[ 371.073133] Code: 08 0f 85 a1 38 ff ff 49 89 fb 48 89 f0 48 89 d7 48 89 ce 4c 89 c2 4d 89 ca 4c 8b 44 24 08 4c 8b 4c 24 10 4c 89 5c 24 08 0f 05 <c3> 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 00 f3 0f 1e fa 55 bf 01 00
[ 371.073135] RSP: 002b:00007ffe8e6f0278 EFLAGS: 00000246 ORIG_RAX: 0000000000000003
[ 371.073136] RAX: ffffffffffffffda RBX: 00007ffe8e6f0300 RCX: 00007f1fb3501732
[ 371.073137] RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000012
[ 371.073138] RBP: 00007ffe8e6f02a0 R08: 0000000000000000 R09: 0000000000000000
[ 371.073139] R10: 0000000000000000 R11: 0000000000000246 R12: 00005585ba46eea0
[ 371.073140] R13: 00007ffe8e6f0360 R14: 00007ffe8e6f0360 R15: 00005585ba458a30
[ 371.073143] </TASK>
[ 371.073144] Modules linked in: rfcomm snd_hrtimer xt_addrtype xt_CHECKSUM xt_MASQUERADE xt_conntrack ipt_REJECT nf_reject_ipv4 xt_tcpudp nft_compat x_tables nft_chain_nat nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 nf_tables overlay cfg80211 bnep snd_hda_codec_intelhdmi snd_hda_codec_hdmi mtd_intel_dg mtd nls_utf8 wmi_bmof mxm_wmi gigabyte_wmi intel_wmi_thunderbolt xe drm_gpuvm drm_gpusvm_helper i2c_algo_bit drm_buddy drm_ttm_helper ttm video drm_suballoc_helper gpu_sched drm_client_lib drm_exec drm_display_helper cec drm_kunit_helpers drm_kms_helper kunit x86_pkg_temp_thermal intel_powerclamp coretemp snd_hda_codec_alc882 snd_hda_codec_realtek_lib snd_hda_codec_generic snd_hda_intel snd_soc_avs snd_soc_hda_codec snd_hda_ext_core snd_hda_codec snd_hwdep snd_hda_core snd_intel_dspcfg snd_soc_core snd_compress ac97_bus snd_pcm snd_seq snd_seq_device snd_timer i2c_i801 btusb i2c_mux i2c_smbus btrtl snd btbcm btmtk btintel bluetooth ecdh_generic rfkill ecc mei_me mei ioatdma dca wmi nfsd drm i2c_dev fuse nfnetlink
[ 371.073198] CR2: 000001ffffffffff
[ 371.073199] ---[ end trace 0000000000000000 ]---Add a guard around file close, and ensure the warnings from drm_mode_config do not trigger. Fix those by allowing an open reference to the file descriptor and cleaning up the file linked list entry in drm_mode_config_cleanup().
--- drivers/gpu/drm/drm_file.c | 5 ++++- drivers/gpu/drm/drm_mode_config.c | 9 ++++++--- 2 files changed, 10 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_file.c +4 -1
@@ -248,6 +248,7 @@ static void drm_events_release(struct drvoid drm_file_free (struct drm_file *file) {struct drm_device *dev; +int idx;if (!file)return ;
@@ -271,9 +272,11 @@ void drm_file_free(struct drm_file *filedrm_events_release (file); -if (drm_core_check_feature (dev,DRIVER_MODESET )) { +if (drm_core_check_feature (dev,DRIVER_MODESET ) && +drm_dev_enter (dev, &idx)) {drm_fb_release (file);drm_property_destroy_user_blobs (dev, file); +drm_dev_exit (idx); }if (drm_core_check_feature (dev,DRIVER_SYNCOBJ ))
drivers/gpu/drm/drm_mode_config.c +6 -3
@@ -543,10 +543,13 @@ void drm_mode_config_cleanup(struct drm_*/ WARN_ON (!list_empty (&dev->mode_config.fb_list));list_for_each_entry_safe (fb, fbt, &dev->mode_config.fb_list, head) { -struct drm_printer p =drm_debug_printer ("[leaked fb]" ); +if (list_empty (&fb->filp_head) ||drm_framebuffer_read_refcount (fb) >1 ) { +struct drm_printer p =drm_debug_printer ("[leaked fb]" ); -drm_printf (&p,"framebuffer[%u]:\n" , fb->base.id); -drm_framebuffer_print_info (&p,1 , fb); +drm_printf (&p,"framebuffer[%u]:\n" , fb->base.id); +drm_framebuffer_print_info (&p,1 , fb); + } +list_del_init (&fb->filp_head);drm_framebuffer_free (&fb->base.refcount); }
Re: [PATCH 5.10 472/491] drm: Fix use-after-free on framebuffers and property blobs when calling drm_dev_unplug
Quoted 7 lines · Greg Kroah-Hartman
5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maarten Lankhorst <[email protected]>
[ Upstream commit
6bee098b91417654703e17eb5c1822c6dfd0c01d]
This has already been reverted upstream (commit 45ebe43ea00d), so please drop it from all queues.
Ben.
Quoted 227 lines
When trying to do a rather aggressive test of igt's "
xe_module_load--r reload" with a full desktop environment and game running I noticed a few OOPSes when dereferencing freed pointers, related to framebuffers and property blobs after the compositor exits.Solve this by guarding the freeing in
drm_filewith drm_dev_enter/exit, and immediately put the references from structdrm_fileobjects duringdrm_dev_unplug().Related warnings for framebuffers on the subtest:
[ 739.713076] ------------[ cut here ]------------ WARN_ON(!list_empty(&dev->mode_config.fb_list)) [ 739.713079] WARNING: drivers/gpu/drm/drm_mode_config.c:584 at drm_mode_config_cleanup+0x30b/0x320 [drm], CPU#12: xe_module_load/13145 .... [ 739.713328] Call Trace: [ 739.713330] <TASK> [ 739.713335] ? intel_pmdemand_destroy_state+0x11/0x20 [xe] [ 739.713574] ? intel_atomic_global_obj_cleanup+0xe4/0x1a0 [xe] [ 739.713794] intel_display_driver_remove_noirq+0x51/0xb0 [xe] [ 739.714041] xe_display_fini_early+0x33/0x50 [xe] [ 739.714284] devm_action_release+0xf/0x20 [ 739.714294] devres_release_all+0xad/0xf0 [ 739.714301] device_unbind_cleanup+0x12/0xa0 [ 739.714305] device_release_driver_internal+0x1b7/0x210 [ 739.714311] device_driver_detach+0x14/0x20 [ 739.714315] unbind_store+0xa6/0xb0 [ 739.714319] drv_attr_store+0x21/0x30 [ 739.714322] sysfs_kf_write+0x48/0x60 [ 739.714328] kernfs_fop_write_iter+0x16b/0x240 [ 739.714333] vfs_write+0x266/0x520 [ 739.714341] ksys_write+0x72/0xe0 [ 739.714345] __x64_sys_write+0x19/0x20 [ 739.714347] x64_sys_call+0xa15/0xa30 [ 739.714355] do_syscall_64+0xd8/0xab0 [ 739.714361] entry_SYSCALL_64_after_hwframe+0x4b/0x53and
[ 739.714459] ------------[ cut here ]------------ [ 739.714461] xe 0000:67:00.0: [drm] drm_WARN_ON(!list_empty(&fb->filp_head)) [ 739.714464] WARNING: drivers/gpu/drm/drm_framebuffer.c:833 at drm_framebuffer_free+0x6c/0x90 [drm], CPU#12: xe_module_load/13145 [ 739.714715] RIP: 0010:drm_framebuffer_free+0x7a/0x90 [drm] ... [ 739.714869] Call Trace: [ 739.714871] <TASK> [ 739.714876] drm_mode_config_cleanup+0x26a/0x320 [drm] [ 739.714998] ? __drm_printfn_seq_file+0x20/0x20 [drm] [ 739.715115] ? drm_mode_config_cleanup+0x207/0x320 [drm] [ 739.715235] intel_display_driver_remove_noirq+0x51/0xb0 [xe] [ 739.715576] xe_display_fini_early+0x33/0x50 [xe] [ 739.715821] devm_action_release+0xf/0x20 [ 739.715828] devres_release_all+0xad/0xf0 [ 739.715843] device_unbind_cleanup+0x12/0xa0 [ 739.715850] device_release_driver_internal+0x1b7/0x210 [ 739.715856] device_driver_detach+0x14/0x20 [ 739.715860] unbind_store+0xa6/0xb0 [ 739.715865] drv_attr_store+0x21/0x30 [ 739.715868] sysfs_kf_write+0x48/0x60 [ 739.715873] kernfs_fop_write_iter+0x16b/0x240 [ 739.715878] vfs_write+0x266/0x520 [ 739.715886] ksys_write+0x72/0xe0 [ 739.715890] __x64_sys_write+0x19/0x20 [ 739.715893] x64_sys_call+0xa15/0xa30 [ 739.715900] do_syscall_64+0xd8/0xab0 [ 739.715905] entry_SYSCALL_64_after_hwframe+0x4b/0x53and then finally file close blows up:
[ 743.186530] Oops: general protection fault, probably for non-canonical address 0xdead000000000122: 0000 [#1] SMP [ 743.186535] CPU: 3 UID: 1000 PID: 3453 Comm: kwin_wayland Tainted: G W 7.0.0-rc1-valkyria+ #110 PREEMPT_{RT,(lazy)} [ 743.186537] Tainted: [W]=WARN [ 743.186538] Hardware name: Gigabyte Technology Co., Ltd. X299 AORUS Gaming 3/X299 AORUS Gaming 3-CF, BIOS F8n 12/06/2021 [ 743.186539] RIP: 0010:drm_framebuffer_cleanup+0x55/0xc0 [drm] [ 743.186588] Code: d8 72 73 0f b6 42 05 ff c3 39 c3 72 e8 49 8d bd 50 07 00 00 31 f6 e8 3a 80 d3 e1 49 8b 44 24 10 49 8d 7c 24 08 49 8b 54 24 08 <48> 3b 38 0f 85 95 7f 02 00 48 3b 7a 08 0f 85 8b 7f 02 00 48 89 42 [ 743.186589] RSP: 0018:ffffc900085e3cf8 EFLAGS: 00010202 [ 743.186591] RAX: dead000000000122 RBX: 0000000000000001 RCX: ffffffff8217ed03 [ 743.186592] RDX: dead000000000100 RSI: 0000000000000000 RDI: ffff88814675ba08 [ 743.186593] RBP: ffffc900085e3d10 R08: 0000000000000000 R09: 0000000000000000 [ 743.186593] R10: 0000000000000000 R11: 0000000000000000 R12: ffff88814675ba00 [ 743.186594] R13: ffff88810d778000 R14: ffff888119f6dca0 R15: ffff88810c660bb0 [ 743.186595] FS: 00007ff377d21280(0000) GS:ffff888cec3f8000(0000) knlGS:0000000000000000 [ 743.186596] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 743.186596] CR2: 000055690b55e000 CR3: 0000000113586003 CR4: 00000000003706f0 [ 743.186597] Call Trace: [ 743.186598] <TASK> [ 743.186603] intel_user_framebuffer_destroy+0x12/0x90 [xe] [ 743.186722] drm_framebuffer_free+0x3a/0x90 [drm] [ 743.186750] ? trace_hardirqs_on+0x5f/0x120 [ 743.186754] drm_mode_object_put+0x51/0x70 [drm] [ 743.186786] drm_fb_release+0x105/0x190 [drm] [ 743.186812] ? rt_mutex_slowunlock+0x3aa/0x410 [ 743.186817] ? rt_spin_lock+0xea/0x1b0 [ 743.186819] drm_file_free+0x1e0/0x2c0 [drm] [ 743.186843] drm_release_noglobal+0x91/0xf0 [drm] [ 743.186865] __fput+0x100/0x2e0 [ 743.186869] fput_close_sync+0x40/0xa0 [ 743.186870] __x64_sys_close+0x3e/0x80 [ 743.186873] x64_sys_call+0xa07/0xa30 [ 743.186879] do_syscall_64+0xd8/0xab0 [ 743.186881] entry_SYSCALL_64_after_hwframe+0x4b/0x53 [ 743.186882] RIP: 0033:0x7ff37e567732 [ 743.186884] Code: 08 0f 85 a1 38 ff ff 49 89 fb 48 89 f0 48 89 d7 48 89 ce 4c 89 c2 4d 89 ca 4c 8b 44 24 08 4c 8b 4c 24 10 4c 89 5c 24 08 0f 05 <c3> 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 00 f3 0f 1e fa 55 bf 01 00 [ 743.186885] RSP: 002b:00007ffc818169a8 EFLAGS: 00000246 ORIG_RAX: 0000000000000003 [ 743.186886] RAX: ffffffffffffffda RBX: 00007ffc81816a30 RCX: 00007ff37e567732 [ 743.186887] RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000012 [ 743.186888] RBP: 00007ffc818169d0 R08: 0000000000000000 R09: 0000000000000000 [ 743.186889] R10: 0000000000000000 R11: 0000000000000246 R12: 000055d60a7996e0 [ 743.186889] R13: 00007ffc81816a90 R14: 00007ffc81816a90 R15: 000055d60a782a30 [ 743.186892] </TASK> [ 743.186893] Modules linked in: rfcomm snd_hrtimer xt_CHECKSUM xt_MASQUERADE xt_conntrack ipt_REJECT nf_reject_ipv4 xt_tcpudp xt_addrtype nft_compat x_tables nft_chain_nat nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 nf_tables overlay cfg80211 bnep mtd_intel_dg snd_hda_codec_intelhdmi mtd snd_hda_codec_hdmi nls_utf8 mxm_wmi intel_wmi_thunderbolt gigabyte_wmi wmi_bmof xe drm_gpuvm drm_gpusvm_helper i2c_algo_bit drm_buddy drm_ttm_helper ttm video drm_suballoc_helper gpu_sched drm_client_lib drm_exec drm_display_helper cec drm_kunit_helpers drm_kms_helper kunit x86_pkg_temp_thermal intel_powerclamp coretemp snd_hda_codec_alc882 snd_hda_codec_realtek_lib snd_hda_codec_generic snd_hda_intel snd_soc_avs snd_soc_hda_codec snd_hda_ext_core snd_hda_codec snd_hwdep snd_hda_core snd_intel_dspcfg snd_soc_core snd_compress ac97_bus snd_pcm snd_seq snd_seq_device snd_timer i2c_i801 i2c_mux snd i2c_smbus btusb btrtl btbcm btmtk btintel bluetooth ecdh_generic rfkill ecc mei_me mei ioatdma dca wmi nfsd drm i2c_dev fuse nfnetlink [ 743.186938] ---[ end trace 0000000000000000 ]---And for property blobs:
void
drm_mode_config_cleanup(struct drm_device *dev){
...list_for_each_entry_safe(blob, bt, &dev->mode_config.property_blob_list, head_global) { drm_property_blob_put(blob); }Resulting in:
[ 371.072940] BUG: unable to handle page fault for address: 000001ffffffffff [ 371.072944] #PF: supervisor read access in kernel mode [ 371.072945] #PF: error_code(0x0000) - not-present page [ 371.072947] PGD 0 P4D 0 [ 371.072950] Oops: Oops: 0000 [#1] SMP [ 371.072953] CPU: 0 UID: 1000 PID: 3693 Comm: kwin_wayland Not tainted 7.0.0-rc1-valkyria+ #111 PREEMPT_{RT,(lazy)} [ 371.072956] Hardware name: Gigabyte Technology Co., Ltd. X299 AORUS Gaming 3/X299 AORUS Gaming 3-CF, BIOS F8n 12/06/2021 [ 371.072957] RIP: 0010:drm_property_destroy_user_blobs+0x3b/0x90 [drm] [ 371.073019] Code: 00 00 48 83 ec 10 48 8b 86 30 01 00 00 48 39 c3 74 59 48 89 c2 48 8d 48 c8 48 8b 00 4c 8d 60 c8 eb 04 4c 8d 60 c8 48 8b 71 40 <48> 39 16 0f 85 39 32 01 00 48 3b 50 08 0f 85 2f 32 01 00 48 89 70 [ 371.073021] RSP: 0018:ffffc90006a73de8 EFLAGS: 00010293 [ 371.073022] RAX: 000001ffffffffff RBX: ffff888118a1a930 RCX: ffff8881b92355c0 [ 371.073024] RDX: ffff8881b92355f8 RSI: 000001ffffffffff RDI: ffff888118be4000 [ 371.073025] RBP: ffffc90006a73e08 R08: ffff8881009b7300 R09: ffff888cecc5b000 [ 371.073026] R10: ffffc90006a73e90 R11: 0000000000000002 R12: 000001ffffffffc7 [ 371.073027] R13: ffff888118a1a980 R14: ffff88810b366d20 R15: ffff888118a1a970 [ 371.073028] FS: 00007f1faccbb280(0000) GS:ffff888cec2db000(0000) knlGS:0000000000000000 [ 371.073029] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 371.073030] CR2: 000001ffffffffff CR3: 000000010655c001 CR4: 00000000003706f0 [ 371.073031] Call Trace: [ 371.073033] <TASK> [ 371.073036] drm_file_free+0x1df/0x2a0 [drm] [ 371.073077] drm_release_noglobal+0x7a/0xe0 [drm] [ 371.073113] __fput+0xe2/0x2b0 [ 371.073118] fput_close_sync+0x40/0xa0 [ 371.073119] __x64_sys_close+0x3e/0x80 [ 371.073122] x64_sys_call+0xa07/0xa30 [ 371.073126] do_syscall_64+0xc0/0x840 [ 371.073130] entry_SYSCALL_64_after_hwframe+0x4b/0x53 [ 371.073132] RIP: 0033:0x7f1fb3501732 [ 371.073133] Code: 08 0f 85 a1 38 ff ff 49 89 fb 48 89 f0 48 89 d7 48 89 ce 4c 89 c2 4d 89 ca 4c 8b 44 24 08 4c 8b 4c 24 10 4c 89 5c 24 08 0f 05 <c3> 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 00 f3 0f 1e fa 55 bf 01 00 [ 371.073135] RSP: 002b:00007ffe8e6f0278 EFLAGS: 00000246 ORIG_RAX: 0000000000000003 [ 371.073136] RAX: ffffffffffffffda RBX: 00007ffe8e6f0300 RCX: 00007f1fb3501732 [ 371.073137] RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000012 [ 371.073138] RBP: 00007ffe8e6f02a0 R08: 0000000000000000 R09: 0000000000000000 [ 371.073139] R10: 0000000000000000 R11: 0000000000000246 R12: 00005585ba46eea0 [ 371.073140] R13: 00007ffe8e6f0360 R14: 00007ffe8e6f0360 R15: 00005585ba458a30 [ 371.073143] </TASK> [ 371.073144] Modules linked in: rfcomm snd_hrtimer xt_addrtype xt_CHECKSUM xt_MASQUERADE xt_conntrack ipt_REJECT nf_reject_ipv4 xt_tcpudp nft_compat x_tables nft_chain_nat nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 nf_tables overlay cfg80211 bnep snd_hda_codec_intelhdmi snd_hda_codec_hdmi mtd_intel_dg mtd nls_utf8 wmi_bmof mxm_wmi gigabyte_wmi intel_wmi_thunderbolt xe drm_gpuvm drm_gpusvm_helper i2c_algo_bit drm_buddy drm_ttm_helper ttm video drm_suballoc_helper gpu_sched drm_client_lib drm_exec drm_display_helper cec drm_kunit_helpers drm_kms_helper kunit x86_pkg_temp_thermal intel_powerclamp coretemp snd_hda_codec_alc882 snd_hda_codec_realtek_lib snd_hda_codec_generic snd_hda_intel snd_soc_avs snd_soc_hda_codec snd_hda_ext_core snd_hda_codec snd_hwdep snd_hda_core snd_intel_dspcfg snd_soc_core snd_compress ac97_bus snd_pcm snd_seq snd_seq_device snd_timer i2c_i801 btusb i2c_mux i2c_smbus btrtl snd btbcm btmtk btintel bluetooth ecdh_generic rfkill ecc mei_me mei ioatdma dca wmi nfsd drm i2c_dev fuse nfnetlink [ 371.073198] CR2: 000001ffffffffff [ 371.073199] ---[ end trace 0000000000000000 ]---Add a guard around file close, and ensure the warnings from
drm_mode_configdo not trigger. Fix those by allowing an open reference to the file descriptor and cleaning up the file linked list entry indrm_mode_config_cleanup().Cc <[email protected]> # v4.18+Fixes bee330f3d672 ("drm: Use srcu to protect drm_device.unplugged")Cc Thomas Hellström <[email protected]>Reviewed-by Thomas Hellström <[email protected]>Signed-off-by Maarten Lankhorst <[email protected]>[ adapted drm_dbg_printer(dev, DRM_UT_KMS, ...) call to older drm_debug_printer(...) API ]Signed-off-by Sasha Levin <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- drivers/gpu/drm/drm_file.c | 5 ++++- drivers/gpu/drm/drm_mode_config.c | 9 ++++++--- 2 files changed, 10 insertions(+), 4 deletions(-)drivers/gpu/drm/drm_file.c +4
-1@@ -248,6 +248,7 @@ static void drm_events_release(struct drvoid drm_file_free (struct drm_file *file) {struct drm_device *dev; +int idx;if (!file)return ;@@ -271,9 +272,11 @@ void drm_file_free(struct drm_file *filedrm_events_release (file); -if (drm_core_check_feature (dev,DRIVER_MODESET )) { +if (drm_core_check_feature (dev,DRIVER_MODESET ) && +drm_dev_enter (dev, &idx)) {drm_fb_release (file);drm_property_destroy_user_blobs (dev, file); +drm_dev_exit (idx); }if (drm_core_check_feature (dev,DRIVER_SYNCOBJ ))drivers/gpu/drm/drm_mode_config.c +6
-3@@ -543,10 +543,13 @@ void drm_mode_config_cleanup(struct drm_*/ WARN_ON (!list_empty (&dev->mode_config.fb_list));list_for_each_entry_safe (fb, fbt, &dev->mode_config.fb_list, head) { -struct drm_printer p =drm_debug_printer ("[leaked fb]" ); +if (list_empty (&fb->filp_head) ||drm_framebuffer_read_refcount (fb) >1 ) { +struct drm_printer p =drm_debug_printer ("[leaked fb]" ); -drm_printf (&p,"framebuffer[%u]:\n" , fb->base.id); -drm_framebuffer_print_info (&p,1 , fb); +drm_printf (&p,"framebuffer[%u]:\n" , fb->base.id); +drm_framebuffer_print_info (&p,1 , fb); + } +list_del_init (&fb->filp_head);drm_framebuffer_free (&fb->base.refcount); }
Signature · 2 lines
Ben Hutchings When in doubt, use brute force. - Ken Thompson
Sasha Levin
maintainerRe: [PATCH 5.10 472/491] drm: Fix use-after-free on framebuffers and property blobs when calling drm_dev_unplug
Quoted 2 lines · Ben Hutchings
This has already been reverted upstream (commit
45ebe43ea00d), so please drop it from all queues.
Dropped from the 5.15 and 5.10 queues, thanks.
Greg Kroah-Hartman
maintainerPATCH 473/491 mmc: core: Drop redundant member in struct mmc host
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ulf Hansson <[email protected]>
[ Upstream commit 951f6ccfcbb7e4a18bf5fef1fb373d21e5831957 ]
The Kconfig option to use the blk-mq support was removed in commit 1bec43a3b181 ("mmc: core: Remove option not to use blk-mq"), but forgot to remove the use_blk_mq member in the struct mmc_host, let's fix it.
Stable-dep-of: 901084c51a0a ("mmc: core: Avoid bitfield RMW for claim/retune flags")
--- include/linux/mmc/host.h | 1 - 1 file changed, 1 deletion(-)
include/linux/mmc/host.h +0 -1
@@ -409,7 +409,6 @@ struct mmc_host { unsigned int doing_retune:1; /* re-tuning in progress */ unsigned int retune_now:1; /* do re-tuning at next req */ unsigned int retune_paused:1; /* re-tuning is temporarily disabled */ - unsigned int use_blk_mq:1; /* use blk-mq */ unsigned int retune_crc_disable:1; /* don't trigger retune upon crc */ unsigned int can_dma_map_merge:1; /* merging can be used */ unsigned int vqmmc_enabled:1; /* vqmmc regulator is enabled */
Greg Kroah-Hartman
maintainerPATCH 474/491 mmc: core: Drop superfluous validations in mmc_hw|sw_reset()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ulf Hansson <[email protected]>
[ Upstream commit fefdd3c91e0a7b3cbb3f25925d93a57c45cb0f31 ]
The mmc_hw|sw_reset() APIs are designed to be called solely from upper layers, which means drivers that operates on top of the struct mmc_card, like the mmc block device driver and an SDIO functional driver.
Additionally, as long as the struct mmc_host has a valid pointer to a struct mmc_card, the corresponding host->bus_ops pointer stays valid and assigned.
For these reasons, let's drop the superfluous reference counting and the redundant validations in mmc_hw|sw_reset().
Stable-dep-of: 901084c51a0a ("mmc: core: Avoid bitfield RMW for claim/retune flags")
--- drivers/mmc/core/block.c | 2 +- drivers/mmc/core/core.c | 21 +-------------------- 2 files changed, 2 insertions(+), 21 deletions(-)
drivers/mmc/core/block.c +1 -1
@@ -987,7 +987,7 @@ static int mmc_blk_reset(struct mmc_blk_ md->reset_done |= type; err =mmc_hw_reset (host);/* Ensure we switch back to the correct partition */ -if (err != -EOPNOTSUPP ) { +if (err) {struct mmc_blk_data *main_md =dev_get_drvdata (&host->card->dev);int part_err;
drivers/mmc/core/core.c +1 -20
@@ -2096,18 +2096,7 @@ int mmc_hw_reset(struct mmc_host *host) {int ret; -if (!host->card) -return -EINVAL ; - -mmc_bus_get (host); -if (!host->bus_ops || host->bus_dead || !host->bus_ops->hw_reset) { -mmc_bus_put (host); -return -EOPNOTSUPP ; - } - ret = host->bus_ops->hw_reset (host); -mmc_bus_put (host); -if (ret <0 )pr_warn ("%s: tried to HW reset card, got error %d\n" ,mmc_hostname (host), ret);
@@ -2120,18 +2109,10 @@ int mmc_sw_reset(struct mmc_host *host) {int ret; -if (!host->card) -return -EINVAL ; - -mmc_bus_get (host); -if (!host->bus_ops || host->bus_dead || !host->bus_ops->sw_reset) { -mmc_bus_put (host); +if (!host->bus_ops->sw_reset)return -EOPNOTSUPP ; - } ret = host->bus_ops->sw_reset (host); -mmc_bus_put (host); -if (ret)pr_warn ("%s: tried to SW reset card, got error %d\n" ,mmc_hostname (host), ret);
Re: [PATCH 5.10 474/491] mmc: core: Drop superfluous validations in mmc_hw|sw_reset()
Quoted 12 lines · Greg Kroah-Hartman
5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ulf Hansson <[email protected]>
[ Upstream commit
fefdd3c91e0a7b3cbb3f25925d93a57c45cb0f31]The mmc_hw|sw_reset() APIs are designed to be called solely from upper layers, which means drivers that operates on top of the struct
mmc_card, like the mmc block device driver and an SDIO functional driver.
Quoted 6 lines
Additionally, as long as the struct
mmc_hosthas a valid pointer to a structmmc_card, the correspondinghost->bus_opspointer stays valid and assigned.For these reasons, let's drop the superfluous reference counting and the redundant validations in mmc_hw|sw_reset().
Is this reasoning still correct for older branches such as 5.10?
And if so, do they also need commit 406e14808ee6 ("mmc: block: Remove error check of hw_reset on reset"), which claims to fix this one? I don't really follow the explanation in its commit message.
Ben.
Quoted 66 lines
Signed-off-by Ulf Hansson <[email protected]>Reviewed-by Adrian Hunter <[email protected]>Stable-dep-of:
901084c51a0a("mmc: core: Avoid bitfield RMW for claim/retune flags")Signed-off-by Sasha Levin <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- drivers/mmc/core/block.c | 2 +- drivers/mmc/core/core.c | 21 +-------------------- 2 files changed, 2 insertions(+), 21 deletions(-)drivers/mmc/core/block.c +1
-1@@ -987,7 +987,7 @@ static int mmc_blk_reset(struct mmc_blk_ md->reset_done |= type; err =mmc_hw_reset (host);/* Ensure we switch back to the correct partition */ -if (err != -EOPNOTSUPP ) { +if (err) {struct mmc_blk_data *main_md =dev_get_drvdata (&host->card->dev);int part_err;drivers/mmc/core/core.c +1
-20@@ -2096,18 +2096,7 @@ int mmc_hw_reset(struct mmc_host *host) {int ret; -if (!host->card) -return -EINVAL ; - -mmc_bus_get (host); -if (!host->bus_ops || host->bus_dead || !host->bus_ops->hw_reset) { -mmc_bus_put (host); -return -EOPNOTSUPP ; - } - ret = host->bus_ops->hw_reset (host); -mmc_bus_put (host); -if (ret <0 )pr_warn ("%s: tried to HW reset card, got error %d\n" ,mmc_hostname (host), ret);@@ -2120,18 +2109,10 @@ int mmc_sw_reset(struct mmc_host *host) {int ret; -if (!host->card) -return -EINVAL ; - -mmc_bus_get (host); -if (!host->bus_ops || host->bus_dead || !host->bus_ops->sw_reset) { -mmc_bus_put (host); +if (!host->bus_ops->sw_reset)return -EOPNOTSUPP ; - } ret = host->bus_ops->sw_reset (host); -mmc_bus_put (host); -if (ret)pr_warn ("%s: tried to SW reset card, got error %d\n" ,mmc_hostname (host), ret);
Signature · 2 lines
Ben Hutchings When in doubt, use brute force. - Ken Thompson
Re: [PATCH 5.10 474/491] mmc: core: Drop superfluous validations in mmc_hw|sw_reset()
Quoted 14 lines · Ben Hutchings
Quoted 12 lines · Greg Kroah-Hartman
5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ulf Hansson <[email protected]>
[ Upstream commit
fefdd3c91e0a7b3cbb3f25925d93a57c45cb0f31]The mmc_hw|sw_reset() APIs are designed to be called solely from upper layers, which means drivers that operates on top of the struct
mmc_card, like the mmc block device driver and an SDIO functional driver.
Quoted 8 lines
Quoted 6 lines
Additionally, as long as the struct
mmc_hosthas a valid pointer to a structmmc_card, the correspondinghost->bus_opspointer stays valid and assigned.For these reasons, let's drop the superfluous reference counting and the redundant validations in mmc_hw|sw_reset().
Is this reasoning still correct for older branches such as 5.10?
Yes, I think it should be fine.
Quoted 4 lines
And if so, do they also need commit
406e14808ee6("mmc: block: Remove error check ofhw_reseton reset"), which claims to fix this one? I don't really follow the explanation in its commit message.
Yes, good point, this commit is needed as well!
Kind regards
Uffe
Quoted 73 lines
Ben.
Quoted 56 lines
Signed-off-by Ulf Hansson <[email protected]>Reviewed-by Adrian Hunter <[email protected]>Stable-dep-of:
901084c51a0a("mmc: core: Avoid bitfield RMW for claim/retune flags")Signed-off-by Sasha Levin <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- drivers/mmc/core/block.c | 2 +- drivers/mmc/core/core.c | 21 +-------------------- 2 files changed, 2 insertions(+), 21 deletions(-)drivers/mmc/core/block.c +1
-1@@ -987,7 +987,7 @@ static int mmc_blk_reset(struct mmc_blk_ md->reset_done |= type; err =mmc_hw_reset (host);/* Ensure we switch back to the correct partition */ -if (err != -EOPNOTSUPP ) { +if (err) {struct mmc_blk_data *main_md =dev_get_drvdata (&host->card->dev);int part_err;drivers/mmc/core/core.c +0
-17@@ -2096,18 +2096,7 @@ int mmc_hw_reset(struct mmc_host *host) {int ret; -if (!host->card) -return -EINVAL ; - -mmc_bus_get (host); -if (!host->bus_ops || host->bus_dead || !host->bus_ops->hw_reset) { -mmc_bus_put (host); -return -EOPNOTSUPP ; - } - ret = host->bus_ops->hw_reset (host); -mmc_bus_put (host); -if (ret <0 )pr_warn ("%s: tried to HW reset card, got error %d\n" ,mmc_hostname (host), ret);@@ -2120,18 +2109,10 @@ int mmc_sw_reset(struct mmc_host *host) {int ret; -if (!host->card) -return -EINVAL ; - -mmc_bus_get (host); -if (!host->bus_ops || host->bus_dead || !host->bus_ops->sw_reset) { -mmc_bus_put (host);drivers/mmc/core/core.c int mmc_sw_reset(struct mmc_host *host) · line 2118
Quoted 10 lines
drivers/mmc/core/core.c +1
-3+if (!host->bus_ops->sw_reset)return -EOPNOTSUPP ; - } ret = host->bus_ops->sw_reset (host); -mmc_bus_put (host); -if (ret)pr_warn ("%s: tried to SW reset card, got error %d\n" ,mmc_hostname (host), ret);--
Ben Hutchings
When in doubt, use brute force. - Ken Thompson
Sasha Levin
maintainerRe: [PATCH 5.10 474/491] mmc: core: Drop superfluous validations in mmc_hw|sw_reset()
Quoted 1 line · Ulf Hansson
Yes, good point, this commit is needed as well!
The companion fix (406e14808ee6) doesn't apply cleanly to 5.10, so I've dropped this patch and its dependency chain from the 5.10 queue instead.
Thanks for the review.
Greg Kroah-Hartman
maintainerPATCH 475/491 mmc: core: Drop reference counting of the bus_ops
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ulf Hansson <[email protected]>
[ Upstream commit e9ce2ce17da626d930812199568bd426b2832f57 ]
When the mmc_rescan work is enabled for execution (host->rescan_disable), it's the only instance per mmc host that is allowed to set/clear the host->bus_ops pointer.
Besides the mmc_rescan work, there are a couple of scenarios when the host->bus_ops pointer may be accessed. Typically, those can be described as as below:
*)
Upper mmc driver layers (like the mmc block device driver or an SDIO functional driver) needs to execute a host->bus_ops callback. This can be considered as safe without having to use some special locking mechanism, because they operate on top of the struct mmc_card. As long as there is a card to operate upon, the mmc core guarantees that there is a host->bus_ops assigned as well. Note that, upper layer mmc drivers are of course responsible to clean up from themselves from their ->remove() callbacks, otherwise things would fall apart anyways.
**)
Via the mmc host instance, we may need to force a removal of an inserted mmc card. This happens when a mmc host driver gets unbind, for example. In this case, we protect the host->bus_ops pointer from concurrent accesses, by disabling the mmc_rescan work upfront (host->rescan_disable). See mmc_stop_host() for example.
This said, it seems like the reference counting of the host->bus_ops pointer at some point have become superfluous. As this is an old mechanism of the mmc core, it a bit difficult to digest the history of when that could have happened. However, let's drop the reference counting to avoid unnecessary code-paths and lockings.
Stable-dep-of: 901084c51a0a ("mmc: core: Avoid bitfield RMW for claim/retune flags")
--- drivers/mmc/core/core.c | 89 ++--------------------------------------------- include/linux/mmc/host.h | 2 - 2 files changed, 4 insertions(+), 87 deletions(-)
drivers/mmc/core/core.c +4 -85
@@ -1389,62 +1389,12 @@ void mmc_power_cycle(struct mmc_host *ho }/* -* Cleanup when the last reference to the bus operator is dropped. -*/ -static void __mmc_release_bus (struct mmc_host *host) -{ -WARN_ON (!host->bus_dead); - - host->bus_ops =NULL ; -} - -/* -* Increase reference count of bus operator -*/ -static inline void mmc_bus_get (struct mmc_host *host) -{ -unsigned long flags; - -spin_lock_irqsave (&host->lock, flags); - host->bus_refs++; -spin_unlock_irqrestore (&host->lock, flags); -} - -/* -* Decrease reference count of bus operator and free it if -* it is the last reference. -*/ -static inline void mmc_bus_put (struct mmc_host *host) -{ -unsigned long flags; - -spin_lock_irqsave (&host->lock, flags); - host->bus_refs--; -if ((host->bus_refs ==0 ) && host->bus_ops) -__mmc_release_bus (host); -spin_unlock_irqrestore (&host->lock, flags); -} - -/* * Assign a mmc bus handler to a host. Only one bus handler may control a * host at any given time. */ void mmc_attach_bus (struct mmc_host *host,const struct mmc_bus_ops *ops) { -unsigned long flags; - -WARN_ON (!host->claimed); - -spin_lock_irqsave (&host->lock, flags); - -WARN_ON (host->bus_ops); -WARN_ON (host->bus_refs); - host->bus_ops = ops; - host->bus_refs =1 ; - host->bus_dead =0 ; - -spin_unlock_irqrestore (&host->lock, flags); }/*
@@ -1452,18 +1402,7 @@ void mmc_attach_bus(struct mmc_host *hos*/ void mmc_detach_bus (struct mmc_host *host) { -unsigned long flags; - -WARN_ON (!host->claimed); -WARN_ON (!host->bus_ops); - -spin_lock_irqsave (&host->lock, flags); - - host->bus_dead =1 ; - -spin_unlock_irqrestore (&host->lock, flags); - -mmc_bus_put (host); + host->bus_ops =NULL ; }void _mmc_detect_change (struct mmc_host *host,unsigned long delay,bool cd_irq)
@@ -2260,32 +2199,15 @@ void mmc_rescan(struct work_struct *work host->trigger_card_event = false; } -mmc_bus_get (host); -/* Verify a registered card to be functional, else remove it. */ -if (host->bus_ops && !host->bus_dead) +if (host->bus_ops) host->bus_ops->detect (host); host->detect_change =0 ; -/* -* Let mmc_bus_put() free the bus/bus_ops if we've found that -* the card is no longer present. -*/ -mmc_bus_put (host); -mmc_bus_get (host); -/* if there still is a card present, stop here */ -if (host->bus_ops !=NULL ) { -mmc_bus_put (host); +if (host->bus_ops !=NULL ) goto out; - } - -/* -* Only we can add a new handler, so it's safe to -* release the lock here. -*/ -mmc_bus_put (host);mmc_claim_host (host); if (mmc_card_is_removable(host) && host->ops->get_cd &&
@@ -2356,18 +2278,15 @@ void mmc_stop_host(struct mmc_host *host/* clear pm flags now and let card drivers set them as needed */ host->pm_flags =0 ; -mmc_bus_get (host); -if (host->bus_ops && !host->bus_dead) { +if (host->bus_ops) {/* Calling bus_ops->remove() with a claimed host can deadlock */ host->bus_ops->remove (host);mmc_claim_host (host);mmc_detach_bus (host);mmc_power_off (host);mmc_release_host (host); -mmc_bus_put (host);return ; } -mmc_bus_put (host);mmc_claim_host (host);mmc_power_off (host);
include/linux/mmc/host.h +0 -2
@@ -403,7 +403,6 @@ struct mmc_host {/* group bitfields together to minimize padding */ unsigned int use_spi_crc:1; unsigned int claimed:1; /* host exclusively claimed */ - unsigned int bus_dead:1; /* bus has been released */ unsigned int doing_init_tune:1; /* initial tuning in progress */ unsigned int can_retune:1; /* re-tuning can be used */ unsigned int doing_retune:1; /* re-tuning in progress */
@@ -435,7 +434,6 @@ struct mmc_host {struct mmc_slot slot;const struct mmc_bus_ops *bus_ops;/* current bus driver */ -unsigned int bus_refs;/* reference counter */ unsigned int sdio_irqs;struct task_struct *sdio_irq_thread;
Greg Kroah-Hartman
maintainerPATCH 476/491 mmc: core: Avoid bitfield RMW for claim/retune flags
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Penghe Geng <[email protected]>
[ Upstream commit 901084c51a0a8fb42a3f37d2e9c62083c495f824 ]
Move claimed and retune control flags out of the bitfield word to avoid unrelated RMW side effects in asynchronous contexts.
The host->claimed bit shared a word with retune flags. Writes to claimed in __mmc_claim_host() or retune_now in mmc_mq_queue_rq() can overwrite other bits when concurrent updates happen in other contexts, triggering spurious WARN_ON(!host->claimed). Convert claimed, can_retune, retune_now and retune_paused to bool to remove shared-word coupling.
--- include/linux/mmc/host.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
include/linux/mmc/host.h +5 -4
@@ -400,14 +400,12 @@ struct mmc_host {struct mmc_ios ios;/* current io bus settings */ +bool claimed;/* host exclusively claimed */ +/* group bitfields together to minimize padding */ unsigned int use_spi_crc:1; - unsigned int claimed:1; /* host exclusively claimed */ unsigned int doing_init_tune:1; /* initial tuning in progress */ - unsigned int can_retune:1; /* re-tuning can be used */ unsigned int doing_retune:1; /* re-tuning in progress */ - unsigned int retune_now:1; /* do re-tuning at next req */ - unsigned int retune_paused:1; /* re-tuning is temporarily disabled */ unsigned int retune_crc_disable:1; /* don't trigger retune upon crc */ unsigned int can_dma_map_merge:1; /* merging can be used */ unsigned int vqmmc_enabled:1; /* vqmmc regulator is enabled */
@@ -415,6 +413,9 @@ struct mmc_host {int rescan_disable;/* disable card detection */ int rescan_entered;/* used with nonremovable devices */ +bool can_retune;/* re-tuning can be used */ +bool retune_now;/* do re-tuning at next req */ +bool retune_paused;/* re-tuning is temporarily disabled */ int need_retune;/* re-tuning is needed */ int hold_retune;/* hold off re-tuning */ unsigned int retune_period;/* re-tuning period in secs */
Greg Kroah-Hartman
maintainerPATCH 477/491 Revert "nvme: nvme-fc: Ensure ->ioerr_work is cancelled in nvme_fc_delete_ctrl()"
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jaskaran Singh <[email protected]>
This reverts commit 3d78e8e01251da032a5f7cbc9728e4ab1a5a5464.
The backport of upstream commit 0a2c5495b6d1 was incorrectly applied. The cancel_work_sync() call for ->ioerr_work was added to nvme_fc_reset_ctrl_work() instead of nvme_fc_delete_ctrl().
Revert this commit so the correct fix can be applied.
--- drivers/nvme/host/fc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/host/fc.c +1 -1
@@ -3259,6 +3259,7 @@ nvme_fc_delete_ctrl(struct nvme_ctrl *nc {struct nvme_fc_ctrl *ctrl =to_fc_ctrl (nctrl); +cancel_work_sync (&ctrl->ioerr_work);cancel_delayed_work_sync (&ctrl->connect_work);/* * kill the association on the link side. this will block
@@ -3322,7 +3323,6 @@ nvme_fc_reset_ctrl_work(struct work_stru/* will block will waiting for io to terminate */ nvme_fc_delete_association (ctrl); -cancel_work_sync (&ctrl->ioerr_work);if (!nvme_change_ctrl_state (&ctrl->ctrl,NVME_CTRL_CONNECTING )) dev_err(ctrl->ctrl.device,
Greg Kroah-Hartman
maintainerPATCH 478/491 nvme: nvme-fc: Ensure ->ioerr_work is cancelled in nvme_fc_delete_ctrl()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jaskaran Singh <[email protected]>
commit 0a2c5495b6d1ecb0fa18ef6631450f391a888256 upstream.
nvme_fc_delete_assocation() waits for pending I/O to complete before returning, and an error can cause ->ioerr_work to be queued after cancel_work_sync() had been called. Move the call to cancel_work_sync() to be after nvme_fc_delete_association() to ensure ->ioerr_work is not running when the nvme_fc_ctrl object is freed. Otherwise the following can occur:
[ 1135.911754] list_del corruption, ff2d24c8093f31f8->next is NULL [ 1135.917705] ------------[ cut here ]------------ [ 1135.922336] kernel BUG at lib/list_debug.c:52! [ 1135.926784] Oops: invalid opcode: 0000 [#1] SMP NOPTI [ 1135.931851] CPU: 48 UID: 0 PID: 726 Comm: kworker/u449:23 Kdump: loaded Not tainted 6.12.0 #1 PREEMPT(voluntary) [ 1135.943490] Hardware name: Dell Inc. PowerEdge R660/0HGTK9, BIOS 2.5.4 01/16/2025 [ 1135.950969] Workqueue: 0x0 (nvme-wq) [ 1135.954673] RIP: 0010:__list_del_entry_valid_or_report.cold+0xf/0x6f [ 1135.961041] Code: c7 c7 98 68 72 94 e8 26 45 fe ff 0f 0b 48 c7 c7 70 68 72 94 e8 18 45 fe ff 0f 0b 48 89 fe 48 c7 c7 80 69 72 94 e8 07 45 fe ff <0f> 0b 48 89 d1 48 c7 c7 a0 6a 72 94 48 89 c2 e8 f3 44 fe ff 0f 0b [ 1135.979788] RSP: 0018:ff579b19482d3e50 EFLAGS: 00010046 [ 1135.985015] RAX: 0000000000000033 RBX: ff2d24c8093f31f0 RCX: 0000000000000000 [ 1135.992148] RDX: 0000000000000000 RSI: ff2d24d6bfa1d0c0 RDI: ff2d24d6bfa1d0c0 [ 1135.999278] RBP: ff2d24c8093f31f8 R08: 0000000000000000 R09: ffffffff951e2b08 [ 1136.006413] R10: ffffffff95122ac8 R11: 0000000000000003 R12: ff2d24c78697c100 [ 1136.013546] R13: fffffffffffffff8 R14: 0000000000000000 R15: ff2d24c78697c0c0 [ 1136.020677] FS: 0000000000000000(0000) GS:ff2d24d6bfa00000(0000) knlGS:0000000000000000 [ 1136.028765] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 1136.034510] CR2: 00007fd207f90b80 CR3: 000000163ea22003 CR4: 0000000000f73ef0 [ 1136.041641] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 1136.048776] DR3: 0000000000000000 DR6: 00000000fffe07f0 DR7: 0000000000000400 [ 1136.055910] PKRU: 55555554 [ 1136.058623] Call Trace: [ 1136.061074] <TASK> [ 1136.063179] ? show_trace_log_lvl+0x1b0/0x2f0 [ 1136.067540] ? show_trace_log_lvl+0x1b0/0x2f0 [ 1136.071898] ? move_linked_works+0x4a/0xa0 [ 1136.075998] ? __list_del_entry_valid_or_report.cold+0xf/0x6f [ 1136.081744] ? __die_body.cold+0x8/0x12 [ 1136.085584] ? die+0x2e/0x50 [ 1136.088469] ? do_trap+0xca/0x110 [ 1136.091789] ? do_error_trap+0x65/0x80 [ 1136.095543] ? __list_del_entry_valid_or_report.cold+0xf/0x6f [ 1136.101289] ? exc_invalid_op+0x50/0x70 [ 1136.105127] ? __list_del_entry_valid_or_report.cold+0xf/0x6f [ 1136.110874] ? asm_exc_invalid_op+0x1a/0x20 [ 1136.115059] ? __list_del_entry_valid_or_report.cold+0xf/0x6f [ 1136.120806] move_linked_works+0x4a/0xa0 [ 1136.124733] worker_thread+0x216/0x3a0 [ 1136.128485] ? __pfx_worker_thread+0x10/0x10 [ 1136.132758] kthread+0xfa/0x240 [ 1136.135904] ? __pfx_kthread+0x10/0x10 [ 1136.139657] ret_from_fork+0x31/0x50 [ 1136.143236] ? __pfx_kthread+0x10/0x10 [ 1136.146988] ret_from_fork_asm+0x1a/0x30 [ 1136.150915] </TASK>
--- drivers/nvme/host/fc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/host/fc.c +1 -1
@@ -3259,13 +3259,13 @@ nvme_fc_delete_ctrl(struct nvme_ctrl *nc {struct nvme_fc_ctrl *ctrl =to_fc_ctrl (nctrl); -cancel_work_sync (&ctrl->ioerr_work);cancel_delayed_work_sync (&ctrl->connect_work);/* * kill the association on the link side. this will block * waiting for io to terminate */ nvme_fc_delete_association (ctrl); +cancel_work_sync (&ctrl->ioerr_work); } static void
Greg Kroah-Hartman
maintainerPATCH 479/491 device property: Add fwnode_is_ancestor_of() and fwnode_get_next_parent_dev()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Saravana Kannan <[email protected]>
[ Upstream commit b5d3e2fbcb10957521af14c4256cd0e5f68b9234 ]
Add fwnode_is_ancestor_of() helper function to check if a fwnode is an ancestor of another fwnode.
Add fwnode_get_next_parent_dev() helper function that take as input a fwnode and finds the closest ancestor fwnode that has a corresponding struct device and returns that struct device.
Stable-dep-of: 2692c614f8f0 ("device property: Allow secondary lookup in fwnode_get_next_child_node()")
--- drivers/base/property.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/property.h | 3 ++ 2 files changed, 55 insertions(+)
drivers/base/property.c +52 -0
@@ -615,6 +615,31 @@ struct fwnode_handle *fwnode_get_next_paEXPORT_SYMBOL_GPL (fwnode_get_next_parent);/** +* fwnode_get_next_parent_dev - Find device of closest ancestor fwnode +* @fwnode: firmware node +* +* Given a firmware node (@fwnode), this function finds its closest ancestor +* firmware node that has a corresponding struct device and returns that struct +* device. +* +* The caller of this function is expected to call put_device() on the returned +* device when they are done. +*/ +struct device *fwnode_get_next_parent_dev (struct fwnode_handle *fwnode) +{ +struct device *dev =NULL ; + +fwnode_handle_get (fwnode); +do { + fwnode =fwnode_get_next_parent (fwnode); +if (fwnode) + dev =get_dev_from_fwnode (fwnode); + }while (fwnode && !dev); +fwnode_handle_put (fwnode); +return dev; +} + +/** * fwnode_count_parents - Return the number of parents a node has * @fwnode: The node the parents of which are to be counted *
@@ -661,6 +686,33 @@ struct fwnode_handle *fwnode_get_nth_parEXPORT_SYMBOL_GPL (fwnode_get_nth_parent);/** +* fwnode_is_ancestor_of - Test if @test_ancestor is ancestor of @test_child +* @test_ancestor: Firmware which is tested for being an ancestor +* @test_child: Firmware which is tested for being the child +* +* A node is considered an ancestor of itself too. +* +* Returns true if @test_ancestor is an ancestor of @test_child. +* Otherwise, returns false. +*/ +bool fwnode_is_ancestor_of (struct fwnode_handle *test_ancestor, +struct fwnode_handle *test_child) +{ +if (!test_ancestor) +return false; + +fwnode_handle_get (test_child); +while (test_child) { +if (test_child == test_ancestor) { +fwnode_handle_put (test_child); +return true; + } + test_child =fwnode_get_next_parent (test_child); + } +return false; +} + +/** * fwnode_get_next_child_node - Return the next child node handle for a node * @fwnode: Firmware node to find the next child node for. * @child: Handle to one of the node's child nodes or a %NULL handle.
include/linux/property.h +3 -0
@@ -85,9 +85,12 @@ const char *fwnode_get_name_prefix(conststruct fwnode_handle *fwnode_get_parent (const struct fwnode_handle *fwnode);struct fwnode_handle *fwnode_get_next_parent (struct fwnode_handle *fwnode); +struct device *fwnode_get_next_parent_dev (struct fwnode_handle *fwnode);unsigned int fwnode_count_parents (const struct fwnode_handle *fwn);struct fwnode_handle *fwnode_get_nth_parent (struct fwnode_handle *fwn,unsigned int depth); +bool fwnode_is_ancestor_of (struct fwnode_handle *test_ancestor, +struct fwnode_handle *test_child);struct fwnode_handle *fwnode_get_next_child_node (const struct fwnode_handle *fwnode,struct fwnode_handle *child); struct fwnode_handle *fwnode_get_next_available_child_node(
Greg Kroah-Hartman
maintainerPATCH 480/491 media: device property: Return true in fwnode_device_is_available for NULL ops
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Scally <[email protected]>
[ Upstream commit 5273382d03763277aaf8c6a2d6088e2afaee0cf0 ]
Some types of fwnode_handle do not implement the device_is_available() check, such as those created by software_nodes. There isn't really a meaningful way to check for the availability of a device that doesn't actually exist, so if the check isn't implemented just assume that the "device" is present.
Stable-dep-of: 2692c614f8f0 ("device property: Allow secondary lookup in fwnode_get_next_child_node()")
--- drivers/base/property.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/base/property.c +6 -0
@@ -837,9 +837,15 @@ EXPORT_SYMBOL_GPL(fwnode_handle_put);/** * fwnode_device_is_available - check if a device is available for use * @fwnode: Pointer to the fwnode of the device. +* +* For fwnode node types that don't implement the .device_is_available() +* operation, this function returns true. */ bool fwnode_device_is_available (const struct fwnode_handle *fwnode) { +if (!fwnode_has_op (fwnode, device_is_available)) +return true; +return fwnode_call_bool_op (fwnode, device_is_available); }EXPORT_SYMBOL_GPL (fwnode_device_is_available);
Greg Kroah-Hartman
maintainerPATCH 481/491 device property: Retrieve fwnode from of_node via accessor
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andy Shevchenko <[email protected]>
[ Upstream commit 3cd8015040d7537a6b88e26f36768a90d9247829 ]
OF provides a specific accessor to retrieve fwnode handle. Use it instead of direct dereferencing.
Stable-dep-of: 2692c614f8f0 ("device property: Allow secondary lookup in fwnode_get_next_child_node()")
--- drivers/base/property.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/base/property.c +2 -2
@@ -21,7 +21,7 @@struct fwnode_handle *dev_fwnode (const struct device *dev) {return IS_ENABLED (CONFIG_OF ) && dev->of_node ? - &dev->of_node->fwnode : dev->fwnode; +of_fwnode_handle (dev->of_node) : dev->fwnode; }EXPORT_SYMBOL_GPL (dev_fwnode);
@@ -763,7 +763,7 @@ struct fwnode_handle *device_get_next_chstruct fwnode_handle *fwnode =NULL , *next;if (dev->of_node) - fwnode = &dev->of_node->fwnode; + fwnode =of_fwnode_handle (dev->of_node);else if (adev) fwnode =acpi_fwnode_handle (adev);
Greg Kroah-Hartman
maintainerPATCH 482/491 device property: Unify access to of_node
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andy Shevchenko <[email protected]>
[ Upstream commit fb38f314fbd173e2e9f9f0f2e720a5f4889562da ]
Historically we have a few variants how we access dev->fwnode and dev->of_node. Some of the functions during development gained different versions of the getters. Unify access to of_node and as a side change slightly refactor ACPI specific branches.
Stable-dep-of: 2692c614f8f0 ("device property: Allow secondary lookup in fwnode_get_next_child_node()")
--- drivers/base/property.c | 29 +++++++++++++---------------- include/linux/property.h | 2 +- 2 files changed, 14 insertions(+), 17 deletions(-)
drivers/base/property.c +13 -16
@@ -759,13 +759,8 @@ EXPORT_SYMBOL_GPL(fwnode_get_next_availastruct fwnode_handle *device_get_next_child_node (struct device *dev,struct fwnode_handle *child) { -struct acpi_device *adev =ACPI_COMPANION (dev); -struct fwnode_handle *fwnode =NULL , *next; - -if (dev->of_node) - fwnode =of_fwnode_handle (dev->of_node); -else if (adev) - fwnode =acpi_fwnode_handle (adev); +const struct fwnode_handle *fwnode =dev_fwnode (dev); +struct fwnode_handle *next;/* Try to find a child in primary fwnode */ next =fwnode_get_next_child_node (fwnode, child);
@@ -868,28 +863,31 @@ EXPORT_SYMBOL_GPL(device_get_child_node_bool device_dma_supported (struct device *dev) { +const struct fwnode_handle *fwnode =dev_fwnode (dev); +/* For DT, this is always supported. * For ACPI, this depends on CCA, which * is determined by the acpi_dma_supported(). */ -if (IS_ENABLED (CONFIG_OF ) && dev->of_node) +if (is_of_node (fwnode))return true; -return acpi_dma_supported (ACPI_COMPANION (dev)); +return acpi_dma_supported (to_acpi_device_node (fwnode)); }EXPORT_SYMBOL_GPL (device_dma_supported);enum dev_dma_attr device_get_dma_attr (struct device *dev) { +const struct fwnode_handle *fwnode =dev_fwnode (dev);enum dev_dma_attr attr =DEV_DMA_NOT_SUPPORTED ; -if (IS_ENABLED (CONFIG_OF ) && dev->of_node) { -if (of_dma_is_coherent (dev->of_node)) +if (is_of_node (fwnode)) { +if (of_dma_is_coherent (to_of_node (fwnode))) attr =DEV_DMA_COHERENT ;else attr =DEV_DMA_NON_COHERENT ; }else - attr =acpi_get_dma_attr (ACPI_COMPANION (dev)); + attr =acpi_get_dma_attr (to_acpi_device_node (fwnode));return attr; }
@@ -1007,14 +1005,13 @@ EXPORT_SYMBOL(device_get_mac_address);* Returns Linux IRQ number on success. Other values are determined * accordingly to acpi_/of_ irq_get() operation. */ -int fwnode_irq_get (struct fwnode_handle *fwnode,unsigned int index) +int fwnode_irq_get (const struct fwnode_handle *fwnode,unsigned int index) { -struct device_node *of_node =to_of_node (fwnode);struct resource res;int ret; -if (IS_ENABLED (CONFIG_OF ) && of_node) -return of_irq_get (of_node, index); +if (is_of_node (fwnode)) +return of_irq_get (to_of_node (fwnode), index); ret =acpi_irq_get (ACPI_HANDLE_FWNODE (fwnode), index, &res);if (ret)
include/linux/property.h +1 -1
@@ -119,7 +119,7 @@ struct fwnode_handle *device_get_named_cstruct fwnode_handle *fwnode_handle_get (struct fwnode_handle *fwnode);void fwnode_handle_put (struct fwnode_handle *fwnode); -int fwnode_irq_get (struct fwnode_handle *fwnode,unsigned int index); +int fwnode_irq_get (const struct fwnode_handle *fwnode,unsigned int index);unsigned int device_get_child_node_count (struct device *dev);
Greg Kroah-Hartman
maintainerPATCH 483/491 device property: Check fwnode->secondary in fwnode_graph_get_next_endpoint()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Scally <[email protected]>
[ Upstream commit b5b41ab6b0c1bb70fe37a0d193006c969e3b5909 ]
Sensor drivers often check for an endpoint to make sure that they're connected to a consuming device like a CIO2 during .probe(). Some of those endpoints might be in the form of software_nodes assigned as a secondary to the device's fwnode_handle. Account for this possibility in fwnode_graph_get_next_endpoint() to avoid having to do it in the sensor drivers themselves.
Stable-dep-of: 2692c614f8f0 ("device property: Allow secondary lookup in fwnode_get_next_child_node()")
--- drivers/base/property.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
drivers/base/property.c +20 -1
@@ -1033,7 +1033,26 @@ struct fwnode_handle * fwnode_graph_get_next_endpoint(const struct fwnode_handle *fwnode, struct fwnode_handle *prev) { - return fwnode_call_ptr_op(fwnode, graph_get_next_endpoint, prev); + const struct fwnode_handle *parent; +struct fwnode_handle *ep; + +/* +* If this function is in a loop and the previous iteration returned +* an endpoint from fwnode->secondary, then we need to use the secondary +* as parent rather than @fwnode. +*/ +if (prev) + parent =fwnode_graph_get_port_parent (prev); +else + parent = fwnode; + + ep =fwnode_call_ptr_op (parent, graph_get_next_endpoint, prev); + +if (IS_ERR_OR_NULL (ep) && + !IS_ERR_OR_NULL (parent) && !IS_ERR_OR_NULL (parent->secondary)) + ep =fwnode_graph_get_next_endpoint (parent->secondary,NULL ); + +return ep; }EXPORT_SYMBOL_GPL (fwnode_graph_get_next_endpoint);
Greg Kroah-Hartman
maintainerPATCH 484/491 device property: Check fwnode->secondary when finding properties
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Scally <[email protected]>
[ Upstream commit c097af1d0a8483b44fa30e86b311991d76b6ae67 ]
fwnode_property_get_reference_args() searches for named properties against a fwnode_handle, but these could instead be against the fwnode's secondary. If the property isn't found against the primary, check the secondary to see if it's there instead.
Stable-dep-of: 2692c614f8f0 ("device property: Allow secondary lookup in fwnode_get_next_child_node()")
--- drivers/base/property.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/base/property.c +11 -2
@@ -479,8 +479,17 @@ int fwnode_property_get_reference_args(c unsigned int nargs, unsigned int index, struct fwnode_reference_args *args) { - return fwnode_call_int_op(fwnode, get_reference_args, prop, nargs_prop, -nargs ,index ,args ); + int ret; + + ret =fwnode_call_int_op (fwnode, get_reference_args, prop, nargs_prop, + nargs, index, args); + +if (ret <0 && !IS_ERR_OR_NULL (fwnode) && + !IS_ERR_OR_NULL (fwnode->secondary)) + ret =fwnode_call_int_op (fwnode->secondary, get_reference_args, + prop, nargs_prop, nargs, index, args); + +return ret; }EXPORT_SYMBOL_GPL (fwnode_property_get_reference_args);
Greg Kroah-Hartman
maintainerPATCH 485/491 device property: Allow error pointer to be passed to fwnode APIs
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andy Shevchenko <[email protected]>
[ Upstream commit 002752af7b89b74c64fe6bec8c5fde3d3a7810d8 ]
Some of the fwnode APIs might return an error pointer instead of NULL or valid fwnode handle. The result of such API call may be considered optional and hence the test for it is usually done in a form of
fwnode = fwnode_find_reference(...); if (IS_ERR(fwnode)) ...error handling...
Nevertheless the resulting fwnode may have bumped the reference count and hence caller of the above API is obliged to call fwnode_handle_put(). Since fwnode may be not valid either as NULL or error pointer the check has to be performed there. This approach uglifies the code and adds a point of making a mistake, i.e. forgetting about error point case.
To prevent this, allow an error pointer to be passed to the fwnode APIs.
Stable-dep-of: 2692c614f8f0 ("device property: Allow secondary lookup in fwnode_get_next_child_node()")
--- drivers/base/property.c | 89 +++++++++++++++++++++++++++--------------------- include/linux/fwnode.h | 10 ++--- 2 files changed, 56 insertions(+), 43 deletions(-)
drivers/base/property.c +51 -38
@@ -48,12 +48,14 @@ bool fwnode_property_present(const struc {bool ret; +if (IS_ERR_OR_NULL (fwnode)) +return false; + ret =fwnode_call_bool_op (fwnode, property_present, propname); -if (ret == false && !IS_ERR_OR_NULL (fwnode) && - !IS_ERR_OR_NULL (fwnode->secondary)) - ret =fwnode_call_bool_op (fwnode->secondary, property_present, - propname); -return ret; +if (ret) +return ret; + +return fwnode_call_bool_op (fwnode->secondary, property_present, propname); }EXPORT_SYMBOL_GPL (fwnode_property_present);
@@ -233,15 +235,16 @@ static int fwnode_property_read_int_arra {int ret; +if (IS_ERR_OR_NULL (fwnode)) +return -EINVAL ; + ret =fwnode_call_int_op (fwnode, property_read_int_array, propname, elem_size, val, nval); -if (ret == -EINVAL && !IS_ERR_OR_NULL (fwnode) && - !IS_ERR_OR_NULL (fwnode->secondary)) - ret =fwnode_call_int_op ( - fwnode->secondary, property_read_int_array, propname, - elem_size, val, nval); +if (ret != -EINVAL ) +return ret; -return ret; +return fwnode_call_int_op (fwnode->secondary, property_read_int_array, propname, + elem_size, val, nval); }/**
@@ -372,14 +375,16 @@ int fwnode_property_read_string_array(co {int ret; +if (IS_ERR_OR_NULL (fwnode)) +return -EINVAL ; + ret =fwnode_call_int_op (fwnode, property_read_string_array, propname, val, nval); -if (ret == -EINVAL && !IS_ERR_OR_NULL (fwnode) && - !IS_ERR_OR_NULL (fwnode->secondary)) - ret =fwnode_call_int_op (fwnode->secondary, - property_read_string_array, propname, - val, nval); -return ret; +if (ret != -EINVAL ) +return ret; + +return fwnode_call_int_op (fwnode->secondary, property_read_string_array, propname, + val, nval); }EXPORT_SYMBOL_GPL (fwnode_property_read_string_array);
@@ -481,15 +486,19 @@ int fwnode_property_get_reference_args(c {int ret; +if (IS_ERR_OR_NULL (fwnode)) +return -ENOENT ; + ret =fwnode_call_int_op (fwnode, get_reference_args, prop, nargs_prop, nargs, index, args); +if (ret ==0 ) +return ret; -if (ret <0 && !IS_ERR_OR_NULL (fwnode) && - !IS_ERR_OR_NULL (fwnode->secondary)) - ret =fwnode_call_int_op (fwnode->secondary, get_reference_args, - prop, nargs_prop, nargs, index, args); +if (IS_ERR_OR_NULL (fwnode->secondary)) +return ret; -return ret; +return fwnode_call_int_op (fwnode->secondary, get_reference_args, prop, nargs_prop, + nargs, index, args); }EXPORT_SYMBOL_GPL (fwnode_property_get_reference_args);
@@ -683,12 +692,13 @@ EXPORT_SYMBOL_GPL(fwnode_count_parents);struct fwnode_handle *fwnode_get_nth_parent (struct fwnode_handle *fwnode,unsigned int depth) { -unsigned int i; -fwnode_handle_get (fwnode); -for (i =0 ; i < depth && fwnode; i++) +do { +if (depth-- ==0 ) +break ; fwnode =fwnode_get_next_parent (fwnode); + }while (fwnode);return fwnode; }
@@ -707,17 +717,17 @@ EXPORT_SYMBOL_GPL(fwnode_get_nth_parent)bool fwnode_is_ancestor_of (struct fwnode_handle *test_ancestor,struct fwnode_handle *test_child) { -if (!test_ancestor) +if (IS_ERR_OR_NULL (test_ancestor))return false;fwnode_handle_get (test_child); -while (test_child) { +do {if (test_child == test_ancestor) {fwnode_handle_put (test_child);return true; } test_child =fwnode_get_next_parent (test_child); - } + }while (test_child);return false; }
@@ -746,7 +756,7 @@ fwnode_get_next_available_child_node(con {struct fwnode_handle *next_child = child; -if (!fwnode) +if (IS_ERR_OR_NULL (fwnode))return NULL ; do {
@@ -771,16 +781,16 @@ struct fwnode_handle *device_get_next_chconst struct fwnode_handle *fwnode =dev_fwnode (dev);struct fwnode_handle *next; +if (IS_ERR_OR_NULL (fwnode)) +return NULL ; +/* Try to find a child in primary fwnode */ next =fwnode_get_next_child_node (fwnode, child);if (next)return next;/* When no more children in primary, continue with secondary */ -if (fwnode && !IS_ERR_OR_NULL (fwnode->secondary)) - next =fwnode_get_next_child_node (fwnode->secondary, child); - -return next; +return fwnode_get_next_child_node (fwnode->secondary, child); }EXPORT_SYMBOL_GPL (device_get_next_child_node);
@@ -847,6 +857,9 @@ EXPORT_SYMBOL_GPL(fwnode_handle_put);*/ bool fwnode_device_is_available (const struct fwnode_handle *fwnode) { +if (IS_ERR_OR_NULL (fwnode)) +return false; +if (!fwnode_has_op (fwnode, device_is_available))return true;
@@ -1054,14 +1067,14 @@ fwnode_graph_get_next_endpoint(const str parent =fwnode_graph_get_port_parent (prev); else parent = fwnode; +if (IS_ERR_OR_NULL (parent)) +return NULL ; ep =fwnode_call_ptr_op (parent, graph_get_next_endpoint, prev); +if (ep) +return ep; -if (IS_ERR_OR_NULL (ep) && - !IS_ERR_OR_NULL (parent) && !IS_ERR_OR_NULL (parent->secondary)) - ep =fwnode_graph_get_next_endpoint (parent->secondary,NULL ); - -return ep; +return fwnode_graph_get_next_endpoint (parent->secondary,NULL ); }EXPORT_SYMBOL_GPL (fwnode_graph_get_next_endpoint);
include/linux/fwnode.h +5 -5
@@ -149,12 +149,12 @@ struct fwnode_operations { struct device *dev); }; -#define fwnode_has_op (fwnode, op) \ - ((fwnode) && (fwnode)->ops && (fwnode)->ops->op) +#define fwnode_has_op (fwnode, op) \ + (!IS_ERR_OR_NULL(fwnode) && (fwnode)->ops && (fwnode)->ops->op) +#define fwnode_call_int_op (fwnode, op, ...) \ - (fwnode ? (fwnode_has_op(fwnode, op) ? \ - (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : -ENXIO) : \ - -EINVAL) + (fwnode_has_op(fwnode, op) ? \ + (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : (IS_ERR_OR_NULL(fwnode) ? -EINVAL : -ENXIO))#define fwnode_call_bool_op (fwnode, op, ...) \ (fwnode_has_op(fwnode, op) ? \
Greg Kroah-Hartman
maintainerPATCH 486/491 device property: Allow secondary lookup in fwnode_get_next_child_node()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andy Shevchenko <[email protected]>
[ Upstream commit 2692c614f8f05929d692b3dbfd3faef1f00fbaf0 ]
When device_get_child_node_count() got split to the fwnode and device respective APIs, the fwnode didn't inherit the ability to traverse over the secondary fwnode. Hence any user, that switches from device to fwnode API misses this feature. In particular, this was revealed by the commit 1490cbb9dbfd ("device property: Split fwnode_get_child_node_count()") that effectively broke the GPIO enumeration on Intel Galileo boards. Fix this by moving the secondary lookup from device to fwnode API.
Note, in general no device_*() API should go into the depth of the fwnode implementation.
--- drivers/base/property.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-)
drivers/base/property.c +13 -14
@@ -740,7 +740,18 @@ struct fwnode_handle * fwnode_get_next_child_node(const struct fwnode_handle *fwnode, struct fwnode_handle *child) { - return fwnode_call_ptr_op(fwnode, get_next_child_node, child); + struct fwnode_handle *next; + +if (IS_ERR_OR_NULL (fwnode)) +return NULL ; + +/* Try to find a child in primary fwnode */ + next =fwnode_call_ptr_op (fwnode, get_next_child_node, child); +if (next) +return next; + +/* When no more children in primary, continue with secondary */ +return fwnode_call_ptr_op (fwnode->secondary, get_next_child_node, child); }EXPORT_SYMBOL_GPL (fwnode_get_next_child_node);
@@ -778,19 +789,7 @@ EXPORT_SYMBOL_GPL(fwnode_get_next_availastruct fwnode_handle *device_get_next_child_node (struct device *dev,struct fwnode_handle *child) { -const struct fwnode_handle *fwnode =dev_fwnode (dev); -struct fwnode_handle *next; - -if (IS_ERR_OR_NULL (fwnode)) -return NULL ; - -/* Try to find a child in primary fwnode */ - next =fwnode_get_next_child_node (fwnode, child); -if (next) -return next; - -/* When no more children in primary, continue with secondary */ -return fwnode_get_next_child_node (fwnode->secondary, child); +return fwnode_get_next_child_node (dev_fwnode (dev), child); }EXPORT_SYMBOL_GPL (device_get_next_child_node);
Greg Kroah-Hartman
maintainerPATCH 487/491 batman-adv: avoid OGM aggregation when skb tailroom is insufficient
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yang Yang <[email protected]>
commit 0d4aef630be9d5f9c1227d07669c26c4383b5ad0 upstream.
When OGM aggregation state is toggled at runtime, an existing forwarded packet may have been allocated with only packet_len bytes, while a later packet can still be selected for aggregation. Appending in this case can hit skb_put overflow conditions.
Reject aggregation when the target skb tailroom cannot accommodate the new packet. The caller then falls back to creating a new forward packet instead of appending.
--- net/batman-adv/bat_iv_ogm.c | 3 +++ 1 file changed, 3 insertions(+)
net/batman-adv/bat_iv_ogm.c +3 -0
@@ -466,6 +466,9 @@ batadv_iv_ogm_can_aggregate(const struct !time_after_eq(aggregation_end_time, forw_packet->send_time))return false; +if (skb_tailroom (forw_packet->skb) < packet_len) +return false; +if (aggregated_bytes >BATADV_MAX_AGGREGATION_BYTES )return false;
Greg Kroah-Hartman
maintainerPATCH 488/491 s390/syscalls: Add spectre boundary for syscall dispatch table
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
[ Upstream commit 48b8814e25d073dd84daf990a879a820bad2bcbd ]
The s390 syscall number is directly controlled by userspace, but does not have an array_index_nospec() boundary to prevent access past the syscall function pointer tables.
[ gor: 5.10 backport. In 5.10, commit 56e62a737028 ("s390: convert to
generic entry") has not been applied — syscall dispatch is in assembly (entry.S), not in C (syscall.c). The equivalent to array_index_nospec() is implemented using the same clgr/slbgr/ngr.
SVC 0 path: the user-controlled syscall number in r1 is clamped via a single unsigned compare (clgr) followed by slbgr/ngr. The original cghi/jnl bounds check branch is replaced — the clamp handles both
cases: in-bounds values pass through, out-of-bounds values are zeroed (producing the same r8=0 dispatch to table[0] as the original branch).
SVC 1-255 path: syscall number from the 8-bit instruction immediate is always in bounds. ]
--- arch/s390/kernel/entry.S | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
arch/s390/kernel/entry.S +5 -2
@@ -420,12 +420,15 @@ ENTRY(system_call) # svc 0: system call number in %r1 llgfr %r1,%r1 # clear high word in r1 sth %r1,__PT_INT_CODE+2(%r11) - cghi %r1,NR_syscalls - jnl .Lsysc_nr_ok + lghi %r0,NR_syscalls-1 + clgr %r1,%r0 # CC0/1 if r1 in bounds + slbgr %r0,%r0 # mask = -1 in bounds, 0 out of bounds + ngr %r1,%r0 # clamp r1 slag %r8,%r1,3 .Lsysc_nr_ok: stg %r2,__PT_ORIG_GPR2(%r11) stg %r7,STACK_FRAME_OVERHEAD(%r15) + xgr %r1,%r1 # scrub r1, unclamped user value for svc 1-255 lg %r9,0(%r8,%r10) # get system call add. TSTMSK __TI_flags(%r12),_TIF_TRACE jnz .Lsysc_tracesys
Greg Kroah-Hartman
maintainerPATCH 489/491 device property: fix of node refcount leak in fwnode_graph_get_next_endpoint()
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yang Yingliang <[email protected]>
commit 39af728649b05e88a2b40e714feeee6451c3f18e upstream.
The 'parent' returned by fwnode_graph_get_port_parent() with refcount incremented when 'prev' is not NULL, it needs be put when finish using it.
Because the parent is const, introduce a new variable to store the returned fwnode, then put it before returning from fwnode_graph_get_next_endpoint().
--- drivers/base/property.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
drivers/base/property.c +12 -6
@@ -1054,26 +1054,32 @@ struct fwnode_handle * fwnode_graph_get_next_endpoint(const struct fwnode_handle *fwnode, struct fwnode_handle *prev) { + struct fwnode_handle *ep, *port_parent = NULL;const struct fwnode_handle *parent; -struct fwnode_handle *ep;/* * If this function is in a loop and the previous iteration returned * an endpoint from fwnode->secondary, then we need to use the secondary * as parent rather than @fwnode. */ -if (prev) - parent =fwnode_graph_get_port_parent (prev); -else +if (prev) { + port_parent =fwnode_graph_get_port_parent (prev); + parent = port_parent; + }else { parent = fwnode; + }if (IS_ERR_OR_NULL (parent))return NULL ; ep =fwnode_call_ptr_op (parent, graph_get_next_endpoint, prev);if (ep) -return ep; + goto out_put_port_parent; -return fwnode_graph_get_next_endpoint (parent->secondary,NULL ); + ep =fwnode_graph_get_next_endpoint (parent->secondary,NULL ); + +out_put_port_parent: +fwnode_handle_put (port_parent); +return ep; }EXPORT_SYMBOL_GPL (fwnode_graph_get_next_endpoint);
Greg Kroah-Hartman
maintainerPATCH 490/491 Revert "PCI: Enable ACS after configuring IOMMU for OF platforms"
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manivannan Sadhasivam <[email protected]>
This reverts commit 573497f350b3cdb526c8c38955ddd287c5d4cc53 which is commit c41e2fb67e26b04d919257875fa954aa5f6e392e upstream.
The original commit attempted to enable ACS in pci_dma_configure() prior to IOMMU group assignment in iommu_init_device() to fix the ACS enablement issue for OF platforms. But that assumption doesn't hold true for kernel versions prior to v6.15, because on these older kernels, pci_dma_configure() is called *after* iommu_init_device(). So the IOMMU groups are already created before the ACS gets enabled. This causes the devices that should have been split into separate groups by ACS, getting merged into one group, thereby breaking the IOMMU isolation as reported on the AMD machines.
So revert the offending commit to restore the IOMMU group assignment on those affected machines. It should be noted that ACS has never really worked on kernel versions prior to v6.15, so the revert doesn't make any difference for OF platforms.
--- drivers/pci/pci-driver.c | 8 -------- drivers/pci/pci.c | 10 +++++++++- drivers/pci/pci.h | 1 - 3 files changed, 9 insertions(+), 10 deletions(-)
drivers/pci/pci-driver.c +0 -8
@@ -1601,14 +1601,6 @@ static int pci_dma_configure(struct devi ret =acpi_dma_configure (dev,acpi_get_dma_attr (adev)); } -/* -* Attempt to enable ACS regardless of capability because some Root -* Ports (e.g. those quirked with *_intel_pch_acs_*) do not have -* the standard ACS capability but still support ACS via those -* quirks. -*/ -pci_enable_acs (to_pci_dev (dev)); -pci_put_host_bridge_device (bridge);return ret; }
drivers/pci/pci.c +9 -1
@@ -894,7 +894,7 @@ static void pci_std_enable_acs(struct pc* pci_enable_acs - enable ACS if hardware support it * @dev: the PCI device */ -void pci_enable_acs (struct pci_dev *dev) +static void pci_enable_acs (struct pci_dev *dev) {if (!pci_acs_enable) goto disable_acs_redir;
@@ -3548,6 +3548,14 @@ bool pci_acs_path_enabled(struct pci_devvoid pci_acs_init (struct pci_dev *dev) { dev->acs_cap =pci_find_ext_capability (dev,PCI_EXT_CAP_ID_ACS ); + +/* +* Attempt to enable ACS regardless of capability because some Root +* Ports (e.g. those quirked with *_intel_pch_acs_*) do not have +* the standard ACS capability but still support ACS via those +* quirks. +*/ +pci_enable_acs (dev); }/**
drivers/pci/pci.h +0 -1
@@ -547,7 +547,6 @@ static inline resource_size_t pci_resour }void pci_acs_init (struct pci_dev *dev); -void pci_enable_acs (struct pci_dev *dev);#ifdef CONFIG_PCI_QUIRKS int pci_dev_specific_acs_enabled (struct pci_dev *dev,u16 acs_flags);int pci_dev_specific_enable_acs (struct pci_dev *dev);
Greg Kroah-Hartman
maintainerPATCH 491/491 io_uring/poll: correctly handle io_poll_add() return value on update
In reply to Greg Kroah-Hartman5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jens Axboe <[email protected]>
Commit 84230ad2d2afbf0c44c32967e525c0ad92e26b4e upstream.
When the core of io_uring was updated to handle completions consistently and with fixed return codes, the POLL_REMOVE opcode with updates got slightly broken. If a POLL_ADD is pending and then POLL_REMOVE is used to update the events of that request, if that update causes the POLL_ADD to now trigger, then that completion is lost and a CQE is never posted.
Additionally, ensure that if an update does cause an existing POLL_ADD to complete, that the completion value isn't always overwritten with -ECANCELED. For that case, whatever io_poll_add() set the value to should just be retained.
--- io_uring/io_uring.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
io_uring/io_uring.c +19 -7
@@ -5980,7 +5980,7 @@ static int io_poll_add_prep(struct io_kireturn 0 ; } -static int io_poll_add (struct io_kiocb *req,unsigned int issue_flags) +static int __io_poll_add (struct io_kiocb *req,unsigned int issue_flags) {struct io_poll_iocb *poll = &req->poll;struct io_poll_table ipt;
@@ -5992,11 +5992,21 @@ static int io_poll_add(struct io_kiocb *if (!ret && ipt.error)req_set_fail (req); ret = ret ?: ipt.error; -if (ret) +if (ret >0 ) {__io_req_complete (req, issue_flags, ret,0 ); +return ret; + }return 0 ; } +static int io_poll_add (struct io_kiocb *req,unsigned int issue_flags) +{ +int ret; + + ret =__io_poll_add (req, issue_flags); +return ret <0 ? ret :0 ; +} +static int io_poll_update (struct io_kiocb *req,unsigned int issue_flags) {struct io_ring_ctx *ctx = req->ctx;
@@ -6012,6 +6022,7 @@ static int io_poll_update(struct io_kioc ret = preq ? -EALREADY : -ENOENT ; goto out; } + preq->result = -ECANCELED ;spin_unlock (&ctx->completion_lock);if (req->poll_update.update_events || req->poll_update.update_user_data) {
@@ -6024,16 +6035,17 @@ static int io_poll_update(struct io_kiocif (req->poll_update.update_user_data) preq->user_data = req->poll_update.new_user_data; - ret2 =io_poll_add (preq, issue_flags); + ret2 =__io_poll_add (preq, issue_flags);/* successfully updated, don't complete poll request */ if (!ret2) goto out; + preq->result = ret2; + } -req_set_fail (preq); -io_req_complete (preq, -ECANCELED ); +if (preq->result <0 ) +req_set_fail (preq); +io_req_complete (preq, preq->result); out: -if (ret <0 ) -req_set_fail (req);/* complete update request, we're done with it */ io_req_complete (req, ret);io_ring_submit_unlock (ctx, !(issue_flags &IO_URING_F_NONBLOCK ));
Re: [PATCH 5.10 491/491] io_uring/poll: correctly handle io_poll_add() return value on update
Quoted 15 lines · Greg Kroah-Hartman
5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jens Axboe <[email protected]>
Commit
84230ad2d2afbf0c44c32967e525c0ad92e26b4eupstream.When the core of
io_uringwas updated to handle completions consistently and with fixed return codes, thePOLL_REMOVEopcode with updates got slightly broken. If aPOLL_ADDis pending and thenPOLL_REMOVEis used to update the events of that request, if that update causes thePOLL_ADDto now trigger, then that completion is lost and a CQE is never posted.
Quoted 4 lines
Additionally, ensure that if an update does cause an existing
POLL_ADDto complete, that the completion value isn't always overwritten with-ECANCELED. For that case, whateverio_poll_add()set the value to should just be retained.
This backport is very different from the upstream version, and I have some questions about that (inline below).
Quoted 29 lines
Fixes 97b388d70b53 ("io_uring: handle completions in the core")Reported-by [email protected]Tested-by [email protected]Signed-off-by Jens Axboe <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- io_uring/io_uring.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)io_uring/io_uring.c +3
-2@@ -5980,7 +5980,7 @@ static int io_poll_add_prep(struct io_kireturn 0 ; } -static int io_poll_add (struct io_kiocb *req,unsigned int issue_flags) +static int __io_poll_add (struct io_kiocb *req,unsigned int issue_flags) {struct io_poll_iocb *poll = &req->poll;struct io_poll_table ipt;@@ -5992,11 +5992,21 @@ static int io_poll_add(struct io_kiocb *if (!ret && ipt.error)req_set_fail (req); ret = ret ?: ipt.error; -if (ret) +if (ret >0 ) {__io_req_complete (req, issue_flags, ret,0 ); +return ret;
io_uring/io_uring.c static int io_poll_add(struct io_kiocb * · line 6007
Quoted 10 lines
io_uring/io_uring.c +7
-0+ }return 0 ; } +static int io_poll_add (struct io_kiocb *req,unsigned int issue_flags) +{ +int ret; + + ret =__io_poll_add (req, issue_flags); +return ret <0 ? ret :0 ;
__io_poll_add() still never returns a negative result, so why is there a check for that here?
Quoted 20 lines
io_uring/io_uring.c +4
-1+} +static int io_poll_update (struct io_kiocb *req,unsigned int issue_flags) {struct io_ring_ctx *ctx = req->ctx;@@ -6012,6 +6022,7 @@ static int io_poll_update(struct io_kioc ret = preq ? -EALREADY : -ENOENT ; goto out; } + preq->result = -ECANCELED ;spin_unlock (&ctx->completion_lock);if (req->poll_update.update_events || req->poll_update.update_user_data) {@@ -6024,16 +6035,17 @@ static int io_poll_update(struct io_kiocif (req->poll_update.update_user_data) preq->user_data = req->poll_update.new_user_data; - ret2 =io_poll_add (preq, issue_flags); + ret2 =__io_poll_add (preq, issue_flags);/* successfully updated, don't complete poll request */
io_uring/io_uring.c static int io_poll_update(struct io_kioc · line 6047
Quoted 10 lines
io_uring/io_uring.c +5
-2if (!ret2) goto out; + preq->result = ret2; + } -req_set_fail (preq); -io_req_complete (preq, -ECANCELED ); +if (preq->result <0 ) +req_set_fail (preq); +io_req_complete (preq, preq->result);
If __io_poll_add() returned an events mask then it completed preq, but then we also complete preq here. Is that really correct?
Ben.
Quoted 8 lines
io_uring/io_uring.c +0
-2out: -if (ret <0 ) -req_set_fail (req);/* complete update request, we're done with it */ io_req_complete (req, ret);io_ring_submit_unlock (ctx, !(issue_flags &IO_URING_F_NONBLOCK ));
Signature · 3 lines
Ben Hutchings Any smoothly functioning technology is indistinguishable from a rigged demo.
Jens Axboe
maintainerRe: [PATCH 5.10 491/491] io_uring/poll: correctly handle io_poll_add() return value on update
Quoted 16 lines · Ben Hutchings
Quoted 15 lines · Greg Kroah-Hartman
5.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jens Axboe <[email protected]>
Commit
84230ad2d2afbf0c44c32967e525c0ad92e26b4eupstream.When the core of
io_uringwas updated to handle completions consistently and with fixed return codes, thePOLL_REMOVEopcode with updates got slightly broken. If aPOLL_ADDis pending and thenPOLL_REMOVEis used to update the events of that request, if that update causes thePOLL_ADDto now trigger, then that completion is lost and a CQE is never posted.
Quoted 7 lines
Quoted 4 lines
Additionally, ensure that if an update does cause an existing
POLL_ADDto complete, that the completion value isn't always overwritten with-ECANCELED. For that case, whateverio_poll_add()set the value to should just be retained.This backport is very different from the upstream version, and I have some questions about that (inline below).
It is, was quite painful.
Quoted 60 lines
Quoted 29 lines
Fixes 97b388d70b53 ("io_uring: handle completions in the core")Reported-by [email protected]Tested-by [email protected]Signed-off-by Jens Axboe <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- io_uring/io_uring.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)io_uring/io_uring.c +3
-2@@ -5980,7 +5980,7 @@ static int io_poll_add_prep(struct io_kireturn 0 ; } -static int io_poll_add (struct io_kiocb *req,unsigned int issue_flags) +static int __io_poll_add (struct io_kiocb *req,unsigned int issue_flags) {struct io_poll_iocb *poll = &req->poll;struct io_poll_table ipt;@@ -5992,11 +5992,21 @@ static int io_poll_add(struct io_kiocb *if (!ret && ipt.error)req_set_fail (req); ret = ret ?: ipt.error; -if (ret) +if (ret >0 ) {__io_req_complete (req, issue_flags, ret,0 ); +return ret;io_uring/io_uring.c static int io_poll_add(struct io_kiocb * · line 6007
Quoted 10 lines
io_uring/io_uring.c +7
-0+ }return 0 ; } +static int io_poll_add (struct io_kiocb *req,unsigned int issue_flags) +{ +int ret; + + ret =__io_poll_add (req, issue_flags); +return ret <0 ? ret :0 ;
__io_poll_add()still never returns a negative result, so why is there a check for that here?Quoted 17 lines
io_uring/io_uring.c +3
-0+} +static int io_poll_update (struct io_kiocb *req,unsigned int issue_flags) {struct io_ring_ctx *ctx = req->ctx;@@ -6012,6 +6022,7 @@ static int io_poll_update(struct io_kioc ret = preq ? -EALREADY : -ENOENT ; goto out; } + preq->result = -ECANCELED ;spin_unlock (&ctx->completion_lock);if (req->poll_update.update_events || req->poll_update.update_user_data) {@@ -6024,16 +6035,17 @@ static int io_poll_update(struct io_kiocif (req->poll_update.update_user_data) preq->user_data = req->poll_update.new_user_data;
Quoted 16 lines
io_uring/io_uring.c static int io_poll_update(struct io_kioc · line 6047
Quoted 13 lines
io_uring/io_uring.c +6
-3- ret2 =io_poll_add (preq, issue_flags); + ret2 =__io_poll_add (preq, issue_flags);/* successfully updated, don't complete poll request */ if (!ret2) goto out; + preq->result = ret2; + } -req_set_fail (preq); -io_req_complete (preq, -ECANCELED ); +if (preq->result <0 ) +req_set_fail (preq); +io_req_complete (preq, preq->result);If
__io_poll_add()returned an events mask then it completed preq, but then we also complete preq here. Is that really correct?
Let me take a closer look, I do agree with you that the final result does not look entirely correct.
Signature · 1 line
Jens Axboe
Jens Axboe
maintainerRe: [PATCH 5.10 491/491] io_uring/poll: correctly handle io_poll_add() return value on update
Quoted 21 lines · Jens Axboe
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0
-0@@ -6024,16 +6035,17 @@ static int io_poll_update(struct io_kioc if (req->poll_update.update_user_data) preq->user_data = req->poll_update.new_user_data;Quoted 16 lines
Review static int io_poll_update(struct io_kioc · line 6047
Quoted 13 lines
(quoted diff) +6
-3- ret2 = io_poll_add(preq, issue_flags); + ret2 = __io_poll_add(preq, issue_flags); /* successfully updated, don't complete poll request */ if (!ret2) goto out; + preq->result = ret2; + } - req_set_fail(preq); - io_req_complete(preq, -ECANCELED); + if (preq->result < 0) + req_set_fail(preq); + io_req_complete(preq, preq->result);If
__io_poll_add()returned an events mask then it completed preq, but then we also complete preq here. Is that really correct?
Quoted 2 lines
Let me take a closer look, I do agree with you that the final result does not look entirely correct.
As far as I can tell, these two should be applied to 5.10 and 5.15 stable. The first one fixes an old backporting issue that I didn't notice until doing some targeted testing just now. The second one should take care of the issues that Ben spotted in the current backport.
Will be nice when 5.x is finally taken out behind the barn :-)
Signature · 1 line
Jens Axboe
From 7fdfffce508f38d89338e8bbed421dd91ddfcb3f Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Tue, 21 Apr 2026 16:41:32 -0600
Subject: [PATCH 1/2] io_uring/poll: fix EPOLL_URING_WAKE sometimes not being
masked in
Rather than do it only when we jump straight to execution, mark it regardless. This ensures it doesn't get lost.
--- io_uring/io_uring.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
io_uring/io_uring.c +8 -9
@@ -5794,17 +5794,16 @@ static int io_poll_wake(struct wait_queue_entry *wait, unsigned mode, int sync,if (mask && !(mask & poll->events))return 0 ; -if (io_poll_get_ownership (req)) { -/* -* If we trigger a multishot poll off our own wakeup path, -* disable multishot as there is a circular dependency between -* CQ posting and triggering the event. -*/ -if (mask &EPOLL_URING_WAKE ) - poll->events |=EPOLLONESHOT ; +/* +* If we trigger a multishot poll off our own wakeup path, +* disable multishot as there is a circular dependency between +* CQ posting and triggering the event. +*/ +if (mask &EPOLL_URING_WAKE ) + poll->events |=EPOLLONESHOT ; +if (io_poll_get_ownership (req))__io_poll_execute (req, mask); - }return 1 ; }
Signature · 1 line
2.53.0
From 7a61c38c4d6ae3d5cbe6efa06885b1ca821a129c Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Tue, 21 Apr 2026 16:44:06 -0600
Subject: [PATCH 2/2] io_uring/poll: fix backport of io_poll_add() changes
The 5.15/5.10 backport of 84230ad2d2af had a few issues, due to the older poll base. Notably return value handling __io_arm_poll_handler() and in return __io_poll_add() as well. Fix them up.
--- io_uring/io_uring.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
io_uring/io_uring.c +4 -8
@@ -6138,19 +6138,15 @@ static int __io_poll_add(struct io_kiocb *req, unsigned int issue_flags)if (!ret && ipt.error)req_set_fail (req); ret = ret ?: ipt.error; -if (ret >0 ) { +if (ret)__io_req_complete (req, issue_flags, ret,0 ); -return ret; - } -return 0 ; +return ret; }static int io_poll_add (struct io_kiocb *req,unsigned int issue_flags) { -int ret; - - ret =__io_poll_add (req, issue_flags); -return ret <0 ? ret :0 ; +__io_poll_add (req, issue_flags); +return 0 ; }static int io_poll_update (struct io_kiocb *req,unsigned int issue_flags)
Signature · 1 line
2.53.0
Jens Axboe
maintainerRe: [PATCH 5.10 491/491] io_uring/poll: correctly handle io_poll_add() return value on update
Quoted 25 lines · Jens Axboe
Quoted 21 lines · Jens Axboe
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0
-0@@ -6024,16 +6035,17 @@ static int io_poll_update(struct io_kioc if (req->poll_update.update_user_data) preq->user_data = req->poll_update.new_user_data;Quoted 16 lines
Review static int io_poll_update(struct io_kioc · line 6047
Quoted 13 lines
(quoted diff) +6
-3- ret2 = io_poll_add(preq, issue_flags); + ret2 = __io_poll_add(preq, issue_flags); /* successfully updated, don't complete poll request */ if (!ret2) goto out; + preq->result = ret2; + } - req_set_fail(preq); - io_req_complete(preq, -ECANCELED); + if (preq->result < 0) + req_set_fail(preq); + io_req_complete(preq, preq->result);If
__io_poll_add()returned an events mask then it completed preq, but then we also complete preq here. Is that really correct?Quoted 2 lines
Let me take a closer look, I do agree with you that the final result does not look entirely correct.
Quoted 6 lines
As far as I can tell, these two should be applied to 5.10 and 5.15 stable. The first one fixes an old backporting issue that I didn't notice until doing some targeted testing just now. The second one should take care of the issues that Ben spotted in the current backport.
Will be nice when 5.x is finally taken out behind the barn :-)
Greg, you adding these 2 for 5.10/5.15?
Signature · 1 line
Jens Axboe
Greg Kroah-Hartman
maintainerRe: [PATCH 5.10 491/491] io_uring/poll: correctly handle io_poll_add() return value on update
Quoted 26 lines · Jens Axboe
Quoted 25 lines · Jens Axboe
Quoted 23 lines · Jens Axboe
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0
-0@@ -6024,16 +6035,17 @@ static int io_poll_update(struct io_kioc if (req->poll_update.update_user_data) preq->user_data = req->poll_update.new_user_data;Quoted 16 lines
Review static int io_poll_update(struct io_kioc · line 6047
Quoted 13 lines
(quoted diff) +6
-3- ret2 = io_poll_add(preq, issue_flags); + ret2 = __io_poll_add(preq, issue_flags); /* successfully updated, don't complete poll request */ if (!ret2) goto out; + preq->result = ret2; + } - req_set_fail(preq); - io_req_complete(preq, -ECANCELED); + if (preq->result < 0) + req_set_fail(preq); + io_req_complete(preq, preq->result);If
__io_poll_add()returned an events mask then it completed preq, but then we also complete preq here. Is that really correct?Let me take a closer look, I do agree with you that the final result does not look entirely correct.
Quoted 8 lines
Quoted 6 lines
As far as I can tell, these two should be applied to 5.10 and 5.15 stable. The first one fixes an old backporting issue that I didn't notice until doing some targeted testing just now. The second one should take care of the issues that Ben spotted in the current backport.
Will be nice when 5.x is finally taken out behind the barn :-)
Greg, you adding these 2 for 5.10/5.15?
Sorry but "these 2" what?
confused,
greg k-h
Greg Kroah-Hartman
maintainerRe: [PATCH 5.10 491/491] io_uring/poll: correctly handle io_poll_add() return value on update
Quoted 32 lines · Greg Kroah-Hartman
Quoted 31 lines · Jens Axboe
Quoted 30 lines · Jens Axboe
Quoted 21 lines · Jens Axboe
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0
-0@@ -6024,16 +6035,17 @@ static int io_poll_update(struct io_kioc if (req->poll_update.update_user_data) preq->user_data = req->poll_update.new_user_data;Quoted 16 lines
Review static int io_poll_update(struct io_kioc · line 6047
Quoted 13 lines
(quoted diff) +6
-3- ret2 = io_poll_add(preq, issue_flags); + ret2 = __io_poll_add(preq, issue_flags); /* successfully updated, don't complete poll request */ if (!ret2) goto out; + preq->result = ret2; + } - req_set_fail(preq); - io_req_complete(preq, -ECANCELED); + if (preq->result < 0) + req_set_fail(preq); + io_req_complete(preq, preq->result);If
__io_poll_add()returned an events mask then it completed preq, but then we also complete preq here. Is that really correct?Quoted 2 lines
Let me take a closer look, I do agree with you that the final result does not look entirely correct.
As far as I can tell, these two should be applied to 5.10 and 5.15 stable. The first one fixes an old backporting issue that I didn't notice until doing some targeted testing just now. The second one should take care of the issues that Ben spotted in the current backport.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Will be nice when 5.x is finally taken out behind the barn :-)
Greg, you adding these 2 for 5.10/5.15?
Sorry but "these 2" what?
Ah, nevermind, missed the attachments, let me go queue them up now, thanks for reminding me!
greg k-h
Greg Kroah-Hartman
maintainerRe: [PATCH 5.10 491/491] io_uring/poll: correctly handle io_poll_add() return value on update
In reply to Jens AxboeQuoted 22 lines · Jens Axboe
Quoted 21 lines · Jens Axboe
Quoted 20 lines
Quoted 7 lines
(quoted diff) +1
-1@@ -6024,16 +6035,17 @@ static int io_poll_update(struct io_kioc if (req->poll_update.update_user_data) preq->user_data = req->poll_update.new_user_data; - ret2 = io_poll_add(preq, issue_flags); + ret2 = __io_poll_add(preq, issue_flags); /* successfully updated, don't complete poll request */Review static int io_poll_update(struct io_kioc · line 6047
Quoted 10 lines
(quoted diff) +5
-2if (!ret2) goto out; + preq->result = ret2; + } - req_set_fail(preq); - io_req_complete(preq, -ECANCELED); + if (preq->result < 0) + req_set_fail(preq); + io_req_complete(preq, preq->result);If
__io_poll_add()returned an events mask then it completed preq, but then we also complete preq here. Is that really correct?
Quoted 7 lines
Quoted 2 lines
Let me take a closer look, I do agree with you that the final result does not look entirely correct.
As far as I can tell, these two should be applied to 5.10 and 5.15 stable. The first one fixes an old backporting issue that I didn't notice until doing some targeted testing just now. The second one should take care of the issues that Ben spotted in the current backport.
Now applied.
Quoted 1 line
Will be nice when 5.x is finally taken out behind the barn :-)
Totally agree...
greg k-h
Jens Axboe
maintainerRe: [PATCH 5.10 491/491] io_uring/poll: correctly handle io_poll_add() return value on update
Quoted 26 lines · Greg Kroah-Hartman
Quoted 25 lines · Jens Axboe
Quoted 23 lines · Jens Axboe
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0
-0@@ -6024,16 +6035,17 @@ static int io_poll_update(struct io_kioc if (req->poll_update.update_user_data) preq->user_data = req->poll_update.new_user_data;Quoted 16 lines
Review static int io_poll_update(struct io_kioc · line 6047
Quoted 13 lines
(quoted diff) +6
-3- ret2 = io_poll_add(preq, issue_flags); + ret2 = __io_poll_add(preq, issue_flags); /* successfully updated, don't complete poll request */ if (!ret2) goto out; + preq->result = ret2; + } - req_set_fail(preq); - io_req_complete(preq, -ECANCELED); + if (preq->result < 0) + req_set_fail(preq); + io_req_complete(preq, preq->result);If
__io_poll_add()returned an events mask then it completed preq, but then we also complete preq here. Is that really correct?Let me take a closer look, I do agree with you that the final result does not look entirely correct.
Quoted 6 lines
Quoted 4 lines
As far as I can tell, these two should be applied to 5.10 and 5.15 stable. The first one fixes an old backporting issue that I didn't notice until doing some targeted testing just now. The second one should take care of the issues that Ben spotted in the current backport.
Now applied.
Thanks!
Signature · 1 line
Jens Axboe
# Librecast Test Results
020/020 [ OK ] liblcrq
010/010 [ OK ] libmld
120/120 [ OK ] liblibrecast
CPU/kernel: Linux auntie 5.10.253-rc1-00492-g0abb5988a311 #1 SMP Mon Apr 13 17:24:27 -00 2026 x86_64 AMD Ryzen 9 9950X 16-Core Processor AuthenticAMD GNU/Linux
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.10.253 release. There are 491 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Wed, 15 Apr 2026 15:57:08 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 8 lines
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.10.253-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-5.10.y
and the diffstat can be found below.thanks,
greg k-h
On ARCH_BRCMSTB using 32-bit and 64-bit ARM kernels, build tested on BMIPS_GENERIC:
Signature · 1 line
Florian
Jon Hunter
maintainerHi Greg,
Quoted 20 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.10.253 release. There are 491 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Wed, 15 Apr 2026 15:57:08 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.10.253-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-5.10.y
and the diffstat can be found below.thanks,
greg k-h
-------------
Pseudo-Shortlog of commits:
...
Quoted 2 lines
Uwe Kleine-König <[email protected]>
bus: omap-ocp2scp: Convert to platform remove callback returning void
I am seeing the following build error due to the above change on ARM platforms ...
drivers/bus/omap-ocp2scp.c:95:10: error: 'struct platform_driver' has no member named 'remove_new'; did you mean 'remove'?
95 | .remove_new = omap_ocp2scp_remove,
| ^~~~~~~~~~
| remove
drivers/bus/omap-ocp2scp.c:95:27: error: initialization of 'int (*)(struct platform_device *)' from incompatible pointer type 'void (*)(struct platform_device *)' [-Werror=incompatible-pointer-types]
95 | .remove_new = omap_ocp2scp_remove,
| ^~~~~~~~~~~~~~~~~~~Thanks
Jon
Signature · 1 line
nvpublic
Quoted 31 lines · Jon Hunter
Hi Greg,
Quoted 20 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.10.253 release. There are 491 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Wed, 15 Apr 2026 15:57:08 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.10.253-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-5.10.y
and the diffstat can be found below.thanks,
greg k-h
-------------
Pseudo-Shortlog of commits:...
Quoted 2 lines
Uwe Kleine-König <[email protected]>
bus: omap-ocp2scp: Convert to platform remove callback returning voidI am seeing the following build error due to the above change on ARM platforms ...
Quoted 8 lines
drivers/bus/omap-ocp2scp.c:95:10: error: 'structplatform_driver' has no member named 'remove_new'; did you mean 'remove'?95 | .remove_new = omap_ocp2scp_remove, | ^~~~~~~~~~ | remove drivers/bus/omap-ocp2scp.c:95:27: error: initialization of 'int (*)(struct platform_device *)' from incompatible pointer type 'void (*)(struct platform_device *)' [-Werror=incompatible-pointer-types] 95 | .remove_new = omap_ocp2scp_remove, | ^~~~~~~~~~~~~~~~~~~
We see that one, too:
https://gitlab.com/cip-project/cip-testing/linux-stable-rc-ci/-/jobs/13901155305
https://gitlab.com/cip-project/cip-testing/linux-stable-rc-ci/-/pipelines/2450043152
Best regards,
Pavel
Quoted 42 lines · Pavel Machek
Quoted 31 lines · Jon Hunter
Hi Greg,
Quoted 20 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.10.253 release. There are 491 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Wed, 15 Apr 2026 15:57:08 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.10.253-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-5.10.y
and the diffstat can be found below.thanks,
greg k-h
-------------
Pseudo-Shortlog of commits:...
Quoted 2 lines
Uwe Kleine-König <[email protected]>
bus: omap-ocp2scp: Convert to platform remove callback returning voidI am seeing the following build error due to the above change on ARM platforms ...
Quoted 8 lines
drivers/bus/omap-ocp2scp.c:95:10: error: 'structplatform_driver' has no member named 'remove_new'; did you mean 'remove'?95 | .remove_new = omap_ocp2scp_remove, | ^~~~~~~~~~ | remove drivers/bus/omap-ocp2scp.c:95:27: error: initialization of 'int (*)(struct platform_device *)' from incompatible pointer type 'void (*)(struct platform_device *)' [-Werror=incompatible-pointer-types] 95 | .remove_new = omap_ocp2scp_remove, | ^~~~~~~~~~~~~~~~~~~
Quoted 6 lines
We see that one, too:
https://gitlab.com/cip-project/cip-testing/linux-stable-rc-ci/-/jobs/13901155305
https://gitlab.com/cip-project/cip-testing/linux-stable-rc-ci/-/pipelines/2450043152Best regards,
This was also observed on KernelCI:
The two issues:
https://dashboard.kernelci.org/issue/maestro%3A67d434ff5d6b71886d45efe758ca00ff45cb969a?iv=1
https://dashboard.kernelci.org/issue/maestro%3Ac970827f049cfd67124148e3c19abe1d4aa8347a?iv=1
Regards
Ben
Quoted 1 line
Pavel
Quoted 51 lines · Ben Copeland
Quoted 42 lines · Pavel Machek
Quoted 31 lines · Jon Hunter
Hi Greg,
Quoted 20 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.10.253 release. There are 491 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Wed, 15 Apr 2026 15:57:08 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.10.253-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-5.10.y
and the diffstat can be found below.thanks,
greg k-h
-------------
Pseudo-Shortlog of commits:...
Quoted 2 lines
Uwe Kleine-König <[email protected]>
bus: omap-ocp2scp: Convert to platform remove callback returning voidI am seeing the following build error due to the above change on ARM platforms ...
Quoted 8 lines
drivers/bus/omap-ocp2scp.c:95:10: error: 'structplatform_driver' has no member named 'remove_new'; did you mean 'remove'?95 | .remove_new = omap_ocp2scp_remove, | ^~~~~~~~~~ | remove drivers/bus/omap-ocp2scp.c:95:27: error: initialization of 'int (*)(struct platform_device *)' from incompatible pointer type 'void (*)(struct platform_device *)' [-Werror=incompatible-pointer-types] 95 | .remove_new = omap_ocp2scp_remove, | ^~~~~~~~~~~~~~~~~~~Quoted 6 lines
We see that one, too:
https://gitlab.com/cip-project/cip-testing/linux-stable-rc-ci/-/jobs/13901155305
https://gitlab.com/cip-project/cip-testing/linux-stable-rc-ci/-/pipelines/2450043152Best regards,
Quoted 8 lines
This was also observed on KernelCI:
The two issues:
https://dashboard.kernelci.org/issue/maestro%3A67d434ff5d6b71886d45efe758ca00ff45cb969a?iv=1
https://dashboard.kernelci.org/issue/maestro%3Ac970827f049cfd67124148e3c19abe1d4aa8347a?iv=1
I bisected it to # first bad commit:
[708f670c8e0849525742cc3a1ce319739fe74c26] bus: omap-ocp2scp: Convert to platform remove callback returning void
Here is the log:
# bad: [0abb5988a311f0e617615aa4b08c90b3ade85c25] Linux 5.10.253-rc1 # good: [fbb1715e3efa70ec20c5b1f755f3301fd3d042eb] Linux 5.10.252 git bisect start '0abb5988a311' 'v5.10.252'
# bad: [0cbe44da7c41f095b72fb599410d0530ca80a9aa] ASoC: soc-core: move snd_soc_runtime_set_dai_fmt() to upside
git bisect bad 0cbe44da7c41f095b72fb599410d0530ca80a9aa
# bad: [9b7ae0b9077850af955e1c8c976808feb269cc44] net: Handle napi_schedule() calls from non-interrupt
git bisect bad 9b7ae0b9077850af955e1c8c976808feb269cc44
# bad: [eb39b81e0f85135e1e5a39b6c7bfbec77e03467b] sh: platform_early:
remove pdev->driver_override check
git bisect bad eb39b81e0f85135e1e5a39b6c7bfbec77e03467b
# bad: [a1ea84bad7500d1e346bf3714850c5a32c4d5c51] net: qrtr: Add GFP flags parameter to qrtr_alloc_ctrl_packet
git bisect bad a1ea84bad7500d1e346bf3714850c5a32c4d5c51
# bad: [e6613448c424bc28ca19cad1e56295ae101cd9c4] usb: gadget:dummy_hcd: fix premature URB completion when ZLP follows partial transfer
git bisect bad e6613448c424bc28ca19cad1e56295ae101cd9c4
# good: [0f8c01ecc1771e45d065f17df934c2bdc4d6a825] drm/tegra: dsi: fix device leak on probe
git bisect good 0f8c01ecc1771e45d065f17df934c2bdc4d6a825
# bad: [5a490afd6710b438b7fab854128d34e05e60c4bf] can: ucan: Fix infinite loop from zero-length messages
git bisect bad 5a490afd6710b438b7fab854128d34e05e60c4bf
# bad: [5ec032ae50ff9959dccf12ccf0438c4b03032e2b] can: mcp251x: fix deadlock in error path of mcp251x_open
git bisect bad 5ec032ae50ff9959dccf12ccf0438c4b03032e2b
# bad: [e2f4d521f05adb048145737f4f87125ab0452f25] scsi: storvsc: Fix scheduling while atomic on PREEMPT_RT
git bisect bad e2f4d521f05adb048145737f4f87125ab0452f25
# bad: [708f670c8e0849525742cc3a1ce319739fe74c26] bus: omap-ocp2scp:
Convert to platform remove callback returning void
git bisect bad 708f670c8e0849525742cc3a1ce319739fe74c26
# bad: [fd70655e816486140fd3b8d190e98bc0390d756b] clk: tegra:
tegra124-emc: fix device leak on set_rate()
git bisect bad fd70655e816486140fd3b8d190e98bc0390d756b
# bad: [7cea67d4c59e7351b459cef6aa062127a4501923] hwmon: (max16065) Use READ/WRITE_ONCE to avoid compiler optimization induced race git bisect bad 7cea67d4c59e7351b459cef6aa062127a4501923
# bad: [efed6d887792cb026aef5fe3b711583b56b8037f] net: arcnet:
com20020-pci: fix support for 2.5Mbit cards
git bisect bad efed6d887792cb026aef5fe3b711583b56b8037f
# bad: [dad08fee3e0e4c9c2103fe7538af96398f7a7567] net: usb: kaweth:
validate USB endpoints
git bisect bad dad08fee3e0e4c9c2103fe7538af96398f7a7567
# bad: [2529a8fc2f31887320b59699da52508055fba791] net: usb: pegasus:
validate USB endpoints
git bisect bad 2529a8fc2f31887320b59699da52508055fba791
# first bad commit: [708f670c8e0849525742cc3a1ce319739fe74c26] bus: omap-ocp2scp: Convert to platform remove callback returning void
Regards,
Ben
Quoted 6 lines
Regards
Ben
Quoted 1 line
Pavel
Quoted 4 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.10.253 release. There are 491 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Josh Law
Tested-by(Compiled and tested on my qemu arm and my qemu x86 machines, no dmesg oddities or issues that should be acknowledged)
Take my
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.10.253 release. There are 491 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Wed, 15 Apr 2026 15:57:08 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 8 lines
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.10.253-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-5.10.y
and the diffstat can be found below.thanks,
greg k-h
I took the 5.10 stable-queue as of commit 586b5ceef9af2e2148a3811f0c4814688b38b85c
("drop 4 mmc patches from queue-5.10 based on RC review feedback"), and applied it on top of 5.10.252. This is up to date with most of the patch drops after 5.10.253-rc1. I then tested the resulting kernel on my Lenovo ThinkPad T14 Gen 1. It works well and I have not observed any regressions.
(As of this writing, stable-queue is now up to commit e84a934b1e8f2f35890b51c6521a7b8678ebdc8f
("drop 1 patch from queue-5.15 and queue-5.10 based on RC review feedback") and a few more patches were dropped from cw1200 and omap-ocp2scp. However, the config I used for testing does not build either of those drivers, so I don't think it really changes anything compared to what I tested.)
Signature · 1 line
-Barry K. Nathan <[email protected]>
Re: [PATCH 5.10 491/491] io_uring/poll: correctly handle io_poll_add() return value on update
In reply to Greg Kroah-HartmanHi Jens,
the patch has some issues even after "[PATCH 2/2] io_uring/poll: fix backport of io_poll_add() changes" has been applied. Please see below.
Quoted 11 lines · Jens Axboe
From: Jens Axboe <[email protected]>
Commit
84230ad2d2afbf0c44c32967e525c0ad92e26b4eupstream.When the core of
io_uringwas updated to handle completions consistently and with fixed return codes, thePOLL_REMOVEopcode with updates got slightly broken. If aPOLL_ADDis pending and thenPOLL_REMOVEis used to update the events of that request, if that update causes thePOLL_ADDto now trigger, then that completion is lost and a CQE is never posted.
Quoted 7 lines
Additionally, ensure that if an update does cause an existing
POLL_ADDto complete, that the completion value isn't always overwritten with-ECANCELED. For that case, whateverio_poll_add()set the value to should just be retained.Fixes 97b388d70b53 ("io_uring: handle completions in the core")
This commit is not present in 5.10/5.15 in any form, to my mind. That is, io_uring changes were imported in big chunks there without preserving upstream git history in some places but still I can't find whether the changes of the mentioned Fixes-commit are present in those old kernels.
So either the Fixes tag is not completely correct or this patch can just be reverted from 5.10/5.15 stables.
Quoted 57 lines
Reported-by [email protected]Tested-by [email protected]Signed-off-by Jens Axboe <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- io_uring/io_uring.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)io_uring/io_uring.c +14
-3@@ -5980,7 +5980,7 @@ static int io_poll_add_prep(struct io_kireturn 0 ; } -static int io_poll_add (struct io_kiocb *req,unsigned int issue_flags) +static int __io_poll_add (struct io_kiocb *req,unsigned int issue_flags) {struct io_poll_iocb *poll = &req->poll;struct io_poll_table ipt;@@ -5992,11 +5992,21 @@ static int io_poll_add(struct io_kiocb *if (!ret && ipt.error)req_set_fail (req); ret = ret ?: ipt.error; -if (ret) +if (ret >0 ) {__io_req_complete (req, issue_flags, ret,0 ); +return ret; + }return 0 ; } +static int io_poll_add (struct io_kiocb *req,unsigned int issue_flags) +{ +int ret; + + ret =__io_poll_add (req, issue_flags); +return ret <0 ? ret :0 ; +} +static int io_poll_update (struct io_kiocb *req,unsigned int issue_flags) {struct io_ring_ctx *ctx = req->ctx;@@ -6012,6 +6022,7 @@ static int io_poll_update(struct io_kioc ret = preq ? -EALREADY : -ENOENT ; goto out; } + preq->result = -ECANCELED ;spin_unlock (&ctx->completion_lock);if (req->poll_update.update_events || req->poll_update.update_user_data) {@@ -6024,16 +6035,17 @@ static int io_poll_update(struct io_kiocif (req->poll_update.update_user_data) preq->user_data = req->poll_update.new_user_data; - ret2 =io_poll_add (preq, issue_flags); + ret2 =__io_poll_add (preq, issue_flags);/* successfully updated, don't complete poll request */
io_uring/io_uring.c static int io_poll_update(struct io_kioc · line 6047
Quoted 10 lines
io_uring/io_uring.c +5
-2if (!ret2) goto out; + preq->result = ret2; + } -req_set_fail (preq); -io_req_complete (preq, -ECANCELED ); +if (preq->result <0 ) +req_set_fail (preq); +io_req_complete (preq, preq->result);
preq->result is of unsigned type in 5.10/5.15 kernels so the check for negative values is a no-op here. Also as Ben pointed out in the initial report, __io_poll_add() already does complete a request if it returns non-zero result. Not sure if completing it twice is good. The extra patch from this thread doesn't address these issues.
I wonder whether these lines may be moved in the else-branch here like
io_uring/io_uring.c +3 -3
@@ -6036,10 +6036,10 @@ static int io_poll_update(struct io_kiocb *req, unsigned int issue_flags) goto out; preq->result = ret2; - } -if (preq->result <0 ) + }else {req_set_fail (preq); -io_req_complete (preq, preq->result); +io_req_complete (preq, preq->result); + } out:/* complete update request, we're done with it */ io_req_complete (req, ret);
but, again, then the __io_poll_add() surrounding logic doesn't become clear enough:
ret2 = __io_poll_add(preq, issue_flags); /* successfully updated, don't complete poll request */ if (!ret2) goto out; preq->result = ret2;
Thus currently I'm for reverting this patch if there is no bug it might fix in 5.10/5.15.
Found by Linux Verification Center (linuxtesting.org) with Svace static analysis tool.
--
Thanks,
Fedor
Sasha Levin
maintainerRe: [PATCH 5.10 491/491] io_uring/poll: correctly handle io_poll_add() return value on update
Quoted 9 lines · Fedor Pchelkin
The Fixes: tag of upstream
84230ad2d2afbpoints to97b388d70b53("io_uring: handle completions in the core", v5.19), which is NOT present in 5.10 or 5.15. Additionally, in 5.10/5.15 'preq->result' is unsigned so the 'if (preq->result< 0)' check is a no-op, and__io_poll_add()already completes the request when it returns non-zero, leading to a potential double-completion.I would suggest to revert the patch from these trees because there appears to be no real bug to fix.
Agreed. I've reverted both the original backport and the followup "fix backport" commit on 5.10 and 5.15.
--
Thanks,
Sasha
Jens Axboe
maintainerRe: [PATCH 5.10 491/491] io_uring/poll: correctly handle io_poll_add() return value on update
Quoted 8 lines · Sasha Levin
Quoted 7 lines · Fedor Pchelkin
The Fixes: tag of upstream
84230ad2d2afbpoints to97b388d70b53("io_uring: handle completions in the core", v5.19), which is NOT present in 5.10 or 5.15. Additionally, in 5.10/5.15 'preq->result' is unsigned so the 'if (preq->result< 0)' check is a no-op, and__io_poll_add()already completes the request when it returns non-zero, leading to a potential double-completion.
Quoted 5 lines
Quoted 2 lines
I would suggest to revert the patch from these trees because there appears to be no real bug to fix.
Agreed. I've reverted both the original backport and the followup "fix backport" commit on 5.10 and 5.15.
Please hold off, I have fully tested these. It's quite possible they are wonky in certain ways, but they currently fix a livelock as well that you can hit on 5.10/15 which is arguably worse. Double claim + complete should be handled by the poll grab side, I'm _assuming_ more cosmetic than anything else.
Please refrain from dropping patches until they have been confirmed by someone that actually knows the code. I've been busy today and haven't had time to look into this one just yet. You're just making more work for me by dropping this you have little insight into.
Signature · 1 line
Jens Axboe
Sasha Levin
maintainerRe: [PATCH 5.10 491/491] io_uring/poll: correctly handle io_poll_add() return value on update
Quoted 21 lines · Jens Axboe
Quoted 8 lines · Sasha Levin
Quoted 7 lines · Fedor Pchelkin
The Fixes: tag of upstream
84230ad2d2afbpoints to97b388d70b53("io_uring: handle completions in the core", v5.19), which is NOT present in 5.10 or 5.15. Additionally, in 5.10/5.15 'preq->result' is unsigned so the 'if (preq->result< 0)' check is a no-op, and__io_poll_add()already completes the request when it returns non-zero, leading to a potential double-completion.Quoted 5 lines
Quoted 2 lines
I would suggest to revert the patch from these trees because there appears to be no real bug to fix.
Agreed. I've reverted both the original backport and the followup "fix backport" commit on 5.10 and 5.15.
Please hold off, I have fully tested these. It's quite possible they are wonky in certain ways, but they currently fix a livelock as well that you can hit on 5.10/15 which is arguably worse. Double claim + complete should be handled by the poll grab side, I'm _assuming_ more cosmetic than anything else.
Quoted 4 lines
Please refrain from dropping patches until they have been confirmed by someone that actually knows the code. I've been busy today and haven't had time to look into this one just yet. You're just making more work for me by dropping this you have little insight into.
I haven't realized that this was a custom backport - I thought that they were pulled in without the Fixes commit being present.
I'll drop the revert, luckily this wasn't pushed to stable-queue yet.
Signature · 2 lines
Thanks, Sasha
Jens Axboe
maintainerRe: [PATCH 5.10 491/491] io_uring/poll: correctly handle io_poll_add() return value on update
Quoted 27 lines · Sasha Levin
Quoted 21 lines · Jens Axboe
Quoted 8 lines · Sasha Levin
Quoted 7 lines · Fedor Pchelkin
The Fixes: tag of upstream
84230ad2d2afbpoints to97b388d70b53("io_uring: handle completions in the core", v5.19), which is NOT present in 5.10 or 5.15. Additionally, in 5.10/5.15 'preq->result' is unsigned so the 'if (preq->result< 0)' check is a no-op, and__io_poll_add()already completes the request when it returns non-zero, leading to a potential double-completion.Quoted 5 lines
Quoted 2 lines
I would suggest to revert the patch from these trees because there appears to be no real bug to fix.
Agreed. I've reverted both the original backport and the followup "fix backport" commit on 5.10 and 5.15.
Please hold off, I have fully tested these. It's quite possible they are wonky in certain ways, but they currently fix a livelock as well that you can hit on 5.10/15 which is arguably worse. Double claim + complete should be handled by the poll grab side, I'm _assuming_ more cosmetic than anything else.
Quoted 4 lines
Please refrain from dropping patches until they have been confirmed by someone that actually knows the code. I've been busy today and haven't had time to look into this one just yet. You're just making more work for me by dropping this you have little insight into.
Quoted 4 lines
I haven't realized that this was a custom backport - I thought that they were pulled in without the Fixes commit being present.
I'll drop the revert, luckily this wasn't pushed to stable-queue yet.
Please just add the fixup, which should go into 5.15-stable as well of course. Both of those have been notified about previously.
Signature · 1 line
Jens Axboe
Jens Axboe
maintainerRe: [PATCH 5.10 491/491] io_uring/poll: correctly handle io_poll_add() return value on update
In reply to Fedor PchelkinQuoted 25 lines · Fedor Pchelkin
Hi Jens,
the patch has some issues even after "[PATCH 2/2]
io_uring/poll: fix backport ofio_poll_add()changes" has been applied. Please see below.Quoted 11 lines · Jens Axboe
From: Jens Axboe <[email protected]>
Commit
84230ad2d2afbf0c44c32967e525c0ad92e26b4eupstream.When the core of
io_uringwas updated to handle completions consistently and with fixed return codes, thePOLL_REMOVEopcode with updates got slightly broken. If aPOLL_ADDis pending and thenPOLL_REMOVEis used to update the events of that request, if that update causes thePOLL_ADDto now trigger, then that completion is lost and a CQE is never posted.Quoted 7 lines
Additionally, ensure that if an update does cause an existing
POLL_ADDto complete, that the completion value isn't always overwritten with-ECANCELED. For that case, whateverio_poll_add()set the value to should just be retained.Fixes 97b388d70b53 ("io_uring: handle completions in the core")
Quoted 7 lines
This commit is not present in 5.10/5.15 in any form, to my mind. That is,
io_uringchanges were imported in big chunks there without preserving upstream git history in some places but still I can't find whether the changes of the mentioned Fixes-commit are present in those old kernels.So either the Fixes tag is not completely correct or this patch can just be reverted from 5.10/5.15 stables.
The fixes tag is wrong.
Quoted 54 lines
Quoted 54 lines
Reported-by [email protected]Tested-by [email protected]Signed-off-by Jens Axboe <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- io_uring/io_uring.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)io_uring/io_uring.c +13
-2@@ -5980,7 +5980,7 @@ static int io_poll_add_prep(struct io_kireturn 0 ; } -static int io_poll_add (struct io_kiocb *req,unsigned int issue_flags) +static int __io_poll_add (struct io_kiocb *req,unsigned int issue_flags) {struct io_poll_iocb *poll = &req->poll;struct io_poll_table ipt;@@ -5992,11 +5992,21 @@ static int io_poll_add(struct io_kiocb *if (!ret && ipt.error)req_set_fail (req); ret = ret ?: ipt.error; -if (ret) +if (ret >0 ) {__io_req_complete (req, issue_flags, ret,0 ); +return ret; + }return 0 ; } +static int io_poll_add (struct io_kiocb *req,unsigned int issue_flags) +{ +int ret; + + ret =__io_poll_add (req, issue_flags); +return ret <0 ? ret :0 ; +} +static int io_poll_update (struct io_kiocb *req,unsigned int issue_flags) {struct io_ring_ctx *ctx = req->ctx;@@ -6012,6 +6022,7 @@ static int io_poll_update(struct io_kioc ret = preq ? -EALREADY : -ENOENT ; goto out; } + preq->result = -ECANCELED ;spin_unlock (&ctx->completion_lock);if (req->poll_update.update_events || req->poll_update.update_user_data) {@@ -6024,16 +6035,17 @@ static int io_poll_update(struct io_kiocif (req->poll_update.update_user_data) preq->user_data = req->poll_update.new_user_data;
Quoted 13 lines
io_uring/io_uring.c static int io_poll_update(struct io_kioc · line 6047
Quoted 13 lines
io_uring/io_uring.c +6
-3- ret2 =io_poll_add (preq, issue_flags); + ret2 =__io_poll_add (preq, issue_flags);/* successfully updated, don't complete poll request */ if (!ret2) goto out; + preq->result = ret2; + } -req_set_fail (preq); -io_req_complete (preq, -ECANCELED ); +if (preq->result <0 ) +req_set_fail (preq); +io_req_complete (preq, preq->result);
This should all be handled in the fixup patch - yes this one ended up being broken, but that's why there's the followup fix.
Now this is all pretty broken because some patches ended up in 5.15 and some in 5.10 and honestly I've almost lost track at this point. Sasha spotted some that were dropped in some broken commit from Greg. For 5.15, the two attached are what I recently asked for to be added. 5.10 should ALWAYS get the exact same patches as 5.15, because of the whole sale backport that was done years ago. I always ask for that explicitly in the emails. But looks like that wasn't always done...
5.10 doesn't look like it ever got what is sha 349ef5d2e7bfb292e7000e6041a984ab56eccf28 in 5.15-stable, hence the fixup can be merged with queueing that backport.
Sigh...
Signature · 1 line
Jens Axboe
From 7fdfffce508f38d89338e8bbed421dd91ddfcb3f Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Tue, 21 Apr 2026 16:41:32 -0600
Subject: [PATCH 1/2] io_uring/poll: fix EPOLL_URING_WAKE sometimes not being
masked in
Rather than do it only when we jump straight to execution, mark it regardless. This ensures it doesn't get lost.
--- io_uring/io_uring.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
io_uring/io_uring.c +8 -9
@@ -5794,17 +5794,16 @@ static int io_poll_wake(struct wait_queue_entry *wait, unsigned mode, int sync,if (mask && !(mask & poll->events))return 0 ; -if (io_poll_get_ownership (req)) { -/* -* If we trigger a multishot poll off our own wakeup path, -* disable multishot as there is a circular dependency between -* CQ posting and triggering the event. -*/ -if (mask &EPOLL_URING_WAKE ) - poll->events |=EPOLLONESHOT ; +/* +* If we trigger a multishot poll off our own wakeup path, +* disable multishot as there is a circular dependency between +* CQ posting and triggering the event. +*/ +if (mask &EPOLL_URING_WAKE ) + poll->events |=EPOLLONESHOT ; +if (io_poll_get_ownership (req))__io_poll_execute (req, mask); - }return 1 ; }
Signature · 1 line
2.53.0
From 7a61c38c4d6ae3d5cbe6efa06885b1ca821a129c Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Tue, 21 Apr 2026 16:44:06 -0600
Subject: [PATCH 2/2] io_uring/poll: fix backport of io_poll_add() changes
The 5.15/5.10 backport of 84230ad2d2af had a few issues, due to the older poll base. Notably return value handling __io_arm_poll_handler() and in return __io_poll_add() as well. Fix them up.
--- io_uring/io_uring.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
io_uring/io_uring.c +4 -8
@@ -6138,19 +6138,15 @@ static int __io_poll_add(struct io_kiocb *req, unsigned int issue_flags)if (!ret && ipt.error)req_set_fail (req); ret = ret ?: ipt.error; -if (ret >0 ) { +if (ret)__io_req_complete (req, issue_flags, ret,0 ); -return ret; - } -return 0 ; +return ret; }static int io_poll_add (struct io_kiocb *req,unsigned int issue_flags) { -int ret; - - ret =__io_poll_add (req, issue_flags); -return ret <0 ? ret :0 ; +__io_poll_add (req, issue_flags); +return 0 ; }static int io_poll_update (struct io_kiocb *req,unsigned int issue_flags)
Signature · 1 line
2.53.0
Jens Axboe
maintainerRe: [PATCH 5.10 491/491] io_uring/poll: correctly handle io_poll_add() return value on update
Quoted 11 lines · Jens Axboe
This should all be handled in the fixup patch - yes this one ended up being broken, but that's why there's the followup fix.
Now this is all pretty broken because some patches ended up in 5.15 and some in 5.10 and honestly I've almost lost track at this point. Sasha spotted some that were dropped in some broken commit from Greg. For 5.15, the two attached are what I recently asked for to be added. 5.10 should ALWAYS get the exact same patches as 5.15, because of the whole sale backport that was done years ago. I always ask for that explicitly in the emails. But looks like that wasn't always done...
Quoted 3 lines
5.10 doesn't look like it ever got what is sha
349ef5d2e7bfb292e7000e6041a984ab56eccf28in 5.15-stable, hence the fixup can be merged with queueing that backport.
That did get included for 5.10.253 - what's needed is the fixup that was added to the 5.15 queue as well. Which I think got reverted with a bunch of other stuff by mistake? At least it was sent in / reminded about earlier as well.
Signature · 1 line
Jens Axboe
Re: [PATCH 5.10 491/491] io_uring/poll: correctly handle io_poll_add() return value on update
In reply to Jens AxboeQuoted 29 lines · Jens Axboe
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0
-0@@ -6024,16 +6035,17 @@ static int io_poll_update(struct io_kioc if (req->poll_update.update_user_data) preq->user_data = req->poll_update.new_user_data;Quoted 13 lines
Review static int io_poll_update(struct io_kioc · line 6047
Quoted 13 lines
(quoted diff) +6
-3- ret2 = io_poll_add(preq, issue_flags); + ret2 = __io_poll_add(preq, issue_flags); /* successfully updated, don't complete poll request */ if (!ret2) goto out; + preq->result = ret2; + } - req_set_fail(preq); - io_req_complete(preq, -ECANCELED); + if (preq->result < 0) + req_set_fail(preq); + io_req_complete(preq, preq->result);This should all be handled in the fixup patch - yes this one ended up being broken, but that's why there's the followup fix.
Now this is all pretty broken because some patches ended up in 5.15 and some in 5.10 and honestly I've almost lost track at this point. Sasha spotted some that were dropped in some broken commit from Greg. For 5.15, the two attached are what I recently asked for to be added. 5.10 should ALWAYS get the exact same patches as 5.15, because of the whole sale backport that was done years ago. I always ask for that explicitly in the emails. But looks like that wasn't always done...
Quoted 5 lines
5.10 doesn't look like it ever got what is sha
349ef5d2e7bfb292e7000e6041a984ab56eccf28in 5.15-stable, hence the fixup can be merged with queueing that backport.Sigh...
Oh, for the fixup patch - it is in the 5.10-queue (or at least was when I wrote up report today). It was taken into consideration. The concern for the Fixes tag is resolved now by you, thanks for clarification.
But that if (preq->result) < 0 thing is not covered by the fixup patch. This check is not correct in 5.10/5.15 because preq->result is unsigned.
Taken that double complete is OK (I had doubts about that), the following change should do the job now:
io_uring/io_uring.c +2 -2
@@ -6006,7 +6006,7 @@ static int io_poll_update(struct io_kiocb *req, unsigned int issue_flags) {struct io_ring_ctx *ctx = req->ctx;struct io_kiocb *preq; -int ret2, ret =0 ; +int ret2 = -ECANCELED , ret =0 ;io_ring_submit_lock (ctx, !(issue_flags &IO_URING_F_NONBLOCK ));
@@ -6037,7 +6037,7 @@ static int io_poll_update(struct io_kiocb *req, unsigned int issue_flags) preq->result = ret2; } -if (preq->result <0 ) +if (ret2 <0 )req_set_fail (preq);io_req_complete (preq, preq->result); out:
The fixup patch may be updated with this if the changes look OK.
--
Thanks,
Fedor
Re: [PATCH 5.10 491/491] io_uring/poll: correctly handle io_poll_add() return value on update
Quoted 70 lines · Fedor Pchelkin
Quoted 29 lines · Jens Axboe
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0
-0@@ -6024,16 +6035,17 @@ static int io_poll_update(struct io_kioc if (req->poll_update.update_user_data) preq->user_data = req->poll_update.new_user_data;Quoted 13 lines
Review static int io_poll_update(struct io_kioc · line 6047
Quoted 13 lines
(quoted diff) +6
-3- ret2 = io_poll_add(preq, issue_flags); + ret2 = __io_poll_add(preq, issue_flags); /* successfully updated, don't complete poll request */ if (!ret2) goto out; + preq->result = ret2; + } - req_set_fail(preq); - io_req_complete(preq, -ECANCELED); + if (preq->result < 0) + req_set_fail(preq); + io_req_complete(preq, preq->result);This should all be handled in the fixup patch - yes this one ended up being broken, but that's why there's the followup fix.
Now this is all pretty broken because some patches ended up in 5.15 and some in 5.10 and honestly I've almost lost track at this point. Sasha spotted some that were dropped in some broken commit from Greg. For 5.15, the two attached are what I recently asked for to be added. 5.10 should ALWAYS get the exact same patches as 5.15, because of the whole sale backport that was done years ago. I always ask for that explicitly in the emails. But looks like that wasn't always done...
Quoted 5 lines
5.10 doesn't look like it ever got what is sha
349ef5d2e7bfb292e7000e6041a984ab56eccf28in 5.15-stable, hence the fixup can be merged with queueing that backport.Sigh...
Oh, for the fixup patch - it is in the 5.10-queue (or at least was when I wrote up report today). It was taken into consideration. The concern for the Fixes tag is resolved now by you, thanks for clarification.
But that
if (preq->result) < 0thing is not covered by the fixup patch. This check is not correct in 5.10/5.15 becausepreq->resultis unsigned.Taken that double complete is OK (I had doubts about that), the following change should do the job now:
io_uring/io_uring.c +2
-2@@ -6006,7 +6006,7 @@ static int io_poll_update(struct io_kiocb *req, unsigned int issue_flags) {struct io_ring_ctx *ctx = req->ctx;struct io_kiocb *preq; -int ret2, ret =0 ; +int ret2 = -ECANCELED , ret =0 ;io_ring_submit_lock (ctx, !(issue_flags &IO_URING_F_NONBLOCK ));@@ -6037,7 +6037,7 @@ static int io_poll_update(struct io_kiocb *req, unsigned int issue_flags) preq->result = ret2; } -if (preq->result <0 ) +if (ret2 <0 )req_set_fail (preq);io_req_complete (preq, preq->result); out:
Quoted 2 lines
The fixup patch may be updated with this if the changes look OK.
Or maybe this one which is less hassle:
io_uring/io_uring.c +1 -1
@@ -6037,7 +6037,7 @@ static int io_poll_update(struct io_kiocb *req, unsigned int issue_flags) preq->result = ret2; } -if (preq->result <0 ) +if (preq->result)req_set_fail (preq);io_req_complete (preq, preq->result); out:
--
Thanks,
Fedor
Jens Axboe
maintainerRe: [PATCH 5.10 491/491] io_uring/poll: correctly handle io_poll_add() return value on update
Quoted 81 lines · Fedor Pchelkin
Quoted 70 lines · Fedor Pchelkin
Quoted 29 lines · Jens Axboe
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0
-0@@ -6024,16 +6035,17 @@ static int io_poll_update(struct io_kioc if (req->poll_update.update_user_data) preq->user_data = req->poll_update.new_user_data;Quoted 13 lines
Review static int io_poll_update(struct io_kioc · line 6047
Quoted 13 lines
(quoted diff) +6
-3- ret2 = io_poll_add(preq, issue_flags); + ret2 = __io_poll_add(preq, issue_flags); /* successfully updated, don't complete poll request */ if (!ret2) goto out; + preq->result = ret2; + } - req_set_fail(preq); - io_req_complete(preq, -ECANCELED); + if (preq->result < 0) + req_set_fail(preq); + io_req_complete(preq, preq->result);This should all be handled in the fixup patch - yes this one ended up being broken, but that's why there's the followup fix.
Now this is all pretty broken because some patches ended up in 5.15 and some in 5.10 and honestly I've almost lost track at this point. Sasha spotted some that were dropped in some broken commit from Greg. For 5.15, the two attached are what I recently asked for to be added. 5.10 should ALWAYS get the exact same patches as 5.15, because of the whole sale backport that was done years ago. I always ask for that explicitly in the emails. But looks like that wasn't always done...
Quoted 5 lines
5.10 doesn't look like it ever got what is sha
349ef5d2e7bfb292e7000e6041a984ab56eccf28in 5.15-stable, hence the fixup can be merged with queueing that backport.Sigh...
Oh, for the fixup patch - it is in the 5.10-queue (or at least was when I wrote up report today). It was taken into consideration. The concern for the Fixes tag is resolved now by you, thanks for clarification.
But that
if (preq->result) < 0thing is not covered by the fixup patch. This check is not correct in 5.10/5.15 becausepreq->resultis unsigned.Taken that double complete is OK (I had doubts about that), the following change should do the job now:
io_uring/io_uring.c +2
-2@@ -6006,7 +6006,7 @@ static int io_poll_update(struct io_kiocb *req, unsigned int issue_flags) {struct io_ring_ctx *ctx = req->ctx;struct io_kiocb *preq; -int ret2, ret =0 ; +int ret2 = -ECANCELED , ret =0 ;io_ring_submit_lock (ctx, !(issue_flags &IO_URING_F_NONBLOCK ));@@ -6037,7 +6037,7 @@ static int io_poll_update(struct io_kiocb *req, unsigned int issue_flags) preq->result = ret2; } -if (preq->result <0 ) +if (ret2 <0 )req_set_fail (preq);io_req_complete (preq, preq->result); out:Quoted 2 lines
The fixup patch may be updated with this if the changes look OK.
Or maybe this one which is less hassle:
io_uring/io_uring.c +0
-0
io_uring/io_uring.c static int io_poll_update(struct io_kiocb *req, unsigned int issue_flags) · line 6043
Quoted 8 lines
io_uring/io_uring.c +1
-1@@ -6037,7 +6037,7 @@ static int io_poll_update(struct io_kiocb *req, unsigned int issue_flags) preq->result = ret2; } -if (preq->result <0 ) +if (preq->result)req_set_fail (preq);io_req_complete (preq, preq->result); out:
That'd be fine. Note that both your patches are white space damaged. I can send out updated fixup patches, the above does improve them. But at this point I don't even know what is queued up where. As far as I can tell neither 5.10-stable or 5.15-stable have the fixup queued up yet, even though I asked for it 10 days ago. Neither the fixup, nor the EPOLL_URING_WAKE patch.
I feel like I spend a lot of time both on stable, and defending stable against people that complain about it. And usually it's all been fine, but lately it does seem like a bit of a mess :(, and as a maintainer, I absolutely 100% need to rely on stable doing what they are asked to do, and if patches fail, then I need to know about it. If patches get yanked for whatever reason, I need to get asked. And if I ask for patches to get included and I get an ack, I should not need to scour various stable branches to check if that actually happened or not.
So let me make it VERY clear - apply the two attached patches to BOTH 5.10-stable and 5.15-stable. Thank you.
Signature · 1 line
Jens Axboe
From 240211bd8270ea42440b1775e4d7bc005908cd46 Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Tue, 21 Apr 2026 16:41:32 -0600
Subject: [PATCH 1/2] io_uring/poll: fix EPOLL_URING_WAKE sometimes not being
masked in
Rather than do it only when we jump straight to execution, mark it regardless. This ensures it doesn't get lost.
--- io_uring/io_uring.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
io_uring/io_uring.c +8 -9
@@ -5794,17 +5794,16 @@ static int io_poll_wake(struct wait_queue_entry *wait, unsigned mode, int sync,if (mask && !(mask & poll->events))return 0 ; -if (io_poll_get_ownership (req)) { -/* -* If we trigger a multishot poll off our own wakeup path, -* disable multishot as there is a circular dependency between -* CQ posting and triggering the event. -*/ -if (mask &EPOLL_URING_WAKE ) - poll->events |=EPOLLONESHOT ; +/* +* If we trigger a multishot poll off our own wakeup path, +* disable multishot as there is a circular dependency between +* CQ posting and triggering the event. +*/ +if (mask &EPOLL_URING_WAKE ) + poll->events |=EPOLLONESHOT ; +if (io_poll_get_ownership (req))__io_poll_execute (req, mask); - }return 1 ; }
Signature · 1 line
2.53.0
From 8f1a401b0fce5a46935153f8572b0681d5b9a00d Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Tue, 21 Apr 2026 16:44:06 -0600
Subject: [PATCH 2/2] io_uring/poll: fix backport of io_poll_add() changes
The 5.15/5.10 backport of 84230ad2d2af had a few issues, due to the older poll base. Notably return value handling __io_arm_poll_handler() and in return __io_poll_add() as well. Fix them up.
--- io_uring/io_uring.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
io_uring/io_uring.c +5 -9
@@ -6138,19 +6138,15 @@ static int __io_poll_add(struct io_kiocb *req, unsigned int issue_flags)if (!ret && ipt.error)req_set_fail (req); ret = ret ?: ipt.error; -if (ret >0 ) { +if (ret)__io_req_complete (req, issue_flags, ret,0 ); -return ret; - } -return 0 ; +return ret; }static int io_poll_add (struct io_kiocb *req,unsigned int issue_flags) { -int ret; - - ret =__io_poll_add (req, issue_flags); -return ret <0 ? ret :0 ; +__io_poll_add (req, issue_flags); +return 0 ; }static int io_poll_update (struct io_kiocb *req,unsigned int issue_flags)
@@ -6188,7 +6184,7 @@ static int io_poll_update(struct io_kiocb *req, unsigned int issue_flags) preq->result = ret2; } -if (preq->result <0 ) +if (ret2 <0 )req_set_fail (preq);io_req_complete (preq, preq->result); out:
Signature · 1 line
2.53.0
Re: [PATCH 5.10 491/491] io_uring/poll: correctly handle io_poll_add() return value on update
Quoted 37 lines · Jens Axboe
Quoted 36 lines · Fedor Pchelkin
Quoted 24 lines
io_uring/io_uring.c +2
-2@@ -6006,7 +6006,7 @@ static int io_poll_update(struct io_kiocb *req, unsigned int issue_flags) {struct io_ring_ctx *ctx = req->ctx;struct io_kiocb *preq; -int ret2, ret =0 ; +int ret2 = -ECANCELED , ret =0 ;io_ring_submit_lock (ctx, !(issue_flags &IO_URING_F_NONBLOCK ));@@ -6037,7 +6037,7 @@ static int io_poll_update(struct io_kiocb *req, unsigned int issue_flags) preq->result = ret2; } -if (preq->result <0 ) +if (ret2 <0 )req_set_fail (preq);io_req_complete (preq, preq->result); out:Quoted 2 lines
The fixup patch may be updated with this if the changes look OK.
Or maybe this one which is less hassle:
io_uring/io_uring.c +0
-0@@ -6037,7 +6037,7 @@ static int io_poll_update(struct io_kiocb *req, unsigned int issue_flags) preq->result = ret2;
Quoted 8 lines
io_uring/io_uring.c static int io_poll_update(struct io_kiocb *req, unsigned int issue_flags) · line 6190
Quoted 6 lines
io_uring/io_uring.c +1
-1} -if (preq->result <0 ) +if (preq->result)req_set_fail (preq);io_req_complete (preq, preq->result); out:That'd be fine. Note that both your patches are white space damaged. I
Argh, my fault.
Quoted 5 lines
can send out updated fixup patches, the above does improve them. But at this point I don't even know what is queued up where. As far as I can tell neither 5.10-stable or 5.15-stable have the fixup queued up yet, even though I asked for it 10 days ago. Neither the fixup, nor the
EPOLL_URING_WAKEpatch.
They've been queued up to 5.10 and 5.15. The queues are available at [1,2] from the official kernel git web urls.
[1]: https://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git/tree/
[2]: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git/
While being in queue, the patches may be fixed up by stable maintainers if I'm correct.
Quoted 4 lines
From
8f1a401b0fce5a46935153f8572b0681d5b9a00dMon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Tue, 21 Apr 2026 16:44:06 -0600
Subject: [PATCH 2/2]io_uring/poll: fix backport ofio_poll_add()changes
[...]
io_uring/io_uring.c static int io_poll_update(struct io_kiocb *req, unsigned int issue_flags) · line 6190
Quoted 9 lines
io_uring/io_uring.c +1
-1@@ -6188,7 +6184,7 @@ static int io_poll_update(struct io_kiocb *req, unsigned int issue_flags) preq->result = ret2; } -if (preq->result <0 ) +if (ret2 <0 )req_set_fail (preq);io_req_complete (preq, preq->result); out:
I'm really uncomfortable to raise this but - ret2 should be initialized in beginning of the function io_poll_update().
Jens Axboe
maintainerRe: [PATCH 5.10 491/491] io_uring/poll: correctly handle io_poll_add() return value on update
Quoted 12 lines · Fedor Pchelkin
io_uring/io_uring.c static int io_poll_update(struct io_kiocb *req, unsigned int issue_flags) · line 6190
Quoted 9 lines
io_uring/io_uring.c +1
-1@@ -6188,7 +6184,7 @@ static int io_poll_update(struct io_kiocb *req, unsigned int issue_flags) preq->result = ret2; } -if (preq->result <0 ) +if (ret2 <0 )req_set_fail (preq);io_req_complete (preq, preq->result); out:I'm really uncomfortable to raise this but - ret2 should be initialized in beginning of the function
io_poll_update().
It's your second version... I'll send out a new set.
Signature · 1 line
Jens Axboe
Jens Axboe
maintainerRe: [PATCH 5.10 491/491] io_uring/poll: correctly handle io_poll_add() return value on update
Quoted 14 lines · Jens Axboe
Quoted 12 lines · Fedor Pchelkin
Review static int io_poll_update(struct io_kiocb *req, unsigned int issue_flags) · line 6190
Quoted 9 lines
(quoted diff) +1
-1@@ -6188,7 +6184,7 @@ static int io_poll_update(struct io_kiocb *req, unsigned int issue_flags) preq->result = ret2; } - if (preq->result < 0) + if (ret2 < 0) req_set_fail(preq); io_req_complete(preq, preq->result); out:I'm really uncomfortable to raise this but - ret2 should be initialized in beginning of the function
io_poll_update().
Quoted 1 line
It's your second version... I'll send out a new set.
OK, here's the new set for both 5.10-stable and 5.15-stable. Ran it through the usual testing.
Let's hope we can put this one to bed now :-)
Signature · 1 line
Jens Axboe
From 38ebae3b93403e03d2e6a44afd2d980cce49db8c Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Tue, 21 Apr 2026 16:41:32 -0600
Subject: [PATCH 1/2] io_uring/poll: fix EPOLL_URING_WAKE sometimes not being
honored
Rather than do the masking only when we jump straight to execution, mark it as EPOLLONESHOT regardless. This ensures it doesn't get lost. And just kill the poll entry upfront, if marked. This is an optimization in later kernels, but it's actually required on the older kernels to note the EPOLL_URING_WAKE mask correctly.
--- io_uring/io_uring.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
io_uring/io_uring.c +12 -7
@@ -5794,14 +5794,19 @@ static int io_poll_wake(struct wait_queue_entry *wait, unsigned mode, int sync,if (mask && !(mask & poll->events))return 0 ; +/* +* If we trigger a multishot poll off our own wakeup path, +* disable multishot as there is a circular dependency between +* CQ posting and triggering the event. +*/ +if (mask &EPOLL_URING_WAKE ) + poll->events |=EPOLLONESHOT ; +if (io_poll_get_ownership (req)) { -/* -* If we trigger a multishot poll off our own wakeup path, -* disable multishot as there is a circular dependency between -* CQ posting and triggering the event. -*/ -if (mask &EPOLL_URING_WAKE ) - poll->events |=EPOLLONESHOT ; +if (mask && poll->events &EPOLLONESHOT ) { +list_del_init (&poll->wait.entry); +smp_store_release (&poll->head,NULL ); + }__io_poll_execute (req, mask); }
Signature · 1 line
2.53.0
From 1a074b61239613231b0d6cb68a33b001ca8e46ce Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Tue, 21 Apr 2026 16:44:06 -0600
Subject: [PATCH 2/2] io_uring/poll: fix backport of io_poll_add() changes
The 5.15/5.10 backport of 84230ad2d2af had a few issues, due to the older poll base. Notably return value handling __io_arm_poll_handler() and in return __io_poll_add() as well. Fix them up.
--- io_uring/io_uring.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
io_uring/io_uring.c +6 -10
@@ -6144,26 +6144,22 @@ static int __io_poll_add(struct io_kiocb *req, unsigned int issue_flags)if (!ret && ipt.error)req_set_fail (req); ret = ret ?: ipt.error; -if (ret >0 ) { +if (ret)__io_req_complete (req, issue_flags, ret,0 ); -return ret; - } -return 0 ; +return ret; }static int io_poll_add (struct io_kiocb *req,unsigned int issue_flags) { -int ret; - - ret =__io_poll_add (req, issue_flags); -return ret <0 ? ret :0 ; +__io_poll_add (req, issue_flags); +return 0 ; }static int io_poll_update (struct io_kiocb *req,unsigned int issue_flags) {struct io_ring_ctx *ctx = req->ctx;struct io_kiocb *preq; -int ret2, ret =0 ; +int ret2 = -ECANCELED , ret =0 ;io_ring_submit_lock (ctx, !(issue_flags &IO_URING_F_NONBLOCK ));
@@ -6194,7 +6190,7 @@ static int io_poll_update(struct io_kiocb *req, unsigned int issue_flags) preq->result = ret2; } -if (preq->result <0 ) +if (ret2 <0 )req_set_fail (preq);io_req_complete (preq, preq->result); out:
Signature · 1 line
2.53.0
Re: [PATCH 5.10 491/491] io_uring/poll: correctly handle io_poll_add() return value on update
Quoted 4 lines · Jens Axboe
OK, here's the new set for both 5.10-stable and 5.15-stable. Ran it through the usual testing.
Let's hope we can put this one to bed now :-)
Hope so as well. Thank you for the updated patches!
Sasha Levin
maintainerRe: [PATCH 5.10 491/491] io_uring/poll: correctly handle io_poll_add() return value on update
In reply to Jens AxboeQuoted 2 lines · Jens Axboe
OK, here's the new set for both 5.10-stable and 5.15-stable. Ran it through the usual testing. Let's hope we can put this one to bed now.
Done. On both pending-5.10 and pending-5.15 I reverted the previously queued v1 pair and applied the new attached set on top.
--
Thanks,
Sasha