From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 985EA326958 for ; Mon, 8 Dec 2025 14:27:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765204071; cv=none; b=sd4GaypbcBYEpSEZaylCJe7Txb5QYh5ZgNumjddotSU/KaJuTpjg/geIcO/W3upn/Jop8zL5OMixBNV/opGCB3VbgyvvXj80r8KYGmlUNU0uglcIX/unlfaGaWL2Oh93V0h54olhUul3XSyOkwFMupMnLF1WYhHUhdDzLoAtEGY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765204071; c=relaxed/simple; bh=jTnfF7MrLhHRJSIMgSg5/ysyFxsWRn2a0qBx+Ru1f9Y=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=BYoff40HUd19wgzWCN8H0Ow49jkS/yI6WWSKUMbMfZt80MLvn4p4Mq6T0ecgbYc8pkAECAu2vwOhM34VMmgkIWfdJGIo72BqRMmpFQXPQdvDtgM4K9dIKa8mvoH58SVBOAiPHdw+e59sarDtNgtBRTDP9H4KgHViVGxl8d9+RD0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jpiecuch.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=NiKggrZ5; arc=none smtp.client-ip=209.85.221.74 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.b="NiKggrZ5" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-42b3c965ce5so3880761f8f.2 for ; Mon, 08 Dec 2025 06:27:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765204068; x=1765808868; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=l/8cz3hpeRpzvKw2n2JmBACMdfDswKtcYuMr2lQefSM=; b=NiKggrZ5qH0FydW4mNAdpUbo0GC94G+av3roby8bARy5xPPIHomBE7jHj3WH8bs8fx QJ1Xaf05zQmN8wkrbHfR1RdI4q+tLRaHOZcH0kcU2UHPbOwuXfYfAI1CUCcqRaNt42j7 1fOaUCVJ1vUIZPvCQ+EXF4O/68zUH0zMLe4Fsfu5eP7n/TSVjfayPVKS3VCsDBUgOeiY Acxa4/AuI/KhXogxTukabohW/2u9F1xJjues5xSWuGCKGXPyF/L/oMnLhUZQ/p2QIyH5 jbatjWQ1tPF6JxYa8RVn2R+PT8qmUfeBEWOYGMFhTw/bfgoxlabOsEJ6mDC2zAJt7Nph STew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765204068; x=1765808868; h=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; bh=l/8cz3hpeRpzvKw2n2JmBACMdfDswKtcYuMr2lQefSM=; b=u4wKlxgtHRn06t1TgGnkERKAs9sICEYdFpGYAiGZy8U9n0RobxOgwSly+vwFt9lnNA gnOlxw+MK4zEe5IMchNFrcda81x1HKmOtw6GFF02u75wNNWjzVmhz7+lcw0GTHihrobX 2FQhHlykJuWI15pdEf5RJaalzx1Blaiys/nvD6KwAvxMf6B1T3NDQosUfEWpMKFfLXKM lqJnpU+13B7mzvlnZwskYxbfKU1DAZxd3VJiGlx5f0nS8BQ6NvrsQYee1nYKTzUItng9 ZqP129Yw20DQrNEvB4LFguSPDSep1XTKKokyNXgV6KKL2wHDVz0RNSqt6G3EOKjLtlJy Q8Ow== X-Forwarded-Encrypted: i=1; AJvYcCUMxTI2BbuIB87CyM5EmEDXaTWRSYKkqM6Dp1mugxXJZr7UBMlem4sEf0gbQetj2JKps8dfb53dyq3AYAw=@vger.kernel.org X-Gm-Message-State: AOJu0YysJeYVQB/qFz1kB2larNabc8+PVTYEW5J9XPElUOW/xlqYpuMy WUK8rDcqj1Nw5BMv+lPc/ZbRAIk8qL6xlRBSyBv1kgXpZ2AhCctVfXhoS9+4mtzLuuSFNr6aDwa bEuyfADfJvcIY9w== X-Google-Smtp-Source: AGHT+IGrufoKKJrGvK9dOr6Y0/ltfC2fuziKEeCBQOmAJaNJdztrUUqNhyxDTP3VmaVgSGmIRZqIRsYinDhiug== X-Received: from wrsy4.prod.google.com ([2002:a5d:4ac4:0:b0:42f:7623:682e]) (user=jpiecuch job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:2c13:b0:429:d6dc:ae10 with SMTP id ffacd0b85a97d-42f89f453e9mr8534652f8f.29.1765204067883; Mon, 08 Dec 2025 06:27:47 -0800 (PST) Date: Mon, 08 Dec 2025 14:27:47 +0000 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251206022218.1541878-1-jstultz@google.com> X-Mailer: aerc 0.20.1 Message-ID: Subject: Re: [RFC][PATCH] sched/ext: Avoid null ptr traversal when ->put_prev_task() is called with NULL next From: Kuba Piecuch To: Kuba Piecuch , John Stultz , LKML Cc: Joel Fernandes , Qais Yousef , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Valentin Schneider , Steven Rostedt , Ben Segall , Zimuzo Ezeozue , Mel Gorman , Will Deacon , Waiman Long , Boqun Feng , "Paul E. McKenney" , Metin Kaya , Xuewen Yan , K Prateek Nayak , Thomas Gleixner , Daniel Lezcano , Suleiman Souhlal , kuyo chang , hupu , Tejun Heo , David Vernet , Andrea Righi , Changwoo Min , , Content-Type: text/plain; charset="UTF-8" On Mon Dec 8, 2025 at 11:15 AM UTC, Kuba Piecuch wrote: > On Mon Dec 8, 2025 at 10:10 AM UTC, Kuba Piecuch wrote: >> It looks like it's impossible for an outside observer holding a CPU's rq lock >> to observe a task that is running on that CPU and isn't queued, i.e. >> 'running' implies 'queued' (I'm new to the scheduler so I may be wrong here). > > A task that blocks in __schedule() can drop the rq lock while picking the next > task, which is after try_to_block_task() dequeues prev. So it's very much > possible for a task on another CPU to grab the rq lock and observe prev as > dequeued but still running. Even with that, I'm not convinced that it's possible to do a NULL deref with the current code. In order for sched_change_begin() to do the NULL deref in put_prev_task_scx(), we would need to have: * rq->donor == p (for sched_change_begin() to call put_prev_task()) * p->on_rq != TASK_ON_RQ_QUEUED (for sched_change_begin() to not call dequeue_task() beforehand) * p->scx.flags & SCX_TASK_QUEUED (for put_prev_task_scx() to enter the branch with the @next deref) >From a brief survey of the code, __assuming proxy execution is disabled__, I don't think it's possible for a remote task holding @rq's lock to observe the second and third condition to be true. Every time p->on_rq is changed away from TASK_ON_RQ_QUEUED, it happens under the rq lock and is paired with a dequeue (see block_task(), deactivate_task()). dequeue_task_scx() always clears SCX_TASK_QUEUED from p->scx.flags. Every time SCX_TASK_QUEUED is set in p->scx.flags (i.e. enqueue_task_scx() is called), it happens under the rq lock and is either gated by p->on_rq == TASK_ON_RQ_QUEUED (see ttwu_runnable(), sched_change_end()) or is paired with p->on_rq being set to TASK_ON_RQ_QUEUED (see activate_task()). It also happens in proxy_tag_curr(), which is a no-op if proxy execution is disabled. Even when it's enabled, proxy_tag_curr() does a dequeue-enqueue cycle while holding the rq lock, which doesn't look dangerous. I'm not trying to say that we shouldn't add a NULL check, all this is just for my own understanding.