7.3.6-rc1 review
Subsystems (4)
Greg Kroah-Hartman
maintainerPATCH 2035/2651 HID: logitech-hidpp: cancel reset_hi_res_work on probe failure
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitriy Geels <[email protected]>
[ Upstream commit 0be03caba6c002385e74d60be934b961aa5e88dc ]
The probe error path cancels hidpp->work before freeing the HID++ device data, but does not cancel reset_hi_res_work.
reset_hi_res_work can be scheduled while probing the device. If probe subsequently fails, the work can run after the driver data has been freed.
Cancel reset_hi_res_work in the probe error path to prevent a potential use-after-free.
--- drivers/hid/hid-logitech-hidpp.c | 1 + 1 file changed, 1 insertion(+)
drivers/hid/hid-logitech-hidpp.c +1 -0
@@ -4791,6 +4791,7 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) hid_hw_start_fail:sysfs_remove_group (&hdev->dev.kobj, &ps_attribute_group);cancel_work_sync (&hidpp->work); +cancel_work_sync (&hidpp->reset_hi_res_work);mutex_destroy (&hidpp->send_mutex);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2036/2651 HID: wacom: fix wacom_intuos_irq NULL pen_input deref
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matheus Alves de Almeida <[email protected]>
[ Upstream commit 2f985de0afbe9366af9d322ea20589712c1dc8fe ]
Currently, wacom_intuos_irq() passes the parent of wacom_wac's pen_input to the dev_dbg() in the unknown report path. However, pen_input can be NULL on interfaces without a pen, causing a NULL pointer dereference.
Get the HID device from the enclosing struct wacom and use hid_dbg() instead.
--- drivers/hid/wacom_wac.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/hid/wacom_wac.c +7 -7
@@ -1027,10 +1027,10 @@ static int wacom_intuos_general(struct wacom_wac *wacom)return 2 ; } -static int wacom_intuos_irq (struct wacom_wac *wacom) +static int wacom_intuos_irq (struct wacom_wac *wacom_wac) { -unsigned char *data = wacom->data; -struct input_dev *input = wacom->pen_input; +unsigned char *data = wacom_wac->data; + struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);int result; if (data[0] != WACOM_REPORT_PENABLED &&
@@ -1041,23 +1041,23 @@ static int wacom_intuos_irq(struct wacom_wac *wacom) data[0] != WACOM_REPORT_CINTIQ && data[0] != WACOM_REPORT_CINTIQPAD && data[0] != WACOM_REPORT_INTUOS5PAD) { -dev_dbg (input->dev.parent, +hid_dbg (wacom->hdev,"%s: received unknown report #%d\n" , __func__, data[0 ]);return 0 ; }/* process pad events */ - result =wacom_intuos_pad (wacom); + result =wacom_intuos_pad (wacom_wac);if (result)return result;/* process in/out prox events */ - result =wacom_intuos_inout (wacom); + result =wacom_intuos_inout (wacom_wac);if (result)return result -1 ;/* process general packets */ - result =wacom_intuos_general (wacom); + result =wacom_intuos_general (wacom_wac);if (result)return result -1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2037/2651 fuse: fix NULL pointer dereference in fuse_request_find
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Miklos Szeredi <[email protected]>
[ Upstream commit f8cef5c74d8b5a982f49cc40d13cd5c3ea2eacf6 ]
fuse_dev_install_with_pq() publishes fud->chan before it stores fud->pq.processing. The write/splice_write and read paths treat a non-NULL fud->chan as "installed" and then walk fpq->processing[] without taking fch->lock, so they can see the new chan while processing is still NULL and oops in fuse_request_find().
Fix by taking fpq->lock around the cmpxchg + fud->pq.processing assignment. This protects all call sites that dereference fpq->processing, since these have fpq->lock held.
--- fs/fuse/dev.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-)
fs/fuse/dev.c +19 -16
@@ -466,24 +466,27 @@ static bool fuse_dev_install_with_pq(struct fuse_dev *fud, struct fuse_chan *fchstruct fuse_chan *old_fch;guard (spinlock)(&fch->lock); -/* -* Pairs with: -* - xchg() in fuse_dev_release() -* - smp_load_acquire() in fuse_dev_fc_get() -*/ - old_fch =cmpxchg (&fud->chan,NULL , fch); -if (old_fch) { +/* protect fud->pq.processing assignment */ + scoped_guard(spinlock, &fud->pq.lock) {/* -* failed to set fud->chan because -* - it was already set to a different fc -* - it was set to disconneted +* Pairs with: +* - xchg() in fuse_dev_release() +* - smp_load_acquire() in fuse_dev_fc_get() */ -kfree (pq); -return false; - } -if (pq) { -WARN_ON (fud->pq.processing); - fud->pq.processing = pq; + old_fch =cmpxchg (&fud->chan,NULL , fch); +if (old_fch) { +/* +* failed to set fud->chan because +* - it was already set to a different fc +* - it was set to disconneted +*/ +kfree (pq); +return false; + } +if (pq) { +WARN_ON (fud->pq.processing); + fud->pq.processing = pq; + } }list_add_tail (&fud->entry, &fch->devices);fuse_conn_get (fch->conn);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2038/2651 fuse: validate folio state before pipe_buf_try_steal() in fuse_try_move_folio()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hui Peng <[email protected]>
[ Upstream commit 15c20483d91589f868fe7a72aec4b97dc68b931b ]
In fuse_try_move_folio(), check that the pipe buffer's folio is not hugetlb, swap-backed, or already mapped/anon before attempting pipe_buf_try_steal() and inserting it into the FUSE inode's page cache, preventing VM_BUG_ON_FOLIO() and page cache state corruption.
--- fs/fuse/dev.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
fs/fuse/dev.c +13 -13
@@ -1151,32 +1151,32 @@ static int fuse_try_move_folio(struct fuse_copy_state *cs, struct folio **foliopif (cs->len !=folio_size (oldfolio)) goto out_fallback; -if (!pipe_buf_try_steal (cs->pipe, buf)) - goto out_fallback; - newfolio =page_folio (buf->page); -folio_clear_uptodate (newfolio); -folio_clear_mappedtodisk (newfolio); -if (folio_test_large (newfolio)) - goto out_fallback_unlock; - -if (fuse_check_folio (newfolio) !=0 ) - goto out_fallback_unlock; + goto out_fallback;/* * This is a new and locked page, it shouldn't be mapped or * have any special flags on it */ if (WARN_ON (folio_mapped (oldfolio))) - goto out_fallback_unlock; + goto out_fallback;if (WARN_ON (folio_has_private (oldfolio))) - goto out_fallback_unlock; + goto out_fallback;if (WARN_ON (folio_test_dirty (oldfolio) ||folio_test_writeback (oldfolio))) - goto out_fallback_unlock; + goto out_fallback;if (WARN_ON (folio_test_mlocked (oldfolio))) + goto out_fallback; + +if (!pipe_buf_try_steal (cs->pipe, buf)) + goto out_fallback; + +folio_clear_uptodate (newfolio); +folio_clear_mappedtodisk (newfolio); + +if (fuse_check_folio (newfolio) !=0 ) goto out_fallback_unlock; err =lock_request (cs->req);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2039/2651 drm/appletbdrm: Fix incorrect error message on encoder attach failure
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adam Azuddin <[email protected]>
[ Upstream commit fa6d4c16f7a0da6dce3eb36a3139bfe01d071f18 ]
drm_connector_attach_encoder() replaced an earlier call to drm_simple_display_pipe_init() during review, but the error message logged on failure was not updated to match and still refers to the old call.
--- drivers/gpu/drm/tiny/appletbdrm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/tiny/appletbdrm.c +1 -1
@@ -725,7 +725,7 @@ static int appletbdrm_setup_mode_config(struct appletbdrm_device *adev) ret =drm_connector_attach_encoder (connector, encoder);if (ret) { -drm_err (drm,"Failed to initialize simple display pipe\n" ); +drm_err (drm,"Failed to attach connector to encoder\n" );return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2040/2651 drm/panthor: Dont invalidate OTHER caches
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Boris Brezillon <[email protected]>
[ Upstream commit b1bbfb6c0245cd35ad197d290e26ee1cdee467ff ]
Don't invalidate the OTHER caches (AKA L1 read-only caches) since this seems to trip out the flush-elimination logic on v13, and it's not needed in practice (can't leak other context data because of TLB invalidation or corrupt physical pages returned to the system because it's a RO cache).
It's also worth noting that the downstream driver has been avoid OTHER caches invalidation from the start, and that we were doing the same until atomic page table update was introduced.
--- drivers/gpu/drm/panthor/panthor_mmu.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/gpu/drm/panthor/panthor_mmu.c +3 -4
@@ -634,7 +634,7 @@ static int panthor_mmu_as_disable(struct panthor_device *ptdev, u32 as_nr,/* Flush+invalidate RW caches, invalidate RO ones. */ ret =panthor_gpu_flush_caches (ptdev,CACHE_CLEAN |CACHE_INV , -CACHE_CLEAN |CACHE_INV ,CACHE_INV ); +CACHE_CLEAN |CACHE_INV ,0 );if (ret)return ret;
@@ -1836,13 +1836,12 @@ static void panthor_vm_unlock_region(struct panthor_vm *vm)if (vm->as.id >=0 ) {int ret; -/* flush+invalidate RW caches and invalidate RO ones. +/* flush+invalidate RW caches. * TODO: See if we can use FLUSH_PA_RANGE when the physical * range is narrow enough and the HW supports it. */ ret =panthor_gpu_flush_caches (ptdev,CACHE_CLEAN |CACHE_INV , -CACHE_CLEAN |CACHE_INV , -CACHE_INV ); +CACHE_CLEAN |CACHE_INV ,0 );/* Unlock the region if the flush is effective. */ if (!ret)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2041/2651 drm/panthor: Fully disable the AS even if its going to be re-assigned
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Boris Brezillon <[email protected]>
[ Upstream commit a431d4ec5d938893060f69a018a2c47651c282d9 ]
We're trying to be smart by skipping the UPDATE(UNMAPPED) step, but it remains to be proven it adds any noticeable overhead. Moreover, it's breaking the assumption that, once the VM is unbound, no access can happen on it.
For instance, say the panthor_mmu_as_enable() call in panthor_vm_active() fails after we've called panthor_vm_release_as_locked(), we're now in a state where the HW still points to the old page table, but SW slot points to the new VM, which is not truly HW-bound.
If, after the as_slots lock is released, the evicted VM itself is released, the HW might have access to memory that has been returned to the system until the reset we scheduled (because of the faulty AS_COMMAND) is effective.
Let's make this bullet-proof by doing a full bound -> unbound -> bound cycle on AS slot recycling.
--- drivers/gpu/drm/panthor/panthor_mmu.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-)
drivers/gpu/drm/panthor/panthor_mmu.c +7 -14
@@ -620,8 +620,7 @@ static int panthor_mmu_as_enable(struct panthor_device *ptdev, u32 as_nr,return as_send_cmd_and_wait (ptdev, as_nr,AS_COMMAND_UPDATE ); } -static int panthor_mmu_as_disable (struct panthor_device *ptdev,u32 as_nr, -bool recycle_slot) +static int panthor_mmu_as_disable (struct panthor_device *ptdev,u32 as_nr) {struct panthor_mmu *mmu = ptdev->mmu;struct panthor_vm *vm = ptdev->mmu->as.slots[as_nr].vm;
@@ -645,12 +644,6 @@ static int panthor_mmu_as_disable(struct panthor_device *ptdev, u32 as_nr,return ret; } -/* If the slot is going to be used immediately, don't bother changing -* the config. -*/ -if (recycle_slot) -return 0 ; -gpu_write64 (mmu->iomem,AS_TRANSTAB (as_nr),0 );gpu_write64 (mmu->iomem,AS_MEMATTR (as_nr),0 );gpu_write64 (mmu->iomem,AS_TRANSCFG (as_nr),AS_TRANSCFG_ADRMODE_UNMAPPED );
@@ -777,7 +770,7 @@ int panthor_vm_active(struct panthor_vm *vm)drm_WARN_ON (&ptdev->base,refcount_read (&lru_vm->as.active_cnt)); as = lru_vm->as.id; - ret =panthor_mmu_as_disable (ptdev, as, true); + ret =panthor_mmu_as_disable (ptdev, as);if (ret) goto out_unlock;
@@ -919,7 +912,7 @@ static void panthor_vm_declare_unusable(struct panthor_vm *vm) vm->unusable = true;mutex_lock (&ptdev->mmu->as.slots_lock);if (vm->as.id >=0 &&drm_dev_enter (&ptdev->base, &cookie)) { -panthor_mmu_as_disable (ptdev, vm->as.id, false); +panthor_mmu_as_disable (ptdev, vm->as.id);drm_dev_exit (cookie); }mutex_unlock (&ptdev->mmu->as.slots_lock);
@@ -1911,7 +1904,7 @@ static void panthor_mmu_irq_handler(struct panthor_device *ptdev, u32 status) ptdev->mmu->as.slots[as].vm->unhandled_fault = true;/* Disable the MMU to kill jobs on this AS. */ -panthor_mmu_as_disable (ptdev, as, false); +panthor_mmu_as_disable (ptdev, as);mutex_unlock (&ptdev->mmu->as.slots_lock); status &= ~mask;
@@ -1940,7 +1933,7 @@ void panthor_mmu_suspend(struct panthor_device *ptdev)if (vm) {drm_WARN_ON (&ptdev->base, -panthor_mmu_as_disable (ptdev, i, false)); +panthor_mmu_as_disable (ptdev, i));panthor_vm_release_as_locked (vm); } }
@@ -2065,7 +2058,7 @@ static void panthor_vm_free(struct drm_gpuvm *gpuvm)int cookie;if (drm_dev_enter (&ptdev->base, &cookie)) { -panthor_mmu_as_disable (ptdev, vm->as.id, false); +panthor_mmu_as_disable (ptdev, vm->as.id);drm_dev_exit (cookie); }
@@ -3360,7 +3353,7 @@ void panthor_mmu_unplug(struct panthor_device *ptdev)if (vm) {drm_WARN_ON (&ptdev->base, -panthor_mmu_as_disable (ptdev, i, false)); +panthor_mmu_as_disable (ptdev, i));panthor_vm_release_as_locked (vm); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2042/2651 pinctrl: stm32: Fix the unit of the hwspinlock timeout
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ju Nan <[email protected]>
[ Upstream commit 544b3f8042dd7c18baa48dcb1a393ff8b6742322 ]
HWSPNLCK_TIMEOUT is passed to hwspin_lock_timeout_in_atomic(), whose timeout argument is in milliseconds, not microseconds:
atomic_delay += HWSPINLOCK_RETRY_DELAY_US;
if (atomic_delay > to * 1000)
return -ETIMEDOUT;The hwspinlock core documents this explicitly:
If the mode is HWLOCK_IN_ATOMIC (called from an atomic context) the timeout is handled with busy-waiting delays, hence shall not exceed few msecs.
--- drivers/pinctrl/stm32/pinctrl-stm32.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/pinctrl/stm32/pinctrl-stm32.c +8 -8
@@ -87,7 +87,7 @@#define gpio_range_to_bank (chip) \ container_of(chip, struct stm32_gpio_bank, range) -#define HWSPNLCK_TIMEOUT 1000/* usec */ +#define HWSPNLCK_TIMEOUT_MS 1static const char *const stm32_gpio_functions[] = {"gpio" ,"af0" ,"af1" ,
@@ -609,7 +609,7 @@ static int stm32_gpio_domain_activate(struct irq_domain *d,if (pctl->hwlock) { ret =hwspin_lock_timeout_in_atomic (pctl->hwlock, -HWSPNLCK_TIMEOUT ); +HWSPNLCK_TIMEOUT_MS );if (ret) {dev_err (pctl->dev,"Can't get hwspinlock\n" );return ret;
@@ -946,7 +946,7 @@ static int stm32_pmx_set_mode(struct stm32_gpio_bank *bank,if (pctl->hwlock) { err =hwspin_lock_timeout_in_atomic (pctl->hwlock, -HWSPNLCK_TIMEOUT ); +HWSPNLCK_TIMEOUT_MS );if (err) {dev_err (pctl->dev,"Can't get hwspinlock\n" ); goto unlock;
@@ -1089,7 +1089,7 @@ static int stm32_pconf_set_driving(struct stm32_gpio_bank *bank,if (pctl->hwlock) { err =hwspin_lock_timeout_in_atomic (pctl->hwlock, -HWSPNLCK_TIMEOUT ); +HWSPNLCK_TIMEOUT_MS );if (err) {dev_err (pctl->dev,"Can't get hwspinlock\n" ); goto unlock;
@@ -1135,7 +1135,7 @@ static int stm32_pconf_set_speed(struct stm32_gpio_bank *bank,if (pctl->hwlock) { err =hwspin_lock_timeout_in_atomic (pctl->hwlock, -HWSPNLCK_TIMEOUT ); +HWSPNLCK_TIMEOUT_MS );if (err) {dev_err (pctl->dev,"Can't get hwspinlock\n" ); goto unlock;
@@ -1181,7 +1181,7 @@ static int stm32_pconf_set_bias(struct stm32_gpio_bank *bank,if (pctl->hwlock) { err =hwspin_lock_timeout_in_atomic (pctl->hwlock, -HWSPNLCK_TIMEOUT ); +HWSPNLCK_TIMEOUT_MS );if (err) {dev_err (pctl->dev,"Can't get hwspinlock\n" ); goto unlock;
@@ -1242,7 +1242,7 @@ static int stm32_pconf_set_advcfgr(struct stm32_gpio_bank *bank, int offset, u32spin_lock_irqsave (&bank->lock, flags);if (pctl->hwlock) { - err =hwspin_lock_timeout_in_atomic (pctl->hwlock,HWSPNLCK_TIMEOUT ); + err =hwspin_lock_timeout_in_atomic (pctl->hwlock,HWSPNLCK_TIMEOUT_MS );if (err) {dev_err (pctl->dev,"Can't get hwspinlock\n" ); goto unlock;
@@ -1320,7 +1320,7 @@ stm32_pconf_set_skew_delay(struct stm32_gpio_bank *bank, int offset, u32 delay,spin_lock_irqsave (&bank->lock, flags);if (pctl->hwlock) { - err =hwspin_lock_timeout_in_atomic (pctl->hwlock,HWSPNLCK_TIMEOUT ); + err =hwspin_lock_timeout_in_atomic (pctl->hwlock,HWSPNLCK_TIMEOUT_MS );if (err) {dev_err (pctl->dev,"Can't get hwspinlock\n" ); goto unlock;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2043/2651 selftests/bpf: Expect at least one kprobe miss in missed/perf_kprobe
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qiliang Yuan <[email protected]>
[ Upstream commit 34d527e513c9a3f3a00f1ddf03fe06f493da14d0 ]
missed_kprobe attaches test1 to bpf_fentry_test1 and test2 to bpf_kfunc_common_test, which test1 calls. test_missed_perf_kprobe() expects the kprobe of test2 to miss exactly one run, the one test1 triggers, since kprobes don't nest.
The test is not serial, and the kprobe on bpf_fentry_test1 is global. Any other test that does bpf_prog_test_run() on a fentry/fexit program calls bpf_fentry_test1() and thereby fires test1, which calls bpf_kfunc_common_test() from kprobe context. The kprobe of test2 then counts an extra miss, and the test reads 2 instead of 1.
Expect at least one miss, as missed_kprobe_recursion does since commit 08a7078feacf ("selftests/bpf: Improve missed_kprobe_recursion test robustness").
--- tools/testing/selftests/bpf/prog_tests/missed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/missed.c +1 -1
@@ -36,7 +36,7 @@ static void test_missed_perf_kprobe(void)ASSERT_EQ (info.type,BPF_LINK_TYPE_PERF_EVENT ,"info.type" );ASSERT_EQ (info.perf_event.type,BPF_PERF_EVENT_KPROBE ,"info.perf_event.type" ); -ASSERT_EQ (info.perf_event.kprobe.missed,1 ,"info.perf_event.kprobe.missed" ); +ASSERT_GE (info.perf_event.kprobe.missed,1 ,"info.perf_event.kprobe.missed" ); cleanup:missed_kprobe__destroy (skel);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2044/2651 bpftool: Fix inverted tracefs validation when scanning /proc/mounts
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuan Chen <[email protected]>
[ Upstream commit 21c755efaab1f40c2588ae5acbfa319a6d7d3638 ]
The /proc/mounts fallback in get_tracefs_pipe() accepts only non-tracefs mount points, so a tracefs mounted outside the default locations is
ignored: bpftool prog tracelog then mounts a second tracefs, or exits silently with --nomount. Negate the condition.
--- tools/bpf/bpftool/tracelog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/bpf/bpftool/tracelog.c +1 -1
@@ -86,7 +86,7 @@ static bool get_tracefs_pipe(char *mnt)fclose (fp);/* The string from fscanf() might be truncated, check mnt is valid */ -if (found &&validate_tracefs_mnt (mnt,TRACEFS_MAGIC )) +if (found && !validate_tracefs_mnt (mnt,TRACEFS_MAGIC )) goto exit_found;if (block_mount)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2045/2651 selftests/bpf: Fix spelling mistakes in descr literal strings
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Colin Ian King <[email protected]>
[ Upstream commit 760c953525bab88f053e61f1c1a6b2a5f76911c0 ]
There are spelling mistakes in the descr literal strings. Fix them.
--- tools/testing/selftests/bpf/prog_tests/sockopt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/sockopt.c +2 -2
@@ -955,7 +955,7 @@ static struct sockopt_test {/* ==================== prog_type ==================== */ { - .descr = "can attach only BPF_CGROUP_SETSOCKOP", + .descr = "can attach only BPF_CGROUP_SETSOCKOPT", .insns = {/* return 1 */ BPF_MOV64_IMM(BPF_REG_0, 1),
@@ -969,7 +969,7 @@ static struct sockopt_test { }, { - .descr = "can attach only BPF_CGROUP_GETSOCKOP", + .descr = "can attach only BPF_CGROUP_GETSOCKOPT", .insns = {/* return 1 */ BPF_MOV64_IMM(BPF_REG_0, 1),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2046/2651 power: sequencing: pcie-m2: Add Foxconn WCN7850 subsystem PCI ID
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Val Packett <[email protected]>
[ Upstream commit eadea156f11b2c9a780b60c1699c2da145c9d1f2 ]
Add a new device match for the PCI subdev id found on the Dell Latitude 7455 laptop.
--- drivers/power/sequencing/pwrseq-pcie-m2.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/power/sequencing/pwrseq-pcie-m2.c +2 -0
@@ -199,6 +199,8 @@ static const struct pci_device_id pwrseq_m2_pci_ids[] = { .driver_data = (kernel_ulong_t)"qcom,wcn7850-bt" }, { PCI_DEVICE_SUB(PCI_VENDOR_ID_QCOM, 0x1107, PCI_VENDOR_ID_LENOVO, 0xe0e9), .driver_data = (kernel_ulong_t)"qcom,wcn7850-bt" }, + { PCI_DEVICE_SUB(PCI_VENDOR_ID_QCOM, 0x1107, PCI_VENDOR_ID_FOXCONN, 0xe0ee), + .driver_data = (kernel_ulong_t)"qcom,wcn7850-bt" }, { } /* Sentinel */ };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2047/2651 ALSA: hda/realtek: Fix hiss/crackle on Lenovo Xiaoxin 14 GT (17aa:3912)
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Viktor Menshin <[email protected]>
[ Upstream commit 2fc28b1186d6fce8b046e6118072cf3ca32f2960 ]
Commit 3a3e810e9108 ("ALSA: hda/realtek: Add quirk for Lenovo Xiaoxin 14 GT") added a quirk mapping SSID 17aa:3912 to ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK_PIN, chosen by analogy with neighboring SSIDs (0x390d, 0x3911, 0x391a) without being verified on hardware, as noted in that commit's own message.
I have since tested it on the actual hardware (Lenovo Xiaoxin Pro 14 ASP10, same 17aa:3912 SSID) and confirmed it does not fix the reported issue. ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK_PIN only repoints pin 0x17 and the preferred DAC pairs for the bass speaker; it does not touch the codec's vendor processing coefficients. The actual symptom - constant electrical hiss/crackle on both the headphone jack and the internal speakers, independent of volume - is unrelated to pin/DAC routing and is also present on stock Windows before the Realtek driver is installed, which points at those coefficients being left at their power-on default.
To find the correct values, I passed the physical HD Audio controller through to a Windows 10 VM (VFIO, with QEMU patched to log CORB verb traffic) and captured the coefficient writes the vendor Realtek driver performs at init. Replaying a single one of them on Linux via hda-verb reproducibly eliminates the headphone jack noise:
hda-verb /dev/snd/hwC#D0 0x20 SET_COEF_INDEX 0x36
hda-verb /dev/snd/hwC#D0 0x20 SET_PROC_COEF 0x77d7This has held up across reboots and kernel updates for several weeks (applied via a small systemd oneshot unit while testing).
Add a dedicated fixup that performs this coefficient write and chains it with the existing ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK_PIN (which may still be relevant for the bass speaker pin wiring on this board), and point the 17aa:3912 quirk entry at it instead.
Honesty note: this fixes the headphone jack. The internal speakers still have noise under certain conditions (notably worse on AC power) that I have not been able to isolate via coefficient-table replay; that part remains open. Sending what is verified to work rather than holding this back.
--- sound/hda/codecs/realtek/alc269.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-)
sound/hda/codecs/realtek/alc269.c +30 -1
@@ -3682,6 +3682,28 @@ static void alc287_fixup_yoga9_14iap7_bass_spk_pin(struct hda_codec *codec, } } +/* +* The Lenovo Xiaoxin 14 GT (SSID 17aa:3912) uses the same bass-speaker +* pin wiring as its 0x390d/0x3911/0x391a siblings, but on this board the +* codec's vendor processing coefficients (node 0x20) are left at their +* power-on default instead of being programmed the way the vendor +* (Windows) driver programs them. That leaves audible hiss/crackle on +* both the headphone jack and the internal speakers, independent of +* volume, regardless of which pin/DAC routing is used. +* +* This single coefficient write was captured from the vendor driver's +* own init sequence (via a VFIO pass-through of the physical codec to a +* Windows VM) and confirmed to eliminate the headphone jack noise. +*/ +static void alc287_fixup_lenovo_xiaoxin_14gt_hp_noise (struct hda_codec *codec, +const struct hda_fixup *fix,int action) +{ +if (action !=HDA_FIXUP_ACT_INIT ) +return ; + +alc_write_coef_idx (codec,0x36 ,0x77d7 ); +} +static void alc_fixup_yoga_pro7_audio (struct hda_codec *codec,const struct hda_fixup *fix,int action) {
@@ -4343,6 +4365,7 @@ enum {ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK ,ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK_PIN ,ALC287_FIXUP_YOGA9_14IMH9_BASS_SPK_PIN , +ALC287_FIXUP_LENOVO_XIAOXIN_14GT_HP_NOISE ,ALC295_FIXUP_DELL_INSPIRON_TOP_SPEAKERS ,ALC236_FIXUP_DELL_DUAL_CODECS , ALC287_FIXUP_CS35L41_I2C_2_THINKPAD_ACPI,
@@ -6844,6 +6867,12 @@ static const struct hda_fixup alc269_fixups[] = { .chained = true, .chain_id = ALC287_FIXUP_CS35L41_I2C_2, }, + [ALC287_FIXUP_LENOVO_XIAOXIN_14GT_HP_NOISE] = { + .type = HDA_FIXUP_FUNC, + .v.func = alc287_fixup_lenovo_xiaoxin_14gt_hp_noise, + .chained = true, + .chain_id = ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK_PIN, + }, [ALC295_FIXUP_DELL_INSPIRON_TOP_SPEAKERS] = { .type = HDA_FIXUP_FUNC, .v.func = alc295_fixup_dell_inspiron_top_speakers,
@@ -8402,7 +8431,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {HDA_CODEC_QUIRK (0x17aa ,0x3907 ,"Legion Pro 7i 16IAX10H / Y9000P IAX10" ,ALC287_FIXUP_LENOVO_LEGION_AW88399 ),SND_PCI_QUIRK (0x17aa ,0x390d ,"Lenovo Yoga Pro 7 14ASP10" ,ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK_PIN_HEADSET ),SND_PCI_QUIRK (0x17aa ,0x3911 ,"Lenovo Yoga Pro 7 14IAH10" ,ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK_PIN ), -SND_PCI_QUIRK (0x17aa ,0x3912 ,"Lenovo Xiaoxin 14 GT" ,ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK_PIN ), +SND_PCI_QUIRK (0x17aa ,0x3912 ,"Lenovo Xiaoxin 14 GT" ,ALC287_FIXUP_LENOVO_XIAOXIN_14GT_HP_NOISE ),SND_PCI_QUIRK (0x17aa ,0x3913 ,"Lenovo 145" ,ALC236_FIXUP_LENOVO_INV_DMIC ),SND_PCI_QUIRK (0x17aa ,0x391f ,"Yoga S990-16 pro Quad YC Quad" ,ALC287_FIXUP_TXNW2781_I2C ), SND_PCI_QUIRK(0x17aa, 0x3920, "Yoga S990-16 pro Quad VECO Quad", ALC287_FIXUP_YOGA9_SPEAKER2_TO_DAC1),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2048/2651 blk-iocost: charge zone appends as writes
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tao Cui <[email protected]>
[ Upstream commit febdbf5682fa7e8f325b07a2c115e7632c4252bd ]
Zone append is a primary write operation for zoned devices; zoned xfs and btrfs use it for data writes. It is priced at zero, so the zone append portion of zoned workloads runs outside the controller: a 1%-weight cgroup issued 16000 appends at zero cost on a zoned null_blk.
Treat REQ_OP_ZONE_APPEND the same as REQ_OP_WRITE so it goes through the existing seq/rand classification and charging.
--- block/blk-iocost.c | 1 + 1 file changed, 1 insertion(+)
block/blk-iocost.c +1 -0
@@ -2545,6 +2545,7 @@ static void calc_vtime_cost_builtin(struct bio *bio, struct ioc_gq *iocg, coef_randio = ioc->params.lcoefs[LCOEF_RRANDIO ]; coef_page = ioc->params.lcoefs[LCOEF_RPAGE ];break ; +case REQ_OP_ZONE_APPEND :case REQ_OP_WRITE : coef_seqio = ioc->params.lcoefs[LCOEF_WSEQIO ]; coef_randio = ioc->params.lcoefs[LCOEF_WRANDIO ];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2049/2651 blk-iocost: account zone append completions in latency stats
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tao Cui <[email protected]>
[ Upstream commit c38975c427cc3d3f6eb66a36143893be5cdf4ebd ]
ioc_rqos_done() only accounts READ and WRITE completions, so zone append completions are excluded from the latency window: the vrate feedback loop cannot see ZA-induced latency, leaving it unable to respond to device saturation caused by zone appends. Similarly, calc_size_vtime_cost_builtin() does not classify zone append as a write operation.
Charging (the cost model) and feedback (the latency window) are separate mechanisms, so this is not covered by the previous patch that prices zone appends.
Treat zone append as WRITE for both latency accounting and cost classification.
--- block/blk-iocost.c | 2 ++ 1 file changed, 2 insertions(+)
block/blk-iocost.c +2 -0
@@ -2589,6 +2589,7 @@ static void calc_size_vtime_cost_builtin(struct request *rq, struct ioc *ioc,case REQ_OP_READ : *costp = pages * ioc->params.lcoefs[LCOEF_RPAGE ];break ; +case REQ_OP_ZONE_APPEND :case REQ_OP_WRITE : *costp = pages * ioc->params.lcoefs[LCOEF_WPAGE ];break ;
@@ -2860,6 +2861,7 @@ static void ioc_rqos_done(struct rq_qos *rqos, struct request *rq) pidx =QOS_RLAT ; rw =READ ;break ; +case REQ_OP_ZONE_APPEND :case REQ_OP_WRITE : pidx =QOS_WLAT ; rw =WRITE ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2050/2651 blk-mq: share one tags_srcu instance across all tag sets
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qiliang Yuan <[email protected]>
[ Upstream commit e1c51edd6a575ba3b6fc5acb57ed2fec6951a910 ]
Freed request pages and flush queues are handed to call_srcu() so that concurrent tag iterators never see them disappear. Each tag set embeds its own srcu_struct for this, which blk_mq_free_tag_set() has to drain with srcu_barrier() before cleanup_srcu_struct(). The barrier waits for a full SRCU grace period even when the callbacks are long done, adding 1-3 ms to every tag set teardown. Drivers that free tag sets under a lock make it worse: ublk does it under the global ublk_ctl_mutex, so deleting devices from many threads serializes on that grace period.
The callbacks free memory that only blk-mq owns. They touch neither the tag set nor driver code, so they don't need a per-set domain. Replace the per-set srcu_struct with a single global one. Freeing a tag set no longer waits for a grace period, and each tag set no longer allocates per-CPU SRCU state. The read side is unchanged. The only cost is that a long-running iterator can now delay these frees for other tag sets too, which only postpones freeing memory.
On 7.3-rc5 in a 16-vCPU VM, with 1 queue and depth 16 per ublk device, median of 3 runs (5 for the 16-thread null_blk case):
before after ublk DEL_DEV p50, serial 3.45 ms 0.17 ms ublk delete 1000 devices, serial 19.5 s 14.9 s ublk delete 4000 devices, 16 thr 19.0 s 2.9 s null_blk destroy 500 devs, serial 9.97 s 9.25 s null_blk destroy 256 devs, 16 thr 5.15 s 4.30 s
--- block/blk-mq-tag.c | 17 ++++++++++++----- block/blk-mq.c | 15 ++++----------- block/blk-mq.h | 2 ++ include/linux/blk-mq.h | 3 --- 4 files changed, 18 insertions(+), 19 deletions(-)
block/blk-mq-tag.c +12 -5
@@ -18,6 +18,13 @@#include "blk-mq.h" #include "blk-mq-sched.h" +/* +* Protects tag iteration against the deferred freeing of tags->page_list and +* flush queues. The callbacks touch neither the tag set nor driver code, so +* one global instance is enough and freeing a tag set needn't wait for them. +*/ +DEFINE_SRCU (blk_mq_tags_srcu); +/* * Recalculate wakeup batch when tag is shared by hctx. */
@@ -443,7 +450,7 @@ void blk_mq_tagset_busy_iter(struct blk_mq_tag_set *tagset,unsigned int flags = tagset->flags;int i, nr_tags, srcu_idx; - srcu_idx =srcu_read_lock (&tagset->tags_srcu); + srcu_idx =srcu_read_lock (&blk_mq_tags_srcu); nr_tags =blk_mq_is_shared_tags (flags) ?1 : tagset->nr_hw_queues;
@@ -452,7 +459,7 @@ void blk_mq_tagset_busy_iter(struct blk_mq_tag_set *tagset,__blk_mq_all_tag_iter (tagset->tags[i], fn, priv,BT_TAG_ITER_STARTED ); } -srcu_read_unlock (&tagset->tags_srcu, srcu_idx); +srcu_read_unlock (&blk_mq_tags_srcu, srcu_idx); }EXPORT_SYMBOL (blk_mq_tagset_busy_iter);
@@ -512,7 +519,7 @@ void blk_mq_queue_tag_busy_iter(struct request_queue *q, busy_tag_iter_fn *fn,if (!percpu_ref_tryget (&q->q_usage_counter))return ; - srcu_idx =srcu_read_lock (&q->tag_set->tags_srcu); + srcu_idx =srcu_read_lock (&blk_mq_tags_srcu);if (blk_mq_is_shared_tags (q->tag_set->flags)) {struct blk_mq_tags *tags = q->tag_set->shared_tags;struct sbitmap_queue *bresv = &tags->breserved_tags;
@@ -542,7 +549,7 @@ void blk_mq_queue_tag_busy_iter(struct request_queue *q, busy_tag_iter_fn *fn,bt_for_each (hctx, q, btags, fn, priv, false); } } -srcu_read_unlock (&q->tag_set->tags_srcu, srcu_idx); +srcu_read_unlock (&blk_mq_tags_srcu, srcu_idx);blk_queue_exit (q); }
@@ -618,7 +625,7 @@ void blk_mq_free_tags(struct blk_mq_tag_set *set, struct blk_mq_tags *tags)return ; } -call_srcu (&set->tags_srcu, &tags->rcu_head, blk_mq_free_tags_callback); +call_srcu (&blk_mq_tags_srcu, &tags->rcu_head, blk_mq_free_tags_callback); }void blk_mq_tag_resize_shared_tags (struct blk_mq_tag_set *set,unsigned int size)
block/blk-mq.c +4 -11
@@ -3696,9 +3696,9 @@ static bool blk_mq_hctx_has_requests(struct blk_mq_hw_ctx *hctx) };int srcu_idx; - srcu_idx =srcu_read_lock (&hctx->queue->tag_set->tags_srcu); + srcu_idx =srcu_read_lock (&blk_mq_tags_srcu);blk_mq_all_tag_iter (tags, blk_mq_has_request, &data); -srcu_read_unlock (&hctx->queue->tag_set->tags_srcu, srcu_idx); +srcu_read_unlock (&blk_mq_tags_srcu, srcu_idx);return data.has_rq; }
@@ -3970,7 +3970,7 @@ static void blk_mq_exit_hctx(struct request_queue *q,if (set->ops->exit_hctx) set->ops->exit_hctx (hctx, hctx_idx); -call_srcu (&set->tags_srcu, &hctx->fq->rcu_head, +call_srcu (&blk_mq_tags_srcu, &hctx->fq->rcu_head, blk_free_flush_queue_callback); hctx->fq =NULL ;
@@ -4898,9 +4898,6 @@ int blk_mq_alloc_tag_set(struct blk_mq_tag_set *set)if (ret) goto out_free_srcu; } - ret =init_srcu_struct (&set->tags_srcu); -if (ret) - goto out_cleanup_srcu;init_rwsem (&set->update_nr_hwq_lock);
@@ -4909,7 +4906,7 @@ int blk_mq_alloc_tag_set(struct blk_mq_tag_set *set)sizeof (struct blk_mq_tags *),GFP_KERNEL , set->numa_node);if (!set->tags) - goto out_cleanup_tags_srcu; + goto out_cleanup_srcu;for (i =0 ; i < set->nr_maps; i++) { set->map[i].mq_map = kcalloc_node(nr_cpu_ids,
@@ -4938,8 +4935,6 @@ int blk_mq_alloc_tag_set(struct blk_mq_tag_set *set) }kfree (set->tags); set->tags =NULL ; -out_cleanup_tags_srcu: -cleanup_srcu_struct (&set->tags_srcu); out_cleanup_srcu:if (set->flags &BLK_MQ_F_BLOCKING )cleanup_srcu_struct (set->srcu);
@@ -4986,8 +4981,6 @@ void blk_mq_free_tag_set(struct blk_mq_tag_set *set)kfree (set->tags); set->tags =NULL ; -srcu_barrier (&set->tags_srcu); -cleanup_srcu_struct (&set->tags_srcu);if (set->flags &BLK_MQ_F_BLOCKING ) {srcu_barrier (set->srcu);cleanup_srcu_struct (set->srcu);
block/blk-mq.h +2 -0
@@ -178,6 +178,8 @@ struct blk_mq_tags *blk_mq_init_tags(unsigned int nr_tags, unsigned int reserved_tags, unsigned int flags, int node);void blk_mq_free_tags (struct blk_mq_tag_set *set,struct blk_mq_tags *tags); +extern struct srcu_struct blk_mq_tags_srcu; +unsigned int blk_mq_get_tag (struct blk_mq_alloc_data *data);unsigned long blk_mq_get_tags (struct blk_mq_alloc_data *data,int nr_tags,unsigned int *offset);
include/linux/blk-mq.h +0 -3
@@ -525,8 +525,6 @@ enum hctx_type {* request_queue.tag_set_list. * @srcu: Use as lock when type of the request queue is blocking * (BLK_MQ_F_BLOCKING). -* @tags_srcu: SRCU used to defer freeing of tags page_list to prevent -* use-after-free when iterating tags. * @update_nr_hwq_lock: * Synchronize updating nr_hw_queues with add/del disk & * switching elevator.
@@ -551,7 +549,6 @@ struct blk_mq_tag_set {struct mutex tag_list_lock;struct list_head tag_list;struct srcu_struct *srcu; -struct srcu_struct tags_srcu;struct rw_semaphore update_nr_hwq_lock; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2051/2651 ima: reject a kexec buffer whose declared size exceeds the buffer
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fabrice Derepas <[email protected]>
[ Upstream commit ceb24c7052cc4649e3b52a51a7cca7dfe4896cec ]
ima_restore_measurement_list() parses the measurement list persisted across kexec. It computes the parse end directly from the blob:
bufendp = buf + khdr->buffer_size;
khdr->buffer_size is a u64 read straight from the persisted buffer. The only length checks in the function are size >= sizeof(*khdr), version == 1 and count -- none relates buffer_size to size, the actual buffer size the caller (ima_load_kexec_buffer()) obtained from the ima-kexec-buffer region. ima_parse_buf() bounds every field read to bufendp, so a blob whose internal buffer_size exceeds the real size makes the parse loop read past the end of the buffer (CWE-125).
The buffer's memory range is validated against addressable RAM by commit cbf9c4b9617b ("of: check previous kernel's ima-kexec-buffer against memory bounds") and commit c5489d04337b ("x86/kexec: add a sanity check on previous kernel's ima kexec buffer"), but the blob's own declared size is never clamped to it. Reject a buffer_size larger than size before the loop.
This is on the boot-time kexec-restore path (__init) and the buffer comes from the previous kernel, so triggering it requires control of the persisted buffer; it is an out-of-bounds read only.
--- security/integrity/ima/ima_template.c | 5 +++++ 1 file changed, 5 insertions(+)
security/integrity/ima/ima_template.c +5 -0
@@ -450,6 +450,11 @@ int ima_restore_measurement_list(loff_t size, void *buf)return -EINVAL ; } +if (khdr->buffer_size > size) { +pr_err ("attempting to restore a corrupted measurement list" ); +return -EINVAL ; + } +bitmap_zero (hdr_mask,HDR__LAST );bitmap_set (hdr_mask,HDR_PCR ,1 );bitmap_set (hdr_mask,HDR_DIGEST ,1 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2052/2651 net: phy: qcom: at803x: Apply IPQ5018 analog settings at probe
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yongzhao Chen <[email protected]>
[ Upstream commit 17baf30a0e64cde0e8a30723b7c6d06417152514 ]
ipq5018_probe() pulses the PHY reset, after which the IPQ5018 internal GE PHY starts autonegotiating with its reset-default analog settings. ipq5018_config_init() writes the analog settings only when the MAC attaches the PHY, usually when the interface is opened. On a board where the PHY connects to a QCA8337 PHY without a cable, 1000BASE-T does not come up in the meantime, SmartSpeed downshifts both PHYs, and only the IPQ5018 side restores its 1000BASE-T advertisement at attach, so the link stays down.
Apply the analog settings in probe right after the reset and restart autonegotiation. Move the settings into a helper shared with config_init() and return MDIO errors from it instead of ignoring them. The values written do not change, only the time of the write.
--- drivers/net/phy/qcom/at803x.c | 98 +++++++++++++++++++++++++---------- 1 file changed, 70 insertions(+), 28 deletions(-)
drivers/net/phy/qcom/at803x.c +70 -28
@@ -1019,10 +1019,10 @@ static int ipq5018_cable_test_start(struct phy_device *phydev)return 0 ; } -static int ipq5018_config_init (struct phy_device *phydev) +static int ipq5018_analog_init (struct phy_device *phydev) {struct ipq5018_priv *priv = phydev->priv; -u16 val; +int val, ret;/* * set LDO efuse: first temporarily store ANA_DAC_FILTER value from
@@ -1030,39 +1030,66 @@ static int ipq5018_config_init(struct phy_device *phydev)* is written to */ val =at803x_debug_reg_read (phydev,IPQ5018_PHY_DEBUG_ANA_DAC_FILTER ); -at803x_debug_reg_mask (phydev,IPQ5018_PHY_DEBUG_ANA_LDO_EFUSE , -IPQ5018_PHY_DEBUG_ANA_LDO_EFUSE_MASK , -IPQ5018_PHY_DEBUG_ANA_LDO_EFUSE_DEFAULT ); -at803x_debug_reg_write (phydev,IPQ5018_PHY_DEBUG_ANA_DAC_FILTER , val); +if (val <0 ) +return val; + + ret =at803x_debug_reg_mask (phydev,IPQ5018_PHY_DEBUG_ANA_LDO_EFUSE , +IPQ5018_PHY_DEBUG_ANA_LDO_EFUSE_MASK , +IPQ5018_PHY_DEBUG_ANA_LDO_EFUSE_DEFAULT ); +if (ret) +return ret; + + ret =at803x_debug_reg_write (phydev,IPQ5018_PHY_DEBUG_ANA_DAC_FILTER , + val); +if (ret) +return ret;/* set 8023AZ EEE TX and RX timer values */ -phy_write_mmd (phydev,MDIO_MMD_PCS ,IPQ5018_PHY_PCS_EEE_TX_TIMER , -IPQ5018_PHY_PCS_EEE_TX_TIMER_VAL ); -phy_write_mmd (phydev,MDIO_MMD_PCS ,IPQ5018_PHY_PCS_EEE_RX_TIMER , -IPQ5018_PHY_PCS_EEE_RX_TIMER_VAL ); + ret =phy_write_mmd (phydev,MDIO_MMD_PCS ,IPQ5018_PHY_PCS_EEE_TX_TIMER , +IPQ5018_PHY_PCS_EEE_TX_TIMER_VAL ); +if (ret) +return ret; + + ret =phy_write_mmd (phydev,MDIO_MMD_PCS ,IPQ5018_PHY_PCS_EEE_RX_TIMER , +IPQ5018_PHY_PCS_EEE_RX_TIMER_VAL ); +if (ret) +return ret;/* set MSE threshold values */ -phy_write_mmd (phydev,MDIO_MMD_PMAPMD ,IPQ5018_PHY_MMD1_MSE_THRESH1 , -IPQ5018_PHY_MMD1_MSE_THRESH1_VAL ); -phy_write_mmd (phydev,MDIO_MMD_PMAPMD ,IPQ5018_PHY_MMD1_MSE_THRESH2 , -IPQ5018_PHY_MMD1_MSE_THRESH2_VAL ); + ret =phy_write_mmd (phydev,MDIO_MMD_PMAPMD , +IPQ5018_PHY_MMD1_MSE_THRESH1 , +IPQ5018_PHY_MMD1_MSE_THRESH1_VAL ); +if (ret) +return ret; + + ret =phy_write_mmd (phydev,MDIO_MMD_PMAPMD , +IPQ5018_PHY_MMD1_MSE_THRESH2 , +IPQ5018_PHY_MMD1_MSE_THRESH2_VAL ); +if (ret) +return ret;/* PHY DAC values are optional and only set in a PHY to PHY link architecture */ -if (priv->set_short_cable_dac) { -/* setting MDAC (Multi-level Digital-to-Analog Converter) in MMD1 */ -phy_modify_mmd (phydev,MDIO_MMD_PMAPMD ,IPQ5018_PHY_MMD1_MDAC , -IPQ5018_PHY_DAC_MASK , -FIELD_PREP (IPQ5018_PHY_DAC_MASK , -IPQ5018_PHY_MMD1_MDAC_VAL )); - -/* setting EDAC (Error-detection and Correction) in debug register */ -at803x_debug_reg_mask (phydev,IPQ5018_PHY_DEBUG_EDAC , -IPQ5018_PHY_DAC_MASK , -FIELD_PREP (IPQ5018_PHY_DAC_MASK , -IPQ5018_PHY_DEBUG_EDAC_VAL )); - } +if (!priv->set_short_cable_dac) +return 0 ; -return 0 ; +/* setting MDAC (Multi-level Digital-to-Analog Converter) in MMD1 */ + ret =phy_modify_mmd (phydev,MDIO_MMD_PMAPMD ,IPQ5018_PHY_MMD1_MDAC , +IPQ5018_PHY_DAC_MASK , +FIELD_PREP (IPQ5018_PHY_DAC_MASK , +IPQ5018_PHY_MMD1_MDAC_VAL )); +if (ret) +return ret; + +/* setting EDAC (Error-detection and Correction) in debug register */ +return at803x_debug_reg_mask (phydev,IPQ5018_PHY_DEBUG_EDAC , +IPQ5018_PHY_DAC_MASK , +FIELD_PREP (IPQ5018_PHY_DAC_MASK , +IPQ5018_PHY_DEBUG_EDAC_VAL )); +} + +static int ipq5018_config_init (struct phy_device *phydev) +{ +return ipq5018_analog_init (phydev); }static void ipq5018_link_change_notify (struct phy_device *phydev)
@@ -1111,6 +1138,21 @@ static int ipq5018_probe(struct phy_device *phydev) phydev->priv = priv; +/* +* The PHY starts autonegotiation as soon as it leaves reset. Apply the +* analog settings now instead of waiting for config_init() at attach +* time, and restart autonegotiation so that it uses them. +*/ + ret =ipq5018_analog_init (phydev); +if (ret) +return dev_err_probe (dev, ret, +"failed to apply analog settings\n" ); + + ret =genphy_restart_aneg (phydev); +if (ret) +return dev_err_probe (dev, ret, +"failed to restart autonegotiation\n" ); +return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2053/2651 usbnet: fix smp_processor_id() use in preemptible context
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ömer Mete Kaya <[email protected]>
[ Upstream commit 95a5c641fc7becab441bf244baa73b0b0f8b7dea ]
tx_complete() calls this_cpu_ptr() before disabling preemption, which triggers a BUG when running with CONFIG_DEBUG_PREEMPT:
BUG: using smp_processor_id() in preemptible code in tx_complete
Fix by using get_cpu_ptr()/put_cpu_ptr() which disable preemption and return the per-CPU pointer atomically. The usbnet_skb_return() hunk is a hardening change: that path runs in softirq context so no warning fires there, but the same fix is applied for consistency.
--- drivers/net/usb/usbnet.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/usb/usbnet.c +6 -2
@@ -325,7 +325,7 @@ static void __usbnet_status_stop_force(struct usbnet *dev)*/ void usbnet_skb_return (struct usbnet *dev,struct sk_buff *skb) { -struct pcpu_sw_netstats *stats64 =this_cpu_ptr (dev->net->tstats); +struct pcpu_sw_netstats *stats64;unsigned long flags;int status;
@@ -338,10 +338,12 @@ void usbnet_skb_return(struct usbnet *dev, struct sk_buff *skb)if (skb->protocol ==0 ) skb->protocol =eth_type_trans (skb, dev->net); + stats64 =get_cpu_ptr (dev->net->tstats); flags =u64_stats_update_begin_irqsave (&stats64->syncp);u64_stats_inc (&stats64->rx_packets);u64_stats_add (&stats64->rx_bytes, skb->len);u64_stats_update_end_irqrestore (&stats64->syncp, flags); +put_cpu_ptr (dev->net->tstats);netif_dbg (dev, rx_status, dev->net,"< rx, len %zu, type 0x%x\n" , skb->len +sizeof (struct ethhdr ), skb->protocol);
@@ -1298,13 +1300,15 @@ static void tx_complete(struct urb *urb)struct usbnet *dev = entry->dev;if (urb->status ==0 ) { -struct pcpu_sw_netstats *stats64 =this_cpu_ptr (dev->net->tstats); +struct pcpu_sw_netstats *stats64;unsigned long flags; + stats64 =get_cpu_ptr (dev->net->tstats); flags =u64_stats_update_begin_irqsave (&stats64->syncp);u64_stats_add (&stats64->tx_packets, entry->packets);u64_stats_add (&stats64->tx_bytes, entry->length);u64_stats_update_end_irqrestore (&stats64->syncp, flags); +put_cpu_ptr (dev->net->tstats); }else { dev->net->stats.tx_errors++;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2054/2651 platform: cznic: turris-omnia-mcu: stop button emulation producers
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit 0045cd6b8ab2319e9d8de46e5e329cdc35ce6d05 ]
The legacy MCU IRQ thread can requeue button-release emulation work after its managed cleanup has canceled it. Since the IRQ is still active at that point, the newly queued work can outlive device teardown and access freed MCU state.
Use disable_delayed_work_sync() to prevent further queueing and drain the worker before the IRQ action is released. Keep the parent IRQ active while the worker completes. devm_add_action_or_reset() also drains the work if action registration fails.
This issue was identified as part of our ongoing research while reviewing kernel code.
--- .../platform/cznic/turris-omnia-mcu-gpio.c | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-)
drivers/platform/cznic/turris-omnia-mcu-gpio.c +15 -16
@@ -11,7 +11,6 @@#include <linux/bug.h> #include <linux/cleanup.h> #include <linux/device.h> -#include <linux/devm-helpers.h> #include <linux/errno.h> #include <linux/gpio/consumer.h> #include <linux/gpio/driver.h>
@@ -841,6 +840,18 @@ static void button_release_emul_fn(struct work_struct *work)generic_handle_irq_safe (mcu->client->irq); } +static void omnia_disable_button_release_work (void *data) +{ +struct delayed_work *work = data; + +/* +* The IRQ thread may requeue this work while the IRQ remains active. +* Disable and drain it before releasing the IRQ action and the MCU +* state used by the worker. +*/ +disable_delayed_work_sync (work); +} + static void fill_int_from_sts(unsigned long *rising, unsigned long *falling, unsigned long rising_sts, unsigned long falling_sts,
@@ -1082,21 +1093,9 @@ int omnia_mcu_register_gpiochip(struct omnia_mcu *mcu)return dev_err_probe (dev, err,"Cannot request IRQ\n" );if (!new_api) { -/* -* The button_release_emul_work has to be initialized before the -* thread is requested, and on driver remove it needs to be -* canceled before the thread is freed. Therefore we can't use -* devm_delayed_work_autocancel() directly, because the order -* devm_delayed_work_autocancel(); -* devm_request_threaded_irq(); -* would cause improper release order: -* free_irq(); -* cancel_delayed_work_sync(); -* Instead we first initialize the work above, and only now -* after IRQ is requested we add the work devm action. -*/ - err =devm_add_action (dev, devm_delayed_work_drop, - &mcu->button_release_emul_work); + err =devm_add_action_or_reset (dev, + omnia_disable_button_release_work, + &mcu->button_release_emul_work);if (err)return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2055/2651 ALSA: 6fire: take stream_mutex in the Digital Thru control
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Piotr Gliźniewicz <[email protected]>
[ Upstream commit d030561d53cb272bb55ba2dd11aaa609e8240b7e ]
usb6fire_control_digital_thru_put() calls usb6fire_control_streaming_update(), which on an idle card with Digital Thru on selects altsetting 2 and writes the clock register for 96 kHz through usb6fire_control_set_rate(). usb6fire_pcm_prepare() calls both functions through usb6fire_pcm_set_rate() under rt->stream_mutex. The put does not take stream_mutex, so the two can run at the same time.
500 runs of a 0.2 s aplay at 48 kHz while a second loop toggled "Digital Thru Playback Route" with amixer (12693 on/off cycles, kernel 7.2.9): in 216 cases the two usb_set_interface() calls ran at the same time and the kernel logged "sysfs: cannot create duplicate filename '.../3-2:1.1/ep_82'" with a stack dump. 27 of the aplay runs failed, and for each of them the kernel logged "could not start pcm stream".
Take stream_mutex in the put. The pcm runtime is created before the controls and freed with the card, so chip->pcm is valid whenever the put runs. The put waits for a running prepare, which makes synchronous USB transfers under stream_mutex; on a card that responds late the wait can reach about 12 s, or 24 s with Digital Thru on, and during the wait the other controls of the card can be neither read nor written, because snd_ctl_elem_write() holds controls_rwsem around the put. Before this patch the put already made transfers of the same kind under controls_rwsem. No code that holds stream_mutex takes controls_rwsem.
The same test on kernel 7.2.10 with this patch (12863 cycles) gave no failed aplay run and no "duplicate filename" message.
--- sound/usb/6fire/control.c | 7 +++++++ 1 file changed, 7 insertions(+)
sound/usb/6fire/control.c +7 -0
@@ -20,6 +20,7 @@#include "control.h" #include "comm.h" #include "chip.h" +#include "pcm.h" static const char *const opt_coax_texts[2 ] = {"Optical" ,"Coax" };static const char *const line_phono_texts[2 ] = {"Line" ,"Phono" };
@@ -383,6 +384,12 @@ static int usb6fire_control_digital_thru_put(struct snd_kcontrol *kcontrol,struct control_runtime *rt =snd_kcontrol_chip (kcontrol);int changed =0 ; +/* +* with Digital Thru on, streaming_update() selects the altsetting and +* writes the clock register of an idle card; prepare does the same +* under stream_mutex +*/ +guard (mutex)(&rt->chip->pcm->stream_mutex);if (rt->digital_thru_switch != ucontrol->value.integer.value[0 ]) { rt->digital_thru_switch = ucontrol->value.integer.value[0 ];usb6fire_control_streaming_update (rt);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2056/2651 btrfs: drop the extent maps of the written part of a failed ordered extent
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tal Zussman <[email protected]>
[ Upstream commit bca2cf55a7331e6b0ff95ad47fc2a7e8ecc7dc74 ]
If a truncated ordered extent fails to complete, the extent maps for the part that was written are kept while the extent itself is freed below. A later read can follow them to blocks that have been reallocated. Drop the maps for the whole range on error.
--- fs/btrfs/inode.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/btrfs/inode.c +3 -1
@@ -3387,6 +3387,8 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)/* * Drop extent maps for the part of the extent we didn't write. +* On error the written part is freed below as well, so drop +* its maps too. * * We have an exception here for the free_space_inode, this is * because when we do btrfs_get_extent() on the free space inode
@@ -3402,7 +3404,7 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)if (!btrfs_is_free_space_inode (inode)) {u64 unwritten_start = start; -if (truncated) +if (truncated && !ret) unwritten_start += logical_len; btrfs_drop_extent_map_range(inode, unwritten_start,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2057/2651 btrfs: update the inode item when removing a free space inode
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tal Zussman <[email protected]>
[ Upstream commit 4e89aff9ad6fcbec555c38169807c4023f93450f ]
btrfs_remove_free_space_inode() adds an orphan item for the free space inode and clears its link count in memory, but never writes the inode item. The item is only removed once the delayed iput evicts the inode, which happens in a later transaction, from the cleaner thread or a throttled transaction end.
If we crash in between, or if evict can't reserve space for the truncation and leaves the orphan item for the next mount, the on-disk inode still has a link count of 1. btrfs_orphan_cleanup() then treats it as an inode with links and only deletes the orphan item. The free space header item is already gone at that point, so nothing ever finds the inode again, and its data extents are leaked.
Write the zero link count to the inode item in the same transaction as the orphan item, so the orphan cleanup evicts the inode instead. Account for the extra tree root item update when removing a block group.
--- fs/btrfs/block-group.c | 6 ++++-- fs/btrfs/free-space-cache.c | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-)
fs/btrfs/block-group.c +4 -2
@@ -1397,12 +1397,14 @@ struct btrfs_trans_handle *btrfs_start_trans_remove_block_group(ASSERT (map->start == chunk_offset);/* -* We need to reserve 3 + N units from the metadata space info in order +* We need to reserve 4 + N units from the metadata space info in order * to remove a block group (done at btrfs_remove_chunk() and at * btrfs_remove_block_group()), which are used for: * * 1 unit for adding the free space inode's orphan (located in the tree * of tree roots). +* 1 unit for updating the free space inode's item (located in the tree +* of tree roots). * 1 unit for deleting the block group item (located in the extent * tree). * 1 unit for deleting the free space item (located in tree of tree
@@ -1415,7 +1417,7 @@ struct btrfs_trans_handle *btrfs_start_trans_remove_block_group(* more device items and remove one chunk item), but this is done at * btrfs_remove_chunk() through a call to check_system_chunk(). */ - num_items =3 + map->num_stripes; + num_items =4 + map->num_stripes;btrfs_free_chunk_map (map);return btrfs_start_transaction_fallback_global_rsv (root, num_items);
fs/btrfs/free-space-cache.c +10 -0
@@ -266,6 +266,16 @@ int btrfs_remove_free_space_inode(struct btrfs_trans_handle *trans,return ret; }clear_nlink (inode); +/* +* Persist the zero link count, so that if the delayed iput below +* doesn't get to evict the inode, the orphan cleanup on the next mount +* evicts it instead of only deleting the orphan item. +*/ + ret =btrfs_update_inode (trans,BTRFS_I (inode)); +if (ret) { +btrfs_add_delayed_iput (BTRFS_I (inode)); +return ret; + }/* One for the block groups ref */ spin_lock (&block_group->lock);if (test_and_clear_bit (BLOCK_GROUP_FLAG_IREF , &block_group->runtime_flags)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2058/2651 ARC: Strip libgcc debug information when generating BTF
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
[ Upstream commit ca201ad6e92a1924138e83ff966f7a091e3bbe6e ]
ARC links against the compiler's libgcc archive. The ARC GNU 2023.03 toolchain ships this library with debug information, including complex floating-point types in integer arithmetic helpers such as __udivdi3. These types reach vmlinux even though the kernel does not use complex floating-point arithmetic.
When floating-point BTF encoding is enabled, pahole rejects those types:
Complex, interval and imaginary float types are not supported Error while encoding BTF.
FAILED: load BTF from .tmp_vmlinux1.BTF.1: No such file or directory
KernelCI's upgrade to pahole 1.31 exposed this long-standing problem as failed ARC builds. As of 1.32, pahole still rejects these types, and older versions will stay in use, so the kernel build has to keep them out of vmlinux. Commit f122668ddcce ("ARC: Add eBPF JIT support") documented the same failure along with a workaround of disabling floating-point BTF encoding, but that also discards supported floating-point types from kernel BTF.
For CONFIG_DEBUG_INFO_BTF, generate a debug-stripped copy of the selected libgcc archive in the output tree and link that copy. Preserve the archive structure so that only needed helpers are linked, and use the normal Kbuild objcopy rule to track input and command changes. The trade-off is that vmlinux in BTF-enabled builds no longer carries DWARF for the libgcc helpers. Debug information for kernel code, the installed toolchain and non-BTF builds stay unchanged.
Reproduced and tested with ARC GCC 12.2.1 and pahole 1.31 and 1.32 using an ARCv2 tinyconfig with BPF_SYSCALL and DWARF4/BTF enabled. Before and after vmlinux.o files are identical after stripping debug information.
--- arch/arc/Makefile | 9 ++++++++- arch/arc/lib/Makefile | 8 ++++++++ 2 files changed, 16 insertions(+), 1 deletion(-)
arch/arc/Makefile +8 -1
@@ -86,7 +86,14 @@ core-$(CONFIG_ARC_PLAT_TB10X) += arch/arc/plat-tb10x/ core-$(CONFIG_ARC_PLAT_AXS10X) += arch/arc/plat-axs10x/ core-$(CONFIG_ARC_SOC_HSDK) += arch/arc/plat-hsdk/ -libs-y += arch/arc/lib/ $(LIBGCC) +libs-y += arch/arc/lib/ + +ifdef CONFIG_DEBUG_INFO_BTF +export LIBGCC := $(LIBGCC) +libs-y += arch/arc/lib/libgcc.a +else +libs-y += $(LIBGCC) +endif boot := arch/arc/boot
arch/arc/lib/Makefile +8 -0
@@ -13,3 +13,11 @@ lib-$(CONFIG_ISA_ARCV2) +=memcpy-archs-unaligned.o else lib-$(CONFIG_ISA_ARCV2) +=memcpy-archs.o endif + +# libgcc can contain complex floating-point debug types unsupported by BTF. +# Strip only the debug information from a local copy of the selected archive. +always-$(CONFIG_DEBUG_INFO_BTF) += libgcc.a +OBJCOPYFLAGS_libgcc.a := --strip-debug + +$(obj)/libgcc.a: $(LIBGCC) FORCE + $(call if_changed,objcopy)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2059/2651 bpf: Claim the per-CPU send_signal irq_work before filling it
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuan Chen <[email protected]>
[ Upstream commit 2d1f101ee619435873ed8a23fcb3bd09204a5024 ]
irq_work_is_busy() cannot see the per-CPU send_signal_work while it is being filled: the check only matches after irq_work_queue() has claimed the work. A concurrent caller therefore passes it, both callers race for the same irq_work, and the loser's signal is silently lost along with its task reference while the queued work runs with a mix of both callers' fields.
kprobe, tracepoint and perf_event programs exclude each other on the same CPU through bpf_prog_active, so for two callers to meet, one of the programs has to be a raw tracepoint or an fentry one. And since commit 87c544108b61 ("bpf: Send signals asynchronously if !preemptible") this path runs with IRQs enabled too, so a hard IRQ can interrupt the fill as well, not only an NMI. Found by code inspection and reproduced with a perf_event NMI program racing an fentry one.
Claim the work through work->task itself: cmpxchg() it from NULL to the target task before touching the other fields, and set it back to NULL once the callback has consumed them. A context finding the work claimed returns the documented -EBUSY.
--- kernel/trace/bpf_trace.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
kernel/trace/bpf_trace.c +5 -2
@@ -823,6 +823,7 @@ const struct bpf_func_proto bpf_task_pt_regs_proto = {struct send_signal_irq_work {struct irq_work irq_work; +/* The claim: NULL marks the slot free for the next caller. */ struct task_struct *task;u32 sig;enum pid_type type;
@@ -842,6 +843,8 @@ static void do_bpf_send_signal(struct irq_work *entry)group_send_sig_info (work->sig, siginfo, work->task, work->type);put_task_struct (work->task); +/* Release once the fields are consumed. */ +smp_store_release (&work->task,NULL ); }static int bpf_send_signal_common (u32 sig,enum pid_type type,struct task_struct *task,u64 value)
@@ -885,14 +888,14 @@ static int bpf_send_signal_common(u32 sig, enum pid_type type, struct task_strucreturn -EINVAL ; work =this_cpu_ptr (&send_signal_work); -if (irq_work_is_busy (&work->irq_work)) +if (cmpxchg (&work->task,NULL , task))return -EBUSY ;/* Add the current task, which is the target of sending signal, * to the irq_work. The current task may change when queued * irq works get executed. */ - work->task =get_task_struct (task); +get_task_struct (task); work->has_siginfo = siginfo == &info;if (work->has_siginfo)copy_siginfo (&work->info, &info);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2060/2651 bpf, x86: Pass a trampolines stack arguments by the calling convention
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yonghong Song <[email protected]>
[ Upstream commit 9f9c30435ca92cddb37e67cda46ec02e26dd0a07 ]
A trampoline on a function of a program that can tail call keeps the tail call counter pointer by pushing rax after allocating its frame. When it calls the original function, for fexit, fmod_ret or fsession, the push sits between the stack arguments and the return address, which the x86-64 calling convention does not allow. For example, in
run() -> call_stack() -> callee_stack(a, b, c, d, e, f, g, h) run() -> subprog_tail() -> bpf_tail_call()
callee_stack() is not on the path to the tail call, so the verifier allows its stack arguments g and h. fexit on it builds, with T the trampoline's rbp:
T-120 h save_args() T-128 g save_args(), RSP after sub rsp, 128 T-136 tail_call_cnt_ptr push rax, RSP at the call T-144 return address call orig_call
and callee_stack() finds the counter pointer where g belongs, at 8(%rsp) on entry, and g where h belongs.
Keep the pointer in a slot of the frame instead, so that the stack arguments sit right above the return address again:
T-120 tail_call_cnt_ptr mov [rbp - 120], rax T-128 (pad to 16) T-136 h save_args() T-144 g save_args(), RSP at the call T-152 return address call orig_call
--- arch/x86/net/bpf_jit_comp.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
arch/x86/net/bpf_jit_comp.c +15 -7
@@ -3413,9 +3413,9 @@ static int invoke_bpf_mod_ret(const struct btf_func_model *m, u8 **pprog,return 0 ; } -/* mov rax, qword ptr [rbp - rounded_stack_depth - 8] */ -#define LOAD_TRAMP_TAIL_CALL_CNT_PTR (stack) \ - __LOAD_TCC_PTR(-round_up(stack, 8) - 8) +/* mov rax, qword ptr [rbp - off] */ +#define LOAD_TRAMP_TAIL_CALL_CNT_PTR (off) \ + __LOAD_TCC_PTR(-(off))/* Example: * __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev);
@@ -3485,6 +3485,7 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *rw_im {int i, ret, nr_regs = m->nr_args, stack_size =0 ;int regs_off, func_meta_off, ip_off, run_ctx_off, arg_stack_off, rbx_off; +int tcc_off =0 ;struct bpf_tramp_nodes *fentry = &tnodes[BPF_TRAMP_FENTRY ];struct bpf_tramp_nodes *fexit = &tnodes[BPF_TRAMP_FEXIT ];struct bpf_tramp_nodes *fmod_ret = &tnodes[BPF_TRAMP_MODIFY_RETURN ];
@@ -3535,11 +3536,12 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *rw_im* * RBP - run_ctx_off [ bpf_tramp_run_ctx ] * +* RBP - tcc_off [ tail_call_cnt_ptr ] BPF_TRAMP_F_TAIL_CALL_CTX +* * [ stack_argN ] BPF_TRAMP_F_CALL_ORIG * [ ... ] * [ stack_arg2 ] * RBP - arg_stack_off [ stack_arg1 ] -* RSP [ tail_call_cnt_ptr ] BPF_TRAMP_F_TAIL_CALL_CTX */ /* room for return value of orig_call or fentry prog */
@@ -3570,6 +3572,11 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *rw_im stack_size += (sizeof (struct bpf_tramp_run_ctx ) +7 ) & ~0x7 ; run_ctx_off = stack_size; +if (flags &BPF_TRAMP_F_TAIL_CALL_CTX ) { + stack_size +=8 ; + tcc_off = stack_size; + } +if (nr_regs >6 && (flags &BPF_TRAMP_F_CALL_ORIG )) {/* the space that used to pass arguments on-stack */ stack_size += (nr_regs -get_nr_used_regs (m)) *8 ;
@@ -3627,7 +3634,8 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *rw_imEMIT4 (0x48 ,0x83 ,0xEC , stack_size); }if (flags &BPF_TRAMP_F_TAIL_CALL_CTX ) -EMIT1 (0x50 );/* push rax */ +/* mov QWORD PTR [rbp - tcc_off], rax */ +emit_stx (&prog,BPF_DW ,BPF_REG_FP ,BPF_REG_0 , -tcc_off);/* mov QWORD PTR [rbp - rbx_off], rbx */ emit_stx (&prog,BPF_DW ,BPF_REG_FP ,BPF_REG_6 , -rbx_off);
@@ -3688,7 +3696,7 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *rw_im/* Before calling the original function, load the * tail_call_cnt_ptr from stack to rax. */ -LOAD_TRAMP_TAIL_CALL_CNT_PTR (stack_size); +LOAD_TRAMP_TAIL_CALL_CNT_PTR (tcc_off); }if (flags &BPF_TRAMP_F_ORIG_STACK ) {
@@ -3752,7 +3760,7 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *rw_im/* Before running the original function, load the * tail_call_cnt_ptr from stack to rax. */ -LOAD_TRAMP_TAIL_CALL_CNT_PTR (stack_size); +LOAD_TRAMP_TAIL_CALL_CNT_PTR (tcc_off); }/* restore return value of orig_call or fentry prog back into RAX */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2061/2651 ASoC: codecs: da732x: Fix definition of ADC2 EQ Overall Volume control
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
[ Upstream commit ebef9212cb469706e28002a20f9d48307d1fd867 ]
The ADC2 EQ overall volume is in DA732X_REG_ADC2_EQ5 (0x9F), not in DA732X_REG_ADC1_EQ5 (0x97), which holds the ADC1 one.
--- sound/soc/codecs/da732x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/da732x.c +1 -1
@@ -511,7 +511,7 @@ static const struct snd_kcontrol_new da732x_snd_controls[] = {SOC_SINGLE_TLV ("ACD2 EQ Band 5 Volume" ,DA732X_REG_ADC2_EQ5 ,DA732X_EQ_BAND5_SHIFT ,DA732X_EQ_VOL_VAL_MAX ,DA732X_INVERT , eq_band_pga_tlv), -SOC_SINGLE_TLV ("ADC2 EQ Overall Volume" ,DA732X_REG_ADC1_EQ5 , +SOC_SINGLE_TLV ("ADC2 EQ Overall Volume" ,DA732X_REG_ADC2_EQ5 ,DA732X_EQ_OVERALL_SHIFT ,DA732X_EQ_OVERALL_VOL_VAL_MAX , DA732X_INVERT, eq_overall_tlv),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2062/2651 ASoC: codecs: tlv320adc3xxx: Fix definition of AGC Target Level control
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
[ Upstream commit 0a9efcb663b5a4d468cbb90de29c6dd3794af124 ]
The right channel AGC target level is in RIGHT_CHN_AGC_1, as on the left, not in RIGHT_CHN_AGC_2, which holds the right noise threshold and hysteresis.
--- sound/soc/codecs/tlv320adc3xxx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/tlv320adc3xxx.c +1 -1
@@ -691,7 +691,7 @@ static const struct snd_kcontrol_new adc3xxx_snd_controls[] = {SOC_DOUBLE_R ("AGC Capture Switch" ,ADC3XXX_LEFT_CHN_AGC_1 ,ADC3XXX_RIGHT_CHN_AGC_1 ,7 ,1 ,0 ),SOC_DOUBLE_R_TLV ("AGC Target Level Capture Volume" ,ADC3XXX_LEFT_CHN_AGC_1 , -ADC3XXX_RIGHT_CHN_AGC_2 ,4 ,0x07 ,1 , agc_target_tlv), +ADC3XXX_RIGHT_CHN_AGC_1 ,4 ,0x07 ,1 , agc_target_tlv),SOC_DOUBLE_R_TLV ("AGC Noise Threshold Capture Volume" ,ADC3XXX_LEFT_CHN_AGC_2 ,ADC3XXX_RIGHT_CHN_AGC_2 ,1 ,0x1f ,1 , agc_thresh_tlv), SOC_DOUBLE_R_TLV("AGC Hysteresis Capture Volume", ADC3XXX_LEFT_CHN_AGC_2,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2063/2651 ASoC: codecs: sta32x: Fix definition of Ch2 and Ch3 Volume Bypass controls
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
[ Upstream commit ea53ab9003d8655cf7e94428de3006e86fbd06a0 ]
Each channel's master volume bypass (CxVBP) is in its own configuration register, C2CFG and C3CFG, not in C1CFG, which holds the channel 1 bit.
--- sound/soc/codecs/sta32x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/soc/codecs/sta32x.c +2 -2
@@ -491,8 +491,8 @@ SOC_SINGLE("Ch2 Tone Control Bypass Switch", STA32X_C2CFG, STA32X_CxCFG_TCB_SHIFSOC_SINGLE ("Ch1 EQ Bypass Switch" ,STA32X_C1CFG , STA32X_CxCFG_EQBP_SHIFT,1 ,0 ),SOC_SINGLE ("Ch2 EQ Bypass Switch" ,STA32X_C2CFG , STA32X_CxCFG_EQBP_SHIFT,1 ,0 ),SOC_SINGLE ("Ch1 Master Volume Bypass Switch" ,STA32X_C1CFG , STA32X_CxCFG_VBP_SHIFT,1 ,0 ), -SOC_SINGLE ("Ch2 Master Volume Bypass Switch" ,STA32X_C1CFG , STA32X_CxCFG_VBP_SHIFT,1 ,0 ), -SOC_SINGLE ("Ch3 Master Volume Bypass Switch" ,STA32X_C1CFG , STA32X_CxCFG_VBP_SHIFT,1 ,0 ), +SOC_SINGLE ("Ch2 Master Volume Bypass Switch" ,STA32X_C2CFG , STA32X_CxCFG_VBP_SHIFT,1 ,0 ), +SOC_SINGLE ("Ch3 Master Volume Bypass Switch" ,STA32X_C3CFG , STA32X_CxCFG_VBP_SHIFT,1 ,0 ),SOC_ENUM ("Ch1 Limiter Select" , sta32x_limiter_ch1_enum),SOC_ENUM ("Ch2 Limiter Select" , sta32x_limiter_ch2_enum), SOC_ENUM("Ch3 Limiter Select", sta32x_limiter_ch3_enum),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2064/2651 ASoC: codecs: sta350: Fix definition of Ch2 and Ch3 Volume Bypass controls
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
[ Upstream commit 7308ce7c8459e994a36a22607e974e3e132a9275 ]
Each channel's master volume bypass (CxVBP) is in its own configuration register, C2CFG and C3CFG, not in C1CFG, which holds the channel 1 bit.
--- sound/soc/codecs/sta350.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/soc/codecs/sta350.c +2 -2
@@ -477,9 +477,9 @@ SOC_SINGLE("Ch2 EQ Bypass Switch",SOC_SINGLE ("Ch1 Master Volume Bypass Switch" ,STA350_C1CFG , STA350_CxCFG_VBP_SHIFT,1 ,0 ),SOC_SINGLE ("Ch2 Master Volume Bypass Switch" , -STA350_C1CFG , STA350_CxCFG_VBP_SHIFT,1 ,0 ), +STA350_C2CFG , STA350_CxCFG_VBP_SHIFT,1 ,0 ),SOC_SINGLE ("Ch3 Master Volume Bypass Switch" , -STA350_C1CFG , STA350_CxCFG_VBP_SHIFT,1 ,0 ), +STA350_C3CFG , STA350_CxCFG_VBP_SHIFT,1 ,0 ),SOC_ENUM ("Ch1 Binary Output Select" , sta350_binary_output_ch1_enum),SOC_ENUM ("Ch2 Binary Output Select" , sta350_binary_output_ch2_enum), SOC_ENUM("Ch3 Binary Output Select", sta350_binary_output_ch3_enum),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2065/2651 calipso: update payload_len when removing the CALIPSO option
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joas Antonio dos Santos <[email protected]>
[ Upstream commit 00accbd9d5021b942a16078bd5717d7865f6971c ]
calipso_skbuff_delattr() removes the CALIPSO option from the hop-by-hop extension header, or the whole extension header if CALIPSO is its only option, and pulls the skb by the removed length. It never updates ipv6hdr->payload_len, so after a successful removal the header still claims the original length.
calipso_skbuff_setattr() already adjusts payload_len by the length it adds; the delete path was missed.
This is reached on the forward path when a packet carrying CALIPSO is sent to a destination mapped to an unlabeled NetLabel domain. The forwarded packet then has a payload_len larger than its real payload by the removed length (8 to 264 bytes), and the receiver drops it as truncated. So removing the label on the forward path has been broken for every packet that is not resegmented later (SYN, UDP, ICMPv6...).
Adjust payload_len after the header is moved. BIG TCP packets carry payload_len == 0 (see ipv6_set_payload_len()), and ipv6_payload_len() then falls back to skb->len, so leave them alone.
Tested with client, router and server network namespaces on one kernel (arm64, QEMU): SELinux permissive with a minimal mdp-generated policy (network_peer_controls=1), "netlabelctl calipso add pass doi:16", the default NetLabel mapping left unlabeled, IPv6 forwarding on the router. The client sends 5 UDP datagrams with a CALIPSO hop-by-hop option (DOI 16, set through IPV6_HOPOPTS) to the server through the router:
before: router Ip6OutForwDatagrams 5, server receives 0,
server Ip6InTruncatedPkts 5
after: router Ip6OutForwDatagrams 5, server receives 5,
server Ip6InTruncatedPkts 0
--- net/ipv6/calipso.c | 4 ++++ 1 file changed, 4 insertions(+)
net/ipv6/calipso.c +4 -0
@@ -1428,6 +1428,10 @@ static int calipso_skbuff_delattr(struct sk_buff *skb)skb_pull (skb, delta);memmove ((char *)ip6_hdr + delta, ip6_hdr, size);skb_reset_network_header (skb); + ip6_hdr =ipv6_hdr (skb); +/* BIG TCP packets have payload_len == 0 */ +if (ip6_hdr->payload_len) +be16_add_cpu (&ip6_hdr->payload_len, -delta); }return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2066/2651 dpll: zl3073x: do not offer 0 Hz as a supported pin frequency
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ivan Vecera <[email protected]>
[ Upstream commit 23171065fb436195981ca32f9e49dcf852dbd018 ]
zl3073x_pin_props_get() always adds the current pin frequency to the supported list without checking it. A sub-Hz frequency reads back as 0 Hz, so 0 Hz can then be requested and the output frequency set callback divides by zero. A 0 Hz entry in the firmware node is not rejected either: it is offered for an input pin, and for an output pin zl3073x_pin_check_freq() divides by it at probe time.
Do not add a 0 Hz current frequency and reject 0 Hz in zl3073x_pin_check_freq(). If the list ends up empty, do not publish it at all, as the DPLL core rejects an empty non-NULL list.
Found by code inspection, not triggered at runtime.
--- drivers/dpll/zl3073x/prop.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)
drivers/dpll/zl3073x/prop.c +19 -4
@@ -30,7 +30,7 @@ static bool zl3073x_pin_check_freq(struct zl3073x_dev *zldev, enum dpll_pin_direction dir, u8 id, u64 freq) { - if (freq > U32_MAX) + if (!freq || freq > U32_MAX) goto err_inv_freq;if (dir ==DPLL_PIN_DIRECTION_INPUT ) {
@@ -295,13 +295,20 @@ struct zl3073x_pin_props *zl3073x_pin_props_get(struct zl3073x_dev *zldev, goto err_alloc_ranges; } -/* Start with current frequency at index 0 */ - ranges[0 ] = (struct dpll_pin_frequency )DPLL_PIN_FREQUENCY (curr_freq); +/* Start with current frequency at index 0. A sub-Hz frequency is +* read back as 0 Hz and cannot be set, so it is not offered. +*/ + j =0 ; +if (curr_freq) { +struct dpll_pin_frequency freq =DPLL_PIN_FREQUENCY (curr_freq); + + ranges[j++] = freq; + }/* Add frequencies from firmware node, skipping current frequency * and filtering out frequencies not representable by device */ -for (i =0 , j =1 ; i < num_freqs; i++) { +for (i =0 ; i < num_freqs; i++) {struct dpll_pin_frequency freq =DPLL_PIN_FREQUENCY (freqs[i]);if (freqs[i] == curr_freq)
@@ -312,6 +319,14 @@ struct zl3073x_pin_props *zl3073x_pin_props_get(struct zl3073x_dev *zldev, } } +/* The DPLL core rejects a non-NULL list without entries, so do +* not publish the array at all when nothing is settable. +*/ +if (!j) { +kfree (ranges); + ranges =NULL ; + } +/* Save number of freq ranges and pointer to them into pin properties */ props->dpll_props.freq_supported = ranges; props->dpll_props.freq_supported_num = j;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2067/2651 dpll: zl3073x: reject inexact frequencies for N-divided outputs
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ivan Vecera <[email protected]>
[ Upstream commit f8993627d3101de0833022ac88083ac0147aae7d ]
For N-divided outputs the P-pin and N-pin share the output divisor and the N-pin frequency is synth_freq / (div * esync_n_period). The frequency set helper computed esync_n_period with a truncating division and only rejected a zero result, so a frequency that does not divide evenly was silently rounded. Setting the P-pin could then shift the N-pin frequency too (e.g. 600 MHz synth, div=60, period=10 gives P=10 MHz, N=1 MHz; setting P to 2.5 MHz moves N to 1.25 MHz). When setting the P-pin, the product esync_n_period * div used for the rescale was computed in 32 bits and could wrap, so a wrong N divider was stored for low N-pin frequencies.
Require esync_n_period >= 2 so the N-pin frequency stays below the P-pin one, reject a P-pin frequency for which the esync_n_period keeping the N-pin frequency does not fit into 32 bits, and check the division remainder and reject the request if it is not exact.
Found by code inspection, not triggered at runtime.
--- drivers/dpll/zl3073x/dpll.c | 46 ++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 18 deletions(-)
drivers/dpll/zl3073x/dpll.c +28 -18
@@ -987,6 +987,7 @@ zl3073x_dpll_output_pin_frequency_set(const struct dpll_pin *dpll_pin,const struct zl3073x_synth *synth;u32 new_div, synth_freq;struct zl3073x_out out; +u64 n_period, rem;u8 out_id;guard (mutex)(&zldpll->lock);
@@ -1014,16 +1015,11 @@ zl3073x_dpll_output_pin_frequency_set(const struct dpll_pin *dpll_pin, }if (zl3073x_dpll_is_p_pin (pin)) { -/* We are going to change output frequency for P-pin but -* if the requested frequency is less than current N-pin -* frequency then indicate a failure as we are not able -* to compute N-pin divisor to keep its frequency unchanged. -* -* Update divisor for N-pin to keep N-pin frequency. +/* Keep the N-pin frequency: the new P-pin frequency has to be +* a multiple of it, at least twice as high. */ - out.esync_n_period = (out.esync_n_period * out.div) / new_div; -if (!out.esync_n_period) -return -EINVAL ; + n_period =mul_u32_u32 (out.esync_n_period, out.div); + n_period =div64_u64_rem (n_period, new_div, &rem);/* Update the output divisor */ out.div = new_div;
@@ -1031,17 +1027,31 @@ zl3073x_dpll_output_pin_frequency_set(const struct dpll_pin *dpll_pin,/* For 50/50 duty cycle the divisor is equal to width */ out.width = out.div; }else { -/* We are going to change frequency of N-pin but if -* the requested freq is greater or equal than freq of P-pin -* in the output pair we cannot compute divisor for the N-pin. -* In this case indicate a failure. -* -* Update divisor for N-pin +/* The N-pin frequency has to divide the P-pin frequency and +* be at most half of it. */ - out.esync_n_period =div64_u64 (synth_freq, frequency * out.div); -if (!out.esync_n_period) -return -EINVAL ; + n_period = frequency * out.div; + n_period =div64_u64_rem (synth_freq, n_period, &rem); + } +if (n_period <2 ) { +NL_SET_ERR_MSG_FMT (extack, +"OUT%uN freq must be at most half of OUT%uP freq" , + out_id, out_id); +return -EINVAL ; + } +if (n_period >U32_MAX ) { +NL_SET_ERR_MSG_FMT (extack, +"OUT%uN freq is too low for OUT%uP freq" , + out_id, out_id); +return -EINVAL ; + } +if (rem !=0 ) { +NL_SET_ERR_MSG_FMT (extack, +"OUT%uN freq must divide OUT%uP freq" , + out_id, out_id); +return -EINVAL ; } + out.esync_n_period = n_period;/* For 50/50 duty cycle the divisor is equal to width */ out.esync_n_width = out.esync_n_period;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2068/2651 dpll: zl3073x: reject output frequencies with too small divisor
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ivan Vecera <[email protected]>
[ Upstream commit 456027325c9cd2be94229687f2c412ae6f351bd8 ]
The output divisor has to be at least 2: a divisor of 1 bypasses the divider and the hardware then ignores the pulse width and eSync registers. For the N-pin of an N-divided output the N divider (>= 2) applies on top, so its effective divisor has to be at least 4.
zl3073x_pin_check_freq() only checked that the frequency divides the synth frequency. Require also the minimum divisor. For N-divided outputs this is necessary but not sufficient, the rest is checked by the frequency set callback.
Hit during development: an N-pin frequency that needs an N divider of 1 was accepted, and with esync_n_period = 1 the N-pin produced no output on an oscilloscope.
--- drivers/dpll/zl3073x/prop.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-)
drivers/dpll/zl3073x/prop.c +27 -6
@@ -22,7 +22,8 @@* The function checks the given frequency is valid for the device. For input * pins it checks that the frequency can be factorized using supported base * frequencies. For output pins it checks that the frequency divides connected -* synth frequency without remainder. +* synth frequency without remainder and that the resulting divisor is not +* below the minimum the driver supports. * * Return: true if the frequency is valid, false if not. */
@@ -41,18 +42,38 @@ zl3073x_pin_check_freq(struct zl3073x_dev *zldev, enum dpll_pin_direction dir,if (rc) goto err_inv_freq; }else { -u32 synth_freq; -u8 out, synth; +u32 synth_freq, div, min_div, rem; +const struct zl3073x_out *out; +u8 out_id, synth;/* Get output pin synthesizer */ - out =zl3073x_output_pin_out_get (id); - synth =zl3073x_dev_out_synth_get (zldev, out); + out_id =zl3073x_output_pin_out_get (id); + synth =zl3073x_dev_out_synth_get (zldev, out_id);/* Get synth frequency */ synth_freq =zl3073x_dev_synth_freq_get (zldev, synth);/* Check the frequency divides synth frequency */ -if (synth_freq % (u32 )freq) + div =div_u64_rem (synth_freq, freq, &rem); +if (rem) + goto err_inv_freq; + +/* The driver requires an output divisor of at least 2 - +* below that the hardware bypasses the divider and ignores +* the pulse width and eSync registers the driver programs. +* For the N-pin of an N-divided output the effective divisor +* also includes the N divider (>= 2), so the minimum is 4. +* For N-divided outputs this is only a necessary condition - +* whether the frequency can be set also depends on the output +* divisor shared by both pins, which is checked when the +* frequency is set. +*/ + out =zl3073x_out_state_get (zldev, out_id); +if (zl3073x_out_is_ndiv (out) &&zl3073x_is_n_pin (id)) + min_div =4 ; +else + min_div =2 ; +if (div < min_div) goto err_inv_freq; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2069/2651 dpll: zl3073x: make embedded sync follow the output carrier frequency
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ivan Vecera <[email protected]>
[ Upstream commit bf6f105f2cb6477e36a9312477d0aa32a43aa13d ]
The eSync period and width are relative to the output carrier, but changing the output frequency did not update them, so eSync ran at a wrong frequency and duty cycle. For a 1 Hz carrier esync_get() returns -EOPNOTSUPP, so eSync left enabled could not be disabled.
Factor out zl3073x_out_esync_{is_enabled,enable,disable}() helpers and use them in frequency_set() to recompute the eSync period and width for the new carrier, or to disable eSync for a 1 Hz carrier.
Also compute the reported pulse width in 64 bits, as 50 * esync_n_width overflows u32 for low carrier frequencies.
Hit during development, confirmed on an oscilloscope.
--- drivers/dpll/zl3073x/dpll.c | 46 +++++++++++++++++++------------------ drivers/dpll/zl3073x/out.h | 36 +++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 22 deletions(-)
drivers/dpll/zl3073x/dpll.c +24 -22
@@ -878,7 +878,7 @@ zl3073x_dpll_output_pin_esync_get(const struct dpll_pin *dpll_pin, esync->range = esync_freq_ranges; esync->range_num =ARRAY_SIZE (esync_freq_ranges); -if (zl3073x_out_clock_type_get (out) !=ZL_OUTPUT_MODE_CLOCK_TYPE_ESYNC ) { +if (!zl3073x_out_esync_is_enabled (out)) {/* No need to read esync data if it is not enabled */ esync->freq =0 ; esync->pulse =0 ;
@@ -894,7 +894,7 @@ zl3073x_dpll_output_pin_esync_get(const struct dpll_pin *dpll_pin,* Note that half pulse width is in units of half synth cycles, which * is why it reduces down to be output_div. */ - esync->pulse = (50 * out->esync_n_width) / out->div; + esync->pulse =div_u64 (mul_u32_u32 (50 , out->esync_n_width), out->div);return 0 ; }
@@ -926,32 +926,17 @@ zl3073x_dpll_output_pin_esync_set(const struct dpll_pin *dpll_pin,if (zl3073x_out_is_ndiv (&out))return -EOPNOTSUPP ; -/* Update clock type in output mode */ -if (freq) -zl3073x_out_clock_type_set (&out, -ZL_OUTPUT_MODE_CLOCK_TYPE_ESYNC ); -else -zl3073x_out_clock_type_set (&out, -ZL_OUTPUT_MODE_CLOCK_TYPE_NORMAL ); - -/* If esync is being disabled just write mailbox and finish */ -if (!freq) +if (!freq) { +zl3073x_out_esync_disable (&out);return zl3073x_out_state_set (zldev, out_id, &out); + }/* Get attached synth frequency */ synth =zl3073x_synth_state_get (zldev,zl3073x_out_synth_get (&out)); synth_freq =zl3073x_synth_freq_get (synth); -/* Compute and update esync period */ - out.esync_n_period = synth_freq / (u32 )freq / out.div; - -/* Half of the period in units of 1/2 synth cycle can be represented by -* the output_div. To get the supported esync pulse width of 25% of the -* period the output_div can just be divided by 2. Note that this -* assumes that output_div is even, otherwise some resolution will be -* lost. -*/ - out.esync_n_width = out.div /2 ; +/* Enable 1PPS eSync for this pin frequency */ +zl3073x_out_esync_enable (&out, synth_freq / out.div);/* Commit output configuration */ return zl3073x_out_state_set (zldev, out_id, &out);
@@ -1010,6 +995,23 @@ zl3073x_dpll_output_pin_frequency_set(const struct dpll_pin *dpll_pin,/* For 50/50 duty cycle the divisor is equal to width */ out.width = new_div; +/* The embedded sync period and width are computed relative to +* the output carrier so they have to be adjusted to follow the +* new frequency. +*/ +if (zl3073x_out_esync_is_enabled (&out)) { +if (frequency ==1 ) { +/* eSync cannot work on a 1 Hz carrier */ +zl3073x_out_esync_disable (&out); + }else { +/* Update esync period and width according to +* the new frequency. +*/ +zl3073x_out_esync_enable (&out, + synth_freq / out.div); + } + } +/* Commit output configuration */ return zl3073x_out_state_set (zldev, out_id, &out); }
drivers/dpll/zl3073x/out.h +36 -0
@@ -134,4 +134,40 @@ static inline u8 zl3073x_out_synth_get(const struct zl3073x_out *out) return FIELD_GET(ZL_OUTPUT_CTRL_SYNTH_SEL, out->ctrl); } +static inline bool zl3073x_out_esync_is_enabled (const struct zl3073x_out *out) +{ +u8 clock_type =zl3073x_out_clock_type_get (out); + +return clock_type ==ZL_OUTPUT_MODE_CLOCK_TYPE_ESYNC ; +} + +static inline +void zl3073x_out_esync_enable (struct zl3073x_out *out,u32 base_freq) +{ +/* Period is expressed as the number of output divider clock cycles. +* So for 1 Hz the period is equal to base frequency. +*/ + out->esync_n_period = base_freq; + +/* Half of the period in units of 1/2 synth cycle can be represented by +* the output_div. To get the supported esync pulse width of 25% of the +* period the output_div can just be divided by 2. Note that this +* assumes that output_div is even, otherwise some resolution will be +* lost. +*/ + out->esync_n_width = out->div /2 ; + +/* Update the clock type */ +zl3073x_out_clock_type_set (out,ZL_OUTPUT_MODE_CLOCK_TYPE_ESYNC ); +} + +static inline +void zl3073x_out_esync_disable (struct zl3073x_out *out) +{ +/* Just update the clock type. The eSync period and width are +* ignored for this clock type. +*/ +zl3073x_out_clock_type_set (out,ZL_OUTPUT_MODE_CLOCK_TYPE_NORMAL ); +} +#endif /* _ZL3073X_OUT_H */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2070/2651 dpll: zl3073x: notify sibling pin when shared output config changes
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ivan Vecera <[email protected]>
[ Upstream commit 0748e473b65a8c8690e250cdf7cc4f5a93252493 ]
The P-pin and N-pin of an output share the divisor, clock type, eSync and phase compensation registers (outside N-divided mode). Changing them through one pin changes the other pin too, but only the requested pin gets a change notification.
Add zl3073x_dpll_output_pin_sibling_get() and notify the sibling from frequency_set(), esync_set() and phase_adjust_set(). The notification re-enters the pin get callbacks, so it has to be sent after zldpll->lock is released and the callbacks switch from guard(mutex) to explicit unlocking.
To always find a registered sibling, add a pin to zldpll->pins before dpll_pin_register() and remove it only after dpll_pin_unregister(), both under zldpll->lock. A pin that is on the list but not registered gets no netlink notification, as dpll_pin_event_send() skips such pins, and the only in-tree DPLL notifier ignores DPLL_PIN_CHANGED.
Found by code inspection, not triggered at runtime.
--- drivers/dpll/zl3073x/dpll.c | 155 +++++++++++++++++++++++++++++++----- 1 file changed, 135 insertions(+), 20 deletions(-)
drivers/dpll/zl3073x/dpll.c +135 -20
@@ -123,6 +123,8 @@ zl3073x_dpll_pin_get_by_ref(struct zl3073x_dpll *zldpll, u8 ref_id) {struct zl3073x_dpll_pin *pin; +lockdep_assert_held (&zldpll->lock); +list_for_each_entry (pin, &zldpll->pins, list) {if (zl3073x_dpll_is_input_pin (pin) &&zl3073x_input_pin_ref_get (pin->id) == ref_id)
@@ -132,11 +134,42 @@ zl3073x_dpll_pin_get_by_ref(struct zl3073x_dpll *zldpll, u8 ref_id)return NULL ; } +/** +* zl3073x_dpll_output_pin_sibling_get - get the other pin of an output pair +* @pin: output pin whose sibling is sought +* +* Output pin ids are allocated in P/N pairs (P even, N odd) that share a +* single HW output. Looks up the other pin of the pair in the pin list +* of this DPLL. A pin is on the list from just before its registration +* until just after its unregistration, so a registered sibling is always +* found, but the returned pin may also be one that is not (yet or any +* longer) registered. +* +* Return: pointer to sibling pin, or NULL if it is not on the pin list +*/ +static struct zl3073x_dpll_pin * +zl3073x_dpll_output_pin_sibling_get (struct zl3073x_dpll_pin *pin) +{ +struct zl3073x_dpll_pin *sibling; + +lockdep_assert_held (&pin->dpll->lock); + +list_for_each_entry (sibling, &pin->dpll->pins, list) { +if (!zl3073x_dpll_is_input_pin (sibling) && + sibling->id == (pin->id ^1 )) +return sibling; + } + +return NULL ; +} +static struct zl3073x_dpll_pin *zl3073x_dpll_nco_pin_get (struct zl3073x_dpll *zldpll) {struct zl3073x_dpll_pin *pin; +lockdep_assert_held (&zldpll->lock); +list_for_each_entry (pin, &zldpll->pins, list) {if (zl3073x_dpll_is_nco_pin (pin))return pin;
@@ -909,12 +942,14 @@ zl3073x_dpll_output_pin_esync_set(const struct dpll_pin *dpll_pin,struct zl3073x_dpll *zldpll = dpll_priv;struct zl3073x_dev *zldev = zldpll->dev;struct zl3073x_dpll_pin *pin = pin_priv; +struct zl3073x_dpll_pin *sibling =NULL ;const struct zl3073x_synth *synth;struct zl3073x_out out;u32 synth_freq;u8 out_id; +int rc; -guard (mutex)(&zldpll->lock); +mutex_lock (&zldpll->lock); out_id =zl3073x_output_pin_out_get (pin->id); out = *zl3073x_out_state_get (zldev, out_id);
@@ -923,12 +958,14 @@ zl3073x_dpll_output_pin_esync_set(const struct dpll_pin *dpll_pin,* for N-division is also used for the esync divider so both cannot * be used. */ -if (zl3073x_out_is_ndiv (&out)) -return -EOPNOTSUPP ; +if (zl3073x_out_is_ndiv (&out)) { + rc = -EOPNOTSUPP ; + goto unlock; + }if (!freq) {zl3073x_out_esync_disable (&out); -return zl3073x_out_state_set (zldev, out_id, &out); + goto commit; }/* Get attached synth frequency */
@@ -937,9 +974,24 @@ zl3073x_dpll_output_pin_esync_set(const struct dpll_pin *dpll_pin,/* Enable 1PPS eSync for this pin frequency */ zl3073x_out_esync_enable (&out, synth_freq / out.div); - +commit:/* Commit output configuration */ -return zl3073x_out_state_set (zldev, out_id, &out); + rc =zl3073x_out_state_set (zldev, out_id, &out); +if (rc) + goto unlock; + +/* The clock type, esync period and esync width are all shared by +* both pins of the output pair, so the sibling pin's esync +* configuration changes too and userspace has to be notified. +*/ + sibling =zl3073x_dpll_output_pin_sibling_get (pin); +unlock: +mutex_unlock (&zldpll->lock); + +if (!rc && sibling) +__dpll_pin_change_ntf (sibling->dpll_pin); + +return rc; } static int
@@ -969,13 +1021,15 @@ zl3073x_dpll_output_pin_frequency_set(const struct dpll_pin *dpll_pin,struct zl3073x_dpll *zldpll = dpll_priv;struct zl3073x_dev *zldev = zldpll->dev;struct zl3073x_dpll_pin *pin = pin_priv; +struct zl3073x_dpll_pin *sibling =NULL ;const struct zl3073x_synth *synth;u32 new_div, synth_freq;struct zl3073x_out out;u64 n_period, rem;u8 out_id; +int rc; -guard (mutex)(&zldpll->lock); +mutex_lock (&zldpll->lock); out_id =zl3073x_output_pin_out_get (pin->id); out = *zl3073x_out_state_get (zldev, out_id);
@@ -988,7 +1042,8 @@ zl3073x_dpll_output_pin_frequency_set(const struct dpll_pin *dpll_pin,/* Check signal format */ if (!zl3073x_out_is_ndiv (&out)) {/* For non N-divided signal formats the frequency is computed -* as division of synth frequency and output divisor. +* as division of synth frequency and output divisor, which +* is shared by both pins of the output pair. */ out.div = new_div;
@@ -1013,7 +1068,16 @@ zl3073x_dpll_output_pin_frequency_set(const struct dpll_pin *dpll_pin, }/* Commit output configuration */ -return zl3073x_out_state_set (zldev, out_id, &out); + rc =zl3073x_out_state_set (zldev, out_id, &out); +if (rc) + goto unlock; + +/* The other pin's frequency changed too - it has to be +* notified about the change. +*/ + sibling =zl3073x_dpll_output_pin_sibling_get (pin); + + goto unlock; }if (zl3073x_dpll_is_p_pin (pin)) {
@@ -1039,19 +1103,22 @@ zl3073x_dpll_output_pin_frequency_set(const struct dpll_pin *dpll_pin,NL_SET_ERR_MSG_FMT (extack,"OUT%uN freq must be at most half of OUT%uP freq" , out_id, out_id); -return -EINVAL ; + rc = -EINVAL ; + goto unlock; }if (n_period >U32_MAX ) {NL_SET_ERR_MSG_FMT (extack,"OUT%uN freq is too low for OUT%uP freq" , out_id, out_id); -return -EINVAL ; + rc = -EINVAL ; + goto unlock; }if (rem !=0 ) {NL_SET_ERR_MSG_FMT (extack,"OUT%uN freq must divide OUT%uP freq" , out_id, out_id); -return -EINVAL ; + rc = -EINVAL ; + goto unlock; } out.esync_n_period = n_period;
@@ -1059,7 +1126,14 @@ zl3073x_dpll_output_pin_frequency_set(const struct dpll_pin *dpll_pin, out.esync_n_width = out.esync_n_period;/* Commit output configuration */ -return zl3073x_out_state_set (zldev, out_id, &out); + rc =zl3073x_out_state_set (zldev, out_id, &out); +unlock: +mutex_unlock (&zldpll->lock); + +if (!rc && sibling) +__dpll_pin_change_ntf (sibling->dpll_pin); + +return rc; } static int
@@ -1098,10 +1172,12 @@ zl3073x_dpll_output_pin_phase_adjust_set(const struct dpll_pin *dpll_pin,struct zl3073x_dpll *zldpll = dpll_priv;struct zl3073x_dev *zldev = zldpll->dev;struct zl3073x_dpll_pin *pin = pin_priv; +struct zl3073x_dpll_pin *sibling =NULL ;struct zl3073x_out out;u8 out_id; +int rc; -guard (mutex)(&zldpll->lock); +mutex_lock (&zldpll->lock); out_id =zl3073x_output_pin_out_get (pin->id); out = *zl3073x_out_state_get (zldev, out_id);
@@ -1110,7 +1186,21 @@ zl3073x_dpll_output_pin_phase_adjust_set(const struct dpll_pin *dpll_pin, out.phase_comp = phase_adjust / pin->phase_gran;/* Update output configuration from mailbox */ -return zl3073x_out_state_set (zldev, out_id, &out); + rc =zl3073x_out_state_set (zldev, out_id, &out); +if (rc) + goto unlock; + +/* The phase compensation register is shared by both pins of the +* output pair, so the sibling pin's phase adjustment changes too. +*/ + sibling =zl3073x_dpll_output_pin_sibling_get (pin); +unlock: +mutex_unlock (&zldpll->lock); + +if (!rc && sibling) +__dpll_pin_change_ntf (sibling->dpll_pin); + +return rc; } static int
@@ -1734,6 +1824,13 @@ zl3073x_dpll_pin_register(struct zl3073x_dpll_pin *pin, u32 index)else ops = &zl3073x_dpll_output_pin_ops; +/* Add the pin to the list before registering it with the DPLL core so +* that it is findable as a sibling as soon as the core publishes it. +*/ +mutex_lock (&zldpll->lock); +list_add (&pin->list, &zldpll->pins); +mutex_unlock (&zldpll->lock); +/* Register the pin */ rc =dpll_pin_register (zldpll->dpll_dev, pin->dpll_pin, ops, pin);if (rc)
@@ -1745,6 +1842,9 @@ zl3073x_dpll_pin_register(struct zl3073x_dpll_pin *pin, u32 index)return 0 ; err_register: +mutex_lock (&zldpll->lock); +list_del (&pin->list); +mutex_unlock (&zldpll->lock);dpll_pin_put (pin->dpll_pin, &pin->tracker); err_pin_get: pin->dpll_pin =NULL ;
@@ -1779,6 +1879,13 @@ zl3073x_dpll_pin_unregister(struct zl3073x_dpll_pin *pin)/* Unregister the pin */ dpll_pin_unregister (zldpll->dpll_dev, pin->dpll_pin, ops, pin); +/* Remove the pin from the list only after it has been unregistered so +* that a still-registered pin is always findable as a sibling. +*/ +mutex_lock (&zldpll->lock); +list_del (&pin->list); +mutex_unlock (&zldpll->lock); +dpll_pin_put (pin->dpll_pin, &pin->tracker); pin->dpll_pin =NULL ;
@@ -1798,9 +1905,11 @@ zl3073x_dpll_pins_unregister(struct zl3073x_dpll *zldpll) {struct zl3073x_dpll_pin *pin, *next; +/* Unregister each pin before removing it from the list so that a +* still-registered pin is always findable as a sibling. +*/ list_for_each_entry_safe (pin, next, &zldpll->pins, list) {zl3073x_dpll_pin_unregister (pin); -list_del (&pin->list);zl3073x_dpll_pin_free (pin); } }
@@ -1913,16 +2022,24 @@ zl3073x_dpll_nco_pin_register(struct zl3073x_dpll *zldpll) goto err_pin_get; } +/* Add the pin to the list before registering it with the DPLL core so +* that a registered pin is always on the list. +*/ +mutex_lock (&zldpll->lock); +list_add (&pin->list, &zldpll->pins); +mutex_unlock (&zldpll->lock); + rc =dpll_pin_register (zldpll->dpll_dev, pin->dpll_pin, &zl3073x_dpll_nco_pin_ops, pin);if (rc) goto err_register; -list_add (&pin->list, &zldpll->pins); -return 0 ; err_register: +mutex_lock (&zldpll->lock); +list_del (&pin->list); +mutex_unlock (&zldpll->lock);dpll_pin_put (pin->dpll_pin, &pin->tracker); err_pin_get: pin->dpll_pin =NULL ;
@@ -1974,8 +2091,6 @@ zl3073x_dpll_pins_register(struct zl3073x_dpll *zldpll)zl3073x_dpll_pin_free (pin); goto error; } - -list_add (&pin->list, &zldpll->pins); }/* Register NCO virtual input pin */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2071/2651 dpaa2-ptp: fix support for PTP_EXTTS_REQUEST2 ioctl
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vincent Jardin <[email protected]>
[ Upstream commit 86a30c4348497bcddcf2796258955bbaaf58c9a3 ]
Commit 7c571ac57d9d ("net: ptp: introduce .supported_extts_flags to ptp_clock_info") moved the validation of the external timestamp request flags into the PTP core. A driver that does not set .supported_extts_flags still accepts the legacy PTP_EXTTS_REQUEST ioctl, but every PTP_EXTTS_REQUEST2 request is rejected with -EOPNOTSUPP.
On an LX2160A board, linuxptp ts2phc arms the external timestamp channel of the 1588 timer with PTP_EXTTS_REQUEST2, gets -EOPNOTSUPP and exits, so the PHC cannot be disciplined from an external 1PPS.
ptp_qoriq_init() programs TMR_CTRL with ETEP1 and ETEP2 cleared, so the timer timestamps the rising edge of its external trigger inputs. Declare that, with PTP_STRICT_FLAGS, so that a falling edge request is rejected instead of being timestamped on the rising edge.
This also makes the legacy PTP_EXTTS_REQUEST ioctl strict: a request for the falling edge, or for both edges, now fails with -EOPNOTSUPP instead of being timestamped on the rising edge. That cannot be avoided: the core adds PTP_STRICT_FLAGS to every PTP_EXTTS_REQUEST2 request, so a driver has to declare it to accept them, and once declared it applies to both ioctls. Commit 3200fdd4021d ("broadcom: fix support for PTP_EXTTS_REQUEST2 ioctl") made the same change for bcm-phy-ptp.
--- drivers/net/ethernet/freescale/dpaa2/dpaa2-ptp.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/freescale/dpaa2/dpaa2-ptp.c +1 -0
@@ -78,6 +78,7 @@ static const struct ptp_clock_info dpaa2_ptp_caps = { .n_per_out = 3, .n_pins = 0, .pps = 1, + .supported_extts_flags = PTP_RISING_EDGE | PTP_STRICT_FLAGS, .adjfine = ptp_qoriq_adjfine, .adjtime = ptp_qoriq_adjtime, .gettime64 = ptp_qoriq_gettime,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2072/2651 net: enetc: fix support for PTP_EXTTS_REQUEST2 ioctl
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vincent Jardin <[email protected]>
[ Upstream commit 8e96c4d393168661704d850bcf818e46efb8ef24 ]
Commit 7c571ac57d9d ("net: ptp: introduce .supported_extts_flags to ptp_clock_info") moved the validation of the external timestamp request flags into the PTP core. A driver that does not set .supported_extts_flags still accepts the legacy PTP_EXTTS_REQUEST ioctl, but every PTP_EXTTS_REQUEST2 request is rejected with -EOPNOTSUPP.
The ENETC timer is the QorIQ 1588 timer, set up by ptp_qoriq_init(), which programs TMR_CTRL with ETEP1 and ETEP2 cleared, so it timestamps the rising edge of its external trigger inputs. Declare that, with PTP_STRICT_FLAGS, so that a falling edge request is rejected instead of being timestamped on the rising edge.
This also makes the legacy PTP_EXTTS_REQUEST ioctl strict: a request for the falling edge, or for both edges, now fails with -EOPNOTSUPP instead of being timestamped on the rising edge. That cannot be avoided: the core adds PTP_STRICT_FLAGS to every PTP_EXTTS_REQUEST2 request, so a driver has to declare it to accept them, and once declared it applies to both ioctls. Commit 3200fdd4021d ("broadcom: fix support for PTP_EXTTS_REQUEST2 ioctl") made the same change for bcm-phy-ptp.
--- drivers/net/ethernet/freescale/enetc/enetc_ptp.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/freescale/enetc/enetc_ptp.c +1 -0
@@ -16,6 +16,7 @@ static struct ptp_clock_info enetc_ptp_caps = { .n_per_out = 0, .n_pins = 0, .pps = 1, + .supported_extts_flags = PTP_RISING_EDGE | PTP_STRICT_FLAGS, .adjfine = ptp_qoriq_adjfine, .adjtime = ptp_qoriq_adjtime, .gettime64 = ptp_qoriq_gettime,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2073/2651 ptp: qoriq: fix support for PTP_EXTTS_REQUEST2 ioctl
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vincent Jardin <[email protected]>
[ Upstream commit d347ab5cf809365e7b3749dc91d77e89e4b7ec3f ]
Commit 7c571ac57d9d ("net: ptp: introduce .supported_extts_flags to ptp_clock_info") moved the validation of the external timestamp request flags into the PTP core. A driver that does not set .supported_extts_flags still accepts the legacy PTP_EXTTS_REQUEST ioctl, but every PTP_EXTTS_REQUEST2 request is rejected with -EOPNOTSUPP, since the core always adds PTP_STRICT_FLAGS to it.
ptp_qoriq_init() programs TMR_CTRL with ETEP1 and ETEP2 cleared, so the timer timestamps the rising edge of its external trigger inputs. Declare that, with PTP_STRICT_FLAGS, so that a falling edge request is rejected instead of being timestamped on the rising edge.
This also makes the legacy PTP_EXTTS_REQUEST ioctl strict: a request for the falling edge, or for both edges, now fails with -EOPNOTSUPP instead of being timestamped on the rising edge. That cannot be avoided: the core adds PTP_STRICT_FLAGS to every PTP_EXTTS_REQUEST2 request, so a driver has to declare it to accept them, and once declared it applies to both ioctls. Commit 3200fdd4021d ("broadcom: fix support for PTP_EXTTS_REQUEST2 ioctl") made the same change for bcm-phy-ptp.
--- drivers/ptp/ptp_qoriq.c | 1 + 1 file changed, 1 insertion(+)
drivers/ptp/ptp_qoriq.c +1 -0
@@ -355,6 +355,7 @@ static const struct ptp_clock_info ptp_qoriq_caps = { .n_per_out = 0, .n_pins = 0, .pps = 1, + .supported_extts_flags = PTP_RISING_EDGE | PTP_STRICT_FLAGS, .adjfine = ptp_qoriq_adjfine, .adjtime = ptp_qoriq_adjtime, .gettime64 = ptp_qoriq_gettime,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2074/2651 gre: keep the UDP tunnel GSO type when completing GRO
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Brad Fitzpatrick <[email protected]>
[ Upstream commit 718f364a20ecee4f25986789c25550cf4da73b4c ]
gre_gro_complete() assigns SKB_GSO_GRE to gso_type rather than OR-ing it in. When GRE is carried over UDP by FOU or GUE, udp_gro_complete() has already set SKB_GSO_UDP_TUNNEL{,_CSUM} before calling into the FOU or GUE gro_complete handler and then gre_gro_complete(), so that bit is lost.
That has broken forwarding of such packets since FOU gained GRO: if a host with a FOU or GUE socket on the tunnel's port merges transit packets and then forwards them out a device that can't segment them itself, udp4_ufo_fragment() finds neither tunnel bit and fails, and the packets are dropped. Since commit 3d010c8031e3 ("udp: do not accept non-tunnel GSO skbs landing in a tunnel"), local receive is broken too:udp_unexpected_gso() considers the merged skb, which reaches the encapsulation socket without either UDP tunnel bit, unexpected and hands it to udp_rcv_segment(). Segmenting fails, so the packet is freed and counted in UdpInErrors. Either way, only packets GRO didn't merge get through, so TCP over FOU or GUE GRE tunnels slows to about one segment per round trip whenever the receiving device has GRO enabled.
OR in SKB_GSO_GRE instead, as ipip_gro_complete() and sit_gro_complete() do for SKB_GSO_IPXIP4. For plain GRE, gso_type is still zero at this point unless the driver set it, so nothing changes there in the usual case.
The assignment dates to commit bf5a755f5e91 ("net-gre-gro: Add GRE support to the GRO stack"), but nothing set gso_type before it until FOU GRO came along, so the Fixes tag points there.
Tested under virtme-ng with bulk TCP over a GRE tunnel between two network namespaces joined by a veth, with GRO on the receiving veth and segmentation off on the sending one, so GRO sees wire-sized packets. 32 MiB took:
before after FOU over IPv4 26.0s, 9658 UDP errors 0.28s, 0 errors GUE over IPv4 26.1s, 9686 UDP errors 0.39s, 0 errors FOU over IPv6 26.4s, 9860 UDP errors 0.16s, 0 errors plain GRE 0.17s 0.15s
Forwarding the same FOU traffic through a third namespace with its own FOU socket on the port, GRO on its ingress and segmentation off on its egress, took 26.0s with 4826 egress drops before and 0.31s with none after. On v6.8, before 3d010c8031e3, local receive was fine but forwarding failed the same way (25.7s, 4764 drops).
With GRO off on the receiver, all took under 0.2s both before and after. The gre_gso.sh and fou_mcast_encap.sh selftests give the same results before and after.
--- net/ipv4/gre_offload.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/gre_offload.c +1 -1
@@ -242,7 +242,7 @@ static int gre_gro_complete(struct sk_buff *skb, int nhoff)__be16 type; skb->encapsulation =1 ; -skb_shinfo (skb)->gso_type =SKB_GSO_GRE ; +skb_shinfo (skb)->gso_type |=SKB_GSO_GRE ; type = greh->protocol;if (greh->flags &GRE_KEY )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2075/2651 bpf: Dont echo user-supplied map info fields back to userspace
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Borkmann <[email protected]>
[ Upstream commit 458575e1f2ddea944d679fe778c92e370a9b61a4 ]
Commit ea2e6467ac36 ("bpf: Return hashes of maps in BPF_OBJ_GET_INFO_BY_FD") started copying struct bpf_map_info in from userspace in order to read the new hash and hash_size input fields. Before that, the kernel ignored the contents of the user buffer and returned a zeroed structure with only the output fields filled in.
Some output fields are only set for certain maps: btf_id, btf_key_type_id and btf_value_type_id when the map has BTF (and btf_vmlinux_id for struct_ops maps, ifindex, netns_dev and netns_ino when the map is offloaded). For all other maps, these fields now return whatever userspace passed in before.
This breaks userspace which reuses one bpf_map_info for several queries. Restore the original behavior by zeroing the structure and copying in only hash and hash_size from userspace before the output fields are filled in.
--- kernel/bpf/syscall.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
kernel/bpf/syscall.c +5 -1
@@ -5427,7 +5427,11 @@ static int bpf_map_get_info_by_fd(struct file *file, info_len =min_t (u32,sizeof (info), info_len);memset (&info,0 ,sizeof (info)); -if (copy_from_user (&info, uinfo, info_len)) + if (info_len >= offsetofend(struct bpf_map_info, hash) && +get_user (info.hash, &uinfo->hash)) +return -EFAULT ; + if (info_len >= offsetofend(struct bpf_map_info, hash_size) && +get_user (info.hash_size, &uinfo->hash_size))return -EFAULT ; info.type = map->map_type;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2076/2651 ALSA: jack: Protect the index scan against control removal
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit ba8c3d5fc27ac3f86962641dd3b6600906234bab ]
A control found during a jack-name index scan must remain alive until snd_ctl_find_id() finishes comparing its ID and count. However, get_available_index() calls it without holding card->controls_rwsem. With CONFIG_SND_CTL_FAST_LOOKUP enabled, the lookup loads a raw control pointer from ctl_hash and dereferences it in elem_id_matches() without any lock that excludes removal.
This can happen when a jack is created while a different jack owner on the same card removes an existing control with the same name and index. For example, probe and unbind of different HDA codecs can reach these paths on a shared card if their generated jack names match. The codec device locks do not serialize operations on different codecs. The unbind path can free the control during the index scan:
Codec A: probe Codec B: unbind
-------------- ---------------
get_available_index()
snd_ctl_find_id()
kctl = xa_load(...)
hda_codec_driver_remove()
snd_hda_codec_cleanup_for_unbind()
snd_hda_jack_tbl_clear()
snd_device_free()
__snd_device_free()
snd_jack_dev_free()
snd_ctl_remove()
snd_ctl_remove_locked()
__snd_ctl_remove()
snd_ctl_free_one()
kfree(kctl)
elem_id_matches(kctl, ...)
read freed id/count -> UAFHold controls_rwsem for read across the index scan so removal cannot free a control until the lookup has finished using it. Release the lock when get_available_index() returns, before the caller adds the new control under the write lock.
--- sound/core/ctljack.c | 1 + 1 file changed, 1 insertion(+)
sound/core/ctljack.c +1 -0
@@ -38,6 +38,7 @@ static int get_available_index(struct snd_card *card, const char *name) sid.iface =SNDRV_CTL_ELEM_IFACE_CARD ;strscpy (sid.name, name,sizeof (sid.name)); +guard (rwsem_read)(&card->controls_rwsem);while (snd_ctl_find_id (card, &sid)) { sid.index++;/* reset numid; otherwise snd_ctl_find_id() hits this again */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2077/2651 PCI: endpoint: pci-epf-vntb: Use a local epf pointer in interrupt setup
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Koichiro Den <[email protected]>
[ Upstream commit 17c4115cbe99da4d147aee778c308da1d4bb000d ]
Use a local epf pointer in epf_ntb_configure_interrupt() to shorten the repeated ntb->epf accesses.
No functional changes.
Stable-dep-of: a5401ce3ab23 ("PCI: endpoint: pci-epf-vntb: Honor MSI-X selection")
--- drivers/pci/endpoint/functions/pci-epf-vntb.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/pci/endpoint/functions/pci-epf-vntb.c +5 -6
@@ -546,12 +546,14 @@ static int epf_ntb_config_spad_bar_alloc(struct epf_ntb *ntb)static int epf_ntb_configure_interrupt (struct epf_ntb *ntb) {const struct pci_epc_features *epc_features; +struct pci_epf *epf = ntb->epf;struct device *dev;int ret; - dev = &ntb->epf->dev; + dev = &epf->dev; - epc_features =pci_epc_get_features (ntb->epf->epc, ntb->epf->func_no, ntb->epf->vfunc_no); + epc_features =pci_epc_get_features (epf->epc, epf->func_no, + epf->vfunc_no);if (!(epc_features->msix_capable || epc_features->msi_capable)) {dev_err (dev,"MSI or MSI-X is required for doorbell\n" );
@@ -565,10 +567,7 @@ static int epf_ntb_configure_interrupt(struct epf_ntb *ntb) }if (epc_features->msi_capable) { - ret =pci_epc_set_msi (ntb->epf->epc, - ntb->epf->func_no, - ntb->epf->vfunc_no, -16 ); + ret =pci_epc_set_msi (epf->epc, epf->func_no, epf->vfunc_no,16 );if (ret) {dev_err (dev,"MSI configuration failed\n" );return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2078/2651 PCI: endpoint: pci-epf-vntb: Honor MSI-X selection
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Koichiro Den <[email protected]>
[ Upstream commit a5401ce3ab2356b7861f53d09205008b7a49d57e ]
ntb_hw_epf tries MSI-X first and falls back to MSI. It reports the result in COMMAND_CONFIGURE_DOORBELL. pci-epf-vntb ignores MSIX_ENABLE, configures only MSI, and always raises peer interrupts with PCI_IRQ_MSI. When MSI-X is selected, the host does not program MSI, so raising it can issue a write to an invalid address. This was observed as IOMMU faults on the RC, with no doorbell interrupts delivered.
Configure MSI-X when supported and use the selected type for peer doorbells and link events. Allocate the MSI-X Table and PBA in the config BAR and configure db_count entries. Use this EPF-owned layout even if the EPC has fixed, hardware-owned Table/PBA regions, as pci-epf-test and nvmet-pci-epf already do.
--- drivers/pci/endpoint/functions/pci-epf-vntb.c | 47 ++++++++++++++++--- 1 file changed, 41 insertions(+), 6 deletions(-)
drivers/pci/endpoint/functions/pci-epf-vntb.c +41 -6
@@ -152,6 +152,7 @@ struct epf_ntb {struct mutex link_lock;bool host_link_enabled;bool vhost_link_enabled; +bool peer_msix;/* * True when doorbells are interrupt-driven (MSI or embedded), false
@@ -159,6 +160,7 @@ struct epf_ntb {*/ bool msi_doorbell;u32 spad_size; +u32 msix_table_offset;enum pci_barno epf_ntb_bar[VNTB_BAR_NUM ];
@@ -202,13 +204,16 @@ static void epf_ntb_update_link(struct epf_ntb *ntb)static int epf_ntb_notify_link (struct ntb_dev *ndev) { -struct pci_epf *epf =ntb_ndev (ndev)->epf; +struct epf_ntb *ntb =ntb_ndev (ndev); +struct pci_epf *epf = ntb->epf; +unsigned int irq_type;int ret;ntb_link_event (ndev); + irq_type = ntb->peer_msix ?PCI_IRQ_MSIX :PCI_IRQ_MSI ; ret =pci_epc_raise_irq (epf->epc, epf->func_no, epf->vfunc_no, -PCI_IRQ_MSI ,EPF_IRQ_LINK +1 ); + irq_type,EPF_IRQ_LINK +1 );if (ret)dev_err (&epf->dev,"Failed to raise link event IRQ: %d\n" , ret);
@@ -311,6 +316,7 @@ static void epf_ntb_teardown_mw(struct epf_ntb *ntb, u32 mw)*/ static void epf_ntb_cmd_handler (struct work_struct *work) { +const struct pci_epc_features *epc_features;struct epf_ntb_ctrl *ctrl;u32 command, argument;struct epf_ntb *ntb;
@@ -343,6 +349,15 @@ static void epf_ntb_cmd_handler(struct work_struct *work)switch (command) {case COMMAND_CONFIGURE_DOORBELL : + epc_features =pci_epc_get_features (ntb->epf->epc, + ntb->epf->func_no, + ntb->epf->vfunc_no); +if (((argument &MSIX_ENABLE ) && !epc_features->msix_capable) || + (!(argument &MSIX_ENABLE ) && !epc_features->msi_capable)) { + ctrl->command_status =COMMAND_STATUS_ERROR ; +break ; + } + ntb->peer_msix = argument &MSIX_ENABLE ; ctrl->command_status =COMMAND_STATUS_OK ;break ;case COMMAND_TEARDOWN_DOORBELL :
@@ -484,8 +499,9 @@ static void epf_ntb_config_spad_bar_free(struct epf_ntb *ntb)* @ntb: NTB device that facilitates communication between HOST and VHOST * * Allocate the Local Memory mentioned in the above diagram. The size of -* CONFIG REGION is sizeof(struct epf_ntb_ctrl) and size of SCRATCHPAD REGION -* is obtained from "spad-count" configfs entry. +* CONFIG REGION is sizeof(struct epf_ntb_ctrl), plus space for the MSI-X +* Table and PBA if supported. The size of SCRATCHPAD REGION is obtained +* from "spad-count" configfs entry. * * Returns: Zero for success, or an error code in case of failure */
@@ -506,6 +522,12 @@ static int epf_ntb_config_spad_bar_alloc(struct epf_ntb *ntb) spad_count = ntb->spad_count; ctrl_size =ALIGN (sizeof (struct epf_ntb_ctrl ),sizeof (u32)); +if (epc_features->msix_capable) { + ntb->msix_table_offset =ALIGN (ctrl_size,8 ); + ctrl_size = ntb->msix_table_offset + + ntb->db_count *PCI_MSIX_ENTRY_SIZE + +BITS_TO_U64 (ntb->db_count) *sizeof (u64); + } spad_size =2 * spad_count *sizeof (u32); base = pci_epf_alloc_space(epf, ctrl_size + spad_size,
@@ -574,6 +596,17 @@ static int epf_ntb_configure_interrupt(struct epf_ntb *ntb) } } +if (epc_features->msix_capable) { + ret =pci_epc_set_msix (epf->epc, epf->func_no, epf->vfunc_no, + ntb->db_count, + ntb->epf_ntb_bar[BAR_CONFIG ], + ntb->msix_table_offset); +if (ret) { +dev_err (dev,"MSI-X configuration failed\n" ); +return ret; + } + } +return 0 ; }
@@ -1579,6 +1612,7 @@ static void vntb_epf_peer_db_work(struct work_struct *work) struct epf_ntb *ntb = container_of(work, struct epf_ntb, peer_db_work);struct pci_epf *epf = ntb->epf;unsigned int budget =VNTB_PEER_DB_WORK_BUDGET ; +unsigned int irq_type;u8 func_no, vfunc_no;unsigned int db_bit;u32 interrupt_num;
@@ -1590,6 +1624,7 @@ static void vntb_epf_peer_db_work(struct work_struct *work) func_no = epf->func_no; vfunc_no = epf->vfunc_no; + irq_type = ntb->peer_msix ?PCI_IRQ_MSIX :PCI_IRQ_MSI ;/* * Drain doorbells from peer_db_pending in snapshots (atomic64_xchg()).
@@ -1603,7 +1638,7 @@ static void vntb_epf_peer_db_work(struct work_struct *work)while (db_bits) {/* -* pci_epc_raise_irq() for MSI expects a 1-based +* pci_epc_raise_irq() for MSI/MSI-X expects a 1-based * interrupt number. The first usable doorbell starts * at EPF_IRQ_DB_START in the legacy slot layout. *
@@ -1623,7 +1658,7 @@ static void vntb_epf_peer_db_work(struct work_struct *work) db_bits &= ~BIT_ULL (db_bit); ret =pci_epc_raise_irq (epf->epc, func_no, vfunc_no, -PCI_IRQ_MSI , interrupt_num); + irq_type, interrupt_num);if (ret) dev_err(&epf->dev, "Failed to raise IRQ for interrupt_num %u: %d\n",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2079/2651 perf test attr: Fix record dwarf sample_type expectation
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 10e2992e5438c39d8404714aebf3261a391bc76d ]
Since commit bdd051e24914 ("perf record: Split --data-mmap option"), record_opts__parse_callchain() sets record_data_mmap instead of record->sample_address for the DWARF unwind mode, so -d/--data and its implied PERF_SAMPLE_DATA_SRC are not enabled implicitly anymore.
As a result, --call-graph dwarf no longer sets PERF_SAMPLE_ADDR and PERF_SAMPLE_DATA_SRC, making the test fail:
expected sample_type=45359, got 12583
where 45359 (0xb12f) is:
IP|TID|TIME|ADDR|CALLCHAIN|PERIOD|REGS_USER|STACK_USER|DATA_SRC
and 12583 (0x3127) is:
IP|TID|TIME|CALLCHAIN|PERIOD|REGS_USER|STACK_USER
i.e. the values differ exactly by PERF_SAMPLE_ADDR (0x8) and PERF_SAMPLE_DATA_SRC (0x8000). The mmap_data=1 expectation is still correct as DWARF now enables record_data_mmap.
This went unnoticed until tests/attr.sh stopped ignoring attr.py's return value.
--- tools/perf/tests/shell/attr/test-record-graph-dwarf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/shell/attr/test-record-graph-dwarf +1 -1
@@ -4,7 +4,7 @@ args = --no-bpf-event --call-graph dwarf -- kill >/dev/null 2>&1 ret = 1 [event:base-record] -sample_type=45359 +sample_type=12583 exclude_callchain_user=1 sample_stack_user=8192 # TODO different for each arch, no support for that now
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2080/2651 perf test attr: Fix legacy event encodings in group tests
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 599311bca66459fc4a7e5acf970b14dee60f88a7 ]
Since commit b1c5efbfd92e ("perf parse-events: Remove hard coded legacy hardware and cache parsing"), event names are resolved with sysfs/JSON priority over the legacy encodings, so bare cache-misses and instructions now become the core PMU sysfs/JSON events (on x86 type 4, configs 0x412e and 0xc0) rather than the legacy PERF_TYPE_HARDWARE/config=3 and config=1 events the tests expect, e.g.:
expected config=3, got 0
expected disabled=0, got 1
expected mmap=0, got 1
expected comm=0, got 1
expected freq=0, got 1
expected enable_on_exec=0, got 1
expected task=0, got 1
FAILED '.../test-record-group-sampling1' - match failure
The shown diff is against the cycles group leader, as no result event matches the expected cache-misses member anymore.
Request the legacy encodings explicitly with the legacy-hardware-config term, added in commit 0012e0fa221bf9cc ("perf jevents: Add legacy-hardware and legacy-cache json"), keeping the original attribute expectations unchanged, in:
test-record-group1
test-record-group2
test-record-group3
test-record-group-sampling
test-record-group-sampling1
test-record-group-sampling2
test-stat-group1
This went unnoticed until tests/attr.sh stopped ignoring attr.py's return value.
--- tools/perf/tests/shell/attr/README | 10 +++++----- tools/perf/tests/shell/attr/test-record-group-sampling | 4 ++-- .../perf/tests/shell/attr/test-record-group-sampling1 | 4 ++-- .../perf/tests/shell/attr/test-record-group-sampling2 | 4 ++-- tools/perf/tests/shell/attr/test-record-group1 | 2 +- tools/perf/tests/shell/attr/test-record-group2 | 2 +- tools/perf/tests/shell/attr/test-record-group3 | 2 +- tools/perf/tests/shell/attr/test-stat-group1 | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-)
tools/perf/tests/shell/attr/README +5 -5
@@ -49,10 +49,10 @@ Following tests are defined (with perf commands): perf record --call-graph dwarf kill (test-record-graph-dwarf) perf record --call-graph fp kill (test-record-graph-fp) perf record --call-graph fp kill (test-record-graph-fp-aarch64) - perf record -e '{cycles,instructions}' kill (test-record-group1) - perf record -e '{cycles/period=1/,instructions/period=2/}:S' kill (test-record-group2) - perf record -e '{cycles,cache-misses}:S' kill (test-record-group-sampling1) - perf record -c 10000 -e '{cycles,cache-misses}:S' kill (test-record-group-sampling2) + perf record -e '{cycles,default_core/legacy-hardware-config=1/}' kill (test-record-group1) + perf record -e '{cycles/period=1234000/,default_core/legacy-hardware-config=1,period=6789000/}:S' kill (test-record-group2) + perf record -e '{cycles,default_core/legacy-hardware-config=3/}:S' kill (test-record-group-sampling1) + perf record -c 10000 -e '{cycles,default_core/legacy-hardware-config=3/}:S' kill (test-record-group-sampling2) perf record -D kill (test-record-no-delay) perf record -i kill (test-record-no-inherit) perf record -n kill (test-record-no-samples)
@@ -67,5 +67,5 @@ Following tests are defined (with perf commands): perf stat -d kill (test-stat-detailed-1) perf stat -dd kill (test-stat-detailed-2) perf stat -ddd kill (test-stat-detailed-3) - perf stat -e '{cycles,instructions}' kill (test-stat-group1) + perf stat -e '{cycles,default_core/legacy-hardware-config=1/}' kill (test-stat-group1) perf stat -i -e cycles kill (test-stat-no-inherit)
tools/perf/tests/shell/attr/test-record-group-sampling +2 -2
@@ -1,6 +1,6 @@ [config] command = record -args = --no-bpf-event -e '{cycles,cache-misses}:S' kill >/dev/null 2>&1 +args = --no-bpf-event -e '{cycles,default_core/legacy-hardware-config=3/}:S' kill >/dev/null 2>&1 ret = 1 kernel_until = 6.12
@@ -15,7 +15,7 @@ inherit=0 fd=2 group_fd=1 -# cache-misses +# cache-misses, explicitly requested with the legacy hardware encoding type=0 config=3
tools/perf/tests/shell/attr/test-record-group-sampling1 +2 -2
@@ -1,6 +1,6 @@ [config] command = record -args = --no-bpf-event -e '{cycles,cache-misses}:S' kill >/dev/null 2>&1 +args = --no-bpf-event -e '{cycles,default_core/legacy-hardware-config=3/}:S' kill >/dev/null 2>&1 ret = 1 kernel_since = 6.12
@@ -30,7 +30,7 @@ inherit=1 fd=2 group_fd=1 -# cache-misses +# cache-misses, explicitly requested with the legacy hardware encoding type=0 config=3
tools/perf/tests/shell/attr/test-record-group-sampling2 +2 -2
@@ -1,6 +1,6 @@ [config] command = record -args = --no-bpf-event -c 10000 -e '{cycles,cache-misses}:S' kill >/dev/null 2>&1 +args = --no-bpf-event -c 10000 -e '{cycles,default_core/legacy-hardware-config=3/}:S' kill >/dev/null 2>&1 ret = 1 kernel_since = 6.12
@@ -36,7 +36,7 @@ write_backward=0 fd=2 group_fd=1 -# cache-misses +# cache-misses, explicitly requested with the legacy hardware encoding type=0 config=3
tools/perf/tests/shell/attr/test-record-group1 +1 -1
@@ -1,6 +1,6 @@ [config] command = record -args = --no-bpf-event -e '{cycles,instructions}' kill >/dev/null 2>&1 +args = --no-bpf-event -e '{cycles,default_core/legacy-hardware-config=1/}' kill >/dev/null 2>&1 ret = 1 [event-1:base-record]
tools/perf/tests/shell/attr/test-record-group2 +1 -1
@@ -1,6 +1,6 @@ [config] command = record -args = --no-bpf-event -e '{cycles/period=1234000/,instructions/period=6789000/}:S' kill >/dev/null 2>&1 +args = --no-bpf-event -e '{cycles/period=1234000/,default_core/legacy-hardware-config=1,period=6789000/}:S' kill >/dev/null 2>&1 ret = 1 kernel_until = 6.12
tools/perf/tests/shell/attr/test-record-group3 +1 -1
@@ -1,6 +1,6 @@ [config] command = record -args = --no-bpf-event -e '{cycles/period=1234000/,instructions/period=6789000/}:S' kill >/dev/null 2>&1 +args = --no-bpf-event -e '{cycles/period=1234000/,default_core/legacy-hardware-config=1,period=6789000/}:S' kill >/dev/null 2>&1 ret = 1 kernel_since = 6.12
tools/perf/tests/shell/attr/test-stat-group1 +1 -1
@@ -1,6 +1,6 @@ [config] command = stat -args = -e '{cycles,instructions}' kill >/dev/null 2>&1 +args = -e '{cycles,default_core/legacy-hardware-config=1/}' kill >/dev/null 2>&1 ret = 1 [event-1:base-stat]
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2081/2651 perf test attr: Fix default stat metrics expectations
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 8158b84e65ed01b80164413cc9cb0655b84fc470 ]
Since commit c7adeb0974f1 ("perf jevents: Add set of common metrics based on default ones") and commit 2dfc0cab3da4 ("perf stat: Add detail -d,-dd,-ddd metrics") the perf stat default metrics open their events in groups, so group leaders and members have read_format=15 and members are enabled without enable_on_exec, while standalone events keep read_format=3 and are disabled until exec.
Also, since commit b1c5efbfd92e ("perf parse-events: Remove hard coded legacy hardware and cache parsing") bare hardware events resolve to the core PMU sysfs/JSON events (type 4), so add the raw encodings the Intel and AMD core PMUs use for instructions, branch-misses, cpu-cycles and stalled-cycles-frontend/backend to test-stat-default and test-stat-detailed-1/2/3.
Add base-stat-group, that accepts both the standalone and the group variants of read_format, disabled and enable_on_exec, and point the four default/detailed expectations at it. test-stat-basic, test-stat-C0 and test-stat-no-inherit keep base-stat, whose events aren't opened in a
group: for those, a change that groups or enables them differently is still something to catch. test-stat-group1 does open its events in a group, but pins read_format, disabled and enable_on_exec itself, the very terms base-stat-group loosens, so it doesn't need it either.
--- tools/perf/tests/shell/attr/base-stat-group | 45 +++++++ tools/perf/tests/shell/attr/test-stat-default | 90 +++++++++----- .../tests/shell/attr/test-stat-detailed-1 | 98 +++++++++------ .../tests/shell/attr/test-stat-detailed-2 | 110 ++++++++++------- .../tests/shell/attr/test-stat-detailed-3 | 114 +++++++++++------- 5 files changed, 307 insertions(+), 150 deletions(-) create mode 100644 tools/perf/tests/shell/attr/base-stat-group
tools/perf/tests/shell/attr/base-stat-group new file +45 -0
@@ -0,0 +1,45 @@ +[event] +fd=1 +group_fd=-1 +# 0 or PERF_FLAG_FD_CLOEXEC flag +flags=0|8 +cpu=* +type=0 +size=176 +config=0 +sample_period=0 +sample_type=65536 +# The default and -d/-dd/-ddd metrics open part of their events in groups: +# the members get read_format=15 and are enabled right away, the standalone +# ones keep read_format=3 and wait for the exec, and the leaders get 15 when +# their group has members, 3 when alone, as create_perf_stat_counter() goes. +read_format=3|15 +disabled=0|1 +inherit=1 +pinned=0 +exclusive=0 +exclude_user=0 +exclude_kernel=0|1 +exclude_hv=0|1 +exclude_idle=0 +mmap=0 +comm=0 +freq=0 +inherit_stat=0 +enable_on_exec=0|1 +task=0 +watermark=0 +precise_ip=0 +mmap_data=0 +sample_id_all=0 +exclude_host=0|1 +exclude_guest=0|1 +exclude_callchain_kernel=0 +exclude_callchain_user=0 +wakeup_events=0 +bp_type=0 +config1=0 +config2=0 +branch_sample_type=0 +sample_regs_user=0 +sample_stack_user=0
tools/perf/tests/shell/attr/test-stat-default +59 -31
259 lines not on this page · raw message
tools/perf/tests/shell/attr/test-stat-detailed-1 +63 -35
292 lines not on this page · raw message
tools/perf/tests/shell/attr/test-stat-detailed-2 +69 -41
340 lines not on this page · raw message
tools/perf/tests/shell/attr/test-stat-detailed-3 +71 -43
356 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2082/2651 perf test attr: Relax group checking for ungrouped expectations
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit ac416cf3eff650ad4b6dabc3407c7174e1826db9 ]
When matching the recorded events back against the expectations, attr.py requires every event opened in a group to match an expectation that declares the same group. The perf stat default metrics open the events of each metric in groups, but the test expectations only verify the event attributes, so test-stat-default fails with:
FAILED '.../test-stat-default' - group failure
Only enforce the group of a recorded event when the expectation it matches declares one. Expectations that ask for a group are still verified in both directions.
--- tools/perf/tests/shell/lib/attr.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
tools/perf/tests/shell/lib/attr.py +7 -4
@@ -307,7 +307,7 @@ class Test(object): else: raise Unsup(self) - def compare(self, expect, result): + def compare(self, expect, result, strict_groups=True): match = {} log.debug(" compare");
@@ -341,8 +341,9 @@ class Test(object): match[exp_name] = exp_list - # For each defined group in the expected events - # check we match the same group in the result. + # Check that each expected group is matched in the result; an event + # opened in a group may match an expectation that doesn't declare + # one, as those only verify the event attributes. for exp_name, exp_event in expect.items(): group = exp_event.group
@@ -351,6 +352,8 @@ class Test(object): for res_name in match[exp_name]: res_group = result[res_name].group + if res_group == '' and not strict_groups: + continue if res_group not in match[group]: raise Fail(self, 'group failure')
@@ -389,7 +392,7 @@ class Test(object): # do the expectation - results matching - both ways self.compare(self.expect, self.result) - self.compare(self.result, self.expect) + self.compare(self.result, self.expect, strict_groups=False) finally: # cleanup
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2083/2651 perf evsel: Mark the event as supported when retrying an open
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit cc956e0cd6a405fbc6ad3055cbbdb178562ef27d ]
Opening a group with perf record on a machine with perf_event_paranoid > 1 and no CAP_PERFMON fails the first perf_event_open() with EACCES, after which evsel__open_cpu() clears evsel->supported; evsel__fallback() then adds exclude_kernel and record__open() retries, and the retry succeeds with supported left false. get_group_fd() treats unsupported events as ungroupable, so the retry opens the group members without their leader:
sys_perf_event_open: pid 12345 cpu 0 group_fd -1 FAILED '.../test-record-group-sampling1' - group failure
which fails the group subtests of "perf test 82", the Perf attribute expectations test, when it is run as a regular user, while it passes as root or with CAP_PERFMON, where the first open doesn't fail.
commit 2cc7aa995ce9 ("perf stat: Refactor retry/skip/fatal error handling") dropped the pos->supported = true that record__open() did after a successful open and moved the resets into the stat code only, while saying "When an event is tried the supported is set to true again". Do that in evsel__open_cpu(), which every open entry point funnels through, so that a retry describes its own try instead of the previous failure.
--- tools/perf/util/evsel.c | 6 ++++++ 1 file changed, 6 insertions(+)
tools/perf/util/evsel.c +6 -0
@@ -2997,6 +2997,12 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus,enum rlimit_action set_rlimit =NO_CHANGE ;struct perf_cpu cpu; +/* +* A failed attempt being retried after evsel__fallback() would +* otherwise keep group members out of their group in get_group_fd(). +*/ + evsel->supported = true; +if (evsel__is_retire_lat (evsel)) { err =evsel__tpebs_open (evsel); goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2084/2651 sched_ext: Fix the running task keeping its protection into bypass
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tejun Heo <[email protected]>
[ Upstream commit 30fb2b1e4d41a641a059f295a717ffa0e24307e7 ]
Protection ends when the scheduler enters bypass, so that bypass scheduling can cut every task's slice. scx_bypass() clears it for the queued tasks by cycling them, and strips the running task's in the same walk over rq->scx.runnable_list. The running task is never on that list. set_next_task_scx() takes it off and put_prev_task_scx() puts it back, so the strip never runs. A protected running task then keeps its slice into bypass, where the tick's attempts to cut it are refused.
Strip the running task's protection outside the walk.
--- kernel/sched/ext/ext.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
kernel/sched/ext/ext.c +10 -7
@@ -6360,6 +6360,16 @@ void scx_bypass(struct scx_sched *sch, bool bypass)continue ; } +/* +* Bypass trumps protection. Cycling the queued tasks below +* clears theirs. The current task isn't on the runnable list, +* so strip its protection here. +*/ + p = rq->curr; +if (bypass && p->sched_class == &ext_sched_class && +scx_is_descendant (scx_task_sched (p), sch)) +scx_task_slice_ended (rq, p); +/* * The use of list_for_each_entry_safe_reverse() is required * because each task is going to be removed from and added back
@@ -6372,13 +6382,6 @@ void scx_bypass(struct scx_sched *sch, bool bypass)if (!scx_is_descendant (scx_task_sched (p), sch))continue ; -/* -* Bypass trumps protection. Cycling clears for queued -* tasks but current task needs explicit stripping. -*/ -if (bypass &&task_current (rq, p)) -scx_task_slice_ended (rq, p); -/* cycling deq/enq is enough, see the function comment */ scoped_guard (sched_change, p, DEQUEUE_SAVE | DEQUEUE_MOVE) {/* nothing */ ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2085/2651 sched_ext: Fix a bypassed task stalling on a cpu its scheduler has no caps on
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tejun Heo <[email protected]>
[ Upstream commit 5809f749fbdbaf9c6b34ecbe6d2b413e56eec6e3 ]
A bypassing sub-scheduler's tasks are run by its nearest ancestor that isn't bypassing. The ancestor puts them on the local DSQ under its own caps. Whether such a task may stay on the cpu and whether a cap revoke reenqueues it are still checked against the caps of the task's own scheduler.
The bypass load balancer moves tasks between cpus without looking at caps, so a bypassed task can run on a cpu where its own scheduler holds none. Once its slice runs out, it can't stay. It goes to the ancestor's bypass DSQ without a kick, and the cpu can go idle with it queued until something else reschedules the cpu.
Make both checks against the caps of the scheduler running the task. When bypass lifts, the running task keeps its slice without a cap check, so evict it then if it can't stay on the cpu.
--- kernel/sched/ext/ext.c | 21 ++++++++++++--------- kernel/sched/ext/internal.h | 17 +++++++++++++++++ kernel/sched/ext/sub.c | 7 +++++-- kernel/sched/ext/sub.h | 6 +++++- 4 files changed, 39 insertions(+), 12 deletions(-)
kernel/sched/ext/ext.c +12 -9
@@ -322,7 +322,6 @@ static const struct sched_class *scx_setscheduler_class(struct task_struct *p)static struct scx_dispatch_q *bypass_enq_target_dsq (struct scx_sched *sch,s32 cpu) { -#ifdef CONFIG_EXT_SUB_SCHED /* * If @sch is a sub-sched which is bypassing, its tasks should go into * the bypass DSQs of the nearest ancestor which is not bypassing. The
@@ -334,11 +333,7 @@ static struct scx_dispatch_q *bypass_enq_target_dsq(struct scx_sched *sch, s32 c* are re-enqueued after scx_bypassing() is turned on, guaranteeing that * all tasks are transferred to the right DSQs. */ -while (scx_parent (sch) &&scx_bypassing (sch, cpu)) - sch =scx_parent (sch); -#endif /* CONFIG_EXT_SUB_SCHED */ - -return scx_bypass_dsq (sch, cpu); +return scx_bypass_dsq (scx_exec_sched (sch, cpu), cpu); }/**
@@ -6364,11 +6359,19 @@ void scx_bypass(struct scx_sched *sch, bool bypass)* Bypass trumps protection. Cycling the queued tasks below * clears theirs. The current task isn't on the runnable list, * so strip its protection here. +* +* When bypass lifts, the current task keeps running on its +* slice without a cap check. Evict it if it can't stay on the +* cpu. */ p = rq->curr; -if (bypass && p->sched_class == &ext_sched_class && -scx_is_descendant (scx_task_sched (p), sch)) -scx_task_slice_ended (rq, p); +if (p->sched_class == &ext_sched_class && +scx_is_descendant (scx_task_sched (p), sch)) { +if (bypass) +scx_task_slice_ended (rq, p); +else if (!scx_task_can_stay_on_cpu (rq, p)) +scx_set_task_slice (p,0 ); + }/* * The use of list_for_each_entry_safe_reverse() is required
kernel/sched/ext/internal.h +17 -0
@@ -2546,4 +2546,21 @@ static inline struct scx_sched *scx_parent(struct scx_sched *sch) { return NULL;#endif /* CONFIG_EXT_SUB_SCHED */ +/** +* scx_exec_sched - Find the sched running @sch's tasks on @cpu +* @sch: sched owning the tasks +* @cpu: cpu of interest +* +* A bypassing sched's tasks are run by its nearest ancestor that isn't +* bypassing. Return @sch if it isn't bypassing on @cpu, otherwise that +* ancestor, or the root if every ancestor is bypassing. Hold @cpu's rq lock for +* a stable answer. +*/ +static inline struct scx_sched *scx_exec_sched (struct scx_sched *sch,s32 cpu) +{ +while (scx_parent (sch) &&scx_bypassing (sch, cpu)) + sch =scx_parent (sch); +return sch; +} +#endif /* _KERNEL_SCHED_EXT_INTERNAL_H */
kernel/sched/ext/sub.c +5 -2
@@ -755,18 +755,21 @@ struct scx_dispatch_q *scx_resolve_local_dsq(struct scx_sched *sch, struct rq *r/* @p lost the caps needed to stay on @rq's local DSQ? Record reason if so. */ bool scx_task_reenq_on_cap_revoke (struct rq *rq,struct task_struct *p) { +s32 cpu =cpu_of (rq);u64 missing;/* migration-disabled tasks and the rescuee are admitted capless */ if (is_migration_disabled (p) || p ==scx_rescuee (rq))return false; - missing =scx_missing_caps (scx_task_sched (p),cpu_of (rq),scx_caps_for_task (p)); +/* check caps against the sched running a bypassed task */ + missing =scx_missing_caps (scx_exec_sched (scx_task_sched (p), cpu), cpu, +scx_caps_for_task (p));if (likely (!missing))return false; p->scx.reenq_reason_caps = missing; - p->scx.reenq_reason_cid =__scx_cpu_to_cid (cpu_of (rq)); + p->scx.reenq_reason_cid =__scx_cpu_to_cid (cpu);return true; }
kernel/sched/ext/sub.h +5 -1
@@ -199,6 +199,8 @@ static inline u64 scx_caps_implied(u64 cap)/* may @p keep running on @rq's cpu? requires baseline cpu access */ static inline bool scx_task_can_stay_on_cpu (struct rq *rq,struct task_struct *p) { +s32 cpu =cpu_of (rq); +if (!scx_has_subs ())return true;
@@ -206,7 +208,9 @@ static inline bool scx_task_can_stay_on_cpu(struct rq *rq, struct task_struct *pif (unlikely (is_migration_disabled (p)))return true; -return likely (!scx_missing_caps (scx_task_sched (p),cpu_of (rq),SCX_CAP_BASE )); +/* check caps against the sched running a bypassed task */ +return likely (!scx_missing_caps (scx_exec_sched (scx_task_sched (p), cpu), cpu, +SCX_CAP_BASE )); }/* the task admitted for rescue on @rq, NULL if none */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2086/2651 bpf: Fix verifier WARN on narrow read of bpf_tcp_sock u64 fields
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiayuan Chen <[email protected]>
[ Upstream commit af873495cbcb066ab029f7f63b94410d4db47628 ]
A BPF program can read the middle of a u64 field in struct bpf_tcp_sock:
tp = bpf_tcp_sock(listener); /* +0x54 is in the middle of the u64 bytes_received */ unsigned hi = *(unsigned *)((char *)tp + 0x54);
bpf_tcp_sock_is_valid_access() allows this 4-byte read (the default case only checks size == 4), but bpf_tcp_sock_convert_ctx_access() only knows the field starts and has no idea how to handle such an offset. It emits no instruction, cnt stays 0 and the fixup pass trips verifier_bug():
verifier bug: error during ctx access conversion (0)
Just disallow the narrower access by matching the whole u64 range of the two fields, so it is turned down at check time:
invalid tcp_sock access off=84 size=4
--- net/core/filter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/filter.c +2 -2
@@ -7607,8 +7607,8 @@ bool bpf_tcp_sock_is_valid_access(int off, int size, enum bpf_access_type type,return false;switch (off) { -case offsetof(struct bpf_tcp_sock , bytes_received): -case offsetof(struct bpf_tcp_sock , bytes_acked): + case bpf_ctx_range(struct bpf_tcp_sock, bytes_received): + case bpf_ctx_range(struct bpf_tcp_sock, bytes_acked):return size ==sizeof (__u64);default :return size ==sizeof (__u32);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2087/2651 power: supply: qcom_battmgr: report the USB type from USB_ADAP_TYPE
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joonhoe Kim <[email protected]>
[ Upstream commit a49f86cd1333c6e12fd37bc0b3234ace10072553 ]
On SM8350 and SM8550 class firmware the USB power supply reads its usb_type from the USB_TYPE property. On a Kaanapali (SM8850) tablet that property is 1 (SDP) whatever is plugged in, while USB_ADAP_TYPE reports the adapter, using the same numbering as POWER_SUPPLY_USB_TYPE_*:
PC port USB_TYPE 1 USB_ADAP_TYPE 1 (SDP) USB-C dock, 5 V PD USB_TYPE 1 USB_ADAP_TYPE 6 (PD) 65 W PPS charger USB_TYPE 1 USB_ADAP_TYPE 8 (PD_PPS)
Qualcomm's downstream qti_battery_charger driver also maps USB_ADAP_TYPE to POWER_SUPPLY_PROP_USB_TYPE.
Request USB_ADAP_TYPE for POWER_SUPPLY_PROP_USB_TYPE instead.
Tested on a Lenovo Legion Tab Y700 gen 5 (qcom,kaanapali-pmic-glink, which uses the SM8550 path). Only tested on this device; the SM8350 variant shares the property map and was not tested.
--- drivers/power/supply/qcom_battmgr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/power/supply/qcom_battmgr.c +2 -2
@@ -976,7 +976,7 @@ static const u8 sm8350_usb_prop_map[] = { [POWER_SUPPLY_PROP_CURRENT_NOW] = USB_CURR_NOW, [POWER_SUPPLY_PROP_CURRENT_MAX] = USB_CURR_MAX, [POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT] = USB_INPUT_CURR_LIMIT, - [POWER_SUPPLY_PROP_USB_TYPE] = USB_TYPE, + [POWER_SUPPLY_PROP_USB_TYPE] = USB_ADAP_TYPE, }; static int qcom_battmgr_usb_sm8350_update(struct qcom_battmgr *battmgr,
@@ -1534,7 +1534,7 @@ static void qcom_battmgr_sm8350_callback(struct qcom_battmgr *battmgr,case USB_INPUT_CURR_LIMIT : battmgr->usb.current_limit =le32_to_cpu (resp->intval.value);break ; -case USB_TYPE : +case USB_ADAP_TYPE : battmgr->usb.usb_type =le32_to_cpu (resp->intval.value);break ;default :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2088/2651 bpf: Use the frame mem type in devmap egress XDP
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit b3ca872947ef322c475ceaa7a76a9ebb3356152e ]
A devmap egress program that removes a whole fragment of a redirected xdp_frame with bpf_xdp_adjust_tail() or bpf_xdp_pull_data() frees it with page_frag_free() whatever the frame's memory type is. For a MEM_TYPE_PAGE_POOL frame from a page_pool based driver this drops the page reference owned by the pool while the pool still accounts the fragment ("page_pool leak" bad page, leaked pp reference).
kernel/bpf/devmap.c:dev_map_bpf_prog_run() points xdp.rxq at an on-stack
struct xdp_rxq_info rxq = { .dev = rx_dev };whose mem.type is 0, i.e. MEM_TYPE_PAGE_SHARED, and net/core/filter.c:bpf_xdp_shrink_data() releases frags according to rxq->mem.type. cpumap, which runs programs on xdp_frames the same way, already copies xdpf->mem_type into its private rxq for each frame.
With 9000 byte frames from virtio_net and an egress program that cuts the fragments off:
BUG: Bad page state in process swapper/3 pfn:10660b page dumped because: page_pool leak bad_page+0xbd/0x190 __free_frozen_pages+0x5c7/0x900 bpf_xdp_adjust_tail+0x3be/0x480 bpf_prog_dad43f894a3faff7_egress+0x15c/0x1cd dev_map_bpf_prog_run+0x288/0x610
The pool waits for these pages for ever when its device is gone. That is the harmless case. A page of the pool can hold more than one fragment while its refcount is 1: the first page_frag_free() frees it under the fragment which is still in use, and the second one runs into
page dumped because: VM_BUG_ON_PAGE(page_ref_count(page) == 0) kernel BUG at include/linux/mm.h:1846!
veth is not affected. It takes references of its own on the pages and redirects the frame as MEM_TYPE_PAGE_SHARED.
Fix by setting rxq.mem.type from each frame before running the devmap program, as cpu_map_bpf_prog_run_xdp() does.
--- kernel/bpf/devmap.c | 1 + 1 file changed, 1 insertion(+)
kernel/bpf/devmap.c +1 -0
@@ -350,6 +350,7 @@ static int dev_map_bpf_prog_run(struct bpf_prog *xdp_prog,xdp_convert_frame_to_buff (xdpf, &xdp); xdp.txq = &txq; + rxq.mem.type = xdpf->mem_type; xdp.rxq = &rxq; act =bpf_prog_run_xdp (xdp_prog, &xdp);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2089/2651 bpf: Report non-sleepable kfunc programs accurately
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kumar Kartikeya Dwivedi <[email protected]>
[ Upstream commit dac3b7a30d7e5384a61ee46f476dc2c45ceb9453 ]
A sleepable kfunc call can fail either because the program is not sleepable or because an otherwise sleepable program has entered a non-sleepable critical section. check_kfunc_call() checks these conditions separately. The first check is only gated by in_sleepable(), so the shared diagnostic can blame an active RCU, preemption-disabled, IRQ-disabled, or locked region even though leaving that region would not make the program sleepable. Adding a second diagnostic entry point only to force the program context would duplicate the API.
Reject the call once based on in_sleepable_context(). Teach the shared bpf_diag_ctx_forbidden() reporter and non_sleepable_context_description() to consider active RCU, preempt, IRQ, and lock regions only when the program is sleepable, and to fall back to the non-sleepable program otherwise. A non-sleepable program can still hold that context state, so relying on the existing no-context fallback alone would keep blaming the critical section.
Select the suggestion at the kfunc, helper, and global-function sites according to that cause, and choose between the two existing kfunc verifier messages the same way, so a sleepable program is told to leave the critical section and a non-sleepable program is told to become sleepable.
This avoids a diagnostic-only wrapper while retaining context history for sleepable programs that enter a forbidden region.
Stable-dep-of: 9bdd5e7f5d83 ("bpf: Forbid sleeping in hash map for_each callbacks")
--- kernel/bpf/diagnostics.c | 21 +++++++------- kernel/bpf/verifier.c | 62 ++++++++++++++++++++++++---------------- 2 files changed, 48 insertions(+), 35 deletions(-)
kernel/bpf/diagnostics.c +11 -10
@@ -1088,16 +1088,17 @@ void bpf_diag_ctx_forbidden(struct bpf_verifier_env *env, u32 insn_idx,const char *constraint, *context;u32 depth; -if (env->cur_state->active_rcu_locks) - ctx_kind =BPF_DIAG_CONTEXT_RCU ; -else if (env->cur_state->active_preempt_locks) - ctx_kind =BPF_DIAG_CONTEXT_PREEMPT ; -else if (env->cur_state->active_irq_id) - ctx_kind =BPF_DIAG_CONTEXT_IRQ ; -else if (env->cur_state->active_locks) - ctx_kind =BPF_DIAG_CONTEXT_LOCK ; -else - ctx_kind =BPF_DIAG_CONTEXT_NONE ; + ctx_kind =BPF_DIAG_CONTEXT_NONE ; +if (env->cur_state->in_sleepable) { +if (env->cur_state->active_rcu_locks) + ctx_kind =BPF_DIAG_CONTEXT_RCU ; +else if (env->cur_state->active_preempt_locks) + ctx_kind =BPF_DIAG_CONTEXT_PREEMPT ; +else if (env->cur_state->active_irq_id) + ctx_kind =BPF_DIAG_CONTEXT_IRQ ; +else if (env->cur_state->active_locks) + ctx_kind =BPF_DIAG_CONTEXT_LOCK ; + } depth =diag_context_depth (env, ctx_kind); opts = (struct bpf_diag_history_opts ) {
kernel/bpf/verifier.c +37 -25
100 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2090/2651 bpf: Forbid sleeping in hash map for_each callbacks
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 9bdd5e7f5d8313fa1f3a210621b4007bb5ad0ec6 ]
A sleepable program (e.g. SEC("syscall"), lsm.s, fentry.s) can pass a callback to bpf_for_each_map_elem() on a hash map and call a sleepable helper or kfunc such as bpf_copy_from_user() from it. The verifier accepts this, but at run time the callback is invoked from inside an RCU read-side critical section:
bpf_for_each_hash_elem()
rcu_read_lock();
callback_fn(map, key, val, ctx, 0);
bpf_copy_from_user() <- may fault and sleep
rcu_read_unlock();bpf_each_rhash_elem() does the same for BPF_MAP_TYPE_RHASH. Sleeping there triggers the "Voluntary context switch within RCU read-side critical section!" warning, delays grace periods, and with CONFIG_PREEMPT_RCU=n silently ends the read-side critical section that the bucket walk relies on.
Synchronous callbacks are verified with the caller's state, so kernel/bpf/verifier.c:in_sleepable_context() only looks at the program's sleepability and the locks the program took itself, and does not know that the helper holds rcu_read_lock() around the callback.
With a SEC("syscall") program whose callback reads a page that has to be read from disk first:
BUG: sleeping function called from invalid context at include/linux/uaccess.h:169 RCU nest depth: 1, expected: 0 __might_fault+0x29/0x80 _copy_from_user+0x26/0x90 bpf_copy_from_user+0x23/0x60 bpf_prog_17d44fa39eebd6cc_cb+0x35/0x46 bpf_for_each_hash_elem+0xdb/0x280
Fix by marking the callback frame of hash map iteration as running under RCU and making in_sleepable_context() false while such a frame is on the call stack, so sleepable helpers, kfuncs and global functions are rejected there as inside bpf_rcu_read_lock(). The rules for trusting RCU protected pointers are left alone, which is conservative and keeps callbacks that verify today and do not sleep working. The flag is compared in func_states_equal() so that pruning never mixes the two contexts. Array map callbacks run without any lock and keep the caller's context.
--- include/linux/bpf_verifier.h | 5 +++++ kernel/bpf/states.c | 3 +++ kernel/bpf/verifier.c | 28 +++++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-)
include/linux/bpf_verifier.h +5 -0
@@ -337,6 +337,11 @@ struct bpf_func_state {bool in_async_callback_fn;bool in_exception_callback_fn;bool no_stack_arg_load; +/* +* The helper invokes this callback under rcu_read_lock(), so the +* callback and its callees run in an RCU read-side critical section. +*/ +bool in_rcu_callback_fn;/* For callback calling functions that limit number of possible * callback executions (e.g. bpf_loop) keeps track of current * simulated iteration number.
kernel/bpf/states.c +3 -0
@@ -952,6 +952,9 @@ static bool func_states_equal(struct bpf_verifier_env *env, struct bpf_func_statif (!old->no_stack_arg_load && cur->no_stack_arg_load)return false; +if (old->in_rcu_callback_fn != cur->in_rcu_callback_fn) +return false; +for (i =0 ; i <MAX_BPF_REG ; i++)if (((1 << i) & live_regs) && !regsafe(env, &old->regs[i], &cur->regs[i],
kernel/bpf/verifier.c +27 -1
@@ -10172,6 +10172,19 @@ static int set_map_elem_callback_state(struct bpf_verifier_env *env,if (err)return err; +switch (map->map_type) { +case BPF_MAP_TYPE_HASH : +case BPF_MAP_TYPE_PERCPU_HASH : +case BPF_MAP_TYPE_LRU_HASH : +case BPF_MAP_TYPE_LRU_PERCPU_HASH : +case BPF_MAP_TYPE_RHASH : +/* Hash tables run the callback under rcu_read_lock(). */ + callee->in_rcu_callback_fn = true; +break ; +default : +break ; + } + callee->in_callback_fn = true; callee->callback_ret_range =retval_range (0 ,1 );return 0 ;
@@ -10869,10 +10882,22 @@ int bpf_get_helper_proto(struct bpf_verifier_env *env, int func_id,return *ptr && (*ptr)->func ?0 : -EINVAL ; } +/* Is any frame on the current path a callback that runs under RCU? */ +static bool in_rcu_callback (struct bpf_verifier_env *env) +{ +struct bpf_verifier_state *state = env->cur_state; +int i; + +for (i =0 ; i <= state->curframe; i++) +if (state->frame[i]->in_rcu_callback_fn) +return true; +return false; +} +/* Check if we're in a sleepable context. */ static inline bool in_sleepable_context (struct bpf_verifier_env *env) { -return !in_rcu_cs (env); +return !in_rcu_cs (env) && !in_rcu_callback (env); }static const char *non_sleepable_context_description (struct bpf_verifier_env *env)
@@ -10886,6 +10911,7 @@ static const char *non_sleepable_context_description(struct bpf_verifier_env *enreturn "IRQ-disabled region" ;if (env->cur_state->active_locks)return "lock region" ; +return "callback running under rcu_read_lock" ; }return "non-sleepable prog" ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2091/2651 bpf: Dont leak the inode when token creation fails
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit f52b699c88634d0161c97247e0f791a840eb868d ]
bpf_token_create() allocates a bpffs inode and hands it to alloc_file_pseudo(). The inode reference only moves to the new file when that call succeeds: alloc_file_pseudo() leaves the caller's reference alone on failure, and FD_PREPARE() does not even evaluate the file expression when it cannot get a descriptor.
Before the conversion to FD_PREPARE() the error path did iput(inode). The conversion dropped it, so each BPF_TOKEN_CREATE that fails with -EMFILE, -ENFILE or -ENOMEM at this point leaks an inode. A task that is allowed to create tokens can hit this at will by lowering RLIMIT_NOFILE, and the leaked inodes make umount of that bpffs instance complain about busy inodes.
Put the inode again if no file was created.
--- kernel/bpf/token.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/bpf/token.c +4 -1
@@ -169,8 +169,11 @@ int bpf_token_create(union bpf_attr *attr)FD_PREPARE (fdf,O_CLOEXEC ,alloc_file_pseudo (inode, path.mnt,BPF_TOKEN_INODE_NAME ,O_RDWR , &bpf_token_fops)); -if (fdf.err) +if (fdf.err) { +/* no file took over the inode reference */ +iput (inode);return fdf.err; + } token =kzalloc_obj (*token,GFP_USER );if (!token)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2092/2651 bpf: Dont hand out a linked element as extra element
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit ccb88db8dac8fabde58656d5d4a33711e89c480a ]
When htab_map_update_elem() replaces an element of a preallocated map, alloc_htab_elem() takes the spare element of this cpu and puts the old element into the per-cpu slot right away, long before the old element is unlinked from its bucket. The bucket lock disables interrupts, but it does not keep out an NMI, or a tracing program on the return of alloc_htab_elem(). bpf_prog_active only helps if both programs are kprobe, tracepoint or perf_event programs. A program that updates an existing key in another bucket of the same map gets to use the slot:
htab_map_update_elem(k1) tc, xdp, fentry, raw_tp, ...
alloc_htab_elem()
l_new = *pl_new
*pl_new = l_old still linked in bucket 1
<NMI>
htab_map_update_elem(k2) perf_event program
l_new = *pl_new the l_old of the outer update
hlist_nulls_add_head_rcu(l_new, bucket 2) hlist_nulls_del_rcu(k2's old element)
</NMI>
hlist_nulls_add_head_rcu(l_new, bucket 1) hlist_nulls_del_rcu(l_old)
If l_old was the first element of bucket 1, the outer add points its pprev at l_new, and the delete takes it out of bucket 1 only. l_new->next now leads into bucket 2, where l_old stays with a poisoned pprev, on which a delete of k2 crashes. If it was not the first, the delete takes it out of bucket 2: k2 is gone from the map, and the chain of bucket 1 still contains l_old, whose next pointer leads into bucket 2.
Either way a walk of bucket 1 ends on the nulls value of bucket 2. lookup_nulls_elem_raw() restarts whenever that happens, so every lookup in bucket 1 which does not find its key spins forever:
rcu: INFO: rcu_preempt detected stalls on CPUs/tasks: __htab_map_lookup_elem+0x354/0x4d0 BUG: KASAN: wild-memory-access in htab_map_delete_elem+0x30c/0x670 Write of size 8 at addr dead000000000122 by task extra/102
An NMI between the load and the store of the slot makes both updates use the same element, with much the same result.
Empty the slot when the spare element is taken, in a way that is atomic on this cpu, and put the old element in only after it has been unlinked and its timers and the like have been cancelled. A nested update that finds the slot empty, which is the case that corrupted the map, fails with -EBUSY.
--- kernel/bpf/hashtab.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
kernel/bpf/hashtab.c +16 -6
@@ -1107,11 +1107,17 @@ static struct htab_elem *alloc_htab_elem(struct bpf_htab *htab, void *key,if (prealloc) {if (old_elem) {/* if we're updating the existing element, -* use per-cpu extra elems to avoid freelist_pop/push +* use per-cpu extra elems to avoid freelist_pop/push. +* The caller puts old_elem into the slot once it is +* unlinked. Until then the slot is empty for an NMI +* or a kprobe that updates this map on this cpu. */ pl_new =this_cpu_ptr (htab->extra_elems); - l_new = *pl_new; - *pl_new = old_elem; + l_new =READ_ONCE (*pl_new); +do { +if (!l_new) +return ERR_PTR (-EBUSY ); + }while (!try_cmpxchg_local (pl_new, &l_new,NULL )); }else {struct pcpu_freelist_node *l;
@@ -1277,11 +1283,15 @@ static long htab_map_update_elem(struct bpf_map *map, void *key, void *value,if (l_old) {hlist_nulls_del_rcu (&l_old->hash_node); -/* l_old has already been stashed in htab->extra_elems, cancel -* its reusable special fields before it is available for reuse. +/* +* l_old replaces the extra element that alloc_htab_elem() took. +* Cancel its reusable special fields first: once it is in the +* slot, the next update on this cpu can reuse it. */ -if (htab_is_prealloc (htab)) +if (htab_is_prealloc (htab)) {check_and_cancel_fields (htab, l_old); +WRITE_ONCE (*this_cpu_ptr (htab->extra_elems), l_old); + } }htab_unlock_bucket (b, flags);if (l_old && !htab_is_prealloc (htab))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2093/2651 bpf: Reject sleepable programs for task_vma iterator
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit dfcd1765911223df60845e288ad392d5237f47a3 ]
A sleepable "iter.s/task_vma" program can be attached, but its ->show() callback runs with the mmap_lock of the iterated mm held for read. As soon as the program runs, bpf_iter_run_prog() calls might_fault(), and any bpf_copy_from_user() or bpf_copy_from_user_task() it does may really fault or take mmap_lock again. With lockdep this is reported as recursive locking of mmap_lock. Without lockdep, a fault on the reader's own mm, or access_process_vm() on the iterated mm, has to take mmap_lock for read again. If a writer queued up in the meantime that blocks behind the writer, which in turn waits for the read lock the iterator already holds, and the read() hangs:
reader (iter.s/task_vma) other thread of the same mm
task_vma_seq_get_next()
mmap_read_lock(mm)
mmap_write_lock(mm) <- waits
bpf prog: copy_from_user()
page fault
mmap_read_lock(mm) <- queued behind the writer
The reader waits killable, so the hang lasts until it gets a fatal signal.
bpf_iter_link_attach() allows sleepable programs for the targets that set BPF_ITER_RESCHED, and task_vma sets it because cond_resched() between VMAs is fine with mmap_lock held. Rescheduling between objects and running a sleepable program inside ->show() are different properties, though, and task_vma only has the first one. The open-coded task_vma iterator does not have this problem since it hands out a snapshot of the VMA and holds no lock when it returns to the program.
The vma handed to the program is only stable under mmap_lock, so the lock can't be dropped around ->show(). Add a feature flag BPF_ITER_NOSLEEP for targets which can't run sleepable programs although they can reschedule, and set it for task_vma.
The check at attach time is not enough. BPF_LINK_UPDATE replaces the program of a link, and bpf_iter_link_replace() only compares the type, the attach type and the BTF id of the two programs, which are the same for a sleepable and a non-sleepable one. Do the check there as well. That also closes this way around the existing rule: so far a sleepable program could be put on a link of a target that doesn't set BPF_ITER_RESCHED, like the hash map element iterator, which runs it under rcu_read_lock().
BPF_LINK_CREATE of a sleepable program for the task_vma target, and BPF_LINK_UPDATE to one, now fail with -EINVAL, also for programs that don't touch user memory and have been working since sleepable iterator programs exist. The programs can still be loaded. They have to be loaded as non-sleepable programs, or use the open-coded iterator.
--- include/linux/bpf.h | 3 ++- kernel/bpf/bpf_iter.c | 17 ++++++++++++++--- kernel/bpf/task_iter.c | 6 +++++- 3 files changed, 21 insertions(+), 5 deletions(-)
include/linux/bpf.h +2 -1
@@ -3019,7 +3019,8 @@ typedef const struct bpf_func_proto * const struct bpf_prog *prog);enum bpf_iter_feature { -BPF_ITER_RESCHED =BIT (0 ), +BPF_ITER_RESCHED =BIT (0 ),/* may cond_resched() between objects */ +BPF_ITER_NOSLEEP =BIT (1 ),/* ->show() can't run sleepable progs */ };#define BPF_ITER_CTX_ARG_MAX 2
kernel/bpf/bpf_iter.c +14 -3
@@ -72,6 +72,15 @@ static inline bool bpf_iter_target_support_resched(const struct bpf_iter_target_return tinfo->reg_info->feature &BPF_ITER_RESCHED ; } +/* Only allow sleepable program for resched-able iterator that can run one */ +static bool bpf_iter_target_support_prog (const struct bpf_iter_target_info *tinfo, +const struct bpf_prog *prog) +{ +return !prog->sleepable || + (bpf_iter_target_support_resched (tinfo) && + !(tinfo->reg_info->feature &BPF_ITER_NOSLEEP )); +} +static bool bpf_iter_support_resched (struct seq_file *seq) {struct bpf_iter_priv_data *iter_priv;
@@ -409,6 +418,8 @@ static int bpf_iter_link_replace(struct bpf_link *link,struct bpf_prog *new_prog, struct bpf_prog *old_prog) { + struct bpf_iter_link *iter_link = + container_of(link, struct bpf_iter_link, link);int ret =0 ;mutex_lock (&link_mutex);
@@ -419,7 +430,8 @@ static int bpf_iter_link_replace(struct bpf_link *link,if (link->prog->type != new_prog->type || link->prog->expected_attach_type != new_prog->expected_attach_type || - link->prog->aux->attach_btf_id != new_prog->aux->attach_btf_id) { + link->prog->aux->attach_btf_id != new_prog->aux->attach_btf_id || + !bpf_iter_target_support_prog (iter_link->tinfo, new_prog)) { ret = -EINVAL ; goto out_unlock; }
@@ -544,8 +556,7 @@ int bpf_iter_link_attach(const union bpf_attr *attr, bpfptr_t uattr,if (!tinfo)return -ENOENT ; -/* Only allow sleepable program for resched-able iterator */ -if (prog->sleepable && !bpf_iter_target_support_resched (tinfo)) +if (!bpf_iter_target_support_prog (tinfo, prog))return -EINVAL ; link =kzalloc_obj (*link,GFP_USER | __GFP_NOWARN);
kernel/bpf/task_iter.c +5 -1
@@ -737,7 +737,11 @@ static const struct bpf_iter_seq_info task_vma_seq_info = {static struct bpf_iter_reg task_vma_reg_info = { .target ="task_vma" , .attach_target = bpf_iter_attach_task, - .feature =BPF_ITER_RESCHED , +/* +* ->show() runs with the mmap_lock of the iterated mm held, which a +* sleepable program takes again when it faults on user memory. +*/ + .feature =BPF_ITER_RESCHED |BPF_ITER_NOSLEEP , .ctx_arg_info_size =2 , .ctx_arg_info = { { offsetof(struct bpf_iter__task_vma , task),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2094/2651 bpf: Forbid sleeping in bpf_find_vma() callbacks
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit c6dc0a288d4e787c578d7ab0464b9c943ad88ecc ]
A sleepable program can call bpf_find_vma() and use a sleepable helper such as bpf_copy_from_user() or bpf_copy_from_user_task() in the callback. The verifier accepts this, but bpf_find_vma() runs the callback with the mmap_lock of the mm held for read. If the user copy faults on that mm, the fault handler has to take mmap_lock again. Lockdep reports recursive locking, and if a writer queued up in between, the fault blocks behind the writer, which waits for the read lock the helper already holds:
sleepable prog other thread of the same mm
bpf_find_vma(current, ...)
mmap_read_trylock(mm)
mmap_write_lock(mm) <- waits
callback: copy_from_user()
page fault
mmap_read_lock(mm) <- queued behind the writer
This is the same problem as with sleepable task_vma iterator programs. The verifier checks synchronous callbacks in the caller's context, so in_sleepable_context() is true in the callback of a sleepable program.
Verify the callback like a hash map for_each callback, as running in an RCU read-side critical section where sleeping is not allowed, and actually hold rcu_read_lock() around it, so that global functions the callback calls, which are then verified for a non-sleepable context, see the RCU protection they are verified with.
Non-sleepable programs already run the callback under RCU, nothing changes for them. A sleepable program whose bpf_find_vma() callback calls any helper, kfunc or global function that may sleep is now rejected by the verifier, including ones that would be harmless under mmap_lock as they don't touch user memory.
--- kernel/bpf/task_iter.c | 6 ++++++ kernel/bpf/verifier.c | 2 ++ 2 files changed, 8 insertions(+)
kernel/bpf/task_iter.c +6 -0
@@ -810,8 +810,14 @@ BPF_CALL_5(bpf_find_vma, struct task_struct *, task, u64, start, vma =find_vma (mm, start);if (vma && vma->vm_start <= start && vma->vm_end > start) { +/* +* The callback must not sleep while mmap_lock is held, and the +* verifier checks it as an RCU read-side critical section. +*/ +rcu_read_lock ();callback_fn ((u64 )(long )task, (u64 )(long )vma, (u64 )(long )callback_ctx,0 ,0 ); +rcu_read_unlock (); ret =0 ; }bpf_mmap_unlock_mm (work, mm);
kernel/bpf/verifier.c +2 -0
@@ -10271,6 +10271,8 @@ static int set_find_vma_callback_state(struct bpf_verifier_env *env,bpf_mark_reg_not_init (env, &callee->regs[BPF_REG_4 ]);bpf_mark_reg_not_init (env, &callee->regs[BPF_REG_5 ]); callee->in_callback_fn = true; +/* bpf_find_vma() runs the callback under mmap_lock and RCU. */ + callee->in_rcu_callback_fn = true; callee->callback_ret_range =retval_range (0 ,1 );return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2095/2651 bpf: Look at all 64 bits of a BPF_JSET mask on 32-bit
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit ee4f44e0e3c8125eebe9ac967b6984bc9253d489 ]
In the branch of a BPF_JSET which is taken, the verifier can learn something about the register only if the mask has a single bit: then this bit is set. regs_refine_cond_op() tests this with is_power_of_2(val) and then ORs val into var_off.
val is a u64, but is_power_of_2() takes an unsigned long. On a 32-bit kernel it only sees the lower half of the mask. For
if r1 & 0xffffffff80000000 goto l
which is a BPF_JSET | BPF_K with an immediate of 0x80000000, the lower half is a power of two. So the verifier takes all 33 bits for set at l, while the branch is taken if any of them is. A mask of 0x100000001 from a register does the same for bit 0.
The log of an i386 kernel, for r6 = bpf_get_prandom_u32() << 31:
3: (45) if r6 & 0x80000000 goto pc+2 from 3 to 6: R6=0xffffffff80000000 R10=fp0 6: (77) r6 >>= 63 ; R6=1
When the program runs, r6 >> 63 is 0.
Quoted 1 line
From then on the verifier works with known bits which the register does
not have at run time. It accepts, for example, an offset into a map value which it derives from these bits and believes to be constant, and the program can access memory outside of the map value.
Count the bits of the whole value.
Only 32-bit kernels are affected. On a 64-bit kernel unsigned long holds the whole mask, and this patch changes nothing.
--- kernel/bpf/verifier.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/verifier.c +1 -1
@@ -16716,7 +16716,7 @@ static void regs_refine_cond_op(struct bpf_reg_state *reg1, struct bpf_reg_state* this restriction. I.e., !(r1 & 0x3) means neither bit 0 nor * bit 1 is set, which we can readily use in adjustments. */ -if (!is_power_of_2 (val)) +if (hweight64 (val) !=1 )break ;if (is_jmp32) { t =tnum_or (tnum_subreg (reg1->var_off),tnum_const (val));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2096/2651 bpf: Dont let bpf_skb_adjust_room() use up the MSS
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 12d07c38e1b0f79e48a37abd7103194212f2da8c ]
When bpf_skb_adjust_room() grows a TCP GSO packet without BPF_F_ADJ_ROOM_FIXED_GSO, gso_size is lowered by the number of bytes added. Nothing looks at how large it is.
gso_size is the size of the segments the peer has sent if the packet comes out of GRO, and what the sender has written into the virtio header if it comes from a tun device or a packet socket. If it equals len_diff the result is 0, and a packet of up to 64 KB is no GSO packet any more. If it is smaller, the 16 bit value wraps around.
One less than len_diff gives GSO_BY_FRAGS. skb_segment() then takes the length of each segment from the frag_list. A packet with more than 64 KB of payload gets that far, and one from a tun device has no frag_list:
BUG: KASAN: null-ptr-deref in skb_segment+0xcf1/0x1a90 BUG: kernel NULL pointer dereference, address: 0000000000000070 tcp_gso_segment+0x1be/0x9f0 inet_gso_segment+0x288/0x740 inet_gso_segment+0x288/0x740 skb_mac_gso_segment+0x179/0x2e0
What is left must not be less than TCP_MIN_GSO_SIZE either. The stack relies on that for the number of segments to fit into gso_segs, see commit c27c449d455a ("virtio-net: Ensure that TCP packets don't overflow gso_segs").
Refuse to grow a packet that would end up with less, with the error that other packets which cannot be adjusted get.
--- net/core/filter.c | 8 ++++++++ 1 file changed, 8 insertions(+)
net/core/filter.c +8 -0
@@ -3619,6 +3619,14 @@ static int bpf_skb_net_grow(struct sk_buff *skb, u32 off, u32 len_diff,return -ENOTSUPP ; } +/* +* The MSS is lowered by len_diff. Leave the least that the stack lets a +* TCP GSO packet have, or gso_segs can overflow. +*/ +if (skb_is_gso (skb) && !(flags &BPF_F_ADJ_ROOM_FIXED_GSO ) && +skb_shinfo (skb)->gso_size < len_diff +TCP_MIN_GSO_SIZE ) +return -ENOTSUPP ; + ret =skb_cow_head (skb, meta_len + len_diff);if (unlikely (ret <0 ))return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2097/2651 bpf: Read the probe of a perf event under event_mutex
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 3ccd700543f16a2b2ab656f35dcaeb6bd7c45e22 ]
For a perf event on a kprobe or uprobe event which was made in tracefs, bpf_get_kprobe_info() and bpf_get_uprobe_info() look the probe up by name in the list of dynamic events, and hand a pointer to its symbol or file name back to the caller. None of the callers holds event_mutex.
The perf event keeps its trace event alive, nothing else. Other dynamic events are removed from the list and freed during the walk. And a probe which shares its event with other probes can be deleted while the event is in use, so even the probe which is found can be freed, together with the string, before the caller has measured and copied it. The result is a use-after-free in the walk, in strlen() and in the copy to user space, or a NULL pointer dereference.
The readers are BPF_OBJ_GET_INFO_BY_FD and fdinfo of a perf link, for whoever holds a descriptor of the link, and BPF_TASK_FD_QUERY. The other side is anybody who may write to dynamic_events, kprobe_events or uprobe_events.
Take event_mutex in bpf_get_perf_event_info() and give the caller a copy of the name, which it has to free.
--- kernel/bpf/syscall.c | 17 +++++++++++------ kernel/trace/bpf_trace.c | 13 +++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-)
kernel/bpf/syscall.c +11 -6
@@ -4000,19 +4000,19 @@ static int bpf_perf_link_fill_common(const struct perf_event *event, *ulenp =1 ; }if (!uname) -return 0 ; + goto out;if (buf) { err =bpf_copy_to_user (uname, buf, ulen, len); -if (err) -return err; }else {char zero ='\0' ;if (put_user (zero, uname)) -return -EFAULT ; + err = -EFAULT ; } -return 0 ; +out: +kfree_const (buf); +return err; }#ifdef CONFIG_KPROBE_EVENTS
@@ -4069,6 +4069,7 @@ static void bpf_perf_link_fdinfo_kprobe(const struct perf_event *event, name, offset, missed, addr, type ==BPF_FD_TYPE_KRETPROBE ?"kretprobe" :"kprobe" , event->bpf_cookie); + kfree_const(name); }#endif
@@ -4122,6 +4123,7 @@ static void bpf_perf_link_fdinfo_uprobe(const struct perf_event *event, name, offset, ref_ctr_offset, type ==BPF_FD_TYPE_URETPROBE ?"uretprobe" :"uprobe" , event->bpf_cookie); + kfree_const(name); }#endif
@@ -4220,6 +4222,7 @@ static void bpf_tracepoint_link_show_fdinfo(const struct perf_event *event,"event_type:\t%s\n" "cookie:\t%llu\n" , name, "tracepoint", event->bpf_cookie); +kfree_const (name); } static void bpf_probe_link_show_fdinfo(const struct perf_event *event,
@@ -5746,11 +5749,13 @@ static int bpf_task_fd_query(const union bpf_attr *attr, err =bpf_get_perf_event_info (event, &prog_id, &fd_type, &buf, &probe_offset, &probe_addr,NULL ); -if (!err) +if (!err) { err =bpf_task_fd_query_copy (attr, uattr, prog_id, fd_type, buf, probe_offset, probe_addr); +kfree_const (buf); + } goto put_file; }
kernel/trace/bpf_trace.c +13 -0
@@ -2209,6 +2209,7 @@ int bpf_probe_unregister(struct bpf_raw_event_map *btp, struct bpf_raw_tp_link *return tracepoint_probe_unregister (btp->tp, (void *)btp->bpf_func, link); } +/* On success the caller releases *buf with kfree_const() */ int bpf_get_perf_event_info(const struct perf_event *event, u32 *prog_id, u32 *fd_type, const char **buf, u64 *probe_offset, u64 *probe_addr,
@@ -2218,6 +2219,12 @@ int bpf_get_perf_event_info(const struct perf_event *event, u32 *prog_id,struct bpf_prog *prog;int flags, err =0 ; +/* +* The list of dynamic events is walked, and a probe which has siblings +* can be deleted, with its strings, while its event is in use. +*/ +guard (mutex)(&event_mutex); + prog = event->prog;if (!prog)return -ENOENT ;
@@ -2258,6 +2265,12 @@ int bpf_get_perf_event_info(const struct perf_event *event, u32 *prog_id,#endif } +if (!err && *buf) { + *buf =kstrdup_const (*buf,GFP_KERNEL ); +if (!*buf) + err = -ENOMEM ; + } +return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2098/2651 bpf: Dont saturate owner_refcnt on the last unpin
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 30a140c9d479974021f5c3eecb64415c96419c3f ]
bpf_local_storage_map_free() pins the owner with refcount_inc_not_zero() while it uncharges an element. The pin counts when bpf_local_storage_destroy() could not get local_storage->lock: destroy() then goes on, drops the owner's reference and spins until the count is zero. So the pin is the last reference whenever it is needed, and refcount_dec() takes that for a bug: it warns "decrement hit 0; leaking memory" and saturates the count. Unless destroy() happens to read the count between the two stores it spins for ever, under rcu_read_lock().
Drop the pin with refcount_dec_and_test().
--- include/linux/bpf_local_storage.h | 13 +++++++++++++ kernel/bpf/bpf_local_storage.c | 6 +++--- 2 files changed, 16 insertions(+), 3 deletions(-)
include/linux/bpf_local_storage.h +13 -0
@@ -104,6 +104,19 @@ struct bpf_local_storage {refcount_t owner_refcnt;/* Used to pin owner when map_free is uncharging */ }; +/* +* Drop a reference got by refcount_inc_not_zero(&local_storage->owner_refcnt). +* bpf_local_storage_destroy() may have dropped the owner's reference meanwhile +* and wait for the count to reach zero, so this one can be the last. +*/ +static inline void +bpf_local_storage_unpin_owner (struct bpf_local_storage *local_storage) +{ +bool last__maybe_unused ; + + last =refcount_dec_and_test (&local_storage->owner_refcnt); +} +/* U16_MAX is much more than enough for sk local storage * considering a tcp_sock is ~2k. */
kernel/bpf/bpf_local_storage.c +3 -3
@@ -199,7 +199,7 @@ static void bpf_selem_unlink_storage_nolock_misc(struct bpf_local_storage_elem * }if (pin_owner) -refcount_dec (&local_storage->owner_refcnt); +bpf_local_storage_unpin_owner (local_storage); }/* local_storage->lock must be held and selem->local_storage == local_storage.
@@ -750,8 +750,8 @@ u32 bpf_local_storage_destroy(struct bpf_local_storage *local_storage)while (refcount_read (&local_storage->owner_refcnt))cpu_relax ();/* -* Paired with refcount_dec() in bpf_selem_unlink_nofail() -* to make sure destroy() sees the correct local_storage->mem_charge. +* Paired with bpf_local_storage_unpin_owner() to make sure +* destroy() sees the correct local_storage->mem_charge. */ smp_mb (); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2099/2651 bpf: Validate the SRH which End.DT6 uncovers in End.BPF
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit e8b084646b946cc6f7976365588035947a296184 ]
input_action_end_bpf() validates the SRH of a packet and pulls it into the head before the program runs. If the program decapsulates the packet with bpf_lwt_seg6_action(SEG6_LOCAL_ACTION_END_DT6), bpf_update_srh_state() looks for a routing header in the inner packet and takes it for the new SRH as it is.
Nobody has looked at that header, and whoever has sent the packet has written it. ipv6_find_hdr() finds it in a fragment of the skb as well, but hdrlen is then read at that offset from skb->data, past the end of the head. The header need not be an SRH, and its hdrlen need not fit into the packet, but it is marked as valid, and bpf_lwt_seg6_adjust_srh() and bpf_lwt_seg6_store_bytes() check their offsets against it.
A program which then adds a TLV at the end of the SRH, where hdrlen has it, makes bpf_lwt_seg6_adjust_srh() move and write memory behind the head of the skb, as far as the sender likes within the 2 KB that hdrlen can say:
BUG: KASAN: slab-out-of-bounds in bpf_skb_net_hdr_push+0x185/0x240 Read of size 2088 at addr ffff888107d6f09e by task srh/102 BUG: KASAN: slab-out-of-bounds in bpf_skb_net_hdr_push+0x1b5/0x240 Write of size 8 at addr ffff888107d6f8be by task srh/102
Use seg6_get_srh(), which pulls and validates the header. Without a valid SRH the state says that there is none, and the packet goes its way as before. The pull can move the head, so compute the data pointers behind it.
--- net/core/filter.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
net/core/filter.c +5 -5
@@ -7032,15 +7032,15 @@ static void bpf_update_srh_state(struct sk_buff *skb) {struct seg6_bpf_srh_state *srh_state =this_cpu_ptr (&seg6_bpf_srh_states); -int srhoff =0 ; -if (ipv6_find_hdr (skb, &srhoff,IPPROTO_ROUTING ,NULL ,NULL ) <0 ) { - srh_state->srh =NULL ; - }else { - srh_state->srh = (struct ipv6_sr_hdr *)(skb->data + srhoff); +/* Behind a decapsulation this is a header that nobody has looked at */ + srh_state->srh =seg6_get_srh (skb,0 ); +if (srh_state->srh) { srh_state->hdrlen = srh_state->srh->hdrlen <<3 ; srh_state->valid = true; } +/* it may have been pulled into the head */ +bpf_compute_data_pointers (skb); } BPF_CALL_4(bpf_lwt_seg6_action, struct sk_buff *, skb,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2100/2651 bpf: Pull the inner header for End.DT6 in End.BPF
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 434324c611a98bc76dc850d45d67756dae5622cf ]
bpf_lwt_seg6_action(SEG6_LOCAL_ACTION_END_DT6) pulls the outer headers off the packet and hands it to seg6_lookup_nexthop(), which reads the inner IPv6 header at skb->data. Nothing says that this header is in the head of the skb, or that there is one. If the head ends with the outer headers, the route is looked up for whatever lies behind the head, and the packet is dropped or leaves by the wrong route. If the program then pushes an SRH with SEG6_LOCAL_ACTION_END_B6, seg6_do_srh_inline() pulls an IPv6 header off a head which has none, and __skb_pull() hits its BUG(): the kernel panics on a packet from the network.
GRO pulls the inner header of a plain IPv6 in IPv6 packet into the head. It takes a packet which GRO does not look into that far, one with a fragment header in front of the inner header for example, or a device without GRO, and a driver which leaves the inner header in a fragment.
Make sure of the inner header together with the outer ones. The program goes on behind an error of the helper, so do it before the packet is changed. A pull which fails can still have moved the head, so look for the SRH again.
--- net/core/filter.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/core/filter.c +6 -1
@@ -7073,9 +7073,14 @@ BPF_CALL_4(bpf_lwt_seg6_action, struct sk_buff *, skb,if (ipv6_find_hdr (skb, &hdroff,IPPROTO_IPV6 ,NULL ,NULL ) <0 )return -EBADMSG ; -if (!pskb_pull (skb, hdroff)) +/* As long as nothing has been changed, the program goes on */ +if (!pskb_may_pull (skb, hdroff +sizeof (struct ipv6hdr ))) { +/* but the head may have moved */ +bpf_update_srh_state (skb);return -EBADMSG ; + } +__skb_pull (skb, hdroff);skb_postpull_rcsum (skb,skb_network_header (skb), hdroff);skb_reset_network_header (skb);skb_reset_transport_header (skb);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2101/2651 bpf: Update the SRH state if End.B6 fails late
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 427e751a231aa781441d51c42e716905ee348099 ]
For SEG6_LOCAL_ACTION_END_B6 and END_B6_ENCAP bpf_lwt_seg6_action() looks for the SRH again only if bpf_push_seg6_encap() has succeeded. That function pushes the new header, for which the head of the skb is reallocated if it has not got the room, and then looks up the route to the first segment. If there is none, it returns an error, and the pointer to the SRH in seg6_bpf_srh_states still points into the old head, which has been freed.
The program goes on behind the error. bpf_lwt_seg6_store_bytes() and bpf_lwt_seg6_adjust_srh() read the SRH through that pointer.
Look for the SRH whatever bpf_push_seg6_encap() says.
--- net/core/filter.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/core/filter.c +4 -4
@@ -7094,8 +7094,8 @@ BPF_CALL_4(bpf_lwt_seg6_action, struct sk_buff *, skb,return -EBADMSG ; err =bpf_push_seg6_encap (skb,BPF_LWT_ENCAP_SEG6_INLINE , param, param_len); -if (!err) -bpf_update_srh_state (skb); +/* The header can be in place although err says otherwise */ +bpf_update_srh_state (skb);return err;case SEG6_LOCAL_ACTION_END_B6_ENCAP :
@@ -7103,8 +7103,8 @@ BPF_CALL_4(bpf_lwt_seg6_action, struct sk_buff *, skb,return -EBADMSG ; err =bpf_push_seg6_encap (skb,BPF_LWT_ENCAP_SEG6 , param, param_len); -if (!err) -bpf_update_srh_state (skb); +/* The header can be in place although err says otherwise */ +bpf_update_srh_state (skb);return err;default :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2102/2651 bpf: Clear sk_refcnt of a clone before its storage is linked
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Starovoitov <[email protected]>
[ Upstream commit 22f100bd013458836c3d0eaf8050b854d7534a66 ]
sk_clone() sets sk_refcnt of the new socket some lines behind bpf_sk_storage_clone(). But the elements which that function copies are linked to their maps at once, and an element leads to its owner: the iterator over a sk_storage map hands the owner to its program. bpf_sk_storage_get() with BPF_SK_STORAGE_GET_F_CREATE and bpf_sk_storage_delete() rely on refcount_inc_not_zero() to tell whether they may touch the socket.
sk_refcnt is in the part of struct sock which sock_copy() leaves out, and sk_prot_alloc() does not clear a clone unless init_on_alloc is on. It is zero in an object which has been a socket before, and anything in one which has not. If it is not zero, a helper gets a reference which refcount_set() wipes out, and the helper's sock_put() then drops one of the two references of the new socket, which is freed too early:
IPv4: Attempt to release TCP socket in state 1
BUG: KASAN: slab-use-after-free in __raw_spin_lock_init+0x47/0x90
In the meantime the helper changes a storage which bpf_sk_storage_clone() fills without taking its lock.
Nothing else can find the clone at this point. Say that it is not alive yet, before the first element is linked. Sockets whose parent has no storage are left alone.
--- net/core/bpf_sk_storage.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/core/bpf_sk_storage.c +7 -0
@@ -164,6 +164,13 @@ int bpf_sk_storage_clone(const struct sock *sk, struct sock *newsk)if (!sk_storage ||hlist_empty (&sk_storage->list)) goto out; +/* +* The maps lead to newsk as soon as an element is linked, but +* sk_clone() sets sk_refcnt only later. Until then it holds whatever +* the slab object held before: no reference can be had yet. +*/ +refcount_set (&newsk->sk_refcnt,0 ); +hlist_for_each_entry_rcu (selem, &sk_storage->list, snode) {struct bpf_local_storage_elem *copy_selem;struct bpf_local_storage_map *smap;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2103/2651 bpf: Fix NULL deref in the sk_storage map iterator
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 6186c9711ac6fb984f6c2093c52bf4e827cc50b1 ]
bpf_sk_storage_map_seq_find_next() hands out an element only if its local_storage pointer is set. __bpf_sk_storage_map_seq_show() then reads the pointer a second time and dereferences it without a test.
Since bpf_local_storage_destroy() unlinks the elements with bpf_selem_unlink_nofail(), the pointer is reset to NULL when the socket which owns the element is destroyed, so it can change between the two reads. Reading the iterator while sockets with an element in the map are closed ends in a NULL pointer dereference. The sockets need not belong to the reader: where a program gives every new socket an element, an unprivileged user who opens and closes sockets is enough.
Skip such an element, as the TCP and UDP iterators skip a socket which has been unhashed.
--- net/core/bpf_sk_storage.c | 3 +++ 1 file changed, 3 insertions(+)
net/core/bpf_sk_storage.c +3 -0
@@ -813,6 +813,9 @@ static int __bpf_sk_storage_map_seq_show(struct seq_file *seq, ctx.map = info->map;if (selem) { sk_storage =rcu_dereference (selem->local_storage); +/* reset since ->next() looked: the socket goes away */ +if (!sk_storage) +return SEQ_SKIP ; ctx.sk = sk_storage->owner; ctx.value =SDATA (selem)->data; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2104/2651 bpf: Link the first element after its storage is published
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Starovoitov <[email protected]>
[ Upstream commit bd897919e4dc18bbfdfc58b696fb948b8bc2c79a ]
bpf_local_storage_alloc() links the first element of a new storage to the bucket of its map, and then publishes the storage in the owner with cmpxchg(). If another cpu has been faster, the element is taken out of the bucket again and is freed together with the storage.
In between the iterator over a sk_storage map can find the element. It stays linked to a storage that points to the socket, but the socket knows nothing of that storage: bpf_sk_storage_free() neither unlinks the element nor waits for anybody who uses the storage. So nothing tells the iterator that the socket has gone away.
Three cpus that create the first storage of a new AF_UNIX socket at the same time, and a fourth that reads the iterator, are enough: in 20 seconds its program was shown some 4000 elements of storages that had lost. If the socket is closed in time, the program is handed a freed socket.
Link the element once the storage is published. Both happens under the lock of the bucket, which holds off whoever finds the element through the owner and wants to unlink it.
--- kernel/bpf/bpf_local_storage.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
kernel/bpf/bpf_local_storage.c +7 -3
@@ -507,8 +507,6 @@ int bpf_local_storage_alloc(void *owner,if (err) goto uncharge; -bpf_selem_link_map_nolock (b, first_selem); - owner_storage_ptr = (struct bpf_local_storage **)owner_storage (smap, owner);/* Publish storage to the owner.
@@ -523,11 +521,17 @@ int bpf_local_storage_alloc(void *owner,*/ prev_storage =cmpxchg (owner_storage_ptr,NULL , storage);if (unlikely (prev_storage)) { -bpf_selem_unlink_map_nolock (first_selem);raw_res_spin_unlock_irqrestore (&b->lock, flags); err = -EAGAIN ; goto uncharge; } +/* +* Not before the storage is published: the owner does not wait for +* users of a storage that it knows nothing of, so that nobody may find +* such a storage through the map. b->lock holds off those who find +* first_selem through the owner and want to unlink it. +*/ +bpf_selem_link_map_nolock (b, first_selem);raw_res_spin_unlock_irqrestore (&b->lock, flags);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2105/2651 bpf: Hold the socket in the sk_storage map iterator
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 070a96b2a98f66087797d8a31d53126de7a5208f ]
The iterator over a sk_storage map passes the owner of an element to its program as ctx->sk, without a reference. All that it holds is the RCU read lock, which keeps the element and the storage, not the socket.
An element is unlinked by bpf_sk_storage_free(), which __sk_destruct() calls right before it frees the socket. That is no better for a socket with SOCK_RCU_FREE: the grace period comes in front of __sk_destruct(), so a reader which starts behind call_rcu() still finds the element. The program and the helpers it hands ctx->sk to, such as bpf_sk_storage_get() or bpf_sk_storage_delete(), use a socket which is being freed on another CPU. It takes nothing but reading the iterator while sockets with an element in the map are closed, by whomever.
Take a reference for the time of the program, and skip the element if there is none to be had. To look at the owner at all, do what bpf_selem_unlink_nofail() does for bpf_local_storage_map_free(): as long as the element is linked under the lock of the storage, bpf_local_storage_destroy() has not got past it, unless it has given up on the lock, and then it waits for owner_refcnt.
The last reference may now be dropped by the iterator. The end of a socket may want process context: rfcomm_sock_destruct() takes a mutex. So only drop the reference under RCU, and free a socket whose last one it was when the RCU read lock has been released, which is at the end of a bucket and of every read() at the latest.
--- net/core/bpf_sk_storage.c | 73 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 68 insertions(+), 5 deletions(-)
net/core/bpf_sk_storage.c +68 -5
@@ -699,8 +699,37 @@ struct bpf_iter_seq_sk_storage_map_info {struct bpf_map *map;unsigned int bucket_id;unsigned skip_elems; +struct rcu_head *dead_sks; }; +/* +* sock_put() in two halves. The end of a socket may want process context: +* rfcomm_sock_destruct() takes a mutex. If the iterator drops the last +* reference, it keeps the socket until it has left the RCU read side critical +* section. Nobody uses sk_rcu before sk_destruct(). +*/ +static void +bpf_sk_storage_map_seq_put_sk (struct bpf_iter_seq_sk_storage_map_info *info, +struct sock *sk) +{ +if (refcount_dec_and_test (&sk->sk_refcnt)) { + sk->sk_rcu.next = info->dead_sks; + info->dead_sks = &sk->sk_rcu; + } +} + +static void +bpf_sk_storage_map_seq_free_sks (struct bpf_iter_seq_sk_storage_map_info *info) +{ +struct sock *sk; + +while (info->dead_sks) { + sk = container_of(info->dead_sks, struct sock, sk_rcu); + info->dead_sks = sk->sk_rcu.next; +sk_free (sk); + } +} +static struct bpf_local_storage_elem *bpf_sk_storage_map_seq_find_next (struct bpf_iter_seq_sk_storage_map_info *info,struct bpf_local_storage_elem *prev_selem)
@@ -729,6 +758,7 @@ bpf_sk_storage_map_seq_find_next(struct bpf_iter_seq_sk_storage_map_info *info,/* not found, unlock and go to the next bucket */ b = &smap->buckets[bucket_id++];rcu_read_unlock (); +bpf_sk_storage_map_seq_free_sks (info); skip_elems =0 ;break ; }
@@ -796,12 +826,44 @@ DEFINE_BPF_ITER_FUNC(bpf_sk_storage_map, struct bpf_iter_meta *meta, struct bpf_map *map, struct sock *sk, void *value) +/* +* Take a reference on the socket which owns @selem. RCU keeps the element, not +* its owner. As long as the element is linked under the lock of the storage, +* the owner has not got past bpf_sk_storage_free(), unless that has given up +* on the lock. Then it still waits for owner_refcnt. +*/ +static struct sock * +bpf_sk_storage_selem_get_sk (struct bpf_local_storage_elem *selem) +{ +struct bpf_local_storage *sk_storage; +struct sock *sk =NULL ; +unsigned long flags; + + sk_storage =rcu_dereference (selem->local_storage); +/* reset since ->next() looked: the socket goes away */ +if (!sk_storage) +return NULL ; + +if (raw_res_spin_lock_irqsave (&sk_storage->lock, flags)) +return NULL ; + +if (!hlist_unhashed (&selem->snode) && +refcount_inc_not_zero (&sk_storage->owner_refcnt)) { + sk = sk_storage->owner; +if (!refcount_inc_not_zero (&sk->sk_refcnt)) + sk =NULL ; +bpf_local_storage_unpin_owner (sk_storage); + } +raw_res_spin_unlock_irqrestore (&sk_storage->lock, flags); + +return sk; +} +static int __bpf_sk_storage_map_seq_show (struct seq_file *seq,struct bpf_local_storage_elem *selem) {struct bpf_iter_seq_sk_storage_map_info *info = seq->private;struct bpf_iter__bpf_sk_storage_map ctx = {}; -struct bpf_local_storage *sk_storage;struct bpf_iter_meta meta;struct bpf_prog *prog;int ret =0 ;
@@ -812,14 +874,14 @@ static int __bpf_sk_storage_map_seq_show(struct seq_file *seq, ctx.meta = &meta; ctx.map = info->map;if (selem) { - sk_storage =rcu_dereference (selem->local_storage); -/* reset since ->next() looked: the socket goes away */ -if (!sk_storage) + ctx.sk =bpf_sk_storage_selem_get_sk (selem); +if (!ctx.sk)return SEQ_SKIP ; - ctx.sk = sk_storage->owner; ctx.value =SDATA (selem)->data; } ret =bpf_iter_run_prog (prog, &ctx); +if (ctx.sk) +bpf_sk_storage_map_seq_put_sk (info, ctx.sk); }return ret;
@@ -837,6 +899,7 @@ static void bpf_sk_storage_map_seq_stop(struct seq_file *seq, void *v) (void )__bpf_sk_storage_map_seq_show (seq, v); elsercu_read_unlock (); +bpf_sk_storage_map_seq_free_sks (seq->private); } static int bpf_iter_init_sk_storage_map(void *priv_data,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2106/2651 bpf: Bound the nesting that the BTF show code follows
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 13ac7c05bc45d3445b580da186548dd3487fae4e ]
btf_struct_show() and btf_array_show() recurse for every nested struct and array. MAX_RESOLVE_DEPTH bounds one resolve walk when BTF is loaded, not the nesting: a member whose type is resolved already is not walked again, so BTF that defines its types from the inside out can nest them as deep as it has types.
Whoever may load BTF, with CAP_BPF or a BPF token, can give such a type to the value of a map. Reading the file of that map in bpffs then overruns the kernel stack: with a few hundred levels the stack guard page is hit and the kernel panics.
Stop at 32 levels. That is MAX_RESOLVE_DEPTH, and __btf_show_indent() has as many columns. Nothing is shown for a member that lies deeper, and the status becomes -E2BIG, which bpf_snprintf_btf() and bpf_seq_printf_btf() return. The types of an x86_64 defconfig kernel nest 14 deep.
--- kernel/bpf/btf.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
kernel/bpf/btf.c +13 -1
@@ -1065,6 +1065,8 @@ static const struct btf_type *btf_type_skip_qualifiers(const struct btf *btf, }#define BTF_SHOW_MAX_ITER 10 +/* nested structs and arrays shown; __btf_show_indent() has as many columns */ +#define BTF_SHOW_MAX_DEPTH 32#define BTF_KIND_BIT (kind) (1ULL << kind)
@@ -1458,8 +1460,18 @@ static void *btf_show_start_aggr_type(struct btf_show *show,const struct btf_type *t, u32 type_id, void *data) { - void *safe_data = btf_show_start_type(show, t, type_id, data); + void *safe_data; +/* +* Structs and arrays are shown by recursion. BTF loading bounds the +* depth of one resolve walk, not how deep resolved types may nest. +*/ +if (show->state.depth >=BTF_SHOW_MAX_DEPTH ) { + show->state.status = -E2BIG ; +return NULL ; + } + + safe_data =btf_show_start_type (show, t, type_id, data);if (!safe_data)return safe_data;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2107/2651 bpf: Fix stale offload->prog pointer after realloc
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 8e83d53596445fcf5b0385e5fbe8bcd971e06d06 ]
bpf_prog_realloc() moves a program that the rewrites of the verifier make outgrow its pages. It updates aux->prog, but not the offload->prog of a device-bound program. When the device is unregistered, __bpf_offload_dev_netdev_unregister() hands the stale pointer to __bpf_prog_offload_destroy(), which faults on the freed program:
BUG: unable to handle page fault for address: ffffc90000071050 RIP: 0010:__bpf_prog_offload_destroy+0x3f/0x310
It takes the right to load a device-bound XDP program, CAP_BPF and CAP_NET_ADMIN or a BPF token, and a device that can be removed.
Commit a1aa9ef47c29 ("bpf: Fix stale offload->prog pointer after constant blinding") repaired the other place that replaces a program. Do the same here.
Nothing keeps the device while a program is loaded, so it can also be unregistered at that very moment. That frees the offload, and it may have read offload->prog already when the old copy of the program is freed. In both places update the pointer under bpf_devs_lock, before the old copy goes.
--- include/linux/bpf.h | 5 +++++ kernel/bpf/core.c | 4 ++-- kernel/bpf/offload.c | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-)
include/linux/bpf.h +5 -0
@@ -3670,6 +3670,7 @@ int bpf_dev_bound_kfunc_check(struct bpf_verifier_log *log,void *bpf_dev_bound_resolve_kfunc (struct bpf_prog *prog,u32 func_id);int bpf_prog_dev_bound_init (struct bpf_prog *prog,union bpf_attr *attr);int bpf_prog_dev_bound_inherit (struct bpf_prog *new_prog,struct bpf_prog *old_prog); +void bpf_prog_dev_bound_moved (struct bpf_prog *prog);void bpf_dev_bound_netdev_unregister (struct net_device *dev);static inline bool bpf_prog_is_dev_bound (const struct bpf_prog_aux *aux)
@@ -3731,6 +3732,10 @@ static inline int bpf_prog_dev_bound_inherit(struct bpf_prog *new_prog,return -EOPNOTSUPP ; } +static inline void bpf_prog_dev_bound_moved (struct bpf_prog *prog) +{ +} +static inline void bpf_dev_bound_netdev_unregister (struct net_device *dev) { }
kernel/bpf/core.c +2 -2
@@ -273,6 +273,7 @@ struct bpf_prog *bpf_prog_realloc(struct bpf_prog *fp_old, unsigned int size,memcpy (fp, fp_old, fp_old->pages *PAGE_SIZE ); fp->pages = pages; fp->aux->prog = fp; +bpf_prog_dev_bound_moved (fp);/* We keep fp->aux from fp_old around in the new * reallocated structure.
@@ -1555,8 +1556,7 @@ void bpf_jit_prog_release_other(struct bpf_prog *fp, struct bpf_prog *fp_other)* know whether fp here is the clone or the original. */ fp->aux->prog = fp; -if (fp->aux->offload) - fp->aux->offload->prog = fp; +bpf_prog_dev_bound_moved (fp);bpf_prog_clone_free (fp_other); }
kernel/bpf/offload.c +16 -0
@@ -96,6 +96,22 @@ static int __bpf_offload_dev_netdev_register(struct bpf_offload_dev *offdev,return err; } +/* +* @prog takes the place of a copy that the caller is about to free. Nothing +* keeps the netdev while a program is loaded: once the lock is dropped, no +* unregistration is left that has got the old copy from offload->prog. +*/ +void bpf_prog_dev_bound_moved (struct bpf_prog *prog) +{ +if (!bpf_prog_is_dev_bound (prog->aux)) +return ; + +down_read (&bpf_devs_lock); +if (prog->aux->offload) + prog->aux->offload->prog = prog; +up_read (&bpf_devs_lock); +} +static void __bpf_prog_offload_destroy (struct bpf_prog *prog) {struct bpf_prog_offload *offload = prog->aux->offload;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2108/2651 bpf: Dont bind a program to a netdev that goes away
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit af929bc938e0d0ecd839e6fed9a2ce5eb5185e5c ]
bpf_prog_dev_bound_init() looks the device up, takes bpf_devs_lock and registers the device for the program. The reference it holds does not keep the device registered. If bpf_dev_bound_netdev_unregister() has run by the time the lock is taken, nobody takes the program off the device any
more: the bpf_offload_netdev and offload->netdev point to a net_device that is freed as soon as the reference is dropped. bpf_dev_bound_resolve_kfunc() dereferences it while the program is verified, and a new device at the same address finds the old entry.
unregister_netdevice_many_notify() leaves NETREG_REGISTERED before it calls bpf_dev_bound_netdev_unregister(), which takes bpf_devs_lock. Look at reg_state under that lock, and treat a device that goes like one that is not there.
--- kernel/bpf/offload.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
kernel/bpf/offload.c +8 -1
@@ -266,7 +266,14 @@ int bpf_prog_dev_bound_init(struct bpf_prog *prog, union bpf_attr *attr) prog->aux->offload_requested = !(attr->prog_flags &BPF_F_XDP_DEV_BOUND_ONLY );down_write (&bpf_devs_lock); - err =__bpf_prog_dev_bound_init (prog, netdev); +/* +* Behind bpf_dev_bound_netdev_unregister() nobody would take the +* program off the device, which goes once the reference is dropped. +*/ +if (READ_ONCE (netdev->reg_state) ==NETREG_REGISTERED ) + err =__bpf_prog_dev_bound_init (prog, netdev); +else + err = -EINVAL ;up_write (&bpf_devs_lock); out:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2109/2651 bpf: Keep a program until its bpf_wq callback has ended
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 1e28a5e52d32b7d3f4c9fb24898774f941166d2b ]
bpf_wq_work() runs the callback under rcu_read_lock_trace() only, since the callback may sleep. The program it belongs to need not be sleepable, and such a program is freed behind a plain RCU grace period. The reference that the bpf_wq holds is dropped when the map element goes, or when another callback is set, no matter whether the work is running.
If that was the last reference the program is freed under the running callback, and the worker goes on in the freed JIT image:
Oops: int3: 0000 [#1] SMP NOPTI RIP: 0010:0xffffffffc0600947
All it takes is to close the map and the program while the callback runs.
Note in the program that it has a callback that runs sleepable, and wait for an RCU Tasks Trace grace period, which implies a plain one, before such a program is freed. Let bpf_wq_work() enter its read side critical section before it reads callback_fn.
bpf_task_work holds a reference to the program until the callback is done.
--- include/linux/bpf.h | 10 ++++++++++ kernel/bpf/helpers.c | 9 ++++++--- kernel/bpf/syscall.c | 4 ++-- kernel/bpf/verifier.c | 2 ++ 4 files changed, 20 insertions(+), 5 deletions(-)
include/linux/bpf.h +10 -0
@@ -1807,6 +1807,7 @@ struct bpf_prog_aux {bool attach_btf_trace;/* true if attaching to BTF-enabled raw tp */ bool attach_tracing_prog;/* true if tracing another tracing program */ bool tramp_linked;/* true if it was ever linked to a trampoline */ +bool sleepable_async_cb;/* has a bpf_wq or bpf_task_work callback */ bool func_proto_unreliable;bool tail_call_reachable;bool xdp_has_frags;
@@ -1940,6 +1941,15 @@ struct bpf_prog { }; }; +/* +* Does the program, or a callback of it, run under RCU Tasks Trace protection +* only, outside of any RCU read side critical section? +*/ +static inline bool bpf_prog_runs_sleepable (const struct bpf_prog *prog) +{ +return prog->sleepable || prog->aux->sleepable_async_cb; +} +struct bpf_array_aux {/* Programs with direct jumps into programs part of this array. */ struct list_head poke_progs;
kernel/bpf/helpers.c +6 -3
@@ -1224,18 +1224,21 @@ static void bpf_wq_work(struct work_struct *work)BTF_TYPE_EMIT (struct bpf_wq ); +/* keeps the program that callback_fn belongs to */ +rcu_read_lock_trace (); + callback_fn =READ_ONCE (cb->callback_fn);if (!callback_fn) -return ; + goto out; key =map_key_from_value (map, value, &idx); -rcu_read_lock_trace (); -migrate_disable (); +migrate_disable ();callback_fn ((u64 )(long )map, (u64 )(long )key, (u64 )(long )value,0 ,0 );migrate_enable (); +out:rcu_read_unlock_trace (); }
kernel/bpf/syscall.c +2 -2
@@ -2465,7 +2465,7 @@ static void __bpf_prog_put_rcu_tasks(struct rcu_head *rcu) { struct bpf_prog *prog = container_of(rcu, struct bpf_prog_aux, rcu)->prog; -if (prog->sleepable) +if (bpf_prog_runs_sleepable (prog))call_rcu_tasks_trace (rcu, __bpf_prog_put_rcu);else call_rcu (rcu, __bpf_prog_put_rcu);
@@ -2485,7 +2485,7 @@ static void __bpf_prog_put_noref(struct bpf_prog *prog, bool deferred)if (deferred) {if (IS_ENABLED (CONFIG_TASKS_RCU ) && prog->aux->tramp_linked)call_rcu_tasks (&prog->aux->rcu, __bpf_prog_put_rcu_tasks); -else if (prog->sleepable) +else if (bpf_prog_runs_sleepable (prog))call_rcu_tasks_trace (&prog->aux->rcu, __bpf_prog_put_rcu);else call_rcu (&prog->aux->rcu, __bpf_prog_put_rcu);
kernel/bpf/verifier.c +2 -0
@@ -9953,6 +9953,8 @@ static int push_callback_call(struct bpf_verifier_env *env, struct bpf_insn *ins is_async_cb_sleepable(env, insn));if (IS_ERR (async_cb))return PTR_ERR (async_cb); +if (is_async_cb_sleepable (env, insn)) + env->prog->aux->sleepable_async_cb = true; callee = async_cb->frame[0 ]; callee->async_entry_cnt = state->frame[0 ]->async_entry_cnt +1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2110/2651 bpf: Count sleepable callbacks as sleepable map users
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 927c9c985f3ef4d30c086884b7e0ecb933f742ef ]
map->sleepable_refcnt tells bpf_map_fd_put_ptr() whether an inner map that is taken out of its outer map has to wait for an RCU Tasks Trace grace period as well. It counts the sleepable programs that use the outer map. The bpf_wq or bpf_task_work callback of a program that is not sleepable runs under rcu_read_lock_trace() only, and is not counted.
Such a callback can look an inner map up and keep it while user space deletes it from the outer map. The inner map is freed behind a plain RCU grace period, under the callback:
BUG: KASAN: slab-use-after-free in array_map_update_elem+0x6bc/0x7d0
Count a program with such a callback. The maps are bound before the verifier meets the callback, so raise the count of those that are bound when it does.
--- kernel/bpf/core.c | 2 +- kernel/bpf/syscall.c | 2 +- kernel/bpf/verifier.c | 17 +++++++++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-)
kernel/bpf/core.c +1 -1
@@ -3035,7 +3035,7 @@ void __bpf_free_used_maps(struct bpf_prog_aux *aux,bool sleepable;u32 i; - sleepable = aux->prog->sleepable; + sleepable =bpf_prog_runs_sleepable (aux->prog);for (i =0 ; i < len; i++) { map = used_maps[i];if (map->ops->map_poke_untrack)
kernel/bpf/syscall.c +1 -1
@@ -6236,7 +6236,7 @@ static int bpf_prog_bind_map(union bpf_attr *attr)/* The bpf program will not access the bpf map, but for the sake of * simplicity, increase sleepable_refcnt for sleepable program as well. */ -if (prog->sleepable) +if (bpf_prog_runs_sleepable (prog))atomic64_inc (&map->sleepable_refcnt);memcpy (used_maps_new, used_maps_old,sizeof (used_maps_old[0 ]) * prog->aux->used_map_cnt);
kernel/bpf/verifier.c +15 -2
@@ -537,6 +537,19 @@ static bool is_async_cb_sleepable(struct bpf_verifier_env *env, struct bpf_insnreturn false; } +/* From here on the maps of the program count it as a sleepable user. */ +static void mark_sleepable_async_cb (struct bpf_verifier_env *env) +{ +int i; + +if (bpf_prog_runs_sleepable (env->prog)) +return ; + + env->prog->aux->sleepable_async_cb = true; +for (i =0 ; i < env->used_map_cnt; i++) +atomic64_inc (&env->used_maps[i]->sleepable_refcnt); +} +bool bpf_is_may_goto_insn (struct bpf_insn *insn) {return insn->code == (BPF_JMP |BPF_JCOND ) && insn->src_reg ==BPF_MAY_GOTO ;
@@ -9954,7 +9967,7 @@ static int push_callback_call(struct bpf_verifier_env *env, struct bpf_insn *insif (IS_ERR (async_cb))return PTR_ERR (async_cb);if (is_async_cb_sleepable (env, insn)) - env->prog->aux->sleepable_async_cb = true; +mark_sleepable_async_cb (env); callee = async_cb->frame[0 ]; callee->async_entry_cnt = state->frame[0 ]->async_entry_cnt +1 ;
@@ -19074,7 +19087,7 @@ static int __add_used_map(struct bpf_verifier_env *env, struct bpf_map *map)if (err)return err; -if (env->prog->sleepable) +if (bpf_prog_runs_sleepable (env->prog))atomic64_inc (&map->sleepable_refcnt);/* hold the map. If the program is rejected by verifier,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2111/2651 bpf: Check the maps that sleepable callbacks use
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 3e6d7522af2cd1b8bf135ee7df6ca962986f44d6 ]
Sleepable programs can only use the kinds of map that do without an RCU read side critical section. check_map_prog_compatibility() sees to that when a map is bound to the program, and asks whether the program is sleepable. That misses the bpf_wq or bpf_task_work callback of a program that is not, which runs sleepable all the same, and it misses an inner map, which is not bound.
The bpf_wq callback of a tc program that looks a key up in a sockhash gets as far as
WARNING: net/core/sock_map.c:903 at __sock_hash_lookup_elem+0x18f/0x1e0
Ask the same question for the map that is handed to a helper in sleepable context, unless the RCU read lock is held: by bpf_rcu_read_lock(), or by the helper that runs the callback, as bpf_for_each_map_elem() does for a hash map. Programs that take the lock go on working. Disabled preemption or interrupts are not enough, since the maps ask for rcu_read_lock_held(). The other parts of the program may use such a map as before.
A global function that is called with preemption or interrupts disabled is verified for the non-sleepable context, in which nothing is known of all that. Verify it for a context of its own: not sleepable, and without the RCU read lock. It differs in what maps can be used, and in nothing else.
What is refused from now on runs into the warning above, or uses what the map frees behind a plain RCU grace period: an entry of a devmap, of a perf event array or of a cgroup array.
A bloom filter does without RCU. Add it to the list, so that callbacks which use one go on loading. As a side effect sleepable programs can use bloom filters as well.
A pointer to the value of a devmap which a program keeps beyond bpf_rcu_read_unlock() is not dealt with here.
--- include/linux/bpf.h | 14 ++++- include/linux/bpf_verifier.h | 2 + kernel/bpf/verifier.c | 109 ++++++++++++++++++++++++----------- 3 files changed, 89 insertions(+), 36 deletions(-)
include/linux/bpf.h +11 -3
@@ -1684,12 +1684,20 @@ static inline void bpf_trampoline_multi_detach(struct bpf_prog *prog,static inline void bpf_trampoline_set_flags (struct bpf_trampoline *tr,u32 flags) {}#endif +/* The contexts that a global function is called in, and is verified for. */ +enum bpf_func_context { +BPF_FUNC_CTX_NON_SLEEPABLE , +BPF_FUNC_CTX_SLEEPABLE , +/* Sleepable code has disabled preemption or interrupts: no RCU read lock. */ +BPF_FUNC_CTX_NO_RCU_LOCK , +BPF_FUNC_CTX_CNT , +}; +struct bpf_func_info_aux {u16 linkage;bool unreliable; -/* Indexed by in_sleepable. */ -bool called[2 ]; -bool verified[2 ]; +bool called[BPF_FUNC_CTX_CNT ]; +bool verified[BPF_FUNC_CTX_CNT ]; };enum bpf_jit_poke_reason {
include/linux/bpf_verifier.h +2 -0
@@ -943,6 +943,8 @@ struct bpf_verifier_env {bool bypass_spec_v1;bool bypass_spec_v4;bool seen_direct_write; +/* a global function is verified for BPF_FUNC_CTX_NO_RCU_LOCK */ +bool no_rcu_read_lock;bool seen_exception;bool signature;u32 insn_aux_data_len;
kernel/bpf/verifier.c +76 -33
157 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2112/2651 bpf: Assume no bounds for buffers behind a tail call
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 7fa323d77688e8b62b2f0bf6c3208a2c96d4a5e7 ]
The bpf_map_elem, bpf_sk_storage_map and sockmap iterators hand the key and the value of an element to the program as buffers. The verifier notes how far a program reaches into them, and the iterator compares that with the map when the program is attached. A program that does not touch the buffers passes. It can tail-call another program of the same target, which gets the same context, and whose reach nobody compares with the map:
BUG: KASAN: slab-out-of-bounds in ___bpf_prog_run+0xa46a/0xae80
The program array can be filled at any time, so there is nothing to look at when the link is made. For the same reason a program with a tail call is taken to use the whole stack and the whole packet. Take it to reach as far as can be into the buffers as well, so that these iterators refuse it with -EACCES.
--- kernel/bpf/fixups.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/bpf/fixups.c +2 -0
@@ -2018,6 +2018,8 @@ int bpf_do_misc_fixups(struct bpf_verifier_env *env)if (!bpf_allow_tail_call_in_subprogs (env)) prog->aux->stack_depth =MAX_BPF_STACK ; prog->aux->max_pkt_offset =MAX_PACKET_OFF ; + prog->aux->max_rdonly_access =U32_MAX ; + prog->aux->max_rdwr_access =U32_MAX ;/* mark bpf_tail_call as different opcode to avoid * conditional branch in the interpreter for every normal
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2113/2651 bpf: Dont take an extension for an iterator program
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 7cc639dc45c5d3b69acb2a2fc834e9eec51e0214 ]
An extension inherits the expected_attach_type of the program it extends. If that is BPF_TRACE_ITER, check_attach_btf_id() hands the extension to bpf_iter_prog_supported(), which goes by the name of the attach function. For an extension that is the name of the subprogram it replaces, so the load fails with -EINVAL, unless that subprogram is called like the function of a target, bpf_iter_bpf_map_elem for example.
Then the extension gets the context of that target. If the subprogram has as many arguments, it can use the key and the value as buffers, but how far it reaches is noted in the extension, where the test of the iterator link does not look: it reads and writes behind the elements of the map. And the id of the subprogram in the BTF of the program is cached as the id of the target, so that programs of that target which are loaded already cannot be attached.
Refuse all extensions here.
--- kernel/bpf/bpf_iter.c | 7 +++++++ 1 file changed, 7 insertions(+)
kernel/bpf/bpf_iter.c +7 -0
@@ -351,6 +351,13 @@ int bpf_iter_prog_supported(struct bpf_prog *prog)const char *prefix =BPF_ITER_FUNC_PREFIX ;int prefix_len =strlen (prefix); +/* +* The attach function of an extension is a subprogram of the iterator +* program that it extends, whatever its name is. +*/ +if (prog->type ==BPF_PROG_TYPE_EXT ) +return -EINVAL ; +if (strncmp (attach_fname, prefix, prefix_len))return -EINVAL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2114/2651 bpf: Assume no bounds for a writable tp with tail calls
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit cd0490e671d70326d70c7d36e82388939fd9b071 ]
A writable raw tracepoint hands a buffer to the program. The verifier notes how far the program reaches into it, and bpf_probe_register() refuses a program that reaches further than the tracepoint allows. A program that does not touch the buffer passes, and can tail-call one of its type that reads and writes behind it.
Take a BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE program with a tail call to reach as far as can be, as for the stack, the packet and the buffers of iterators. It cannot be attached any more. Plain raw tracepoint programs, for which the limit is zero, cannot get at the buffer, and a tail call stays within one type: they are left alone.
--- kernel/bpf/fixups.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/bpf/fixups.c +2 -0
@@ -2020,6 +2020,8 @@ int bpf_do_misc_fixups(struct bpf_verifier_env *env) prog->aux->max_pkt_offset =MAX_PACKET_OFF ; prog->aux->max_rdonly_access =U32_MAX ; prog->aux->max_rdwr_access =U32_MAX ; +if (prog->type ==BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE ) + prog->aux->max_tp_access =U32_MAX ;/* mark bpf_tail_call as different opcode to avoid * conditional branch in the interpreter for every normal
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2115/2651 bpf: Dont take an extension for a writable raw tracepoint program
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Starovoitov <[email protected]>
[ Upstream commit 7fe348f18b37b3f4c8beb981ef3f84564047380a ]
bpf_probe_register() compares max_tp_access of the program that is attached with the size of the buffer that the tracepoint lets programs write to. An extension of that program, or of one of its global functions, gets the same context and the same pointer to the buffer. What it accesses is noted in its own max_tp_access, which nobody looks at. So it reads and writes behind the buffer, of a tracepoint that may have none:
BUG: KASAN: stack-out-of-bounds in bpf_prog_5843f2b820eb4929_tr26_ext_far+0xf4/0x10c Write of size 4 at addr ffffc90000d8f894 by task wext/103
Refuse such extensions.
--- kernel/bpf/verifier.c | 9 +++++++++ 1 file changed, 9 insertions(+)
kernel/bpf/verifier.c +9 -0
@@ -20364,6 +20364,15 @@ int bpf_check_attach_target(struct bpf_verifier_log *log, "Extension programs should be JITed\n");return -EINVAL ; } +/* +* How much of the buffer of the tracepoint is used +* is checked for the program that is attached to it. +*/ +if (tgt_prog->type ==BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE ) { +bpf_log (log, +"Cannot extend a writable raw tracepoint program\n" ); +return -EINVAL ; + } tgt_changes_pkt_data = aux->func ? aux->func[subprog]->aux->changes_pkt_data : aux->changes_pkt_data;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2116/2651 bpf: Free what map_free() unlinks for sleepable readers
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 5bdd61e98da5468140aff5b5abc0e8544deaf2ee ]
bpf_local_storage_map_free() takes the elements of the map off the lists of their owners, which are alive, and frees them, and the storage of an owner with its last element, behind a plain RCU grace period. Nobody uses the map any more, but the other maps of these owners are in use. A sleepable program calls the get and delete helpers under rcu_read_lock_trace() only. While it walks the list of an owner for its own map, or is about to lock the storage, the element it stands on, or the storage, can be freed under it.
Whatever else takes an element off the list of a live owner frees it behind an RCU Tasks Trace grace period, which implies a plain one. Do so in bpf_local_storage_map_free() as well. It waits for these callbacks before it frees the map.
This does not help a sleepable program that hands an owner to the helpers which nobody holds, and which may be gone by then.
--- kernel/bpf/bpf_local_storage.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
kernel/bpf/bpf_local_storage.c +6 -2
@@ -429,13 +429,17 @@ static void bpf_selem_unlink_nofail(struct bpf_local_storage_elem *selem,* then freed after an RCU grace period. However, if destroy() and map_free() are * racing or rqspinlock returns errors in unlikely situations (unlink != 2), free * the selem only after both map_free() and destroy() see the selem. +* +* The owner that map_free() takes an selem from is alive: sleepable code, which +* is in no RCU read side critical section, may be walking its list for another +* map. */ if (unlink ==2 ||atomic_cmpxchg (&selem->state,SELEM_UNLINKED ,SELEM_TOFREE ) ==SELEM_UNLINKED ) -bpf_selem_free (selem, true); +bpf_selem_free (selem, !in_map_free);if (free_storage) -bpf_local_storage_free (local_storage, true); +bpf_local_storage_free (local_storage, !in_map_free); } void __bpf_local_storage_insert_cache(struct bpf_local_storage *local_storage,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2117/2651 power: supply: qcom_battmgr: report full batteries
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bjorn Andersson <[email protected]>
[ Upstream commit 6c8098e04ee4d233399e40e7311715844910f8f8 ]
The SC8280XP battery-status response has no explicit full state. When a battery reaches its full capacity on external power, neither the charging nor discharging bit is set. The driver consequently reports "Not charging", which can make userspace show the system as battery powered.
Use the response's power-online bit and the reported capacity to identify a battery that is full while externally powered. Preserve "Not charging" for a battery whose charging is inhibited below its full capacity.
--- drivers/power/supply/qcom_battmgr.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
drivers/power/supply/qcom_battmgr.c +11 -5
@@ -1277,6 +1277,7 @@ static void qcom_battmgr_sc8280xp_callback(struct qcom_battmgr *battmgr, size_t len) {unsigned int opcode =le32_to_cpu (resp->hdr.opcode); +unsigned int power_state;unsigned int source;unsigned int state;size_t payload_len = len -sizeof (struct pmic_glink_hdr );
@@ -1327,19 +1328,24 @@ static void qcom_battmgr_sc8280xp_callback(struct qcom_battmgr *battmgr,return ; } + battmgr->status.capacity =le32_to_cpu (resp->status.capacity) *1000 ; + battmgr->status.power_now =le32_to_cpu (resp->status.rate) *1000 ; + battmgr->status.voltage_now =le32_to_cpu (resp->status.battery_voltage) *1000 ; + battmgr->status.temperature =qcom_battmgr_sc8280xp_convert_temp (le32_to_cpu (resp->status.temperature)); + state =le32_to_cpu (resp->status.battery_state); + power_state =le32_to_cpu (resp->status.power_state);if (state &BIT (0 )) battmgr->status.status =POWER_SUPPLY_STATUS_DISCHARGING ;else if (state &BIT (1 )) battmgr->status.status =POWER_SUPPLY_STATUS_CHARGING ; +else if ((power_state &BIT (0 )) && + battmgr->info.last_full_capacity && + battmgr->status.capacity >= battmgr->info.last_full_capacity) + battmgr->status.status =POWER_SUPPLY_STATUS_FULL ;else battmgr->status.status =POWER_SUPPLY_STATUS_NOT_CHARGING ; - battmgr->status.capacity =le32_to_cpu (resp->status.capacity) *1000 ; - battmgr->status.power_now =le32_to_cpu (resp->status.rate) *1000 ; - battmgr->status.voltage_now =le32_to_cpu (resp->status.battery_voltage) *1000 ; - battmgr->status.temperature =qcom_battmgr_sc8280xp_convert_temp (le32_to_cpu (resp->status.temperature)); - source =le32_to_cpu (resp->status.charging_source);qcom_battmgr_sc8280xp_set_online (battmgr->ac_psy, &battmgr->ac.online, source ==BATTMGR_CHARGING_SOURCE_AC );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2118/2651 netfilter: conntrack: fix unlikely UaF in gc worker
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit 9836164821a46af07428bb2a5e14137bf0c7bd6e ]
When early-drop scan is enabled, gc_worker() reads tmp->ct_net, resolves cnet with nf_ct_pernet(), and reads cnet->count with RCU read lock held but before acquiring a reference to tmp.
Its unlikely but possible that the worker gets preempted before reading cnet->count while nf_conntrack_cleanup_net_list manages to unlink all conntracks and returns in the mean time.
This allows for the pernet memory to get free'd.
On resume, use after free would occur when the worker reads cnet->count.
This can be solved either via another synchronize_rcu() in nf_conntrack_cleanup_net_list or via cheaper flush_work(). If work wasn't running no race can happen as next call cannot observe already-unlinked conntrack objects.
This is an LLM finding with no reproducer, but it appears to be correct.
--- net/netfilter/nf_conntrack_core.c | 5 +++++ 1 file changed, 5 insertions(+)
net/netfilter/nf_conntrack_core.c +5 -0
@@ -2507,6 +2507,11 @@ void nf_conntrack_cleanup_net_list(struct list_head *net_exit_list) goto i_see_dead_people; } +/* must wait for current scan loop, worker also looks at +* struct nf_conntrack_net, which is about to be free'd. +*/ +flush_work (&conntrack_gc_work.dwork.work); +list_for_each_entry (net, net_exit_list, exit_list) {warn_on_keymap_list_leak (net);nf_conntrack_ecache_pernet_fini (net);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2119/2651 selftests: netfilter: fix return value in zone subtest
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit a20a01ae89813ef493dc416d69f2b2ad17afb54c ]
zone subtest prints FAIL, but did not set 'ret=1', so kselftest framework reports success.
While at it, also fail when "nft -f" returns an error.
Noticed thanks to a (broken) local patch that should have caused this selftest (resp. the kselftest framework) to report a failure.
--- .../selftests/net/netfilter/conntrack_vrf.sh | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-)
tools/testing/selftests/net/netfilter/conntrack_vrf.sh +22 -3
@@ -84,7 +84,7 @@ busywait $BUSYWAIT_TIMEOUT listener_ready "$ns1" # as decided by the first iteration of the ruleset. test_ct_zone_in() { -ip netns exec "$ns0" nft -f - <<EOF +if ! ip netns exec "$ns0" nft -f - <<EOF table testct { chain rawpre { type filter hook prerouting priority raw;
@@ -105,6 +105,12 @@ table testct { } } EOF + then + echo "FAIL: cannot load testct nft ruleset" + ret=1 + return + fi + ip netns exec "$ns1" ping -W 1 -c 1 -I veth0 "$IP0" > /dev/null # should be in zone 1, not zone 2
@@ -113,6 +119,7 @@ EOF echo "PASS: entry found in conntrack zone 1" else echo "FAIL: entry not found in conntrack zone 1" + ret=1 count=$(ip netns exec "$ns0" conntrack -L -s $IP1 -d $IP0 -p icmp --zone 2 2> /dev/null | wc -l) if [ "$count" -eq 1 ]; then echo "FAIL: entry found in zone 2 instead"
@@ -137,7 +144,7 @@ test_masquerade_vrf() ip netns exec "$ns0" conntrack -F 2>/dev/null -ip netns exec "$ns0" nft -f - <<EOF +if ! ip netns exec "$ns0" nft -f - <<EOF flush ruleset table ip nat { chain rawout {
@@ -158,6 +165,12 @@ table ip nat { } } EOF + then + echo "FAIL: cannot load ip nat nft ruleset" + ret=1 + return + fi + if ! ip netns exec "$ns0" ip vrf exec tvrf socat -u -4 STDIN TCP:"$IP1":55555 < /dev/null > /dev/null;then echo "FAIL: connect failure with masquerade + sport rewrite on vrf device" ret=1
@@ -184,7 +197,7 @@ EOF test_masquerade_veth() { ip netns exec "$ns0" conntrack -F 2>/dev/null -ip netns exec "$ns0" nft -f - <<EOF +if ! ip netns exec "$ns0" nft -f - <<EOF flush ruleset table ip nat { chain postrouting {
@@ -193,6 +206,12 @@ table ip nat { } } EOF + then + echo "FAIL: cannot load ip nat postrouting ruleset" + ret=1 + return + fi + if ! ip netns exec "$ns0" ip vrf exec tvrf socat -u -4 STDIN TCP:"$IP1":55555 < /dev/null > /dev/null;then echo "FAIL: connect failure with masquerade + sport rewrite on veth device" ret=1
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2120/2651 netfilter: nft_compat: restrict raw table targets/matches
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit ac364eb4d6d747b15df17e5fc9e442c318afaaac ]
xt targets and matches declaring .table = "raw" (CT, NOTRACK) rely on only ever running in the legacy raw table's prerouting/output chains, ahead of conntrack. nft_compat_chain_validate_dependency() already enforces this kind of correspondence for "nat" by requiring the chain type to actually be NAT, but did nothing for "raw": a rule wrapping the CT target could be loaded into any hook and any priority via nft_compat, including after the real conntrack hook has already run.
The CT target attaches a conntrack template to the skb when none is set yet.
Require that a "raw" table dependency actually matches what xtables enforces via the implict/builtin table dependency.
--- net/netfilter/nft_compat.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
net/netfilter/nft_compat.c +15 -0
@@ -14,6 +14,7 @@#include <linux/netfilter/nf_tables.h> #include <linux/netfilter/nf_tables_compat.h> #include <linux/netfilter/x_tables.h> +#include <linux/netfilter_ipv4.h> #include <linux/netfilter_ipv4/ip_tables.h> #include <linux/netfilter_ipv6/ip6_tables.h> #include <linux/netfilter_bridge/ebtables.h>
@@ -45,6 +46,20 @@ static int nft_compat_chain_validate_dependency(const struct nft_ctx *ctx, type =NFT_CHAIN_T_NAT ;if (basechain->type->type != type)return -EINVAL ; + }else if (strcmp (tablename,"raw" ) ==0 ) { +/* iptables-nft emulates the legacy raw table, which only +* ever has prerouting/output chains at this exact priority. +*/ +if (ctx->family !=NFPROTO_IPV4 && + ctx->family !=NFPROTO_IPV6 ) +return -EINVAL ; + +if (basechain->ops.hooknum !=NF_INET_PRE_ROUTING && + basechain->ops.hooknum !=NF_INET_LOCAL_OUT ) +return -EINVAL ; + +if (basechain->ops.priority !=NF_IP_PRI_RAW ) +return -EINVAL ; }return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2121/2651 bpf: Dont take a program with a target program for an iterator
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Starovoitov <[email protected]>
[ Upstream commit b83bacf2161d0f8583e3f1e9c90402638992ad82 ]
bpf_iter_prog_supported() goes by the name of the attach function. Commit 7cc639dc45c5 ("bpf: Don't take an extension for an iterator program") keeps out extensions, for which that is the name of a function of another program. A tracing program with BPF_TRACE_ITER that is loaded with attach_prog_fd gets there as well: unlike for BPF_TRACE_RAW_TP, bpf_check_attach_target() does not mind the target program.
If the function is called like that of an iterator target, bpf_iter_bpf_map for example, its id in the BTF of the program is cached as the id of the target, even if the load fails later. Programs of that target which are loaded already cannot be attached any more. And the program itself can be attached as an iterator of that target, with a context that the verifier has taken from the prototype of that function:
BUG: KASAN: stack-out-of-bounds in bpf_prog_66d4234e2e50f5b6_ts26_forged+0x12a/0x20b Read of size 8 at addr ffffc90000d9fc48 by task ts26/104
Refuse every program that has a target program. That covers extensions.
--- kernel/bpf/bpf_iter.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/bpf/bpf_iter.c +3 -3
@@ -352,10 +352,10 @@ int bpf_iter_prog_supported(struct bpf_prog *prog)int prefix_len =strlen (prefix);/* -* The attach function of an extension is a subprogram of the iterator -* program that it extends, whatever its name is. +* The attach function of a program that has a target program is a +* function of that program, whatever its name is. */ -if (prog->type ==BPF_PROG_TYPE_EXT ) +if (prog->aux->dst_prog)return -EINVAL ;if (strncmp (attach_fname, prefix, prefix_len))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2122/2651 bpf: Dont let an extension reach further into the context than its target
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Starovoitov <[email protected]>
[ Upstream commit fcbfa99aa657627528b75e7dc1023bcb0b84e558 ]
How large the context of a raw tracepoint, tracepoint or syscall program is depends on what the program is attached to, or is run with. bpf_probe_register(), perf_event_set_bpf_prog() and the test runs compare that with max_ctx_offset of the program.
An extension of the program, or of one of its global functions, gets the same context. How far it reaches is noted in its own max_ctx_offset, which nobody looks at. On a tracepoint with one argument it reads the stack behind the arguments, in a test run the memory behind the context, or from NULL if there is none:
BUG: KASAN: stack-out-of-bounds in bpf_prog_954b5d2051843629_ts28_ext_far+0x7e/0x113 Read of size 8 at addr ffffc90000def7b8 by task ts28/104 BUG: KASAN: slab-out-of-bounds in bpf_prog_954b5d2051843629_ts28_ext_far+0x7e/0x113 Read of size 8 at addr ffff88810712c3e8 by task ts28/104
Refuse to attach an extension that reaches further than the program which it extends. A program that leaves the context to its extensions has to touch as much of it as they do.
--- kernel/bpf/syscall.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
kernel/bpf/syscall.c +13 -0
@@ -3831,6 +3831,19 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog, err = -EINVAL ; goto out_unlock; } +/* +* The size of these contexts depends on what the program is attached +* to, or run with. That is compared with max_ctx_offset of the program, +* and nobody looks at the one of its extensions. +*/ +if (prog->type ==BPF_PROG_TYPE_EXT && + (tgt_prog->type ==BPF_PROG_TYPE_RAW_TRACEPOINT || + tgt_prog->type ==BPF_PROG_TYPE_TRACEPOINT || + tgt_prog->type ==BPF_PROG_TYPE_SYSCALL ) && + prog->aux->max_ctx_offset > tgt_prog->aux->max_ctx_offset) { + err = -EINVAL ; + goto out_unlock; + } err =bpf_link_prime (&link->link.link, &link_primer);if (err)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2123/2651 bpf: Keep values of a dead owner for sleepable programs
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit f693030a187b56a3946b36521bb90d785f906669 ]
bpf_local_storage_destroy() frees the elements of an owner behind a plain RCU grace period, on the ground that no program can refer to an owner that goes away. But the pointer that bpf_task_storage_get() and its like return stays valid for the verifier after the program has released the owner, or has left the bpf_rcu_read_lock() section it had the owner from. A sleepable program is in no RCU read side critical section, so it can write to the value after the owner has died and the element was freed:
BUG: KASAN: slab-use-after-free in _copy_from_user+0x42/0xa0 Write of size 8 at addr ffff8880074404a8 by task lsuaf/55
Free the element behind an RCU Tasks Trace grace period if sleepable code may use the map. A program that a map is bound to was loaded, and counted in map->sleepable_refcnt, before it got a value from the live owner, and stays counted until a grace period behind its last run.
A program can also get at a storage map by a lookup in an outer map. Then only the outer map is counted, its programs can come after the inner map was put into it, and can hold on to the inner map after it was taken out. So note in a map that it has been an inner map, and treat it like one with sleepable users from then on.
The same goes for what the special fields of the value hold. The page of a uptr has to stay pinned, and a kptr which the program stores after the owner has died has to be released. Leave the fields, and the smap that it takes to free them, to bpf_selem_free_trace_rcu(), as bpf_selem_unlink() does. bpf_local_storage_map_free() waits for that callback, and leaves smap alone if it comes across such an element.
Elements of such maps now wait for sleepable programs that are running when their owner dies. Other maps are freed as before.
--- include/linux/bpf.h | 1 + kernel/bpf/bpf_local_storage.c | 31 +++++++++++++++++++++++++------ kernel/bpf/map_in_map.c | 7 +++++-- 3 files changed, 31 insertions(+), 8 deletions(-)
include/linux/bpf.h +1 -0
@@ -337,6 +337,7 @@ struct bpf_map {bool frozen;/* write-once; write-protected by freeze_mutex */ bool free_after_mult_rcu_gp;bool free_after_rcu_gp; +bool was_inner_map;atomic64_t sleepable_refcnt;s64 __percpu *elem_count;u64 cookie;/* write-once */
kernel/bpf/bpf_local_storage.c +25 -6
@@ -350,7 +350,8 @@ int bpf_selem_unlink(struct bpf_local_storage_elem *selem)static void bpf_selem_unlink_nofail (struct bpf_local_storage_elem *selem,struct bpf_local_storage_map_bucket *b) { -bool in_map_free = !!b, free_storage = false; +bool in_map_free = !!b, free_storage = false, sleepable_users = false; +bool keep_fields = false;struct bpf_local_storage *local_storage;struct bpf_local_storage_map *smap;unsigned long flags;
@@ -360,17 +361,26 @@ static void bpf_selem_unlink_nofail(struct bpf_local_storage_elem *selem, smap =rcu_dereference_check (SDATA (selem)->smap,bpf_rcu_lock_held ());if (smap) { +/* A map that is freed, or NULL here, has no program left. */ + sleepable_users = !in_map_free && + (atomic64_read (&smap->map.sleepable_refcnt) || +READ_ONCE (smap->map.was_inner_map)); b = b ? :select_bucket (smap, local_storage); err =raw_res_spin_lock_irqsave (&b->lock, flags);if (!err) {/* * Call bpf_obj_free_fields() under b->lock to make sure it is done * exactly once for an selem. Safe to free special fields immediately -* as no BPF program should be referencing the selem. +* as no BPF program should be referencing the selem, unless it +* is sleepable: see below. */ if (likely (selem_linked_to_map (selem))) {hlist_del_init_rcu (&selem->map_node); -bpf_obj_free_fields (smap->map.record,SDATA (selem)->data); +if (sleepable_users) + keep_fields = true; +else +bpf_obj_free_fields (smap->map.record, +SDATA (selem)->data); unlink++; }raw_res_spin_unlock_irqrestore (&b->lock, flags);
@@ -385,7 +395,15 @@ static void bpf_selem_unlink_nofail(struct bpf_local_storage_elem *selem,* with selem1 as raw_res_spin_lock_irqsave() returns -ETIMEDOUT. */ WARN_ON_ONCE (err && in_map_free); -if (!err || in_map_free) +/* +* A sleepable program can still use, and fill, the fields of a value +* that it got before it let go of the owner. As for bpf_selem_unlink(), +* bpf_selem_free_trace_rcu() frees them, and takes smap for that: +* map_free() waits for this RCU read side critical section and then +* for the callback. It must not take smap away from an selem that +* destroy() has unlinked from the map. +*/ +if (in_map_free ? err || unlink : !err && !keep_fields)RCU_INIT_POINTER (SDATA (selem)->smap,NULL ); }
@@ -432,11 +450,12 @@ static void bpf_selem_unlink_nofail(struct bpf_local_storage_elem *selem,* * The owner that map_free() takes an selem from is alive: sleepable code, which * is in no RCU read side critical section, may be walking its list for another -* map. +* map. And it can still use a value that it got before it let go of an owner +* that destroy() is called for. */ if (unlink ==2 ||atomic_cmpxchg (&selem->state,SELEM_UNLINKED ,SELEM_TOFREE ) ==SELEM_UNLINKED ) -bpf_selem_free (selem, !in_map_free); +bpf_selem_free (selem, !in_map_free && !sleepable_users);if (free_storage)bpf_local_storage_free (local_storage, !in_map_free);
kernel/bpf/map_in_map.c +5 -2
@@ -106,10 +106,13 @@ void *bpf_map_fd_get_ptr(struct bpf_map *map,return ERR_PTR (-ENOTSUPP ); inner_map_meta = map->inner_map_meta; -if (inner_map_meta->ops->map_meta_equal (inner_map_meta, inner_map)) +if (inner_map_meta->ops->map_meta_equal (inner_map_meta, inner_map)) {bpf_map_inc (inner_map); -else +/* Its users are those of the outer maps from now on */ +WRITE_ONCE (inner_map->was_inner_map, true); + }else { inner_map =ERR_PTR (-EINVAL ); + }return inner_map; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2124/2651 bpf: Keep the symbols of a program until it has ended
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 4eaf4d71b91a983489227336adcab33d8eae58a5 ]
When the last reference to a program goes, __bpf_prog_put_noref() takes its symbols out of the kallsyms tree and frees its line info at once, and waits for the grace periods only with the rest. But the program may still be running: the link or the array it was called from is gone, the call is not over.
search_bpf_extables() finds the exception table of a program by its symbol. A load that faults, and that the table is there to fix up, is fatal from then on:
Oops: general protection fault, probably for non-canonical address 0xdead0000000006f8: 0000 [#1] SMP NOPTI RIP: 0010:0xffffffffc06008f6
It takes a program that is detached and closed on one CPU while it runs on another. Unwinders and bpf_prog_find_from_stack() do not know the program any more either, and the stack dump of a BPF stream reads the freed line info.
Free the line info behind the grace periods the program needs, as it is done with the BTF that its text comes from. Remove the symbols in bpf_prog_free_deferred(), which runs behind them as well. The symbols are looked up under rcu_read_lock(), so the images and the program itself are freed one more grace period later. All that the program refers to is released when it was before.
--- include/linux/bpf.h | 1 + kernel/bpf/core.c | 50 +++++++++++++++++++++++++++++++------------- kernel/bpf/syscall.c | 5 ++--- 3 files changed, 38 insertions(+), 18 deletions(-)
include/linux/bpf.h +1 -0
@@ -1902,6 +1902,7 @@ struct bpf_prog_aux {union {struct work_struct work;struct rcu_head rcu; +struct rcu_work rwork; };struct bpf_stream stream[2 ];struct mutex st_ops_assoc_mutex;
kernel/bpf/core.c +35 -15
67 lines not on this page · raw message
kernel/bpf/syscall.c +2 -3
@@ -2449,6 +2449,8 @@ static void __bpf_prog_put_rcu(struct rcu_head *rcu) struct bpf_prog_aux *aux = container_of(rcu, struct bpf_prog_aux, rcu);btf_put (aux->btf); +kvfree (aux->jited_linfo); +kvfree (aux->linfo);kvfree (aux->func_info);kfree (aux->func_info_aux);free_uid (aux->user);
@@ -2473,10 +2475,7 @@ static void __bpf_prog_put_rcu_tasks(struct rcu_head *rcu)static void __bpf_prog_put_noref (struct bpf_prog *prog,bool deferred) { -bpf_prog_kallsyms_del_all (prog);module_put (prog->aux->mod); -kvfree (prog->aux->jited_linfo); -kvfree (prog->aux->linfo);kfree (prog->aux->kfunc_tab);kfree (prog->aux->ctx_arg_info);if (prog->aux->attach_btf)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2125/2651 bpf: Use the socket of a sk_lookup test run under RCU
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 6aff0129f327b159c86a54e6bea64a027630ff6b ]
bpf_sk_lookup_assign() accepts only sockets which are freed by RCU, and takes no reference. bpf_prog_test_run_sk_lookup() looks at sk_reuseport of the selected socket and generates its cookie, which is a write, behind bpf_test_timer_leave(), that is outside of the RCU read side critical section in which the program ran. If the socket is closed in the meantime it may be gone.
Do both before the section ends.
--- net/bpf/test_run.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
net/bpf/test_run.c +9 -10
@@ -1656,20 +1656,19 @@ int bpf_prog_test_run_sk_lookup(struct bpf_prog *prog, const union bpf_attr *kat ctx.selected_sk =NULL ; retval =BPF_PROG_SK_LOOKUP_RUN_ARRAY (progs, ctx, bpf_prog_run); }while (bpf_test_timer_continue (&t,1 , repeat, &ret, &duration)); -bpf_test_timer_leave (&t); - -if (ret <0 ) - goto out; +/* Nothing but RCU keeps the selected socket */ user_ctx->cookie =0 ; -if (ctx.selected_sk) { -if (ctx.selected_sk->sk_reuseport && !ctx.no_reuseport) { +if (!ret && ctx.selected_sk) { +if (ctx.selected_sk->sk_reuseport && !ctx.no_reuseport) ret = -EOPNOTSUPP ; - goto out; - } - - user_ctx->cookie =sock_gen_cookie (ctx.selected_sk); +else + user_ctx->cookie =sock_gen_cookie (ctx.selected_sk); } +bpf_test_timer_leave (&t); + +if (ret <0 ) + goto out; ret =bpf_test_finish (kattr, uattr,NULL ,NULL ,0 ,0 , retval, duration);if (!ret)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2126/2651 bpf, cpumap: Hold the device of frames in the queue
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit f99351272933ba2e1221484a5e53b7a5d2c035f0 ]
A frame that is redirected to another CPU waits in the queue of the cpumap entry with a plain pointer to the device it came from, and an skb from generic XDP with skb->dev. Nothing keeps that device. Closing and unregistering it waits for its NAPI and for RCU, but not for the kthread of the entry. If the kthread is late by more than that, since its CPU is busy with something of a higher priority, it builds skbs for a device that has been freed and hands them to the stack:
BUG: KASAN: use-after-free in dev_gro_receive+0x1f51/0x2b30 Read of size 8 at addr ffff88800a7340b0 by task cpumap/1/map:1/54
Take a reference to the device for each entry of the queue. The kthread cannot drop it at the end of the batch, since its GRO node may keep the skb for longer. Let it note the devices and drop the references behind a full GRO flush, which it does whenever the queue is empty, and from now on also when it has noted about 2048 of them.
A device whose frames are stuck in a queue is now unregistered only when the kthread has got to them. RTNL is not held meanwhile, but if the device goes with its network namespace, the cleanup of all namespaces waits.
--- kernel/bpf/cpumap.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-)
kernel/bpf/cpumap.c +28 -7
@@ -45,6 +45,7 @@*/ #define CPU_MAP_BULK_SIZE 8/* 8 == one cacheline on 64-bit archs */ +#define CPU_MAP_HELD_DEVS 2048struct bpf_cpu_map_entry ;struct bpf_cpu_map ;
@@ -74,6 +75,13 @@ struct bpf_cpu_map_entry {struct completion kthread_running;struct rcu_work free_work; + +/* +* Every frame and skb in the queue holds a reference to its device. +* The kthread keeps it until nothing is left in GRO. +*/ +struct net_device *held[CPU_MAP_HELD_DEVS ]; +u32 nr_held; };struct bpf_cpu_map {
@@ -129,9 +137,11 @@ static void __cpu_map_ring_cleanup(struct ptr_ring *ring)WARN_ON_ONCE (1 );if (unlikely (__ptr_test_bit (0 , &ptr))) {__ptr_clear_bit (0 , &ptr); +dev_put (((struct sk_buff *)ptr)->dev);kfree_skb (ptr);continue ; } +dev_put (((struct xdp_frame *)ptr)->dev_rx);xdp_return_frame (ptr); } }
@@ -311,7 +321,7 @@ static int cpu_map_kthread_run(void *data)void *frames[CPUMAP_BATCH ];void *skbs[CPUMAP_BATCH ];u32 i, n, m; -bool empty; +bool empty, full;/* Release CPU reschedule checks */ if (__ptr_ring_empty (rcpu->queue)) {
@@ -344,10 +354,12 @@ static int cpu_map_kthread_run(void *data)struct sk_buff *skb = f;__ptr_clear_bit (0 , &skb); + rcpu->held[rcpu->nr_held++] = skb->dev; skbs[ret.skb_n++] = skb;continue ; } + rcpu->held[rcpu->nr_held++] = ((struct xdp_frame *)f)->dev_rx; frames[ret.xdp_n++] = f; page =virt_to_page (f);
@@ -398,10 +410,13 @@ static int cpu_map_kthread_run(void *data)/* Flush either every 64 packets or in case of empty ring */ packets += n; empty =__ptr_ring_empty (rcpu->queue); -if (packets >=NAPI_POLL_WEIGHT || empty) { -cpu_map_gro_flush (rcpu, empty); + full = empty || rcpu->nr_held >CPU_MAP_HELD_DEVS -CPUMAP_BATCH ; +if (packets >=NAPI_POLL_WEIGHT || full) { +cpu_map_gro_flush (rcpu, full); packets =0 ; } +while (full && rcpu->nr_held) +dev_put (rcpu->held[--rcpu->nr_held]);local_bh_enable ();/* resched point, may call do_softirq() */ }
@@ -738,12 +753,14 @@ static void bq_flush_to_queue(struct xdp_bulk_queue *bq)for (i =0 ; i < bq->count; i++) {struct xdp_frame *xdpf = bq->q[i]; -int err; - err =__ptr_ring_produce (q, xdpf); -if (err) { +if (__ptr_ring_full (q)) { drops++;xdp_return_frame_rx_napi (xdpf); + }else { +/* The device cannot go before the flush, from now on it can */ +dev_hold (xdpf->dev_rx); +__ptr_ring_produce (q, xdpf); } processed++; }
@@ -807,11 +824,15 @@ int cpu_map_generic_redirect(struct bpf_cpu_map_entry *rcpu,__skb_pull (skb, skb->mac_len);skb_set_redirected (skb, false); +dev_hold (skb->dev);__ptr_set_bit (0 , &skb); ret =ptr_ring_produce (rcpu->queue, skb); -if (ret <0 ) +if (ret <0 ) { +__ptr_clear_bit (0 , &skb); +dev_put (skb->dev); goto trace; + }wake_up_process (rcpu->kthread); trace:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2127/2651 bpf: Let bpf_dynptr_write() mark a global function
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 589998616e0f9190ba6f6644a19532c5b2ba66d0 ]
The caller of a global function loses its packet pointers if the function may change packet data. That is found out by a scan for calls of the helpers which bpf_helper_changes_pkt_data() lists.
bpf_dynptr_write() is not on the list, because it depends on the type of the dynptr: check_helper_call() looks at it. The scan cannot do that, and so a global function which makes a dynptr from the skb, or gets one as an argument, and writes through it counts as harmless. The write can reallocate the head of the skb, and the caller goes on with pointers into the old one, which has been freed.
Let every call of bpf_dynptr_write() mark the function, as a tail call does. The same mark decides whether a program may replace a function.
--- kernel/bpf/cfg.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/bpf/cfg.c +3 -1
@@ -529,7 +529,9 @@ static int visit_insn(int t, struct bpf_verifier_env *env)*/ if (ret ==0 && fp->might_sleep)mark_subprog_might_sleep (env, t); -if (bpf_helper_changes_pkt_data (insn->imm)) +/* nobody knows yet whether the dynptr is that of an skb */ +if (bpf_helper_changes_pkt_data (insn->imm) || + insn->imm == BPF_FUNC_dynptr_write)mark_subprog_changes_pkt_data (env, t);if (insn->imm == BPF_FUNC_tail_call) { ret =visit_abnormal_return_insn (env, t);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2128/2651 bpf: Dont take a dynptr argument for a local dynptr
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit b7f97db88948aa511bcd989978f181e1367e0e8b ]
A global function is verified on its own. A dynptr which it gets as an argument is assumed to be of type BPF_DYNPTR_TYPE_LOCAL, but the callers may pass one of any type, that of an skb for example.
The type decides whether a write through the dynptr invalidates packet pointers, and whether a slice of it is invalidated together with them. Inside of the function neither happens. It can take a packet pointer from its context argument, or a slice from the dynptr, write through the dynptr and go on using the pointer, although the write may have reallocated the head of the skb.
Assume the type of an skb dynptr instead. Nothing becomes forbidden for the dynptr itself, and a clone inherits the caution. The dynptr which the callback of bpf_user_ringbuf_drain() gets is known to be local, and stays so.
--- kernel/bpf/verifier.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
kernel/bpf/verifier.c +6 -2
@@ -19734,8 +19734,12 @@ static int do_check_common(struct bpf_verifier_env *env, int subprog, reg->type =SCALAR_VALUE ;mark_reg_unknown (env, regs, i); }else if (arg->arg_type ==ARG_PTR_TO_DYNPTR ) { -/* assume unspecial LOCAL dynptr type */ -__mark_dynptr_reg (reg,BPF_DYNPTR_TYPE_LOCAL , true, ++env->id_gen,0 ); +/* +* The callers may hand in a dynptr of any type. +* Take it for that of an skb, so that a write +* through it and its slices are treated with care. +*/ +__mark_dynptr_reg (reg,BPF_DYNPTR_TYPE_SKB , true, ++env->id_gen,0 ); }else if (base_type (arg->arg_type) ==ARG_PTR_TO_MEM ) { reg->type =PTR_TO_MEM ; reg->type |= arg->arg_type &
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2129/2651 bpf: Follow the head if an skb is written from a slice
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 1c19f2b3b2f3b55c8017092257634cb8229b7d97 ]
The source of bpf_dynptr_write() may be a slice of the skb which is written to, that is a pointer into its head. bpf_dynptr_copy() does it by itself for a copy inside of one skb, if the source is linear and the destination is not.
__bpf_skb_store_bytes() and __bpf_skb_meta_store_bytes() make the skb writable first. If that reallocates the head, the source points to the old one, and freed memory is copied into the packet.
The offsets in the head do not change when it is reallocated here. Move the source along with the head.
--- net/core/filter.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
net/core/filter.c +20 -2
@@ -1715,6 +1715,24 @@ static inline void bpf_pull_mac_rcsum(struct sk_buff *skb)skb_postpull_rcsum (skb,skb_mac_header (skb), skb->mac_len); } +/* +* The source of a write through a dynptr may be a slice of the same skb. +* Making the skb writable can move its head: follow the move. +*/ +static int bpf_try_make_writable_from (struct sk_buff *skb,u32 write_len, +const void **from) +{ +const void *head = skb->head; +bool in_head = *from >= head && + *from < (const void *)skb_end_pointer (skb); +int err; + + err =bpf_try_make_writable (skb, write_len); +if (!err && in_head) + *from = skb->head + (*from - head); +return err; +} + BPF_CALL_5(bpf_skb_store_bytes, struct sk_buff *, skb, u32, offset, const void *, from, u32, len, u64, flags) {
@@ -1724,7 +1742,7 @@ BPF_CALL_5(bpf_skb_store_bytes, struct sk_buff *, skb, u32, offset,return -EINVAL ;if (unlikely (offset >INT_MAX ))return -EFAULT ; -if (unlikely (bpf_try_make_writable (skb, offset + len))) +if (unlikely (bpf_try_make_writable_from (skb, offset + len, &from)))return -EFAULT ; ptr = skb->data + offset;
@@ -12422,7 +12440,7 @@ int __bpf_skb_meta_store_bytes(struct sk_buff *skb, u32 offset, {if (unlikely (flags))return -EINVAL ; -if (unlikely (bpf_try_make_writable (skb,0 ))) +if (unlikely (bpf_try_make_writable_from (skb,0 , &from)))return -EFAULT ;memmove (bpf_skb_meta_pointer (skb, offset), from, len);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2130/2651 bpf: Use memmove() to store bytes in an skb
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 1db084f42884c5af881fedf3df4777fe2095b20b ]
Through bpf_dynptr_write() and bpf_dynptr_copy() the source of bpf_skb_store_bytes() can be a slice of the same skb which overlaps the destination. memcpy() then reads bytes which it has overwritten already. On x86 with FSRM it repeats the first bytes of the source instead of copying it. Local, ringbuf and skb metadata dynptrs are written with memmove() for that reason.
--- net/core/filter.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/core/filter.c +2 -1
@@ -1749,7 +1749,8 @@ BPF_CALL_5(bpf_skb_store_bytes, struct sk_buff *, skb, u32, offset,if (flags &BPF_F_RECOMPUTE_CSUM )__skb_postpull_rcsum (skb, ptr, len, offset); -memcpy (ptr, from, len); +/* through a dynptr the source may be an overlapping slice of the skb */ +memmove (ptr, from, len);if (flags &BPF_F_RECOMPUTE_CSUM )__skb_postpush_rcsum (skb, ptr, len, offset);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2131/2651 bpf: Use memmove() to store bytes in an xdp_buff
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Starovoitov <[email protected]>
[ Upstream commit ab08863c58b1a96ff8378e373cb3d277cbe65b68 ]
bpf_dynptr_write() to the dynptr of an xdp_buff ends in bpf_xdp_store_bytes(). The source can be a slice of the same xdp_buff which overlaps the destination, and the helper itself takes such a slice as well. memcpy() then reads bytes which it has overwritten already. On x86 with FSRM
p = bpf_dynptr_slice_rdwr(&ptr, 0, NULL, 64); bpf_dynptr_write(&ptr, 8, p, 64, 0);
repeats the first 8 bytes of the packet instead of moving 64.
A write that crosses from the linear part into a fragment is copied piece by piece, where the first piece can overwrite what the second one has yet to read. That is not dealt with here.
--- net/core/filter.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/core/filter.c +2 -1
@@ -4337,7 +4337,8 @@ BPF_CALL_4(bpf_xdp_store_bytes, struct xdp_buff *, xdp, u32, offset,if (!ptr)bpf_xdp_copy_buf (xdp, offset, buf, len, true);else -memcpy (ptr, buf, len); +/* through a dynptr the source may be an overlapping slice */ +memmove (ptr, buf, len);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2132/2651 usb: gadget: dummy_hcd: fix SuperSpeed ep0 maxpacket
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Igor Skalkin <[email protected]>
[ Upstream commit e68f245bcb1f863aeb8eab617bd06878c078029a ]
For USB_SPEED_SUPER, dummy_hcd sets ep0 maxpacket to 9. That is incorrect for SuperSpeed ep0 and breaks short packet handling in control transfer tests.
Set ep0 maxpacket to 512 for SuperSpeed.
--- drivers/usb/gadget/udc/dummy_hcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/udc/dummy_hcd.c +1 -1
@@ -918,7 +918,7 @@ static int dummy_set_selfpowered(struct usb_gadget *_gadget, int value)static void dummy_udc_update_ep0 (struct dummy *dum) {if (dum->gadget.speed ==USB_SPEED_SUPER ) - dum->ep[0 ].ep.maxpacket =9 ; + dum->ep[0 ].ep.maxpacket =512 ;else dum->ep[0 ].ep.maxpacket =64 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2133/2651 usb: gadget: dummy_hcd: prevent unbind via sysfs
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aleksandr Nogikh <[email protected]>
[ Upstream commit bdf12cde30830d46a8ef1ba93986356f1164b4f1 ]
The dummy_hcd (Host Controller) and dummy_udc (Device Controller) are implemented as two separate platform drivers that share the same underlying state (struct dummy). They are designed to be created and destroyed together during the module's init and exit phases.
If userspace forces the dummy_hcd driver to unbind from the device via sysfs, dummy_hcd_remove() cleans up the host controllers and sets the pointers to NULL (dum->hs_hcd = NULL). However, the dummy_udc driver is still bound to its device, meaning the USB gadget is still registered with the udc-core subsystem.
If a new gadget driver is subsequently registered, it binds to the still-registered dummy_udc gadget, invoking the dummy_udc_start() callback. This callback attempts to retrieve the HCD state using gadget_to_dummy_hcd(), which returns NULL because of the unbind. This results in a null-pointer dereference:
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000000: 0000 [#1] SMP KASAN NOPTI KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007] ... RIP: 0010:dummy_udc_start+0xd0/0x1f0 drivers/usb/gadget/udc/dummy_hcd.c:1022 ... Call Trace: <TASK> usb_gadget_udc_start_locked drivers/usb/gadget/udc/core.c:1237 [inline] gadget_bind_driver+0x3a8/0x9e0 drivers/usb/gadget/udc/core.c:1667 call_driver_probe drivers/base/dd.c:-1 [inline] really_probe+0x254/0xae0 drivers/base/dd.c:706 __driver_probe_device+0x1e8/0x360 drivers/base/dd.c:868 driver_probe_device+0x4f/0x240 drivers/base/dd.c:898 __driver_attach+0x339/0x600 drivers/base/dd.c:1292 bus_for_each_dev+0x23b/0x2c0 drivers/base/bus.c:383 bus_add_driver+0x345/0x670 drivers/base/bus.c:763 driver_register+0x23a/0x320 drivers/base/driver.c:174 usb_gadget_register_driver_owner+0xf9/0x270 drivers/usb/gadget/udc/core.c:1752 raw_ioctl_run drivers/usb/gadget/legacy/raw_gadget.c:596 [inline] raw_ioctl+0x1541/0x41c0 drivers/usb/gadget/legacy/raw_gadget.c:1307
Adding NULL checks to the UDC callbacks is not a robust solution because there is no synchronization between dummy_hcd_remove() and the UDC callbacks, which would result in a use-after-free race condition if the HCD were unbound concurrently.
Fix this by setting .suppress_bind_attrs = true in both driver definitions. This prevents userspace from unbinding these drivers dynamically, ensuring their lifecycles remain strictly synchronized with the module's load/unload process.
--- drivers/usb/gadget/udc/dummy_hcd.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/gadget/udc/dummy_hcd.c +2 -0
@@ -1184,6 +1184,7 @@ static struct platform_driver dummy_udc_driver = { .resume = dummy_udc_resume, .driver = { .name = gadget_name, + .suppress_bind_attrs = true, }, };
@@ -2806,6 +2807,7 @@ static struct platform_driver dummy_hcd_driver = { .resume = dummy_hcd_resume, .driver = { .name = driver_name, + .suppress_bind_attrs = true, }, };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2134/2651 power: supply: gpio-charger: Report discharging without input power
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Igor Velkov <[email protected]>
[ Upstream commit f0f400459bf6a037e70768de623fff3f8920b8bb ]
The status property follows only the charge-status GPIO. Without input power a charger such as the BQ24133 releases its open-drain STAT pin, and depending on the board the GPIO then reads as charging.
On Kobol Helios64 the board runs from its battery after a mains loss, and the charger reports online 0 with status "Charging".
Report "Discharging" whenever the online GPIO is present and inactive.
--- drivers/power/supply/gpio-charger.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/power/supply/gpio-charger.c +4 -1
@@ -101,7 +101,10 @@ static int gpio_charger_get_property(struct power_supply *psy, val->intval =gpiod_get_value_cansleep (gpio_charger->gpiod);break ;case POWER_SUPPLY_PROP_STATUS : -if (gpiod_get_value_cansleep (gpio_charger->charge_status)) +/* Without input power the battery discharges, whatever the status pin says */ +if (gpio_charger->gpiod && !gpiod_get_value_cansleep (gpio_charger->gpiod)) + val->intval =POWER_SUPPLY_STATUS_DISCHARGING ; +else if (gpiod_get_value_cansleep (gpio_charger->charge_status)) val->intval =POWER_SUPPLY_STATUS_CHARGING ;else val->intval =POWER_SUPPLY_STATUS_NOT_CHARGING ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2135/2651 RDMA/core: Preserve the selected source GID on failed AH modification
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leon Romanovsky <[email protected]>
[ Upstream commit d01ee4c84193196b6e4be4caf1ff8fdcc441ed96 ]
When an address-handle modification fails, the core replaces its source-GID reference. The old address then loses the reference which keeps its source entry alive.
--- drivers/infiniband/core/verbs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/infiniband/core/verbs.c +2 -1
@@ -1011,7 +1011,8 @@ int rdma_modify_ah(struct ib_ah *ah, struct rdma_ah_attr *ah_attr) ah->device->ops.modify_ah(ah, ah_attr) : -EOPNOTSUPP ; - ah->sgid_attr =rdma_update_sgid_attr (ah_attr, ah->sgid_attr); +if (!ret) + ah->sgid_attr =rdma_update_sgid_attr (ah_attr, ah->sgid_attr);rdma_unfill_sgid_attr (ah_attr, old_sgid_attr);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2136/2651 RDMA/core: Free unpublished port statistics after initial-read failure
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leon Romanovsky <[email protected]>
[ Upstream commit d74bdcfa89fa45d3a506cddc37b3bf1b76cea0ce ]
An initial port counter read can fail after allocating its statistics buffer and wrapper. Free these both allocations.
--- drivers/infiniband/core/sysfs.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/infiniband/core/sysfs.c +7 -2
@@ -996,8 +996,8 @@ static int setup_hw_port_stats(struct ib_port *port, data->stats->num_counters);if (ret != data->stats->num_counters) {if (WARN_ON (ret >=0 )) -return -EINVAL ; -return ret; + ret = -EINVAL ; + goto err_free_data; } data->stats->timestamp = jiffies;
@@ -1031,6 +1031,11 @@ static int setup_hw_port_stats(struct ib_port *port, port->hw_stats_data = data;return 0 ; + +err_free_data: +rdma_free_hw_stats_struct (data->stats); +kfree (data); +return ret; } struct rdma_hw_stats *ib_get_hw_stats_port(struct ib_device *ibdev,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2137/2651 RDMA/core: Reject LAG selection when source MAC lookup fails
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leon Romanovsky <[email protected]>
[ Upstream commit fdfd099222d9de9e2f1b8d69e94494c5489272cc ]
GID deletion can clear the source device association after LAG lookup retains the bonding master. Ignoring the resulting L2 lookup failure copies uninitialized source MAC bytes into the synthetic hash packet.
Read the source MAC before allocating the packet and propagate lookup errors to the caller, so failed lookups cannot influence slave selection.
--- drivers/infiniband/core/lag.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/infiniband/core/lag.c +8 -4
@@ -19,6 +19,11 @@ static struct sk_buff *rdma_build_skb(struct net_device *netdev,u8 smac[ETH_ALEN ];bool is_ipv4;int hdr_len; +int ret; + + ret =rdma_read_gid_l2_fields (ah_attr->grh.sgid_attr,NULL , smac); +if (ret) +return ERR_PTR (ret); is_ipv4 =ipv6_addr_v4mapped ((struct in6_addr *)ah_attr->grh.dgid.raw); hdr_len =ETH_HLEN +sizeof (struct udphdr ) +LL_RESERVED_SPACE (netdev);
@@ -26,7 +31,7 @@ static struct sk_buff *rdma_build_skb(struct net_device *netdev, skb =alloc_skb (hdr_len, flags);if (!skb) -return NULL ; +return ERR_PTR (-ENOMEM ); skb->dev = netdev;skb_reserve (skb, hdr_len);
@@ -70,7 +75,6 @@ static struct sk_buff *rdma_build_skb(struct net_device *netdev,skb_reset_mac_header (skb); eth =eth_hdr (skb); skb->protocol = eth->h_proto =htons (is_ipv4 ?ETH_P_IP :ETH_P_IPV6 ); -rdma_read_gid_l2_fields (ah_attr->grh.sgid_attr,NULL , smac);memcpy (eth->h_source, smac,ETH_ALEN );memcpy (eth->h_dest, ah_attr->roce.dmac,ETH_ALEN );
@@ -86,8 +90,8 @@ static struct net_device *rdma_get_xmit_slave_udp(struct ib_device *device,struct sk_buff *skb; skb =rdma_build_skb (master, ah_attr, flags); -if (!skb) -return ERR_PTR (-ENOMEM ); +if (IS_ERR (skb)) +return ERR_CAST (skb);rcu_read_lock (); slave = netdev_get_xmit_slave(master, skb,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2138/2651 RDMA/srp: Avoid reading uninitialized has_port on srp_parse_in() failure
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Serhat Kumral <[email protected]>
[ Upstream commit 4b8f20dc8d25f575e8b8bb5abb09ab803a7e1a3f ]
srp_parse_in() returns -ENOMEM without initializing *has_port if kstrdup() fails. Only check has_port when srp_parse_in() succeeds.
--- drivers/infiniband/ulp/srp/ib_srp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/ulp/srp/ib_srp.c +1 -1
@@ -3499,7 +3499,7 @@ static int srp_parse_options(struct net *net, const char *buf, } ret =srp_parse_in (net, &target->rdma_cm.dst.ss, p, &has_port); -if (!has_port) +if (ret ==0 && !has_port) ret = -EINVAL ;if (ret <0 ) {pr_warn ("bad dest parameter '%s'\n" , p);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2139/2651 ASoC: codecs: sta32x: Fix definition of limiter threshold controls
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
[ Upstream commit e06bf60ee5bffa9eeacff0bf8b03d4572b04f67d ]
The limiter attack and release thresholds are the two 4-bit halves of one register, so their maximum is 15, not 16. With 16 the controls on bits 3:0 also write bit 4, which belongs to the other threshold.
--- sound/soc/codecs/sta32x.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
sound/soc/codecs/sta32x.c +8 -8
@@ -507,21 +507,21 @@ SOC_ENUM("Limiter2 Release Rate (dB/ms)", sta32x_limiter2_release_rate_enum),* two different enum definitions; provide both */ SOC_SINGLE_TLV ("Limiter1 Attack Threshold (AC Mode)" ,STA32X_L1ATRT , STA32X_LxA_SHIFT, -16 ,0 , sta32x_limiter_ac_attack_tlv), +15 ,0 , sta32x_limiter_ac_attack_tlv),SOC_SINGLE_TLV ("Limiter2 Attack Threshold (AC Mode)" ,STA32X_L2ATRT , STA32X_LxA_SHIFT, -16 ,0 , sta32x_limiter_ac_attack_tlv), +15 ,0 , sta32x_limiter_ac_attack_tlv),SOC_SINGLE_TLV ("Limiter1 Release Threshold (AC Mode)" ,STA32X_L1ATRT , STA32X_LxR_SHIFT, -16 ,0 , sta32x_limiter_ac_release_tlv), +15 ,0 , sta32x_limiter_ac_release_tlv),SOC_SINGLE_TLV ("Limiter2 Release Threshold (AC Mode)" ,STA32X_L2ATRT , STA32X_LxR_SHIFT, -16 ,0 , sta32x_limiter_ac_release_tlv), +15 ,0 , sta32x_limiter_ac_release_tlv),SOC_SINGLE_TLV ("Limiter1 Attack Threshold (DRC Mode)" ,STA32X_L1ATRT , STA32X_LxA_SHIFT, -16 ,0 , sta32x_limiter_drc_attack_tlv), +15 ,0 , sta32x_limiter_drc_attack_tlv),SOC_SINGLE_TLV ("Limiter2 Attack Threshold (DRC Mode)" ,STA32X_L2ATRT , STA32X_LxA_SHIFT, -16 ,0 , sta32x_limiter_drc_attack_tlv), +15 ,0 , sta32x_limiter_drc_attack_tlv),SOC_SINGLE_TLV ("Limiter1 Release Threshold (DRC Mode)" ,STA32X_L1ATRT , STA32X_LxR_SHIFT, -16 ,0 , sta32x_limiter_drc_release_tlv), +15 ,0 , sta32x_limiter_drc_release_tlv),SOC_SINGLE_TLV ("Limiter2 Release Threshold (DRC Mode)" ,STA32X_L2ATRT , STA32X_LxR_SHIFT, -16 ,0 , sta32x_limiter_drc_release_tlv), +15 ,0 , sta32x_limiter_drc_release_tlv),BIQUAD_COEFS ("Ch1 - Biquad 1" ,0 ), BIQUAD_COEFS("Ch1 - Biquad 2", 5),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2140/2651 ASoC: codecs: sta350: Fix definition of limiter threshold controls
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
[ Upstream commit 77623752c156763d7a80414afe5b769ba4532bd3 ]
The limiter attack and release thresholds are the two 4-bit halves of one register, so their maximum is 15, not 16. With 16 the controls on bits 3:0 also write bit 4, which belongs to the other threshold.
--- sound/soc/codecs/sta350.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
sound/soc/codecs/sta350.c +8 -8
@@ -502,28 +502,28 @@ SOC_ENUM("Limiter2 Release Rate (dB/ms)", sta350_limiter2_release_rate_enum),*/ SOC_SINGLE_TLV ("Limiter1 Attack Threshold (AC Mode)" ,STA350_L1ATRT , STA350_LxA_SHIFT, -16 ,0 , sta350_limiter_ac_attack_tlv), +15 ,0 , sta350_limiter_ac_attack_tlv),SOC_SINGLE_TLV ("Limiter2 Attack Threshold (AC Mode)" ,STA350_L2ATRT , STA350_LxA_SHIFT, -16 ,0 , sta350_limiter_ac_attack_tlv), +15 ,0 , sta350_limiter_ac_attack_tlv),SOC_SINGLE_TLV ("Limiter1 Release Threshold (AC Mode)" ,STA350_L1ATRT , STA350_LxR_SHIFT, -16 ,0 , sta350_limiter_ac_release_tlv), +15 ,0 , sta350_limiter_ac_release_tlv),SOC_SINGLE_TLV ("Limiter2 Release Threshold (AC Mode)" ,STA350_L2ATRT , STA350_LxR_SHIFT, -16 ,0 , sta350_limiter_ac_release_tlv), +15 ,0 , sta350_limiter_ac_release_tlv),SOC_SINGLE_TLV ("Limiter1 Attack Threshold (DRC Mode)" ,STA350_L1ATRT , STA350_LxA_SHIFT, -16 ,0 , sta350_limiter_drc_attack_tlv), +15 ,0 , sta350_limiter_drc_attack_tlv),SOC_SINGLE_TLV ("Limiter2 Attack Threshold (DRC Mode)" ,STA350_L2ATRT , STA350_LxA_SHIFT, -16 ,0 , sta350_limiter_drc_attack_tlv), +15 ,0 , sta350_limiter_drc_attack_tlv),SOC_SINGLE_TLV ("Limiter1 Release Threshold (DRC Mode)" ,STA350_L1ATRT , STA350_LxR_SHIFT, -16 ,0 , sta350_limiter_drc_release_tlv), +15 ,0 , sta350_limiter_drc_release_tlv),SOC_SINGLE_TLV ("Limiter2 Release Threshold (DRC Mode)" ,STA350_L2ATRT , STA350_LxR_SHIFT, -16 ,0 , sta350_limiter_drc_release_tlv), +15 ,0 , sta350_limiter_drc_release_tlv),BIQUAD_COEFS ("Ch1 - Biquad 1" ,0 ), BIQUAD_COEFS("Ch1 - Biquad 2", 5),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2141/2651 ASoC: tlv320aic32x4: Fix definition of TAS2505 HP Driver Gain Volume control
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
[ Upstream commit f28c09b7e62fb5ead65bdfab93012a86d64b6540 ]
The TAS2505 HP volume is bits 6:0 of page 1 register 22, not of register 16, which holds the HP driver mute (bit 6) and gain (bits 5:0).
--- sound/soc/codecs/tlv320aic32x4.c | 2 +- sound/soc/codecs/tlv320aic32x4.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
sound/soc/codecs/tlv320aic32x4.c +1 -1
@@ -1063,7 +1063,7 @@ static const struct snd_kcontrol_new aic32x4_tas2505_snd_controls[] = {SOC_ENUM ("DAC Playback PowerTune Switch" , l_ptm_enum),SOC_SINGLE_TLV ("HP Driver Gain Volume" , -AIC32X4_HPLGAIN ,0 ,0x74 ,1 , tlv_tas_driver_gain), +TAS2505_HPVOL ,0 ,0x74 ,1 , tlv_tas_driver_gain),SOC_SINGLE ("HP DAC Playback Switch" ,AIC32X4_HPLGAIN ,6 ,1 ,1 ), SOC_SINGLE_TLV("Speaker Driver Playback Volume",
sound/soc/codecs/tlv320aic32x4.h +1 -0
@@ -94,6 +94,7 @@ int aic32x4_register_clocks(struct device *dev, const char *mclk_name);#define AIC32X4_LOLGAIN AIC32X4_REG(1, 18)#define AIC32X4_LORGAIN AIC32X4_REG(1, 19)#define AIC32X4_HEADSTART AIC32X4_REG(1, 20) +#define TAS2505_HPVOL AIC32X4_REG(1, 22)#define TAS2505_SPK AIC32X4_REG(1, 45)#define TAS2505_SPKVOL1 AIC32X4_REG(1, 46)#define TAS2505_SPKVOL2 AIC32X4_REG(1, 48)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2142/2651 RDMA/rxe: Clear pkt->qp before the early drop exits in rxe_rcv()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhiwei Zhang <[email protected]>
[ Upstream commit 7d7214b39b14c9763c14445b139f63369063b65e ]
rxe_rcv() puts pkt->qp at its drop label, but leaves pkt->qp uninitialized on the two paths that take an early goto:
if (unlikely(skb->len < RXE_BTH_BYTES)) goto drop; if (rxe_chk_dgid(rxe, skb) < 0) goto drop; pkt->opcode = bth_opcode(pkt); pkt->psn = bth_psn(pkt); pkt->qp = NULL; <- too late for the gotos above ... drop: if (pkt->qp) rxe_put(pkt->qp);
pkt points into skb->cb, which rxe does not own at this point: the network stack has used that space for its own state. For IPv6, ip6_rcv_core() memsets inet6_skb_parm and then writes
IP6CB(skb)->nhoff = offsetof(struct ipv6hdr, nexthdr);
at offset 14, so the qword at cb + 8, which is where pkt->qp lives, reads back as 0x0006000000000000 for every IPv6 packet.
Any IPv6 datagram to port 4791 whose payload is shorter than the BTH takes the first goto and reaches the drop label with that value, so rxe_put() runs refcount_dec_and_test() on 0x0006000000000150 and the kernel faults, in softirq, on a non-canonical address:
general protection fault, probably for non-canonical address 0x0006000000000150: 0000 [#1] PREEMPT SMP RIP: 0010:__rxe_put+0x.../... Call Trace: <IRQ> rxe_rcv+0x.../... [rdma_rxe] rxe_udp_encap_recv+0x.../... [rdma_rxe] udp_queue_rcv_one_skb ... Kernel panic - not syncing: Fatal exception in interrupt
The fault happens in softirq, so it panics even with panic_on_oops=0, and with panic=0 the machine hangs until it is power cycled. A remote sender only needs to send an empty UDP datagram to port 4791; no RDMA connection, GID or other state is involved and the rxe socket is bound in init_net.
IPv4 is not affected: ip_rcv_core() memsets the whole inet_skb_parm, so the pkt->qp slot is zero there.
Fix by clearing pkt->qp before the first early exit. pkt->qp is only ever assigned a reference-owning value by hdr_check() and rxe_rcv_mcast_pkt(), both of which run after this point, so the put at the drop label stays balanced.
The ordering has been unsafe since the driver was merged: the two early gotos have preceded pkt->qp = NULL in every version since 8700e3e7c485.
Testing done: the driver was built and run on a 6.2 vendor tree that carries this code, where a single 0-byte IPv6 datagram to port 4791 reproduced the panic above (that tree does not pull the UDP header in rxe_udp_encap_recv(), so payloads of 0..3 bytes reach the first goto there, versus 0..11 on mainline). With this change, the same packets are dropped as intended and tracing the drop label shows pkt->qp is 0 on every path that reaches it. Not done: the mainline tree was not built in the environment used to prepare this, and the reproducer is left out of this message on purpose - both are available on request.
--- drivers/infiniband/sw/rxe/rxe_recv.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/infiniband/sw/rxe/rxe_recv.c +8 -1
@@ -320,6 +320,14 @@ void rxe_rcv(struct sk_buff *skb)struct rxe_dev *rxe = pkt->rxe;unsigned int skblen = skb->len -skb_network_offset (skb); +/* +* pkt lives in skb->cb, which the network stack has already used +* for its own state: for IPv6 the qword holding pkt->qp holds +* inet6_skb_parm.nhoff. The drop label puts pkt->qp, so clear +* it before the first early exit. +*/ + pkt->qp =NULL ; +if (unlikely (skb->len <RXE_BTH_BYTES )) goto drop;
@@ -328,7 +336,6 @@ void rxe_rcv(struct sk_buff *skb) pkt->opcode =bth_opcode (pkt); pkt->psn =bth_psn (pkt); - pkt->qp =NULL ; pkt->mask |= rxe_opcode[pkt->opcode].mask;/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2143/2651 RDMA/usnic: Bound buffer size to sizeof(buf) in flowinfo_read()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Serhat Kumral <[email protected]>
[ Upstream commit 9dd8b9a337af844291edcd9139c927d0f7958dbe ]
In flowinfo_read(), 'left' tracks the remaining space in the 512-byte stack buffer 'buf', but it is initialized to 'count'.
Initialize 'left' to sizeof(buf) instead of 'count'.
--- drivers/infiniband/hw/usnic/usnic_debugfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/usnic/usnic_debugfs.c +1 -1
@@ -76,7 +76,7 @@ static ssize_t flowinfo_read(struct file *f, char __user *data, qp_flow = f->private_data; ptr = buf; - left = count; + left =sizeof (buf);if (*ppos >0 )return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2144/2651 locking/atomic: arc, hexagon, openrisc: Define arch_cmpxchg_local()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
[ Upstream commit 8cebaa3be829c88a59957900f8de98fed09daefe ]
Commit ccb88db8dac8 ("bpf: Don't hand out a linked element as extra element") made alloc_htab_elem() take the per-cpu spare element with try_cmpxchg_local(), the first caller of cmpxchg_local() outside of architecture code. It doesn't build on arc, hexagon and openrisc:
include/linux/atomic/atomic-arch-fallback.h:384:27: error: implicit declaration of function 'arch_cmpxchg_local'; did you mean 'raw_cmpxchg_local'? [-Werror=implicit-function-declaration]
raw_cmpxchg_local() maps to arch_cmpxchg_local() unconditionally, but these three architectures don't define it, and unlike nios2 and microblaze they don't get it from asm-generic/cmpxchg.h either.
cmpxchg_local() only has to be atomic with respect to the local CPU, so an architecture's own arch_cmpxchg() can serve for the sizes it supports. arc uses its relaxed LLOCK/SCOND variant when ARC_HAS_LLSC is set and its atomic_ops_lock() variant otherwise, and openrisc uses its LL/SC arch_cmpxchg(), the way arm64, riscv and s390 alias theirs. The hexagon arch_cmpxchg() only handles 32-bit words, so hexagon uses the generic version that disables interrupts, like sh, sparc32 and xtensa do. Linux has no NMIs on hexagon, so that is sufficient there.
--- arch/arc/include/asm/cmpxchg.h | 4 ++++ arch/hexagon/include/asm/cmpxchg.h | 6 ++++++ arch/openrisc/include/asm/cmpxchg.h | 2 ++ 3 files changed, 12 insertions(+)
arch/arc/include/asm/cmpxchg.h +4 -0
@@ -59,6 +59,8 @@ _prev_; \ }) +#define arch_cmpxchg_local arch_cmpxchg_relaxed +#else #define arch_cmpxchg (ptr, old, new) \
@@ -80,6 +82,8 @@ _prev_; \ }) +#define arch_cmpxchg_local arch_cmpxchg +#endif /*
arch/hexagon/include/asm/cmpxchg.h +6 -0
@@ -8,6 +8,8 @@#ifndef _ASM_CMPXCHG_H#define _ASM_CMPXCHG_H +#include <asm-generic/cmpxchg-local.h> +/* * __arch_xchg - atomically exchange a register and a memory location * @x: value to swap
@@ -72,4 +74,8 @@ __arch_xchg(unsigned long x, volatile void *ptr, int size) __oldval; \ }) +#define arch_cmpxchg_local (ptr, o, n) \ + ((__typeof__(*(ptr)))__generic_cmpxchg_local((ptr), \ + (unsigned long)(o), (unsigned long)(n), sizeof(*(ptr)))) +#endif /* _ASM_CMPXCHG_H */
arch/openrisc/include/asm/cmpxchg.h +2 -0
@@ -140,6 +140,8 @@ static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old, sizeof(*(ptr))); \ }) +#define arch_cmpxchg_local arch_cmpxchg +/* * This function doesn't exist, so you'll get a linker error if * something tries to do an invalidly-sized xchg().
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2145/2651 bpf: Zero-extend the index in inlined bpf_get_func_arg()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Woojin Ji <[email protected]>
[ Upstream commit 1c1dda9ba9f3af9cd511a197dcc86de2465d8fe5 ]
bpf_get_func_arg() takes a u32 index, but the inlined expansion compared only the low 32 bits of R2 with the argument count and then shifted the full 64-bit register to compute the context address. R2 is ARG_ANYTHING, so nothing guarantees that its upper bits are zero: an index of 1ULL << 32 passes the bounds check as index zero while the load is performed at ctx + (1ULL << 35).
Shift the index as a 32-bit value. When the 32-bit bounds check passes, the low 32 bits of R2 are below R0, and R0 is at most 255: the trampoline arm masks the argument count with 0xFF and the raw_tp arm uses the BTF argument count minus one, which the verifier caps at MAX_BPF_FUNC_ARGS. The 3-bit shift therefore cannot overflow and it clears the upper bits of the register. Widening the comparison instead would reject indices whose low 32 bits are valid. The check itself is unchanged, so this cannot change which programs are accepted, only the address that is computed.
--- kernel/bpf/fixups.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/fixups.c +1 -1
@@ -2330,7 +2330,7 @@ int bpf_do_misc_fixups(struct bpf_verifier_env *env) cnt =2 ; } insn_buf[cnt++] =BPF_JMP32_REG (BPF_JGE ,BPF_REG_2 ,BPF_REG_0 ,6 ); - insn_buf[cnt++] =BPF_ALU64_IMM (BPF_LSH ,BPF_REG_2 ,3 ); + insn_buf[cnt++] =BPF_ALU32_IMM (BPF_LSH ,BPF_REG_2 ,3 ); insn_buf[cnt++] =BPF_ALU64_REG (BPF_ADD ,BPF_REG_2 ,BPF_REG_1 ); insn_buf[cnt++] =BPF_LDX_MEM (BPF_DW ,BPF_REG_0 ,BPF_REG_2 ,0 ); insn_buf[cnt++] =BPF_STX_MEM (BPF_DW ,BPF_REG_3 ,BPF_REG_0 ,0 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2146/2651 dt-bindings: vendor-prefixes: Add Sensylink
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Troy Mitchell <[email protected]>
[ Upstream commit f4ba4f8cc8e8df45e57c1754955b3a6b9b089a97 ]
Add the vendor prefix for Sensylink Microelectronics.
--- Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++ 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
@@ -1511,6 +1511,8 @@ patternProperties: description: Sensirion AG "^sensortek,.*": description: Sensortek Technology Corporation + "^sensylink,.*": + description: Sensylink Microelectronics Technology Co., Ltd. "^sercomm,.*": description: Sercomm (Suzhou) Corporation "^sff,.*":
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2147/2651 alpha: fix stale user_stack_pointer()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matt Turner <[email protected]>
[ Upstream commit bceba446fa2bc66a905ec0bbf6fd80e98701c1d1 ]
PALcode keeps the user stack pointer in the PCB, not the trap frame, so pt_regs->usp is only valid where entry code stores it: entSys, do_entArith() and do_entIF(). Interrupts, page faults and unaligned traps leave it stale, and ptrace and /proc/<pid>/syscall read it through user_stack_pointer().
A user-mode pt_regs is at the top of its task's stack, so find the thread_info from it and use rdusp() for current or pcb.usp otherwise, as KSTK_ESP() and the regset code already do.
--- arch/alpha/include/asm/ptrace.h | 7 +------ arch/alpha/kernel/ptrace.c | 12 ++++++++++++ 2 files changed, 13 insertions(+), 6 deletions(-)
arch/alpha/include/asm/ptrace.h +1 -6
@@ -24,11 +24,6 @@ static inline unsigned long regs_return_value(struct pt_regs *regs) return regs->r0; } -/* Helpers for working with the user stack pointer */ -static inline unsigned long user_stack_pointer (struct pt_regs *regs) -{ -/* Valid for user-mode regs */ -return regs->usp; -} +unsigned long user_stack_pointer (struct pt_regs *regs);#endif
arch/alpha/kernel/ptrace.c +12 -0
@@ -405,6 +405,18 @@ ptrace_cancel_bpt(struct task_struct * child)return (nsaved !=0 ); } +/* +* PALcode keeps the user stack pointer in the PCB, not the trap frame. +* A user-mode pt_regs sits at the top of its task's stack, so the +* thread_info is at the base. +*/ +unsigned long user_stack_pointer (struct pt_regs *regs) +{ +struct thread_info *ti = (void *)((unsigned long )regs & -THREAD_SIZE ); + +return ti ==current_thread_info () ?rdusp () : ti->pcb.usp; +} +void user_enable_single_step (struct task_struct *child) {/* Mark single stepping. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2148/2651 selftests/bpf: Fix stack arg pruning test JOIN log expectation
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: KaFai Wan <[email protected]>
[ Upstream commit 8342d47ad791d70a42ab9cf262bd477fb41fdff2 ]
Commit f414d20879ae ("bpf: Save DFS postorder numbers for program instructions") changed bpf_compute_postorder() to use a real DFS, which changes the postorder of this test's instructions and thus the insn edge the arg track join at insn 10 is reported on:
arg JOIN insn 8 -> 10 r1: _ + fp0-8 => fp0-8|fp0+0 arg JOIN insn 8 -> 10 sa0: _ + fp0-8 => fp0-8|fp0+0
Update the r1 and sa0 expectations to the new output.
--- tools/testing/selftests/bpf/progs/verifier_stack_arg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/progs/verifier_stack_arg.c +2 -2
@@ -116,8 +116,8 @@ SEC("tc") __description("stack_arg: pruning with different stack arg types") __failure __log_level(2) __flag(BPF_F_TEST_STATE_FREQ) -__msg("arg JOIN insn 9 -> 10 r1: fp0-8 + _ => fp0-8|fp0+0") -__msg("arg JOIN insn 9 -> 10 sa0: fp0-8 + _ => fp0-8|fp0+0") +__msg("arg JOIN insn 8 -> 10 r1: _ + fp0-8 => fp0-8|fp0+0") +__msg("arg JOIN insn 8 -> 10 sa0: _ + fp0-8 => fp0-8|fp0+0") __msg("R{{[0-9]}} invalid mem access 'scalar'")__naked void stack_arg_pruning_type_mismatch (void ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2149/2651 selftests/bpf: Use _exit() in uprobe_multi_test clone-ed child
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: KaFai Wan <[email protected]>
[ Upstream commit ce42271dc517baa880352d76548d301850e7385b ]
child_func() terminates with exit(), but spawn_child_flag() also starts it via clone(CLONE_VM), which shares the parent's address space. That exit() then runs atexit handlers and static destructors against globals the parent is still using.
LLVM commit 3c3ed59c6a2a ("[llvm] Add format check for MCSubtargetFeatures") [1], included in the LLVM 23.1 releases, added Target::isValidFeatureListFormat() with a function-local static holding the compiled regex:
static const llvm::Regex pattern("^([+-][^,]+)(,[+-][^,]+)*,?$");
return pattern.match(Features);The child exit destroys that static while its guard variable still marks it as initialized, so the regex is never rebuilt in the parent. From that point on, get_jited_program_text() gets NULL from LLVMCreateDisasmCPUFeatures(), so every jited program text check in the tests running after filter_clone_vm fails, e.g. "verifier_jit_convergence", "verifier_private_stack", "verifier_tailcall_jit" and "verifier_jit_inline".
Use _exit(), which runs neither atexit handlers nor static destructors, as uprobe_syscall.c already does for its own CLONE_VM child.
[1] https://github.com/llvm/llvm-project/pull/180943
--- tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c +2 -2
@@ -94,14 +94,14 @@ static int child_func(void *arg)/* wait for parent's kick */ err =read (child->go[0 ], &c,1 );if (err !=1 ) -exit (err); +_exit (err);uprobe_multi_func_1 ();uprobe_multi_func_2 ();uprobe_multi_func_3 ();usdt_trigger (); -exit (errno); +_exit (errno); }static int spawn_child_flag (struct child *child,bool clone_vm)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2150/2651 bpf: Fix incorrect handling of user flags in bpf_percpu_array_update
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Masoud Aghasi <[email protected]>
[ Upstream commit a898ff0f3e9968b5f7c248d2af3cf1ddaf239e51 ]
For BPF_MAP_TYPE_PERCPU_ARRAY map, bpf_percpu_array_update() is not considering the possibility of a combination of (BPF_NOEXIST, BPF_EXIST) flags with (BPF_F_CPU, BPF_F_ALL_CPUS) flags. This causes the (BPF_NOEXIST, BPF_EXIST) flags to lose their effect in some cases.
For example, using the (BPF_F_ALL_CPUS | BPF_EXIST) flag combination with bpf_map_update_elem() results in an incorrect EINVAL error response, even though the flag combination is valid.
This patch fixes the bug by adding proper flag validations and checks. Before this patch, bpf_percpu_array_update() rejected BPF_F_ALL_CPUS | BPF_EXIST and BPF_F_ALL_CPUS | BPF_NOEXIST with -EINVAL. Also the BPF_F_CPU | BPF_NOEXIST were accepted. After the patch BPF_F_ALL_CPUS | BPF_EXIST is accepted and BPF_F_ALL_CPUS | BPF_NOEXIST and BPF_F_CPU | BPF_NOEXIST result in -EEXIST.
This patch also starts returning -EINVAL for (BPF_EXIST | BPF_NOEXIST), with or without BPF_F_CPU, which was previously accepted.
--- include/linux/bpf.h | 3 +++ kernel/bpf/arraymap.c | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-)
include/linux/bpf.h +3 -0
@@ -4256,6 +4256,9 @@ static inline bool bpf_map_is_percpu_map(enum bpf_map_type map_type) } } +#define BPF_EXIST_FLAGS (BPF_EXIST | BPF_NOEXIST) +#define BPF_CPU_FLAGS (BPF_F_CPU | BPF_F_ALL_CPUS) +static inline int bpf_map_check_op_flags (struct bpf_map *map,u64 flags,u64 allowed_flags) {u32 cpu;
kernel/bpf/arraymap.c +3 -3
@@ -438,15 +438,15 @@ int bpf_percpu_array_update(struct bpf_map *map, void *key, void *value,u32 size;int cpu, off =0 ; -if (unlikely ((map_flags &BPF_F_LOCK ) || (u32 )map_flags >BPF_F_ALL_CPUS )) -/* unknown flags */ +if (unlikely (((map_flags &BPF_EXIST_FLAGS ) ==BPF_EXIST_FLAGS ) || + ((u32 )map_flags & ~(BPF_EXIST_FLAGS |BPF_CPU_FLAGS ))))return -EINVAL ;if (unlikely (index >= array->map.max_entries))/* all elements were pre-allocated, cannot insert a new one */ return -E2BIG ; -if (unlikely (map_flags ==BPF_NOEXIST )) +if (unlikely (map_flags &BPF_NOEXIST ))/* all elements already exist */ return -EEXIST ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2151/2651 bpf: Fix incorrect handling of user flags by percpu hash map updates
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Masoud Aghasi <[email protected]>
[ Upstream commit 4a9b25fe8d138f2e0e65b337ecf829ce7ce42d09 ]
For BPF_MAP_TYPE_PERCPU_HASH and BPF_MAP_TYPE_LRU_PERCPU_HASH maps, htab_map_check_update_flags() and check_flags() are not considering the possibility of a combination of (BPF_NOEXIST, BPF_EXIST) flags with (BPF_F_CPU, BPF_F_ALL_CPUS) flags. This causes the (BPF_NOEXIST, BPF_EXIST) flags to lose their effect in some cases.
For example, when using (BPF_F_CPU | BPF_EXIST) or (BPF_F_CPU | BPF_NOEXIST) flag combinations with bpf_map_update_elem() on a percpu hash map, the BPF_EXIST flag does not prevent new insertions as expected and BPF_NOEXIST flag does not prevent modification of existing entries as expected.
This patch fixes the bug by adding proper flag validations and checks. Before this patch, htab_map_check_update_flags() rejected (BPF_F_ALL_CPUS | BPF_EXIST) and (BPF_F_ALL_CPUS | BPF_NOEXIST) with -EINVAL. After the patch those combinations are accepted.
This patch also starts returning -EINVAL for (BPF_EXIST | BPF_NOEXIST), with or without BPF_F_CPU, which was previously accepted.
--- kernel/bpf/hashtab.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
kernel/bpf/hashtab.c +6 -4
@@ -1186,11 +1186,11 @@ static struct htab_elem *alloc_htab_elem(struct bpf_htab *htab, void *key,static int check_flags (struct bpf_htab *htab,struct htab_elem *l_old,u64 map_flags) { -if (l_old && (map_flags & ~BPF_F_LOCK ) ==BPF_NOEXIST ) +if (l_old && (map_flags &BPF_NOEXIST ))/* elem already exists */ return -EEXIST ; -if (!l_old && (map_flags & ~BPF_F_LOCK ) ==BPF_EXIST ) +if (!l_old && (map_flags &BPF_EXIST ))/* elem doesn't exist, cannot update it */ return -ENOENT ;
@@ -1377,9 +1377,11 @@ static long htab_lru_map_update_elem(struct bpf_map *map, void *key, void *valuestatic int htab_map_check_update_flags (bool onallcpus,u64 map_flags) { +if (unlikely ((map_flags &BPF_EXIST_FLAGS ) ==BPF_EXIST_FLAGS )) +return -EINVAL ;if (unlikely (!onallcpus && map_flags >BPF_EXIST ))return -EINVAL ; -if (unlikely (onallcpus && ((map_flags &BPF_F_LOCK ) || (u32 )map_flags >BPF_F_ALL_CPUS ))) +if (unlikely (onallcpus && ((u32 )map_flags & ~(BPF_EXIST_FLAGS |BPF_CPU_FLAGS ))))return -EINVAL ;return 0 ; }
@@ -1477,7 +1479,7 @@ static long __htab_lru_percpu_map_update_elem(struct bpf_map *map, void *key,* to remove older elem from htab and this removal * operation will need a bucket lock. */ -if (map_flags !=BPF_EXIST ) { +if (!(map_flags &BPF_EXIST )) { l_new =prealloc_lru_pop (htab, key, hash);if (!l_new)return -ENOMEM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2152/2651 selftests/bpf: Run the cpumask map insert tests only for the test task
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qiliang Yuan <[email protected]>
[ Upstream commit e2c978ad415ce223e71f6ddaa92778225eca0bef ]
verify_success() attaches each cpumask test program to task_newtask, forks a single child, and expects err to be 0 afterwards. Most programs return right away for other tasks than the test one.
test_insert_leave and test_insert_remove_release don't, and insert a cpumask into the single entry of __cpumask_map for every task created in the system while they are attached. test_insert_leave leaves its cpumask in the map, so a second task created, for instance by a test running in parallel, fails to insert one and sets err to 3. Two tasks created at the same time can do the same to test_insert_remove_release.
Return early for other tasks than the test one in both programs, as the other programs do.
--- tools/testing/selftests/bpf/progs/cpumask_success.c | 6 ++++++ 1 file changed, 6 insertions(+)
tools/testing/selftests/bpf/progs/cpumask_success.c +6 -0
@@ -460,6 +460,9 @@ int BPF_PROG(test_insert_leave, struct task_struct *task, u64 clone_flags) {struct bpf_cpumask *cpumask; +if (!is_test_task ()) +return 0 ; + cpumask =create_cpumask ();if (!cpumask)return 0 ;
@@ -476,6 +479,9 @@ int BPF_PROG(test_insert_remove_release, struct task_struct *task, u64 clone_flastruct bpf_cpumask *cpumask;struct __cpumask_map_value *v; +if (!is_test_task ()) +return 0 ; + cpumask =create_cpumask ();if (!cpumask)return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2153/2651 gpiolib: fix memory leak in gpiod_set_array_value_complex() EPERM error path
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kent Gibson <[email protected]>
[ Upstream commit 138d7365c20efe47b4caa92c46f086ec39b81f78 ]
A drive-by review by Sashiko reports that, where the line has not been configured as an output, gpiod_set_array_value_complex() can return without freeing potentially alloced bitmaps, thus leaking memory.
Cleanup the bitmaps before returning.
--- drivers/gpio/gpiolib.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpio/gpiolib.c +6 -4
@@ -3850,7 +3850,7 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep, unsigned long *value_bitmap) {struct gpio_chip *gc; -int i =0 , ret; +int i =0 , ret =0 ;/* * Validate array_info against desc_array and its size.
@@ -3928,8 +3928,10 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep,int hwgpio =gpiod_hwgpio (desc);int value =test_bit (i, value_bitmap); -if (unlikely (!test_bit (GPIOD_FLAG_IS_OUT , &desc->flags))) -return -EPERM ; +if (unlikely (!test_bit (GPIOD_FLAG_IS_OUT , &desc->flags))) { + ret = -EPERM ; + goto cleanup_bitmap; + }/* * Pins applicable for fast input but not for
@@ -3962,10 +3964,10 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep, }while ((i < array_size) &&gpio_device_chip_cmp (desc_array[i]->gdev, guard.gc));/* push collected bits to outputs */ - ret =0 ;if (count !=0 ) ret =gpiochip_set_multiple (guard.gc, mask, bits); +cleanup_bitmap:if (mask != fastpath_mask)bitmap_free (mask);if (bits != fastpath_bits)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2154/2651 gpiolib: clear the event clock flags when a line is released
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Ambrozewicz <[email protected]>
[ Upstream commit d35f61581ee67f8d4d58c325bac813cea528b6b9 ]
gpiod_free_commit() clears the flags that a request sets on a line, but not GPIOD_FLAG_EVENT_CLOCK_REALTIME and GPIOD_FLAG_EVENT_CLOCK_HTE, which gpio_v2_line_config_flags_to_desc_flags() sets from the uAPI v2 line config. Once a line requested with GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME or GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE is released, GPIO_V2_GET_LINEINFO_IOCTL and the line info changed events, the "released" one included, keep reporting that event clock for the free line:
GPIO_V2_GET_LINE_IOCTL, line 1, input, event clock realtime: ok close()
GPIO_V2_GET_LINEINFO_IOCTL, line 1: input, event clock realtime
The flags are set before edge detection is set up, so a request that fails in hte_ts_get(), for instance because no HTE provider handles the line, leaves GPIOD_FLAG_EVENT_CLOCK_HTE behind as well. The next uAPI v2 request rewrites both flags, but requests through uAPI v1, sysfs exports and in-kernel consumers do not, and the line info then shows the event clock of an earlier user for them too.
Clear both flags together with the other flags of the request.
Reproduced under QEMU with a test GPIO chip: after a released request with the realtime event clock, and on a kernel with CONFIG_HTE=y but no HTE provider after a failed request with the HTE event clock, the line info of the free line still reports that event clock. With this change it reports none.
--- drivers/gpio/gpiolib.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpio/gpiolib.c +2 -0
@@ -2682,6 +2682,8 @@ void gpiod_free_commit(struct gpio_desc *desc)clear_bit (GPIOD_FLAG_BIAS_DISABLE , &flags);clear_bit (GPIOD_FLAG_EDGE_RISING , &flags);clear_bit (GPIOD_FLAG_EDGE_FALLING , &flags); +clear_bit (GPIOD_FLAG_EVENT_CLOCK_REALTIME , &flags); +clear_bit (GPIOD_FLAG_EVENT_CLOCK_HTE , &flags);clear_bit (GPIOD_FLAG_IS_HOGGED , &flags);#ifdef CONFIG_OF_DYNAMIC WRITE_ONCE (desc->hog,NULL );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2155/2651 ALSA: pcm: Protect the unregister notifier traversal
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 680be9f82d4977d3410c513d3bfe912d100f64fc ]
snd_pcm_free() traverses snd_pcm_notify_list and calls n_unregister without register_mutex, although snd_pcm_notify() takes that mutex to add and remove notifiers. PCM disconnect releases the mutex before the free callback runs, so it does not protect this later traversal.
With no open OSS file, normal snd-pcm-oss removal can overlap PCM card teardown, for example when unbinding snd-dummy:
PCM card teardown snd-pcm-oss unload
----------------- ------------------
snd_pcm_dev_disconnect()
remove PCM under register_mutex
unlock register_mutex
snd_pcm_free()
fetch notifier
snd_pcm_notify(..., 1)
unlink notifier under mutex
free module storage
read notifier->n_unregister
invoke callback
The free path can then read the notifier from released module storage or call its unloaded code.
Hold register_mutex across the unregister traversal and its callbacks. Notifier removal must wait until both have finished. This also protects the traversal if a callback releases the last module reference: module exit cannot unlink its notifier until the free path releases the mutex. Drop the mutex before private_free and the remaining stream cleanup.
--- sound/core/pcm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
sound/core/pcm.c +4 -2
@@ -853,8 +853,10 @@ static int snd_pcm_free(struct snd_pcm *pcm) {if (!pcm)return 0 ; -if (!pcm->internal) -pcm_call_notify (pcm, n_unregister); +if (!pcm->internal) { + scoped_guard(mutex, ®ister_mutex) +pcm_call_notify (pcm, n_unregister); + }if (pcm->private_free) pcm->private_free (pcm);snd_pcm_lib_preallocate_free_for_all (pcm);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2156/2651 ALSA: oss: Keep emulation modules loaded until object teardown
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit f0780cfa6acf72576464dc3b40431db389f46ee8 ]
OSS proc entries and notifier callbacks can remain in use without an open OSS device file. Normal snd-pcm-oss removal can therefore delete an existing PCM's OSS proc entry while late HDA codec binding repeats snd_card_register() on the same live card:
OSS PCM module unload Card registration
--------------------- -----------------
snd_info_free_entry(entry)
proc_remove(entry->p)
clear entry->p
snd_info_card_register()
republish linked entry
unlink and free entry
The new proc node retains a pointer to freed storage. Mixer OSS removal can likewise release an adapter while a card notification still uses it.
Hold a snd-pcm-oss module reference for each PCM registered with its notifier and a snd-mixer-oss reference for each card adapter. Release them at final unregister or FREE, after proc and adapter cleanup. Normal module unload can no longer initiate removal while these objects exist.
Track PCM OSS registration with a separate bool registered. Unlike oss.reg, this state also covers unmapped PCMs and remains set across DISCONNECT until final unregister. BUILD-state and creation-error cleanup must not drop a reference when registration never acquired one. The PCM notifier's register_mutex serialization keeps the final put ahead of notifier removal and module teardown until dispatch has finished.
For mixer OSS, serialize callback publication, dispatch and withdrawal in the core so module exit waits for callbacks, including one dropping the last reference, to return. Keep card enumeration in the OSS module, with card references released after dispatch drops the mutex. Ignore duplicate REGISTER notifications so a delayed registration cannot replace an adapter retained across DISCONNECT and leak its module pin.
Partial HDA codec teardown can still remove an individual PCM while the card remains registered; its object-lifetime handling is separate.
--- include/sound/core.h | 3 ++- include/sound/pcm_oss.h | 1 + sound/core/init.c | 29 +++++++++++++++++++++-------- sound/core/oss/mixer_oss.c | 36 ++++++++++++++++++++---------------- sound/core/oss/pcm_oss.c | 12 ++++++++++++ 5 files changed, 56 insertions(+), 25 deletions(-)
include/sound/core.h +2 -1
@@ -301,7 +301,8 @@ int snd_card_locked(int card);#define SND_MIXER_OSS_NOTIFY_REGISTER 0#define SND_MIXER_OSS_NOTIFY_DISCONNECT 1#define SND_MIXER_OSS_NOTIFY_FREE 2 -extern int (*snd_mixer_oss_notify_callback)(struct snd_card *card,int cmd); +void snd_mixer_oss_set_notify (int (*callback)(struct snd_card *card,int cmd)); +void snd_mixer_oss_notify (struct snd_card *card,int cmd);#endif int snd_card_new(struct device *parent, int idx, const char *xid,
include/sound/pcm_oss.h +1 -0
@@ -70,6 +70,7 @@ struct snd_pcm_oss_stream {struct snd_pcm_oss {int reg;unsigned int reg_mask; +bool registered; };#endif /* __SOUND_PCM_OSS_H */
sound/core/init.c +21 -8
@@ -82,8 +82,24 @@ static int module_slot_match(struct module *module, int idx) }#if IS_ENABLED (CONFIG_SND_MIXER_OSS ) -int (*snd_mixer_oss_notify_callback)(struct snd_card *card,int free_flag); -EXPORT_SYMBOL (snd_mixer_oss_notify_callback); +static DEFINE_MUTEX (mixer_oss_notify_mutex); +static int (*mixer_oss_notify_callback)(struct snd_card *card,int cmd); + +void snd_mixer_oss_notify (struct snd_card *card,int cmd) +{ +guard (mutex)(&mixer_oss_notify_mutex); +if (mixer_oss_notify_callback) +mixer_oss_notify_callback (card, cmd); +} +EXPORT_SYMBOL (snd_mixer_oss_notify); + +void snd_mixer_oss_set_notify (int (*callback)(struct snd_card *,int )) +{ +/* Wait for callbacks, including a final module_put(), to return. */ +guard (mutex)(&mixer_oss_notify_mutex); + mixer_oss_notify_callback = callback; +} +EXPORT_SYMBOL (snd_mixer_oss_set_notify);#endif static int check_empty_slot (struct module *module,int slot)
@@ -530,8 +546,7 @@ void snd_card_disconnect(struct snd_card *card)/* at this point, they cannot respond to any calls except release() */ #if IS_ENABLED (CONFIG_SND_MIXER_OSS ) -if (snd_mixer_oss_notify_callback) -snd_mixer_oss_notify_callback (card,SND_MIXER_OSS_NOTIFY_DISCONNECT ); +snd_mixer_oss_notify (card,SND_MIXER_OSS_NOTIFY_DISCONNECT );#endif /* notify all devices that we are disconnected */
@@ -589,8 +604,7 @@ static int snd_card_do_free(struct snd_card *card) card->releasing = true;#if IS_ENABLED (CONFIG_SND_MIXER_OSS ) -if (snd_mixer_oss_notify_callback) -snd_mixer_oss_notify_callback (card,SND_MIXER_OSS_NOTIFY_FREE ); +snd_mixer_oss_notify (card,SND_MIXER_OSS_NOTIFY_FREE );#endif snd_device_free_all (card);kfree (card->components);
@@ -934,8 +948,7 @@ int snd_card_register(struct snd_card *card)return err;#if IS_ENABLED (CONFIG_SND_MIXER_OSS ) -if (snd_mixer_oss_notify_callback) -snd_mixer_oss_notify_callback (card,SND_MIXER_OSS_NOTIFY_REGISTER ); +snd_mixer_oss_notify (card,SND_MIXER_OSS_NOTIFY_REGISTER );#endif return 0 ; }
sound/core/oss/mixer_oss.c +20 -16
@@ -1308,13 +1308,22 @@ static int snd_mixer_oss_free1(void *private)static int snd_mixer_oss_notify_handler (struct snd_card *card,int cmd) {struct snd_mixer_oss *mixer; +int err;if (cmd ==SND_MIXER_OSS_NOTIFY_REGISTER ) { -int idx, err; +int idx; + +/* Module loading and card registration can both notify us. */ +if (card->mixer_oss) +return 0 ; mixer =kzalloc_objs (*mixer,2 );if (mixer ==NULL )return -ENOMEM ; +if (!try_module_get (THIS_MODULE )) { +kfree (mixer); +return -ENODEV ; + }mutex_init (&mixer->reg_mutex); err = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MIXER, card, 0,
@@ -1324,6 +1333,7 @@ static int snd_mixer_oss_notify_handler(struct snd_card *card, int cmd)"unable to register OSS mixer device %i:%i\n" , card->number, 0);kfree (mixer); +module_put (THIS_MODULE );return err; } mixer->oss_dev_alloc =1 ;
@@ -1357,7 +1367,10 @@ static int snd_mixer_oss_notify_handler(struct snd_card *card, int cmd)if (cmd ==SND_MIXER_OSS_NOTIFY_DISCONNECT )return 0 ;snd_mixer_oss_proc_done (mixer); -return snd_mixer_oss_free1 (mixer); + err =snd_mixer_oss_free1 (mixer); +if (!err) +module_put (THIS_MODULE ); +return err; }return 0 ; }
@@ -1366,12 +1379,12 @@ static int __init alsa_mixer_oss_init(void) {struct snd_card *card;int idx; - - snd_mixer_oss_notify_callback = snd_mixer_oss_notify_handler; + +snd_mixer_oss_set_notify (snd_mixer_oss_notify_handler);for (idx =0 ; idx <SNDRV_CARDS ; idx++) { card =snd_card_ref (idx);if (card) { -snd_mixer_oss_notify_handler (card,SND_MIXER_OSS_NOTIFY_REGISTER ); +snd_mixer_oss_notify (card,SND_MIXER_OSS_NOTIFY_REGISTER );snd_card_unref (card); } }
@@ -1380,17 +1393,8 @@ static int __init alsa_mixer_oss_init(void) static void __exit alsa_mixer_oss_exit(void) { -struct snd_card *card; -int idx; - - snd_mixer_oss_notify_callback =NULL ; -for (idx =0 ; idx <SNDRV_CARDS ; idx++) { - card =snd_card_ref (idx); -if (card) { -snd_mixer_oss_notify_handler (card,SND_MIXER_OSS_NOTIFY_FREE ); -snd_card_unref (card); - } - } +/* Live adapters hold module references and prevent normal unload. */ +snd_mixer_oss_set_notify (NULL ); }module_init (alsa_mixer_oss_init)
sound/core/oss/pcm_oss.c +12 -0
@@ -3151,6 +3151,12 @@ static void register_oss_dsp(struct snd_pcm *pcm, int index)static int snd_pcm_oss_register_minor (struct snd_pcm *pcm) { +if (pcm->oss.registered) +return 0 ; +if (!try_module_get (THIS_MODULE )) +return -ENODEV ; + pcm->oss.registered = true; + pcm->oss.reg =0 ;if (dsp_map[pcm->card->number] == (int )pcm->device) {char name[128 ];
@@ -3205,8 +3211,14 @@ static int snd_pcm_oss_disconnect_minor(struct snd_pcm *pcm)static int snd_pcm_oss_unregister_minor (struct snd_pcm *pcm) { +/* BUILD-state and creation-error cleanup need not have registered us. */ +if (!pcm->oss.registered) +return 0 ; +snd_pcm_oss_disconnect_minor (pcm);snd_pcm_oss_proc_done (pcm); + pcm->oss.registered = false; +module_put (THIS_MODULE );return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2157/2651 octeontx2-af: Fix CQ enable state tracking after AQ writes
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alok Tiwari <[email protected]>
[ Upstream commit 07bd391eb9572e74f073c49acef327611234f9bb ]
Use the CQ context's ena field when updating the CQ enable bitmap. The current code reads rq.ena, which overlaps bit 0 of the CQ base address and can leave the bitmap out of sync with the hardware context. This can cause enabled CQs to be skipped during teardown.
Use sq.ena for the SQ bitmap update as well, so each queue type reads its own context.
--- drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c +2 -2
@@ -1239,7 +1239,7 @@ static int rvu_nix_blk_aq_enq_inst(struct rvu *rvu, struct nix_hw *nix_hw,__clear_bit (req->qidx, pfvf->rq_bmap); }if (req->ctype ==NIX_AQ_CTYPE_SQ ) { - ena = (req->rq.ena & req->sq_mask.ena) | + ena = (req->sq.ena & req->sq_mask.ena) | (test_bit (req->qidx, pfvf->sq_bmap) & ~req->sq_mask.ena);if (ena)
@@ -1248,7 +1248,7 @@ static int rvu_nix_blk_aq_enq_inst(struct rvu *rvu, struct nix_hw *nix_hw,__clear_bit (req->qidx, pfvf->sq_bmap); }if (req->ctype ==NIX_AQ_CTYPE_CQ ) { - ena = (req->rq.ena & req->cq_mask.ena) | + ena = (req->cq.ena & req->cq_mask.ena) | (test_bit (req->qidx, pfvf->cq_bmap) & ~req->cq_mask.ena);if (ena)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2158/2651 mm/slub: initialize the free pointer of the bootstrap kmem_cache_node
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit d15d7703166daf7bd62c844a3cb1b3a6279adb4c ]
With slub_debug=FZPU, validating kmem_cache_node reports
BUG kmem_cache_node (Not tainted): Freepointer corrupt Object 0xffff888000140040 @offset=64 fp=0x5a5a5a5a5a5a5a5a
and taints the kernel. Poisoning places the bootstrap object's free pointer outside the object, where check_object() checks it even while allocated.
early_kmem_cache_node_alloc() previously took this object from a freelist with an initialized pointer. It now takes it from the slab iterator and builds the freelist only for the remaining objects, leaving its pointer filled with POISON_INUSE.
Initialize the bootstrap object's free pointer to NULL.
--- mm/slub.c | 1 + 1 file changed, 1 insertion(+)
mm/slub.c +1 -0
@@ -7778,6 +7778,7 @@ static void early_kmem_cache_node_alloc(int node) n =next_slab_obj (kmem_cache_node, &iter);BUG_ON (!n); +set_freepointer (kmem_cache_node, n,NULL ); slab->inuse =1 ;build_slab_freelist (kmem_cache_node, slab, &iter);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2159/2651 netfilter: nf_conntrack: avoid truncating IPv6 nexthdr offset
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jérémy Jean <[email protected]>
[ Upstream commit 48d522b65fb0ce2bd54f8f5838d77b48afcf1f3e ]
find_prev_fhdr() returns the offset of the Next Header field before an IPv6 Fragment header through an int pointer, but stores the offset in a u8 local. An extension header chain can put this field beyond byte 255, causing the offset to wrap before it is saved in the fragment queue.
Reassembly later uses the wrapped value to update the preceding Next Header field. This overwrites another byte in the IPv6 header chain and can make conntrack parse a different transport tuple from the one used by IPv6 local delivery. A two-fragment packet can, for example, be recorded as UDP destination port 53 while its payload is delivered to UDP port 9999.
Use int for the working offset, matching the output argument and the other offset variables in this path.
--- net/ipv6/netfilter/nf_conntrack_reasm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/netfilter/nf_conntrack_reasm.c +1 -1
@@ -401,7 +401,7 @@ find_prev_fhdr(struct sk_buff *skb, u8 *prevhdrp, int *prevhoff, int *fhoff) {u8 nexthdr =ipv6_hdr (skb)->nexthdr;const int netoff =skb_network_offset (skb); -u8 prev_nhoff = netoff + offsetof(struct ipv6hdr , nexthdr); +int prev_nhoff = netoff + offsetof(struct ipv6hdr , nexthdr);int start = netoff +sizeof (struct ipv6hdr );int len = skb->len - start;u8 prevhdr =NEXTHDR_IPV6 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2160/2651 ipvs: fix more races around the overload flag
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Julian Anastasov <[email protected]>
[ Upstream commit 3ba20137287f4f34ddbf0afb53c5d1ba03b6a8c2 ]
Sashiko warns that we still have races when the dest overload thresholds are updated. If we narrow the range between thresholds the lockless readers (ip_vs_bind_dest and ip_vs_unbind_dest) may use old threshold values and as result to skip the required flag change.
To solve the problem ip_vs_bind_dest() and ip_vs_unbind_dest() will have the chance as before to change the overload state not only at the exact threshold positions but
at any conn count below the lower and above the upper thresholds. To make it work without entering the locked region for every connection, we introduce l_threshold_val. Together with u_threshold_val we will switch between two states:
1. not overloaded: where l_threshold_val is set to 0 to close the door for more ip_vs_unbind_dest() calls to clear the overload state.
2. overloaded: where u_threshold_val is set to INT_MAX to close the door for more ip_vs_bind_dest() calls to set the overload state.
If a race occurs, multiple CPUs can repeat the state change but this should be for short time window.
With the introduction of l_threshold_val the IP_VS_DEST_F_OVERLOAD flag and the 'flags' field are not needed anymore. We will use the ip_vs_dest_is_overloaded() helper for all places that read the overload state.
Do not check IP_VS_DEST_CF_AVAILABLE in ip_vs_dh.c because we do not hold reference to dest after it is removed and rely on RCU to access the available dests.
To reduce the cacheline accesses while selecting destination, keep the mostly used fields (weight and l_threshold_val) at the first read-mostly cacheline together with the hash nodes.
--- include/net/ip_vs.h | 50 ++++++++++++++++++++------------ net/netfilter/ipvs/ip_vs_conn.c | 8 ++--- net/netfilter/ipvs/ip_vs_ctl.c | 38 ++++++++++++------------ net/netfilter/ipvs/ip_vs_dh.c | 16 ++-------- net/netfilter/ipvs/ip_vs_fo.c | 2 +- net/netfilter/ipvs/ip_vs_lblc.c | 4 +-- net/netfilter/ipvs/ip_vs_lblcr.c | 8 ++--- net/netfilter/ipvs/ip_vs_lc.c | 2 +- net/netfilter/ipvs/ip_vs_mh.c | 2 +- net/netfilter/ipvs/ip_vs_nq.c | 2 +- net/netfilter/ipvs/ip_vs_ovf.c | 2 +- net/netfilter/ipvs/ip_vs_rr.c | 2 +- net/netfilter/ipvs/ip_vs_sed.c | 4 +-- net/netfilter/ipvs/ip_vs_sh.c | 2 +- net/netfilter/ipvs/ip_vs_twos.c | 4 +-- net/netfilter/ipvs/ip_vs_wlc.c | 4 +-- net/netfilter/ipvs/ip_vs_wrr.c | 2 +- 17 files changed, 76 insertions(+), 76 deletions(-)
include/net/ip_vs.h +32 -18
@@ -36,9 +36,6 @@#define IP_VS_HDR_INVERSE 1#define IP_VS_HDR_ICMP 2 -/* Destination Server Flags */ -#define IP_VS_DEST_F_OVERLOAD 0x0002/* server is overloaded */ -/* Destination Server Config Flags */ #define IP_VS_DEST_CF_AVAILABLE 0x0001/* server is available */
@@ -973,32 +970,43 @@ struct ip_vs_dest_dst {* and so on. */ struct ip_vs_dest { +/* Cacheline for hash table nodes - read-mostly */ +struct list_head n_list;/* for the dests in the service */ struct hlist_node d_list;/* for table with all the dests */ -u16 af;/* address family */ -__be16 port;/* port number of the server */ -union nf_inet_addr addr;/* IP address of the server */ -volatile unsigned int flags;/* dest status flags */ -atomic_t conn_flags;/* flags to copy to conn */ atomic_t weight;/* server weight */ -unsigned long cflags;/* config flags */ atomic_t last_weight;/* server latest weight */ + +/* connection thresholds */ +u32 l_threshold_val;/* used lower threshold */ +u32 u_threshold_val;/* used upper threshold */ +/* 32/48 */ +u32 l_threshold;/* lower threshold */ +u32 u_threshold;/* upper threshold */ + +unsigned long cflags;/* config flags */ + +/* 44/64 */ +atomic_t conn_flags;/* flags to copy to conn */ +__u16 tun_type;/* tunnel type */ __be16 tun_port;/* tunnel port */ __u16 tun_flags;/* tunnel flags */ -refcount_t refcnt;/* reference counter */ -struct ip_vs_stats stats;/* statistics */ -unsigned long idle_start;/* start time, jiffies */ +u16 af;/* address family */ +__be16 port;/* port number of the server */ +/* 60/80 */ +union nf_inet_addr addr;/* IP address of the server */ -/* connection counters and thresholds */ -atomic_t activeconns;/* active connections */ +/* connection counters */ atomic_t totalconns;/* total connections */ +atomic_t activeconns;/* active connections */ atomic_t persistconns;/* persistent connections */ -__u32 u_threshold;/* upper threshold */ -__u32 l_threshold;/* lower threshold */ -__u32 l_threshold_val;/* used lower threshold */ + +refcount_t refcnt;/* reference counter */ +struct ip_vs_stats stats;/* statistics */ +unsigned long idle_start;/* start time, jiffies */ /* for destination cache */ spinlock_t dst_lock;/* lock of dst_cache */
@@ -1915,7 +1923,13 @@ static inline void ip_vs_dest_put_and_free(struct ip_vs_dest *dest)kfree (dest); } -void ip_vs_dest_update_overload (struct ip_vs_dest *dest,int mode); +void ip_vs_dest_update_overload (struct ip_vs_dest *dest,bool overload); + +/* Check if dest is in overloaded state */ +static inline bool ip_vs_dest_is_overloaded (const struct ip_vs_dest *dest) +{ +return READ_ONCE (dest->l_threshold_val); +}/* IPVS sync daemon data and function prototypes * (from ip_vs_sync.c)
net/netfilter/ipvs/ip_vs_conn.c +4 -4
@@ -1153,8 +1153,8 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)if (!(flags &IP_VS_CONN_F_INACTIVE ))atomic_inc (&dest->activeconns); tc =atomic_inc_return (&dest->totalconns); -if (tc ==READ_ONCE (dest->u_threshold)) -ip_vs_dest_update_overload (dest,1 ); +if (tc >=READ_ONCE (dest->u_threshold_val)) +ip_vs_dest_update_overload (dest, true); }else {/* It is a persistent connection/template, so increase the persistent connection counter */
@@ -1246,8 +1246,8 @@ static inline void ip_vs_unbind_dest(struct ip_vs_conn *cp)if (!(cp->flags &IP_VS_CONN_F_INACTIVE ))atomic_dec (&dest->activeconns); tc =atomic_fetch_dec (&dest->totalconns); -if (tc ==READ_ONCE (dest->l_threshold_val)) -ip_vs_dest_update_overload (dest,-1 ); +if (tc <=READ_ONCE (dest->l_threshold_val)) +ip_vs_dest_update_overload (dest, false); }else {/* It is a persistent connection/template, so decrease the persistent connection counter */
net/netfilter/ipvs/ip_vs_ctl.c +18 -20
@@ -1309,32 +1309,32 @@ void ip_vs_stats_free(struct ip_vs_stats *stats)* - conns reach u_threshold and exceed it: set the flag * - conns go below l_threshold (or 75% of u_threshold): clear the flag */ -static void __ip_vs_dest_update_overload (struct ip_vs_dest *dest,int mode) +static void __ip_vs_dest_update_overload (struct ip_vs_dest *dest,bool overload) {int conns;u32 l, u;lockdep_assert_held (&dest->dst_lock); u =READ_ONCE (dest->u_threshold); -if (!u) - goto unset; - l =READ_ONCE (dest->l_threshold_val); - conns =atomic_read (&dest->totalconns); -if (conns >= (mode >0 ? l : u)) { - dest->flags |=IP_VS_DEST_F_OVERLOAD ; -return ; +if (u) { +/* Low threshold defaults to 75% of upper threshold */ + l =READ_ONCE (dest->l_threshold) ? : (u - (u >>2 )); + conns =atomic_read (&dest->totalconns); +if (conns >= (overload ? l : u)) { +WRITE_ONCE (dest->u_threshold_val,INT_MAX ); +WRITE_ONCE (dest->l_threshold_val, l); +return ; + } } -if (conns >= (mode <0 ? u : l)) -return ; -unset: - dest->flags &= ~IP_VS_DEST_F_OVERLOAD ; +WRITE_ONCE (dest->u_threshold_val, u ? :INT_MAX ); +WRITE_ONCE (dest->l_threshold_val,0 ); } -void ip_vs_dest_update_overload (struct ip_vs_dest *dest,int mode) +void ip_vs_dest_update_overload (struct ip_vs_dest *dest,bool overload) {spin_lock_bh (&dest->dst_lock); -__ip_vs_dest_update_overload (dest, mode); +__ip_vs_dest_update_overload (dest, overload);spin_unlock_bh (&dest->dst_lock); }
@@ -1406,15 +1406,13 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,if (READ_ONCE (dest->u_threshold) != udest->u_threshold ||READ_ONCE (dest->l_threshold) != udest->l_threshold) { +bool overload; +spin_lock_bh (&dest->dst_lock);WRITE_ONCE (dest->u_threshold, udest->u_threshold);WRITE_ONCE (dest->l_threshold, udest->l_threshold); -/* Low threshold defaults to 75% of upper threshold */ -WRITE_ONCE (dest->l_threshold_val, - udest->l_threshold ? : - (udest->u_threshold - - (udest->u_threshold >>2 ))); -__ip_vs_dest_update_overload (dest,0 ); + overload =ip_vs_dest_is_overloaded (dest); +__ip_vs_dest_update_overload (dest, overload);spin_unlock_bh (&dest->dst_lock); }
net/netfilter/ipvs/ip_vs_dh.c +2 -14
@@ -195,16 +195,6 @@ static int ip_vs_dh_dest_changed(struct ip_vs_service *svc, } -/* -* If the dest flags is set with IP_VS_DEST_F_OVERLOAD, -* consider that the server is overloaded here. -*/ -static inline int is_overloaded (struct ip_vs_dest *dest) -{ -return dest->flags &IP_VS_DEST_F_OVERLOAD ; -} - -/* * Destination hashing scheduling */
@@ -219,10 +209,8 @@ ip_vs_dh_schedule(struct ip_vs_service *svc, const struct sk_buff *skb, s = (struct ip_vs_dh_state *) svc->sched_data; dest =ip_vs_dh_get (svc->af, s, &iph->daddr); -if (!dest || - !(dest->cflags &IP_VS_DEST_CF_AVAILABLE ) - ||atomic_read (&dest->weight) <=0 - ||is_overloaded (dest)) { +if (!dest ||atomic_read (&dest->weight) <=0 || +ip_vs_dest_is_overloaded (dest)) {ip_vs_scheduler_err (svc,"no destination available" );return NULL ; }
net/netfilter/ipvs/ip_vs_fo.c +1 -1
@@ -29,7 +29,7 @@ ip_vs_fo_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,* Find virtual server with highest weight and send it traffic */ list_for_each_entry_rcu (dest, &svc->destinations, n_list) { -if (!(dest->flags &IP_VS_DEST_F_OVERLOAD ) && +if (!ip_vs_dest_is_overloaded (dest) &&atomic_read (&dest->weight) > hw) { hweight = dest; hw =atomic_read (&dest->weight);
net/netfilter/ipvs/ip_vs_lblc.c +2 -2
@@ -418,7 +418,7 @@ __ip_vs_lblc_schedule(struct ip_vs_service *svc)* new connection. */ list_for_each_entry_rcu (dest, &svc->destinations, n_list) { -if (dest->flags &IP_VS_DEST_F_OVERLOAD ) +if (ip_vs_dest_is_overloaded (dest))continue ;if (atomic_read (&dest->weight) >0 ) { least = dest;
@@ -433,7 +433,7 @@ __ip_vs_lblc_schedule(struct ip_vs_service *svc)*/ nextstage:list_for_each_entry_continue_rcu (dest, &svc->destinations, n_list) { -if (dest->flags &IP_VS_DEST_F_OVERLOAD ) +if (ip_vs_dest_is_overloaded (dest))continue ; doh =ip_vs_dest_conn_overhead (dest);
net/netfilter/ipvs/ip_vs_lblcr.c +4 -4
@@ -166,7 +166,7 @@ static inline struct ip_vs_dest *ip_vs_dest_set_min(struct ip_vs_dest_set *set)/* select the first destination server, whose weight > 0 */ list_for_each_entry_rcu (e, &set->list, list) { least = e->dest; -if (least->flags &IP_VS_DEST_F_OVERLOAD ) +if (ip_vs_dest_is_overloaded (least))continue ; if ((atomic_read(&least->weight) > 0) &&
@@ -181,7 +181,7 @@ static inline struct ip_vs_dest *ip_vs_dest_set_min(struct ip_vs_dest_set *set) nextstage:list_for_each_entry_continue_rcu (e, &set->list, list) { dest = e->dest; -if (dest->flags &IP_VS_DEST_F_OVERLOAD ) +if (ip_vs_dest_is_overloaded (dest))continue ; doh =ip_vs_dest_conn_overhead (dest);
@@ -580,7 +580,7 @@ __ip_vs_lblcr_schedule(struct ip_vs_service *svc)* new connection. */ list_for_each_entry_rcu (dest, &svc->destinations, n_list) { -if (dest->flags &IP_VS_DEST_F_OVERLOAD ) +if (ip_vs_dest_is_overloaded (dest))continue ;if (atomic_read (&dest->weight) >0 ) {
@@ -596,7 +596,7 @@ __ip_vs_lblcr_schedule(struct ip_vs_service *svc)*/ nextstage:list_for_each_entry_continue_rcu (dest, &svc->destinations, n_list) { -if (dest->flags &IP_VS_DEST_F_OVERLOAD ) +if (ip_vs_dest_is_overloaded (dest))continue ; doh =ip_vs_dest_conn_overhead (dest);
net/netfilter/ipvs/ip_vs_lc.c +1 -1
@@ -38,7 +38,7 @@ ip_vs_lc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,*/ list_for_each_entry_rcu (dest, &svc->destinations, n_list) { -if ((dest->flags &IP_VS_DEST_F_OVERLOAD ) || +if (ip_vs_dest_is_overloaded (dest) ||atomic_read (&dest->weight) ==0 )continue ; doh =ip_vs_dest_conn_overhead (dest);
net/netfilter/ipvs/ip_vs_mh.c +1 -1
@@ -80,7 +80,7 @@ static inline void generate_hash_secret(hsiphash_key_t *hash1,static inline bool is_unavailable (struct ip_vs_dest *dest) {return atomic_read (&dest->weight) <=0 || - dest->flags &IP_VS_DEST_F_OVERLOAD ; +ip_vs_dest_is_overloaded (dest); }/* Returns hash value for IPVS MH entry */
net/netfilter/ipvs/ip_vs_nq.c +1 -1
@@ -72,7 +72,7 @@ ip_vs_nq_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,list_for_each_entry_rcu (dest, &svc->destinations, n_list) { -if (dest->flags &IP_VS_DEST_F_OVERLOAD || +if (ip_vs_dest_is_overloaded (dest) || !atomic_read (&dest->weight))continue ;
net/netfilter/ipvs/ip_vs_ovf.c +1 -1
@@ -33,7 +33,7 @@ ip_vs_ovf_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,*/ list_for_each_entry_rcu (dest, &svc->destinations, n_list) { w =atomic_read (&dest->weight); -if ((dest->flags &IP_VS_DEST_F_OVERLOAD ) || +if (ip_vs_dest_is_overloaded (dest) ||atomic_read (&dest->activeconns) > w || w ==0 )continue ;
net/netfilter/ipvs/ip_vs_rr.c +1 -1
@@ -66,7 +66,7 @@ ip_vs_rr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,list_for_each_entry_continue_rcu (dest, &svc->destinations, n_list) { -if (!(dest->flags &IP_VS_DEST_F_OVERLOAD ) && +if (!ip_vs_dest_is_overloaded (dest) &&atomic_read (&dest->weight) >0 )/* HIT */ goto out;
net/netfilter/ipvs/ip_vs_sed.c +2 -2
@@ -75,7 +75,7 @@ ip_vs_sed_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,*/ list_for_each_entry_rcu (dest, &svc->destinations, n_list) { -if (!(dest->flags &IP_VS_DEST_F_OVERLOAD ) && +if (!ip_vs_dest_is_overloaded (dest) &&atomic_read (&dest->weight) >0 ) { least = dest; loh =ip_vs_sed_dest_overhead (least);
@@ -90,7 +90,7 @@ ip_vs_sed_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,*/ nextstage:list_for_each_entry_continue_rcu (dest, &svc->destinations, n_list) { -if (dest->flags &IP_VS_DEST_F_OVERLOAD ) +if (ip_vs_dest_is_overloaded (dest))continue ; doh =ip_vs_sed_dest_overhead (dest); if ((__s64)loh * atomic_read(&dest->weight) >
net/netfilter/ipvs/ip_vs_sh.c +1 -1
@@ -73,7 +73,7 @@ struct ip_vs_sh_state {static inline bool is_unavailable (struct ip_vs_dest *dest) {return atomic_read (&dest->weight) <=0 || - dest->flags &IP_VS_DEST_F_OVERLOAD ; +ip_vs_dest_is_overloaded (dest); }/*
net/netfilter/ipvs/ip_vs_twos.c +2 -2
@@ -52,7 +52,7 @@ static struct ip_vs_dest *ip_vs_twos_schedule(struct ip_vs_service *svc,/* Generate a random weight between [0,sum of all weights) */ list_for_each_entry_rcu (dest, &svc->destinations, n_list) { -if (!(dest->flags &IP_VS_DEST_F_OVERLOAD )) { +if (!ip_vs_dest_is_overloaded (dest)) { weight =atomic_read (&dest->weight);if (weight >0 ) { total_weight += weight;
@@ -75,7 +75,7 @@ static struct ip_vs_dest *ip_vs_twos_schedule(struct ip_vs_service *svc,/* Pick two weighted servers */ list_for_each_entry_rcu (dest, &svc->destinations, n_list) { -if (dest->flags &IP_VS_DEST_F_OVERLOAD ) +if (ip_vs_dest_is_overloaded (dest))continue ; weight =atomic_read (&dest->weight);
net/netfilter/ipvs/ip_vs_wlc.c +2 -2
@@ -47,7 +47,7 @@ ip_vs_wlc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,*/ list_for_each_entry_rcu (dest, &svc->destinations, n_list) { -if (!(dest->flags &IP_VS_DEST_F_OVERLOAD ) && +if (!ip_vs_dest_is_overloaded (dest) &&atomic_read (&dest->weight) >0 ) { least = dest; loh =ip_vs_dest_conn_overhead (least);
@@ -62,7 +62,7 @@ ip_vs_wlc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,*/ nextstage:list_for_each_entry_continue_rcu (dest, &svc->destinations, n_list) { -if (dest->flags &IP_VS_DEST_F_OVERLOAD ) +if (ip_vs_dest_is_overloaded (dest))continue ; doh =ip_vs_dest_conn_overhead (dest); if ((__s64)loh * atomic_read(&dest->weight) >
net/netfilter/ipvs/ip_vs_wrr.c +1 -1
@@ -176,7 +176,7 @@ ip_vs_wrr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,list_for_each_entry_continue_rcu (dest, &svc->destinations, n_list) { -if (!(dest->flags &IP_VS_DEST_F_OVERLOAD ) && +if (!ip_vs_dest_is_overloaded (dest) &&atomic_read (&dest->weight) >= mark->cw) goto found;if (dest == stop)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2161/2651 netfilter: flowtable: use the vlan id, not the full tci, in the tuple key
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuangfeng He <[email protected]>
[ Upstream commit c203ecf905745d979de5df28fa657121f2e9342d ]
nf_flow_tuple_encap() stores the skb vlan tag in the encap tuple id using skb_vlan_tag_get(), which returns the unmasked TCI including the 3 PCP priority bits. The flowtable entry, however, is programmed by nf_dev_path_info() with vlan_dev_vlan_id(), a plain 12-bit VID.
When a NIC delivers RX vlan offload skbs with a non-zero priority (an RTL9617C EPON ONU was observed handing over vid 818 skbs with tci 0x6332, PCP 3), the runtime lookup key never matches the programmed entry, so every packet misses the flow table and software flow offload is silently defeated.
Mask both parse sites to the 12-bit VID so the lookup key matches for any priority. The in-header variant has the same problem for frames received with PCP != 0 on a non-offload path.
The egress side is unaffected: nf_flow_encap_push() restores tags from the programmed tuple id, which never carried priority bits.
Measured on an RTL9617C ONU (PPPoE over VLAN 818 WAN, NATed 6-flow download over a 1G EPON line), before -> after:
download throughput 377 Mbps -> 936 Mbps
CPU0 %soft at that rate 91.5% -> 70.9%
--- net/netfilter/nf_flow_table_ip.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nf_flow_table_ip.c +2 -2
@@ -170,14 +170,14 @@ static void nf_flow_tuple_encap(struct nf_flowtable_ctx *ctx,int i =0 ;if (skb_vlan_tag_present (skb)) { - tuple->encap[i].id =skb_vlan_tag_get (skb); + tuple->encap[i].id =skb_vlan_tag_get_id (skb); tuple->encap[i].proto = skb->vlan_proto; i++; }switch (skb->protocol) {case htons (ETH_P_8021Q ): veth = (struct vlan_ethhdr *)skb_mac_header (skb); - tuple->encap[i].id =ntohs (veth->h_vlan_TCI); + tuple->encap[i].id =ntohs (veth->h_vlan_TCI) &VLAN_VID_MASK ; tuple->encap[i].proto = skb->protocol; offset +=VLAN_HLEN ;break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2162/2651 netfilter: nft_set_rbtree: narrow down range completion to anonymous sets
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pablo Neira Ayuso <[email protected]>
[ Upstream commit 86d47d4c84a1b8470ba3fc16df13ea2a220b74ff ]
For anonymous sets, when adjacent ranges are found, the end element is not added to the set to pack the set representation. Use next start element to complete this interval.
Jérémy Jean says:
Consider two ranges in a netfilter verdict map:
* keys 10-19 accept packets, and
* keys 30-39 jump to chain 'victim'.
Now, delete the end marker at 20. The lookup array now uses element 30 as the first range's end, so an INTERVAL_END query for key 15 returns element 30, including its jump verdict and chain pointer. This can make KASAN reports a UAF after the GC releases reference chain for 30 that has expired:
BUG: KASAN: slab-use-after-free in nft_verdict_dump+0xdd/0x110 Read of size 8 at addr ff110000009dfb58 by task repro/50 ... Call Trace: ... nft_verdict_dump+0xdd/0x110 nft_data_dump+0x4d/0x80 nf_tables_fill_setelem+0x30b/0x8a0 ? __asan_memcpy+0x3c/0x60 nf_tables_fill_setelem_info+0x1b0/0x200 nft_get_set_elem+0x3fd/0x4b0 ... Freed by task 24: ... kfree+0x1a5/0x280 nf_tables_trans_destroy_work+0x2cb/0x520
--- net/netfilter/nft_set_rbtree.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/nft_set_rbtree.c +2 -1
@@ -1091,7 +1091,8 @@ static void nft_rbtree_commit(struct nft_set *set)* representation. Use next start element to complete this * interval. */ -if (nft_rbtree_interval_start (rbe) && +if (nft_set_is_anonymous (set) && +nft_rbtree_interval_start (rbe) &&nft_rbtree_interval_start (prev_rbe) && priv->array_next->intervals[num_intervals].from) priv->array_next->intervals[num_intervals++].to = &prev_rbe->ext;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2163/2651 netfilter: xt_dccp: handle reserved options as single-byte
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sung Byeongchan <[email protected]>
[ Upstream commit 2edda78aa4eb04cd8f112a81897510ee0cdd7099 ]
The DCCP UAPI defines option numbers 3 through 31 as reserved. Like Padding and Mandatory, these options occupy one byte. dccp_find_option() only treats values below 2 as single-byte and interprets the byte after a reserved option as a TLV length.
This can skip a later option and invert an XT_DCCP_OPTION rule result. A local production-hook fixture installed the same DROP rule for IPv4 and IPv6. In three fresh boots per kernel, a target-only packet was dropped 20/20 times, while adding reserved option 3 before the same target let 20/20 packets reach the protected receiver. The fixed kernel dropped all trigger packets in three fresh boots and preserved the normal controls.
Treat every option up to DCCPO_MAX_RESERVED as single-byte, matching the protocol definition. Triggering requires CONFIG_NETFILTER_XTABLES_LEGACY, CONFIG_NETFILTER_XT_MATCH_DCCP, an option-based rule, and remote protocol-33 reachability. The touched source is unchanged at 0c2669a9f4a1d607e7591ae50ccf3c432a0aff08, where the patch applies and builds cleanly.
--- net/netfilter/xt_dccp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/xt_dccp.c +1 -1
@@ -62,7 +62,7 @@ dccp_find_option(u_int8_t option,return true; } -if (op[i] <2 || i == optlen -1 ) +if (op[i] <=DCCPO_MAX_RESERVED || i == optlen -1 ) i++;else i += op[i +1 ] ? :1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2164/2651 netfilter: flowtable: reset transport header after nf_flow_encap_pop()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Bianconi <[email protected]>
[ Upstream commit 08f7882637f2db5b98f521498eeaf94770383a6e ]
nf_flow_encap_pop() pulls vlan/pppoe or ip tunnel headers and resets the network header, but leaves the transport header pointing into the removed outer header. Reset the transport header to the inner L4 header, otherwise later consumers (e.g. GSO segmentation) parse a bogus header.
--- net/netfilter/nf_flow_table_ip.c | 2 ++ 1 file changed, 2 insertions(+)
net/netfilter/nf_flow_table_ip.c +2 -0
@@ -502,6 +502,7 @@ static int nf_flow_offload_forward(struct nf_flowtable_ctx *ctx,nf_flow_encap_pop (ctx, skb, tuplehash); thoff -= ctx->offset; +skb_set_transport_header (skb, thoff); iph =ip_hdr (skb);nf_flow_nat_ip (flow, skb, thoff, dir, iph);
@@ -1097,6 +1098,7 @@ static int nf_flow_offload_ipv6_forward(struct nf_flowtable_ctx *ctx,flow_offload_refresh (flow_table, flow, false);nf_flow_encap_pop (ctx, skb, tuplehash); +skb_set_transport_header (skb,sizeof (*ip6h)); ip6h =ipv6_hdr (skb);nf_flow_nat_ipv6 (flow, skb, dir, ip6h);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2165/2651 dax: add fsdev_dax_from_file()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Miklos Szeredi <[email protected]>
[ Upstream commit c87dd99b6d0fe07e836c1593c03e8174029c66f4 ]
If the file is a fsdev_dax open, take the dax_dev from the device inode's i_cdev. Return with a reference grabbed on the private dax inode.
Make dax_dev_get() static again (internal to super.c for alloc_dax), export fsdev_dax_from_file() instead.
This fix is in response to a Sashiko review, and some subsequent analysis.
About the 'fixes' tag: this removes the export of dax_dev_get(), which was flawed, and replaces it with fsdev_dax_from_file(). It feels like the fixes tag makes sense for correcting an ABI error.
--- drivers/dax/fsdev.c | 23 +++++++++++++++++++++++ drivers/dax/super.c | 3 +-- include/linux/dax.h | 3 ++- 3 files changed, 26 insertions(+), 3 deletions(-)
drivers/dax/fsdev.c +23 -0
@@ -234,6 +234,29 @@ static const struct file_operations fsdev_fops = { .release = fsdev_release, }; +/** +* fsdev_dax_from_file - get dax_device from an open file +* @file: open device file +* +* Returns a dax_device pointer if @file refers to a fsdev_dax device. +* Otherwise return NULL. +* +* Caller must put_dax() the returned device when done. +*/ +struct dax_device *fsdev_dax_from_file (struct file *file) +{ +struct dax_device *dax_dev; + +if (file->f_op != &fsdev_fops) +return NULL ; + + dax_dev =inode_dax (file_inode (file)); +ihold (dax_inode (dax_dev)); + +return dax_dev; +} +EXPORT_SYMBOL_GPL (fsdev_dax_from_file); +/* * Acquire the dev_pagemap for probe: the static (pre-populated) one if * present, or a devm-allocated one for the dynamic case. Note that
drivers/dax/super.c +1 -2
@@ -565,7 +565,7 @@ static int dax_set(struct inode *inode, void *data)return 0 ; } -struct dax_device *dax_dev_get (dev_t devt) +static struct dax_device *dax_dev_get (dev_t devt) {struct dax_device *dax_dev;struct inode *inode;
@@ -588,7 +588,6 @@ struct dax_device *dax_dev_get(dev_t devt)return dax_dev; } -EXPORT_SYMBOL_GPL (dax_dev_get);struct dax_device *alloc_dax (void *private,const struct dax_operations *ops) {
include/linux/dax.h +2 -1
@@ -54,7 +54,6 @@ struct dax_device *alloc_dax(void *private, const struct dax_operations *ops);void *dax_holder (struct dax_device *dax_dev);void put_dax (struct dax_device *dax_dev);void kill_dax (struct dax_device *dax_dev); -struct dax_device *dax_dev_get (dev_t devt);void dax_write_cache (struct dax_device *dax_dev,bool wc);bool dax_write_cache_enabled (struct dax_device *dax_dev);bool dax_synchronous (struct dax_device *dax_dev);
@@ -323,3 +322,5 @@ typedef int (*walk_hmem_fn)(struct device *dev, int target_nid, const struct resource *res);int walk_hmem_resources (struct device *dev,walk_hmem_fn fn);#endif + +struct dax_device *fsdev_dax_from_file (struct file *file);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2166/2651 tools/power turbostat: pmt: Improve sscanf() hygiene
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Len Brown <[email protected]>
[ Upstream commit e817a533bbc0aef5a9cb6255153941ed968d2fb1 ]
Explicitly check sscanf() return values for number of matches, and handle EOF (-1).
Defensive programming -- not an issue actively seen by users.
--- tools/power/x86/turbostat/turbostat.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
tools/power/x86/turbostat/turbostat.c +5 -3
@@ -1995,15 +1995,17 @@ int pmt_telemdir_filter(const struct dirent *e) {unsigned int dummy; -return sscanf (e->d_name,"telem%u" , &dummy); +return (sscanf (e->d_name,"telem%u" , &dummy) ==1 ); }int pmt_telemdir_sort (const struct dirent **a,const struct dirent **b) {unsigned int aidx =0 , bidx =0 ; -sscanf ((*a)->d_name,"telem%u" , &aidx); -sscanf ((*b)->d_name,"telem%u" , &bidx); +if (sscanf ((*a)->d_name,"telem%u" , &aidx) !=1 ) + aidx =0 ; +if (sscanf ((*b)->d_name,"telem%u" , &bidx) !=1 ) + bidx =0 ;return (aidx > bidx) ?1 : (aidx < bidx) ?-1 :0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2167/2651 nios2: ksyms: Declare __mulsi3 export
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Weißschuh <[email protected]>
[ Upstream commit 2180d11e06fb56fd13643ae59964f144896870be ]
GCC may emit libcalls to __mulsi3(). As modpost is not aware that this function is provided through the linked in libgcc, it fails:
ERROR: modpost: kernel/locking/test-ww_mutex.ko: symbol '__mulsi3' undefined!
ERROR: modpost: kernel/time/test_udelay.ko: symbol '__mulsi3' undefined!
ERROR: modpost: kernel/resource_kunit.ko: symbol '__mulsi3' undefined!
ERROR: modpost: fs/fuse/virtiofs.ko: symbol '__mulsi3' undefined! etc.
Make sure modpost can see the symbol from libgcc.
--- arch/nios2/kernel/nios2_ksyms.c | 1 + 1 file changed, 1 insertion(+)
arch/nios2/kernel/nios2_ksyms.c +1 -0
@@ -38,6 +38,7 @@ DECLARE_EXPORT(__udivsi3);DECLARE_EXPORT (__umoddi3);DECLARE_EXPORT (__umodsi3);DECLARE_EXPORT (__muldi3); +DECLARE_EXPORT (__mulsi3);DECLARE_EXPORT (__ucmpdi2);DECLARE_EXPORT (__lshrdi3);DECLARE_EXPORT (__ashldi3);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2168/2651 ALSA: pcmtest: Pin the module while pattern files are open
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 069003afab42b5a9394faa6985a3d76bd4700e72 ]
The fill_pattern_fops table must remain alive until the final release of each pattern debugfs file. It has no .owner, so the fops_get() call in full_proxy_open_regular() does not take a PCMTest module reference.
With snd-pcmtest loaded as a module, a user with permission to open a fill_patternN file and unload the module can retain the descriptor across normal unload, provided no PCM file or other module reference prevents it. The following ordering is possible:
Pattern file user Module unload
----------------- -------------
open(fill_patternN)
full_proxy_open_regular()
fops_get(fill_pattern_fops)
owner == NULL: no module pin
keep the descriptor open
mod_exit()
clear_debug_files()
debugfs_remove_recursive()
drain active operations
return from mod_exit()
free_module()
free the module image
close(fd)
full_proxy_release()
read real_fops->release -> UAF
fops_put(real_fops)
read real_fops->owner
access freed module memoryEven though the table has no release callback, reading those fields is a use-after-free and can fault. The retained dentry keeps the proxy's bookkeeping alive, but does not retain the module storage.
Set .owner to THIS_MODULE so the existing fops_get()/fops_put() pair pins PCMTest until final release has finished accessing the table. Normal module unload is then blocked while any pattern file is open.
--- sound/drivers/pcmtest.c | 1 + 1 file changed, 1 insertion(+)
sound/drivers/pcmtest.c +1 -0
@@ -638,6 +638,7 @@ static ssize_t pattern_read(struct file *file, char __user *u_buff, size_t len, }static const struct file_operations fill_pattern_fops = { + .owner =THIS_MODULE , .read = pattern_read, .write = pattern_write, };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2169/2651 ALSA: pcm: Remove channel-map controls before freeing substreams
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit d5dd05c1f72a95d8ab06828d7272a185ad2b9185 ]
A late HDA codec bind on an already registered card builds new PCMs before registering them. add_std_chmaps() publishes generic channel-map controls during this BUILD stage. If an earlier chmap succeeds and a later allocation fails, probe cleanup frees the BUILD PCM while the card's control device remains accessible.
These generic controls are added directly by snd_pcm_add_chmap_ctls(); snd_hda_ctls_clear() only removes codec-tracked mixer controls. BUILD devices also skip dev_disconnect. snd_pcm_free_stream() then frees the substreams before free_chmap() withdraws their generic control:
Late HDA codec bind / rollback Control GET on the live card
------------------------------ ----------------------------
hda_codec_driver_probe()
snd_hda_codec_build_pcms()
PCM is BUILD
snd_hda_codec_build_controls()
add_std_chmaps()
publish an earlier chmap
later allocation: -ENOMEM
snd_hda_codec_cleanup_for_unbind()
snd_hda_ctls_clear()
generic chmap remains
codec_release_pcms()
snd_device_free()
BUILD: skip dev_disconnect snd_pcm_free_stream()
kfree(substream)
snd_ctl_elem_read()
down_read(controls_rwsem) pcm_chmap_ctl_get()
walk freed substream
free_chmap()
snd_ctl_remove()
wait for GET
up_read(controls_rwsem)
The control read lock cannot protect a substream already freed before control removal starts. The failure above occurs before snd_card_register(), so the PCM has not transitioned out of BUILD.
Move free_chmap() before the substream free loop. Its snd_ctl_remove() withdraws the control and drains readers under controls_rwsem before any substream is released. Normal registered-device disconnect already removes the control, so the later call remains harmless on that path.
--- sound/core/pcm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
sound/core/pcm.c +3 -1
@@ -819,6 +819,9 @@ static void snd_pcm_free_stream(struct snd_pcm_str * pstr)/* free all proc files under the stream */ snd_pcm_stream_proc_done (pstr); +/* Drain channel-map callbacks before freeing the substreams. */ +free_chmap (pstr); + substream = pstr->substream;while (substream) { substream_next = substream->next;
@@ -833,7 +836,6 @@ static void snd_pcm_free_stream(struct snd_pcm_str * pstr) kfree(setup); }#endif -free_chmap (pstr);if (pstr->substream_count)put_device (pstr->dev); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2170/2651 ALSA: usb-audio: Avoid applying boot quirk for Behringer UMC204HD
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit e88f4749c02fba11c62e880c29d35d254b7e69d0 ]
There have been reports about a regression with the recent boot quirk for Behringer devices; it broke UMC204HD models(1397:0508 and 1397:0509). The quirk was to just run usb_get_descriptor(), so I expected it rather harmful, but in this case, it doesn't look so, resulting in an error like 'failed to read device descriptor: -110' that leads to a fatal probe error.
As a quick workaround, skip the quirk for those UMC204HD models.
--- sound/usb/quirks.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
sound/usb/quirks.c +8 -1
@@ -1705,8 +1705,15 @@ int snd_usb_apply_boot_quirk_once(struct usb_device *dev, }/* Behringer devices may need explicit device descriptor read at boot */ -if (USB_ID_VENDOR (id) ==0x1397 ) +if (USB_ID_VENDOR (id) ==0x1397 ) { +/* the quirk seems breaking on some Behringer devices */ +switch (id) { +case USB_ID (0x1397 ,0x0508 ):/* UMC204HD */ +case USB_ID (0x1397 ,0x0509 ):/* UMC204HD */ +return 0 ; + }return snd_usb_cm1a_boot_quirk (dev); + }return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2171/2651 ALSA: jack: Pin the module while debugfs files are open
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 8b479b265301e97bfbec0ef25de1c1f7eb4d2f74 ]
With CONFIG_SND=m and CONFIG_SND_JACK_INJECTION_DEBUG enabled, an in-tree HDA jack creates these debugfs files through snd_jack_new() and snd_jack_add_debugfs(). Their file_operations live in snd, but none sets .owner. full_proxy_open_regular() therefore takes no snd module reference when it calls fops_get(real_fops).
A debugfs descriptor can outlive removal of its HDA card. Once the card and dependent modules, including the OSS emulation modules, have been removed, snd can be unloaded while that descriptor is still open:
Descriptor holder Card/module teardown
----------------- --------------------
open jack debugfs file
full_proxy_open_regular()
fops_get(real_fops)
owner == NULL: no snd pin
keep descriptor open
remove HDA card
snd_card_disconnect()
snd_jack_dev_disconnect()
remove debugfs nodes
snd_jack_dev_free()
unload dependent modules
rmmod snd
alsa_sound_exit()
free_module(): unmap snd
close descriptor
full_proxy_release()
read real_fops->release
fops_put(real_fops)
read real_fops->ownerdebugfs_remove() drains active operations, but does not wait for idle open descriptors. Release deliberately bypasses removal protection and reads the real table even when no release callback is installed. The last close can therefore access unloaded snd storage.
Set .owner to THIS_MODULE in all six tables. The existing proxy fops_get()/fops_put() pair then keeps snd loaded through the final table access on close.
--- sound/core/jack.c | 6 ++++++ 1 file changed, 6 insertions(+)
sound/core/jack.c +6 -0
@@ -306,6 +306,7 @@ static ssize_t jack_type_read(struct file *file, }static const struct file_operations jack_type_fops = { + .owner =THIS_MODULE , .open = simple_open, .read = jack_type_read, .llseek = default_llseek,
@@ -313,6 +314,7 @@ static const struct file_operations jack_type_fops = {#endif static const struct file_operations sw_inject_enable_fops = { + .owner =THIS_MODULE , .open = simple_open, .read = sw_inject_enable_read, .write = sw_inject_enable_write,
@@ -320,24 +322,28 @@ static const struct file_operations sw_inject_enable_fops = { };static const struct file_operations jackin_inject_fops = { + .owner =THIS_MODULE , .open = simple_open, .write = jackin_inject_write, .llseek = default_llseek, };static const struct file_operations jack_kctl_id_fops = { + .owner =THIS_MODULE , .open = simple_open, .read = jack_kctl_id_read, .llseek = default_llseek, };static const struct file_operations jack_kctl_mask_bits_fops = { + .owner =THIS_MODULE , .open = simple_open, .read = jack_kctl_mask_bits_read, .llseek = default_llseek, };static const struct file_operations jack_kctl_status_fops = { + .owner =THIS_MODULE , .open = simple_open, .read = jack_kctl_status_read, .llseek = default_llseek,
Signature · 1 line
2.53.0