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=1796398101; b=rX6vfrq4+FYw5isdU43s/iBYB7xfOL50iM4YMYr2MJktBFD0gVDDFpPIkCvLP/jnBNqT EnaC11X+2Ea6gajPkaGgRLvxfNfiTI9NiD9z0hsT3vfLhIuJksGQj6pLjRVpp9deY500B BiY7IY4apNu99XrmLb/iMQfhaJQ+u6EPEYKTN/UB6FLglIuxF7n1A6kldWaoFuwILNuzc wM40gdimqUmnSgGbIBcilc23y67vYR6PgMWkCp/E1m73eykM0/2dpD7AaGJLUHjfTLQ5K v47v+J225BLQehVxqZl3/gucC9Y7IB+gi10HYLy0lsBEP9ssAPo+0G4h30MvLq4uxrA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796398101; 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=3GG5JnuPGCLRHui0OfATAOxkbLcNDAxvYvKlJ5Y6jCDe8OcGUu7uZL28izZzdJvns7bD Pzs4RNE+p+94jbefUHH3i9CvJ7pkSjlN9zyZU4YPH4R7v35V6JRe9siJpPp9H7EO8s+vq rsHhLGwf0SDvuFY445MfHvzM+Hw0xY4TVpRQV3VDRJ/0deln+EhU+JlSih+DLzeKisUJP 2bxWZWAp8u6JuhoeyWq1nhl+NO4KeDC24ZECGgQ6xjt4tiNY6bMYJA3O6MV2rVUmHRgIU OCNTRi8LXJwbUJufHTyTQRTmfsGN/gBWkOUG9vGbso3Ndv0Zu1l56wlmcVorUSWqbKw== 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=VWhspMGE; 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 9212F606A322 for ; Fri, 4 Dec 2026 15:28:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9212F606A322 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=VWhspMGE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796398099; 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=VWhspMGEUseP86anaFqu7GB89lU0epHDAx+915TzXW0bJK6WRkuIsm4LJ1E4OcfT+NA7hT V6SIJdYKHG4f6J30BsjVQsR+5bnc3yHzREetrpqDebOypPQxrexJfqFY2FD94/IwU7hP5x a+AU2UHHKL67W3xUJ8oAN3+XB77+svg= 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: linux-kernel@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.