From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A71373ACA46 for ; Wed, 12 Aug 2026 07:55:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786521324; cv=none; b=s/M6sDfYMAQKmzfDdvr7jr1gQ//4adxQibdMns8M9vmcTCHDYqsRY7nWL4LR7jHA/1R4CRuzhD/UfgisxiDAJ7eV7u44JOu8fW472pH+dDq6is0pvoPk6VAeFSpgZgPnrnq2su1wRGvOgCr/jbcCispz5GFwPwAHOFsg0AjD6lg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786521324; c=relaxed/simple; bh=pJjhzHVN9aSh+KxxsqdmrTWcOzAHuYfdNZB07vPbxT0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Kf5cC61XzmLWiQ04HEcE64HMhMF/0ZFqk+kEDkV1MQgbdZLTs5y9AxpD6DE0wZgnz4+HH3UxapN9V0eo5LgL1n+ZwZcsoGrJcM+lDhQa5Z84J0ER+O1c+Ar2VpwapYYbN8ZTAQjq0n5Quv6q/Ma56z8i0xbhiZWuBRP+MhoZ78Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Q+VI+wNQ; arc=none smtp.client-ip=170.10.129.124 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.b="Q+VI+wNQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786521319; 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=weChesNwSLzBUfUP2muJXca8Wh0lDFucZx40tgHo4X4=; b=Q+VI+wNQHkZ9ZOz1aItzJo+SxDwFsKr18bjXNn4V2Ak9j9btbh37i/kS2VtGzelFjnZ2JY Nah0jyUn3RwkYaAYVIsKieW4rQXSNWVYO8UfdPnWGXMy96eIxh1clGTlom5tXzf8K2eXa/ x4eF455mMt74KLhw8wTXS//iuHRW2T8= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-211-2Z5_6PfyN5KFN3Prlw1Syw-1; Wed, 12 Aug 2026 03:55:13 -0400 X-MC-Unique: 2Z5_6PfyN5KFN3Prlw1Syw-1 X-Mimecast-MFC-AGG-ID: 2Z5_6PfyN5KFN3Prlw1Syw_1786521311 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9280F180034F; Wed, 12 Aug 2026 07:55:11 +0000 (UTC) Received: from fedora (unknown [10.44.32.184]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 88B6E19560AB; Wed, 12 Aug 2026 07:55:07 +0000 (UTC) Received: by fedora (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Wed, 12 Aug 2026 09:55:11 +0200 (CEST) Date: Wed, 12 Aug 2026 09:55:05 +0200 From: Oleg Nesterov To: Alex Elder Cc: akpm@linux-foundation.org, david@kernel.org, pjw@kernel.org, brauner@kernel.org, ljs@kernel.org, demiobenour@gmail.com, tglx@kernel.org, debug@rivosinc.com, thomas.weissschuh@linutronix.de, linux-kernel@vger.kernel.org Subject: Re: [PATCH] kernel/sys.c: use RCU when accessing task_struct->real_parent Message-ID: References: <20260811190501.1486442-1-elder@riscstar.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260811190501.1486442-1-elder@riscstar.com> X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Just in case, I am travelling without my work laptop until Aug 19, can't read the code and I rarely read emails... On 08/11, Alex Elder wrote: > > In the setpgid() syscall definition, a check is made to determine > whether the target process is in the same thread group as the > current process. The check accesses the target process's real_parent > pointer directly, however that field is supposed to be accessed via > RCU. Use rcu_dereference() to avoid this C=1 build warning: > > kernel/sys.c:1144:32: warning: incorrect type in argument 1 (different address spaces) This is the sparse warning... Do we really care? We have a lot more users of ->real_parent without rcu_dereference(). Note also that the "rcu" annotation of ->real_parent is misleading. If the task exits, task->real_parent points to nowhere. Same for ->group_leader. This reminds me... months ago I was going to introduce the helper to access ->group_leader and move it to signal_struct. Then I was going to do the same with ->real_parent. I sent some preparations, but then I was distracted. I'll try to return to this after PTO. > SYSCALL_DEFINE2(setpgid, pid_t, pid, pid_t, pgid) > { > struct task_struct *p; > + struct task_struct *real_parent; > struct task_struct *group_leader = current->group_leader; > struct pid *pids[PIDTYPE_MAX] = { 0 }; > struct pid *pgrp; > @@ -1141,7 +1142,8 @@ SYSCALL_DEFINE2(setpgid, pid_t, pid, pid_t, pgid) > if (!thread_group_leader(p)) > goto out; > > - if (same_thread_group(p->real_parent, group_leader)) { > + real_parent = rcu_dereference(p->real_parent); > + if (same_thread_group(real_parent, group_leader)) { > err = -EPERM; > if (task_session(p) != task_session(group_leader)) > goto out; IIRC, this code runs under tasklist_lock (at least it should ;) ->real_parent is stable. I'd prefer to leave this code as is (see above), but even if we really want to shut up sparse we don't need rcu_dereference() anyway, we are not going to dereference this pointer. We have other helpers to read the "rcu" pointers, but I can't recall the names... Oleg.