From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.71 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796054000; b=1tcnejBtKHDkbJt6kTiRs/z8BJj7Gdx7pXnzInFM+2t8t2+dKl6Zb/nE3Sq3CgloQR71 ZBcvTHDpffTK4rn/LNDzKVpkrTsGZHw3fgmK3wPzmKgs8YO+hNm7BmGDNxAtqFhbSm57g QJzZeSAZlw1UR+gdlsLS4WGldo4NTXXb4742Fq1izHCmKVWh6+S38wmfjE4t/3d7lhZu0 VMu2FPdCYjrevBoud35mbgMoYMNStAKjD2THsQXpFqNbYhSvxxVKsc1vNeG1kigq5Gu3A Jq/rikPl3+aTD4ksabxOjVlGkguSHbw40SAZ7fSMsMzBD3AnqzBbVDcQVFphoB0eM1A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796054000; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:Mime-Version: X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=IpcnttV5upZRiO5alibXS4h2+JLYiiI9cOHu6kxLhvI=; b=MJVhSmHU9M8+koBMhpuxcjChexu+ILqAw82TwJZ8ked13ytqPLCdQw1o8jn1qKbxTHgg /5AOHGlB4tcNOITo/1qZHYTz88VaaG6fA9bm7C6i50IkB1zzm0OsFJ2bDp/vP8dX2xypu WwV8b35o0TMEeIE0wFDyywCQ/+ZSG9JBFrxdTQuldYukS4LswdZgJrheaKEJ72M9P3B3d 6H2gpcx0LTW/z+yxeA13Sa7esy7X/j+UD0qNRtIPrZiCEV20HjYipUFbY6ggzhRGQV/P4 +oK1IGGq8VvthYNQcmRSLwvHAYISfOZrzaXE2fzzzuG2mjFxiK/KclJoELLnJeNIMPA== 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=kRDkiygt; arc=none smtp.remote-ip=209.85.128.71 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (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 E74FA606A31C for ; Mon, 30 Nov 2026 15:53:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E74FA606A31C 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=kRDkiygt Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4bb68d624baso70225725e9.2 for ; Mon, 30 Nov 2026 07:53:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796053998; x=1796658798; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=IpcnttV5upZRiO5alibXS4h2+JLYiiI9cOHu6kxLhvI=; b=kRDkiygt2xzJ9RlLPL6PrSH4rba1RpcvGLvl07fPigjXxAdFZShs4RvPl6Rkm6Rs4+ srGi2ffWOcMangQFCuMsA9Uj9+BOssP2P1uL9xvIEAAxdhqrsox8o2gMAmnGoyFcNk7d DE7v2kXQiUhNIw1kiZ0+te6kUk77EoXFlm8Oza4sJtw1yayBUwNqLwsgwRR9Ad8LOqe4 xHEO4stwYGb0rFBvQr8KD1OR4JkhezxVR9m8QrPEA1G1Vev6iKn97a7lbgcvyAvu1oCI xkr3grjoG2yTNTNK0ZzQphfvS7LSDYTX9rX8wC5LWSz3zkVnu97rZs5yvGkDriBRgs4M pkBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796053998; x=1796658798; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=IpcnttV5upZRiO5alibXS4h2+JLYiiI9cOHu6kxLhvI=; b=xz25gYPNovLhICk3a5d1Zp4qcYJZcv6z36m1avXIC3iwmHsdK6uK2ye0e5mJ0jD4wD EYKmW1nTogOEpKnud1AQ2PdzTR7/qmOPLGRcCzqruz75ZqvYUkvgyEtc+cZTVN5qrA/g e46xx5ScPwPCnIzx6yBgUfl8Gc0v3Q/B/ksdlpm+yIkY8Ny0SufdDSH6IiIm045S/idm a9pKu3ghPXMpCzWs2s25MeyWxQxwseJKRWMUMlF1xjfimdcjYJcVqwG2epIXFITry6YT BnbBVOluuApP5kclB/utAHTaDQSOMO9U8XB75VOaq+BU3jwfRoGJmIa+BPDyY9gHuhU7 1f8Q== X-Forwarded-Encrypted: i=1; AL+hErHdi5nEp2O7KKXzAqAWMFGRUbNu9SDU8OR6+4jzNKYQrmPIDaxHrTJh9wY+HLFVpa9H2aWq2jhJoThKyDo=@vger.kernel.org X-Gm-Message-State: APuU4Z9GqknPOi0n0udt2m459VZAd1SdI9w5HZ6A8l4dgaWGml0qTB9j fQp/A/GS6fVsuZ4voMd9Za2DEgl7Rnb/obBEVJDxG8X5zBgVeTeq9MkAzzxZmdrkxeslRtH79WZ 8hr1/OIgdxPy7bA== X-Received: from wmcq5.prod.google.com ([2002:a05:600c:c105:b0:4bb:7ad9:3047]) (user=jpiecuch job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:a088:b0:4a8:cb23:f71b with SMTP id 5b1f17b1804b1-4bb8880b7bamr617305415e9.18.1796053997932; Mon, 30 Nov 2026 07:53:17 -0800 (PST) Date: Mon, 30 Nov 2026 15:53:14 +0000 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 X-Mailer: git-send-email 2.56.1.839.g22a8290db9-goog Message-ID: <20261130155148.2948874-1-jpiecuch@google.com> Subject: [PATCHSET sched_ext/for-7.4-fixes] 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, so __SCX_CALL_OP() leaves scx_locked_rq_state and scx_dump_data untouched, while scx_sub_seed_caps() runs it unlocked. Depending on how the parent called grant or revoke, ops.sub_caps_updated() either runs unlocked or inherits the parent's rq lock or dump state: - scx_bpf_cidperf_set() aborts the sub-scheduler with "Invalid target CPU" on any cid outside the parent's locked rq, or takes the target rq lock when unlocked. - scx_bpf_locked_rq() aborts when unlocked and returns the parent's rq when locked. - scx_bpf_dsq_nr_queued() (for SCX_DSQ_LOCAL), scx_bpf_dsq_reenq(), scx_bpf_reenqueue_local___v2(), and bpf_iter_scx_dsq_destroy() consult scx_locked_rq(). - scx_bpf_dump_bstr() aborts outside dump contexts and writes into the parent's dump buffer when called from ops.dump*(). As agreed on the list, ops.sub_caps_updated() is only for tracking held caps and propagating grants and revokes to children (while cap-acting operations like scx_bpf_cidperf_set() belong in ops.sub_ecaps_updated()), so rejecting these kfuncs at BPF load time prevents the misuse up front. Patch 1 adds scx_kfunc_ids_no_sub_caps (overlapping scx_kfunc_ids_any with matching KF_* flags) and rejects those kfuncs from ops.sub_caps_updated() in scx_kfunc_context_filter(). scx_bpf_cpuperf_set() is already rejected because ops.sub_caps_updated() is only attachable on sched_ext_ops_cid, where scx_kfunc_ids_cpu_only forbids it. Patch 2 adds the sub_caps_kfunc selftest. Without patch 1, sub_caps_kfunc fails because the verifier accepts the restricted kfuncs in ops.sub_caps_updated(): ERR: sub_caps_kfunc.c:91 fail_cidperf loaded when it should have been rejected not ok 1 sub_caps_kfunc # The patches were written with the help of an AI coding assistant. I have reviewed the patches and verified the tests run by the tool. Kuba Piecuch (2): sched_ext: Reject rq-lock-sensitive kfuncs from ops.sub_caps_updated() selftests/sched_ext: Add sub_caps_kfunc test kernel/sched/ext/ext.c | 49 +++++++- tools/testing/selftests/sched_ext/Makefile | 1 + .../selftests/sched_ext/sub_caps_kfunc.bpf.c | 66 +++++++++++ .../selftests/sched_ext/sub_caps_kfunc.c | 107 +++++++++++++++++ .../sched_ext/sub_caps_kfunc_fail.bpf.c | 109 ++++++++++++++++++ 5 files changed, 331 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/sched_ext/sub_caps_kfunc.bpf.c create mode 100644 tools/testing/selftests/sched_ext/sub_caps_kfunc.c create mode 100644 tools/testing/selftests/sched_ext/sub_caps_kfunc_fail.bpf.c base-commit: d43078a237230fd8fb6bf082ff285c93d0ccd763 -- 2.56.1.839.g22a8290db9-goog