From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796398104; b=MoLltEd8PPy/QocY1EzlqmsHl//sNdAM6OyKHJ6rZvbHjDxjeNj0/MMLxeaq8oEKo30z O7U72K9F7LHTipdYk71vqNRUM1F6PMtsGsiruPhXQ2Im8kMbuAR+3XY+3FDpV86LXQk2D dIK0LyXo2fQ7PKe9pk+oVq2S51ohEj3oPMXtbTvNvTjs136A0kVZhwyqAOoPo2QnNNxvg LHjGqFOKZV9ySP8aBLSL/GMNgjiJ1ls8vy+LMjgtl309Wi2rViNPuMZQc6+hkb0XQa4sl YM+Y9jFXfLU0DHb3NU8fDNABa89boL6o7dAkybS5tT8XI/WcnkDe7jJgn7JJlV+DQ2w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796398104; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:Received:Date:From:To:Cc: Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To:X-Scanned-By; bh=ZwwNHYBJK6LujB9Oj9S2xNBooikYkkzU1oj9yEJgCY4=; b=s1NeO6SxHlpQWOO/Mrw8CXDycXaarN3SE7mWpgiGExL8oVBNqYSQ8l90XwjbJR5G+6ih a6zhNNmX+gzd/NaAuEJD9lLQRJPXJbea/uWIBROjerjz0daUlB+cQaGagg1qP2ITTMCiK OyjyTSgCMRN/O/iJaGntRNvn0hpJGCzaFilgLHAN7mS221oeZu7mTzxQJJzO738GSChwg JIy+pawd/PA02nQIm+sb9GzFbwMB/8/D9eppEgDRo9kcbXX761y+0TbIITLncKolWthI6 oVIQZGjwxFxs9VMRS/jSllOqPCqjnx8l9M4R7aLmlA0cZbqg0jmNEoG3zuG+21fG+Jw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=RSlFaYLU; arc=none smtp.remote-ip=170.10.129.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65069606A322 for ; Fri, 4 Dec 2026 15:28:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 65069606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=RSlFaYLU DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796398103; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ZwwNHYBJK6LujB9Oj9S2xNBooikYkkzU1oj9yEJgCY4=; b=RSlFaYLUUR1LTZsgiVIkoPnlAj3xqOJ3q6al2SMoGOWOWmYDidjoDG7a9NR/0yoMIZ/U3x kOVloDWoLdRuQtSuep9Hj/TSVEQKeIUCPQmkgLBYylh8OUyTL54C+y1OXQBKkYtYhMl4z6 lEdRyr2ofBid4ebV1nKFaAuXqsPR2T4= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-339--cvKf4feNUyFo1_3jkhw7A-1; Fri, 4 Dec 2026 15:28:16 +0000 X-MC-Unique: -cvKf4feNUyFo1_3jkhw7A-1 X-Mimecast-MFC-AGG-ID: -cvKf4feNUyFo1_3jkhw7A_1796398088 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9D4AB1923B19; Fri, 4 Dec 2026 15:28:04 +0000 (UTC) Received: from onestero-thinkpadp1gen7.tpbc.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 11E4E1955E80; Fri, 4 Dec 2026 15:27:58 +0000 (UTC) Received: by onestero-thinkpadp1gen7.tpbc.csb (nbSMTP-1.00) for uid 13628 oleg@redhat.com; Fri, 4 Dec 2026 16:28:04 +0100 (CET) Date: Fri, 4 Dec 2026 16:27:58 +0100 From: Oleg Nesterov To: Chris Mason Cc: brauner@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, peterz@infradead.org, mingo@redhat.com, kees@kernel.org, tj@kernel.org, eddyz87@gmail.com, memxor@gmail.com, yonghong.song@linux.dev, martin.lau@linux.dev, song@kernel.org, jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev, sched-ext@lists.linux.dev Subject: Re: [PATCH 1/3] fork: make the creator the parent of an unlinked task Message-ID: References: <20261203200612.26376-1-mason@kernel.org> <20261203200612.26376-2-mason@kernel.org> X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261203200612.26376-2-mason@kernel.org> X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 On 12/03, Chris Mason wrote: > > copy_process() lets BPF hit a use-after-free through the new task's > ->real_parent if the forking task's parent is reaped during the fork. > > The verifier lets BPF programs follow ->real_parent and ->parent under > RCU, but forget_original_parent() only updates linked tasks. The new task > isn't linked until the end of copy_process(), and the task_alloc LSM hook > and sched_ext's ops.init_task() and ops.exit_task() see it before that. > dup_task_struct() just copies both pointers, without taking a reference: > > B, child of A A and its parent > ============= ================ > copy_process() > dup_task_struct() > p->real_parent = A > exit_notify() > forget_original_parent() > B->real_parent = reaper > release_task(A) > put_task_struct_rcu_user() > delayed_put_task_struct() > security_task_alloc(p) > bpf: p->real_parent->pid I know nothing about bpf, could you add more details please ? OK, B, child of A, does copy_process(). A exits right after dup_task_struct(). p->real_parent points to nowhere. Who exactly can dererence p->real_parent at this point? With the change in dup_task_struct(), why is it correct to pretend that p->real_parent == B ? > The idle tasks have the same problem. Init forks the ones for the > secondary CPUs, so their ->real_parent is init's thread group leader. > They are never linked, so nothing updates the pointer. If another thread > of init calls execve(), de_thread() releases the old leader, but > sched_show_task() and BPF programs at sched_switch can still follow > ->real_parent to it. Yes... perhaps fork_idle() should use CLONE_PARENT... but your change looks fine. > The fix used here is to point both pointers at the forking task until the > fork can no longer fail, OK, this change suggests that we have another problem: copy_process() with CLONE_PARENT or CLONE_THREAD can fail and drop tasklist_lock after it sets p->real_parent = A. A can exit. Who can derefence ->real_parent of the soon-to-be-freed and not-yet-linked task p? I am just trying to understand the problem. Perhaps we should change dup_task_struct() to nullify p->thread_pid to make pid_alive(p) false? Oleg.