From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.69 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796054002; b=R1k/3A807Q0haFBIrapFPk9EdoN6ZrvC79D0fUs5g4sbXWbwOO16YfnngjE4BacBCRSh vGixODUaMAcqpxtxJJeujlR0LU5o2QczSG6sdUYUF+i0sGBSL5MhUlNoUq+YF0a7WI6vq Fw4DsDvqsrn0Z7c4l/mNqDirjgixQf62ytdOqjGOMiHG1uA/3qRzF+fhpFG+bBMLrc5VF PpVP9+MyOREY+R//d6gVN34oRlQd9CXvMCCVGX/JgX/ksD2+BRL39hP+wn8rpcZb4l2EA nD71rHZkcSocnrS+1xKnfJUsd2lqmcFBNssuCoatCP8Uv7qMfHkKAKYtKofCVn2sZFA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796054002; 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=cfKvwohDJ/nUL73slEad9PB4wgCIm96fEivyxZNRRqTKBSQA5A//2bo/9JhYEQAEslkq Ydd/PYIp4CZ1D9UYqk5r9+CPZZCcbvsfWrujeiG+Hb6TjRId1AQ711fCN0AA8knqFZR5W eol2c3krC3aN52cgpe+eAcG5AhWuBhJspp64c+Hx1S0fvZ1QaVlnfmEDKDy2RZ60dgPR3 GkN03bhn+suDSac68eDlbOAQslYh0uhpUmJNdHfJzBNuy1Ym1xXhWMH9YMjK5BSZ/b/6w 0kjhijDNZ6Rd973dwFjgMbQEG3j2huBghBbbGLD1mLhX6vW9y++3aW2wZajPUZWYxIw== 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=bGwSoV9t; arc=none smtp.remote-ip=209.85.221.69 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (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 5F56C606A335 for ; Mon, 30 Nov 2026 15:53:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5F56C606A335 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=bGwSoV9t Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-48e4d1e29f3so8740730f8f.3 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=vger.kernel.org; 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=bGwSoV9tv8EKkvHXaGli8NEZJLznblU/xp+zZFBgncLqyR4fCYvzoUPyzhUAMZMJCR lNDIUJcYqZieDD5te/S83yfFUSTdxVCE8pbnlTo/2/wdJzmECc6TH7uIIqn2GhUf2Mn7 ARYr9oW3KEXO7/CAp++G1gZSb+j1cE8eAqA2fObdBouabbFS1DyMj/Q6DZ5xw/mYHlI7 Ou4XsCHtvuQ0NP4G7uSGwYkvUxtvF8SXbrlghJuS9tEdf2AnEZUUdm9Mjl1e5y89yuVt WeaZBVhsKDM2wTRZarBFjhNBlfA1owHARQYwDc6xDPB6O5DSYYBSemSe6RWgY5R6IXqb T7Eg== 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=mUOnISpdiqc5sng6mIKjS4cNeQrpPjWdUrR0o0fb50T/QzBvuzZF6vPwytWM+ViISe iqh/uok1/qsh6qZppgqqq4zv0uDdfZ+LkjBgpfGBKTQNoEBrn7AKbjs1iZmuHRT2GT85 ObZPocHh9S7vqPU0Yol0TRDcWseBTXho9SrXRJ1BouArEIV5CrmANkgAb8Fo/ggRoOIG iaUTAadCDsgyJQagvcndGv5LRRYqCd3Owbhl6q6myUHb7egRqWCGvNeHX3BqwYcutTBE wUlGuJ49okKgtAvj5zr0tEOHgfXMqxj2epzNUcy/lmQ8rekEfPWmyLwgD7pMBzriMXxs Vmtg== X-Forwarded-Encrypted: i=1; AL+hErGDmE4Wvj54b237ieY8ucYY+6E5bTZZyeiueeXPGUzGaHTVZrRKm9EES/Vg1SbBMT4C/ec7e59jcS60PgY=@vger.kernel.org X-Gm-Message-State: APuU4Z8b0YF7D/0sv7tbVA0PlzH2Qrm1eE8Zo5v2MRm7Lzq9tk87Vk/8 EgJtsLMXem/Vdwzh5FvjGOvzpF6LOf/hQW4LZkBT/so4jGx/JqmU0yN8RcJ0nbw1Qh2ffrPmXWH J2qG1eU0IEUAkGQ== 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: linux-kernel@vger.kernel.org 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