From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.70 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796054001; b=VtT7OA9S9zyzO/uHFunCY8aVXSsZgH9Tmnv7FBIzrep+IwQUg11Lqi6TfFHcjGs5AX4S vAVZVyJSCPash3Ed7PJBPCIpJF3bZJ1IcLo/lMwDZSjj5GDYf8vWT1W2AkKMaotKsVFnX +X5ktiO4mt/qsfQFifacVxmUeXpuN9yb2mxytpRKyezR1YKx/SLVAt+kFtLek5fdc2d7Y D7XEIIeEvLel9kFGhxGH9rrXLeoRDIE0DpcNYfjC0ADyMNwVyYgZ443hR3wgyt0qy+gxg zP4F3MF1sCDPDWQ/w2JDAJ5DOpnxfZG52PvAYK71UJo2UhYhUcEqnxi1eZ7q0b36W3w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796054001; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=BUjEw+VVkhIwrzm5LZiFRRxYwaL5T5ijrD6lskN4kMM=; b=g9KcK8JgQx50EC7i2UnITs303jxGr1Z06Xx5E8OxrWI1xgcBPuf6osbreUyCMARLM/z3 fVp+X6uzI2Od7pCQy6rcQJsIQk/7Mg8bsLAzxZyq8yiQAnHmPLgGlysTZuQq44B2pF2/J VS3jW5mOsoAsKMbBvx5NPu3m6Qj8UNeSc/Gz8Dpc5LKOaWSUuvALDeVGcoFIs5Hg22H2e mIhm/KthLh1waBQzwDm39xgvm92EKJ3jElN7DG+7e7xIHGDdUveOB0PjyVKFEieZ/q40F lhxQWIBJ6oKKSjrazZNZITgsSLH+A48yPSWPDw22gMkPqp/jQZyvSg+Kczc8MzLlkXA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--jpiecuch.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=TeDPvZuB; arc=none smtp.remote-ip=209.85.221.70 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E582606A334 for ; Mon, 30 Nov 2026 15:53:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5E582606A334 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jpiecuch.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=TeDPvZuB Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-4bbc86e1eb0so4199905f8f.0 for ; Mon, 30 Nov 2026 07:53:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796054000; x=1796658800; darn=lists.linux.dev; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=BUjEw+VVkhIwrzm5LZiFRRxYwaL5T5ijrD6lskN4kMM=; b=TeDPvZuBfaw8ZNJbOcF4NY5MrqkfSwt4P0wsQzD13TM4BvB9BtyaxExAhhbIuwS6fZ uqAzp0ruRbaN81ho0+bQTx3SLiASeqLvcVpwjeF/PkTAsyI/JbCT1KJURwp0D9/UlCPO WfhYDx6CHegZoLVUDqGTFjZ5G5hB5DzAkdw77xnK/zQ4FVmCSVSLrz1kD/U9VKyd5r8c RMV2nHuqukxWiskzyjml3blNAJjjekDxzVxZtMmS3vZQ4jo1Kkh0Awo4trFkBGaat5Vq bATuJJRGL5j6iWHq1IQ3Opz3EOWFX96XOiXG22rbh2u2dOhcRgd4ug+dVPQxbC3nLOOE VFpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796054000; x=1796658800; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=BUjEw+VVkhIwrzm5LZiFRRxYwaL5T5ijrD6lskN4kMM=; b=u7WYjshi/+G3fOGkDnnov3Xb4jtC5XUuWkYj15x5SO1xyTGJ+UjRwc/vN/iJX3uUOI P7qy90a6np7pYn3oZHzxG5SzTlC1+PT1MqYeSPXK6CywJfHTRhT0jdRfHIo+F3JNhW0n Z0d/dC/nzxPui1E4y/kj9ipAlDV2qxeOBFr3X6wfJ1nIVcGz+iu7me8Jo/q2am3Up6g5 fjmAmEOc+4+5aOLYTrqX7vfB9whNE2+wpRplLTfsvvbdXBFL+IyCpnksE1FLSejEC88l 2tblKWSa4u/gQZzXE220k5qMtKGE0pWMVGKZd9KUNqumX+WERwztLB65kmLYTSIhF2LT ot4A== X-Forwarded-Encrypted: i=1; AL+hErE/3hY1+iwx7IgcR9Xj1rHVrAiQf3cTKxZf6JnmWMRkg4dPfdenjLZUX3SUEJDQN/S73mgcPtrQ1VQ=@lists.linux.dev X-Gm-Message-State: APuU4Z/5NuzY//L+KKqjY30TNhK3qtKtHZU3DPszze4xoRvcSdEFFz97 6LdXHWEvraSTglAmk/bFUgLfwj6vj0jxp1LW10NkgyRr607AmLCC8GzdesG4da2G102hRaswXRl 3635pJmm8BP3uDw== X-Received: from wmpr22.prod.google.com ([2002:a05:600c:3216:b0:4a1:e780:89af]) (user=jpiecuch job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4f4a:b0:4bb:6752:8413 with SMTP id 5b1f17b1804b1-4bb8880015bmr771119375e9.8.1796053999176; Mon, 30 Nov 2026 07:53:19 -0800 (PST) Date: Mon, 30 Nov 2026 15:53:15 +0000 In-Reply-To: <20261130155148.2948874-1-jpiecuch@google.com> X-Mailing-List: sched-ext@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261130155148.2948874-1-jpiecuch@google.com> X-Mailer: git-send-email 2.56.1.839.g22a8290db9-goog Message-ID: <20261130155148.2948874-2-jpiecuch@google.com> Subject: [PATCH 1/2] sched_ext: Reject rq-lock-sensitive kfuncs from ops.sub_caps_updated() From: Kuba Piecuch To: Tejun Heo , David Vernet , Andrea Righi , Changwoo Min Cc: Kuba Piecuch , sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" scx_bpf_sub_grant() and scx_bpf_sub_revoke() deliver ops.sub_caps_updated() synchronously with locked_rq = NULL, while scx_sub_seed_caps() invokes it unlocked. ops.sub_caps_updated() therefore either runs unlocked or inherits the parent's rq lock or dump state, rather than providing a known locking context. ops.sub_caps_updated() currently permits every kfunc in scx_kfunc_ids_any. As discussed on the list, ops.sub_caps_updated() is only for tracking held caps and propagating grants and revokes to children, whereas acting on caps belongs in ops.sub_ecaps_updated(). Add scx_kfunc_ids_no_sub_caps and reject kfuncs that depend on being called from an rq-holding or dump context from ops.sub_caps_updated() at BPF load time in scx_kfunc_context_filter(). Fixes: 5f2a9a4c2e6c ("sched_ext: Add coalescing sub_caps_updated() notifier for sub-schedulers") Cc: stable@vger.kernel.org # v7.3+ Link: https://lore.kernel.org/all/aw2KiAUML23tN-L3@slm.duckdns.org/ Signed-off-by: Kuba Piecuch --- kernel/sched/ext/ext.c | 49 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c index a4a93ed97f7b..b8e5251edd2b 100644 --- a/kernel/sched/ext/ext.c +++ b/kernel/sched/ext/ext.c @@ -12280,6 +12280,42 @@ BTF_ID_FLAGS(func, bpf_iter_scx_dsq_next, KF_ITER_NEXT | KF_RET_NULL) BTF_ID_FLAGS(func, bpf_iter_scx_dsq_destroy, KF_ITER_DESTROY) BTF_KFUNCS_END(scx_kfunc_ids_no_tracing) +/* + * Kfuncs forbidden from ops.sub_caps_updated(). + * + * ops.sub_caps_updated() runs synchronously from the parent's + * scx_bpf_sub_grant() / scx_bpf_sub_revoke() (inheriting whatever rq lock or + * dump state the parent holds) or unlocked from scx_sub_seed_caps(). It is + * meant only for tracking held caps and propagating grants/revokes to + * children; acting on caps belongs in ops.sub_ecaps_updated(). + * + * - scx_bpf_cidperf_set() consults scx_locked_rq() and aborts when it points + * to another CPU's rq, or acquires the target rq lock when unlocked. + * (scx_bpf_cpuperf_set() is already rejected because ops.sub_caps_updated() + * only attaches on cid-form schedulers, where scx_kfunc_ids_cpu_only forbids + * it.) + * - scx_bpf_locked_rq() aborts when unlocked and exposes the parent's rq when + * locked. + * - scx_bpf_dsq_nr_queued(), scx_bpf_dsq_reenq(), + * scx_bpf_reenqueue_local___v2(), and bpf_iter_scx_dsq_destroy() consult + * scx_locked_rq(). Excluding bpf_iter_scx_dsq_destroy() also rejects + * bpf_for_each(scx_dsq, ...) loops. + * - scx_bpf_dump_bstr() checks scx_dump_data.cpu, aborting outside dump + * contexts and writing into the parent's dump when called from ops.dump*(). + * + * Members must stay in scx_kfunc_ids_any and carry matching KF_* flags (see + * the flag-intersection comment below). + */ +BTF_KFUNCS_START(scx_kfunc_ids_no_sub_caps) +BTF_ID_FLAGS(func, scx_bpf_dsq_nr_queued, KF_IMPLICIT_ARGS) +BTF_ID_FLAGS(func, scx_bpf_dsq_reenq, KF_IMPLICIT_ARGS) +BTF_ID_FLAGS(func, scx_bpf_reenqueue_local___v2, KF_IMPLICIT_ARGS) +BTF_ID_FLAGS(func, bpf_iter_scx_dsq_destroy, KF_ITER_DESTROY) +BTF_ID_FLAGS(func, scx_bpf_dump_bstr, KF_IMPLICIT_ARGS) +BTF_ID_FLAGS(func, scx_bpf_cidperf_set, KF_IMPLICIT_ARGS) +BTF_ID_FLAGS(func, scx_bpf_locked_rq, KF_IMPLICIT_ARGS | KF_RET_NULL) +BTF_KFUNCS_END(scx_kfunc_ids_no_sub_caps) + /* * cpu-form kfuncs that are forbidden from cid-form schedulers * (bpf_sched_ext_ops_cid). Programs targeting the cid struct_ops type must @@ -12393,6 +12429,7 @@ int scx_kfunc_context_filter(const struct bpf_prog *prog, u32 kfunc_id) bool in_cpu_only = btf_id_set8_contains(&scx_kfunc_ids_cpu_only, kfunc_id); bool in_cid = btf_id_set8_contains(&scx_kfunc_ids_cid, kfunc_id); bool in_no_tracing = btf_id_set8_contains(&scx_kfunc_ids_no_tracing, kfunc_id); + bool in_no_sub_caps = btf_id_set8_contains(&scx_kfunc_ids_no_sub_caps, kfunc_id); u32 moff, flags; /* Not an SCX kfunc - allow. */ @@ -12439,11 +12476,21 @@ int scx_kfunc_context_filter(const struct bpf_prog *prog, u32 kfunc_id) if (prog->aux->st_ops == &bpf_sched_ext_ops_cid && in_cpu_only) return -EACCES; + moff = prog->aux->attach_st_ops_member_off; + + /* + * ops.sub_caps_updated() inherits the caller's locking and dump state + * or runs unlocked. Reject kfuncs that depend on scx_locked_rq() or + * scx_dump_data. + */ + if (moff == offsetof(struct sched_ext_ops, sub_caps_updated) && + in_no_sub_caps) + return -EACCES; + /* SCX struct_ops: check the per-op allow list. */ if (in_any || in_idle || in_cid) return 0; - moff = prog->aux->attach_st_ops_member_off; flags = scx_kf_allow_flags[SCX_MOFF_IDX(moff)]; if ((flags & SCX_KF_ALLOW_UNLOCKED) && in_unlocked) -- 2.56.1.839.g22a8290db9-goog