Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp707836ybv; Fri, 7 Feb 2020 07:07:37 -0800 (PST) X-Google-Smtp-Source: APXvYqyjHUMiBQD/677mDdZZItHusPIBBerdLb+PEhAID8XVFfFp0Lh60GW1QltdkIFbfniMb/Xw X-Received: by 2002:a05:6808:aac:: with SMTP id r12mr2378115oij.59.1581088057666; Fri, 07 Feb 2020 07:07:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581088057; cv=none; d=google.com; s=arc-20160816; b=E7ME2XSjBJrybmcEWjRdlnj/8YfiejjnMWCZH6CrUgVsibWBCl78ndA8vxIm6hUT1K aAzClXzZMk7K0uAwNLaXy7c4Mm3YNd3JD1CSXsu+jy0U4cc0zXGtvkGu/uGrf5nKAiWR V3joYPYh5wEuW3wqRsnduzqq3SinfCEFV86pLkyCqEuFlPqFdK1Xvrsm0tGyY9r2Jt4j kewhLrTnEchKWQ/xVcB7YqC+MoZW2YYEur+nq6CDrjDaj7KQIoBUJy55sFd9l7UJerbS KAFAgHXsa8++l9n/MwGrh84rRfnMd8d7hziHjf20pEOQSOrtb3xmGDA5wnrfjtdcumxY y+Aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:date:from:dkim-signature; bh=NWcReeVPxFQUsyqNOiabJmMKrw4xIyAeqiGyEJARbUw=; b=mZUsPsgSotueVCCqnIN8ke8woH2JFrUOJB4AE9pxvKhhz3KEdxCiqkYXuoW5zkEG9b 6+xZYZjdc1hoyINvPfjMtzhMlhJ5RD9Zcop7Py4mwCeZ6dZKj8795KZeRLntUCRv1uE3 6oyyxFjHotasPTOq1WibMSmO0cWohmohMH2ZFRgOQ5PW43AGVpuX9TCtcqNaEHMocCM6 Jx0xld+YX7GPTjaRy2HmZn1zWEmlTADrUWpPxhGHXiMbT+7NndhM8m/amgizmybcvWBe hdDCLQT03ABSnRtZeiKuyRaGJnv70xVn29jUSqsYm9fDxT11RJd9A8AYWRqngW/0CHxY toJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FzBzif0c; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f194si4040064oig.243.2020.02.07.07.07.22; Fri, 07 Feb 2020 07:07:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FzBzif0c; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727347AbgBGPEi (ORCPT + 99 others); Fri, 7 Feb 2020 10:04:38 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:37739 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727129AbgBGPEi (ORCPT ); Fri, 7 Feb 2020 10:04:38 -0500 Received: by mail-pl1-f193.google.com with SMTP id c23so1109122plz.4 for ; Fri, 07 Feb 2020 07:04:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=NWcReeVPxFQUsyqNOiabJmMKrw4xIyAeqiGyEJARbUw=; b=FzBzif0c26bz63UUbza8ankdHil2hoE1+L2oOv4PvnYpcGJZBmj1XnWrOa/YsgbHky urQ2lx7mDS+gdjJBVEhUhk35XKRKREii4xy2pUgBm9QFkvbsxFdwHOsY84AaFbbNGTbM cvnilZjaaJusu0v3hataDjbF3cZehHbaOAgkguz87KDgJ0aYM6oFil3aToDUhC0Z0mZE zn4+vTs6gRwGKxJEFufufJG3wLpERyMZlz2LHFuKr3iy9/LRj+P9McRv4Qu5iqYJUuwX ZgmZhvdya27sBFDHkog0hUGz0cDKSStY5iO/T55dSVtCc/XKEX5OwVjzUKMkFK2/E742 l4Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=NWcReeVPxFQUsyqNOiabJmMKrw4xIyAeqiGyEJARbUw=; b=DjEBX48XQudw3sS+dtUai9F/pmUjeDU7NVvsJscr0E3WlwzWiLf7777nUJQefR7yMF QCIb1uOBF4H80nrbJspPVcm5NRblYttRGsBNQBsppd8nnyCEjeXupsQ50AK8VW/AksEu o18ImJGvlBBNyUiZi3JNTLw3sThBQ1/P2I8u8dCUOfT53ac0mAiI27nl11sDLXTc594u jjcFUCl5+K92EbR67gGbt4bdLm44Wys1lrshna2EOcEchVBr+Rud5LErGxibH7JXOFQY fiBH5bPiOm7Zfd4Mb2kqnubl3y4dPePb4SLiuDLjYT2s1R4U0w9slL2mPbiusdqRLMw3 RGtw== X-Gm-Message-State: APjAAAW9b+t5dfXrc6xmroTfeDkVNKRWBjNLWbPtZtUBwKVk7AgPhFsg s8FMB8JDaGjwMSE9+C7J+A== X-Received: by 2002:a17:90a:200d:: with SMTP id n13mr4526087pjc.16.1581087877563; Fri, 07 Feb 2020 07:04:37 -0800 (PST) Received: from madhuparna-HP-Notebook ([2402:3a80:545:29e1:fc5b:5bfd:1ab4:4848]) by smtp.gmail.com with ESMTPSA id y16sm3386521pgf.41.2020.02.07.07.04.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Feb 2020 07:04:36 -0800 (PST) From: Madhuparna Bhowmik X-Google-Original-From: Madhuparna Bhowmik Date: Fri, 7 Feb 2020 20:34:29 +0530 To: Joel Fernandes Cc: Madhuparna Bhowmik , "Eric W. Biederman" , ebiederm@xmission.com, oleg@redhat.com, christian.brauner@ubuntu.com, guro@fb.com, tj@kernel.org, linux-kernel@vger.kernel.org, paulmck@kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, frextrite@gmail.com Subject: Re: [PATCH] signal.c: Fix sparse warnings Message-ID: <20200207150429.GB10751@madhuparna-HP-Notebook> References: <20200205172437.10113-1-madhuparnabhowmik10@gmail.com> <87wo90myhj.fsf@x220.int.ebiederm.org> <20200206110051.GA4531@madhuparna-HP-Notebook> <20200206202511.GC36876@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200206202511.GC36876@google.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 06, 2020 at 03:25:11PM -0500, Joel Fernandes wrote: > On Thu, Feb 06, 2020 at 04:30:51PM +0530, Madhuparna Bhowmik wrote: > > On Wed, Feb 05, 2020 at 04:59:52PM -0600, Eric W. Biederman wrote: > > > madhuparnabhowmik10@gmail.com writes: > > > > > > > From: Madhuparna Bhowmik > > > > > > > > This patch fixes the following two sparse warnings caused due to > > > > accessing RCU protected pointer tsk->parent without rcu primitives. > > > > > > > > kernel/signal.c:1948:65: warning: incorrect type in argument 1 (different address spaces) > > > > kernel/signal.c:1948:65: expected struct task_struct *tsk > > > > kernel/signal.c:1948:65: got struct task_struct [noderef] *parent > > > > kernel/signal.c:1949:40: warning: incorrect type in argument 1 (different address spaces) > > > > kernel/signal.c:1949:40: expected void const volatile *p > > > > kernel/signal.c:1949:40: got struct cred const [noderef] *[noderef] * > > > > kernel/signal.c:1949:40: warning: incorrect type in argument 1 (different address spaces) > > > > kernel/signal.c:1949:40: expected void const volatile *p > > > > kernel/signal.c:1949:40: got struct cred const [noderef] *[noderef] * > > > > > > > > Signed-off-by: Madhuparna Bhowmik > > > > --- > > > > kernel/signal.c | 4 ++-- > > > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > > > > > diff --git a/kernel/signal.c b/kernel/signal.c > > > > index 9ad8dea93dbb..8227058ea8c4 100644 > > > > --- a/kernel/signal.c > > > > +++ b/kernel/signal.c > > > > @@ -1945,8 +1945,8 @@ bool do_notify_parent(struct task_struct *tsk, int sig) > > > > * correct to rely on this > > > > */ > > > > rcu_read_lock(); > > > > - info.si_pid = task_pid_nr_ns(tsk, task_active_pid_ns(tsk->parent)); > > > > - info.si_uid = from_kuid_munged(task_cred_xxx(tsk->parent, user_ns), > > > > + info.si_pid = task_pid_nr_ns(tsk, task_active_pid_ns(rcu_dereference(tsk->parent))); > > > > + info.si_uid = from_kuid_munged(task_cred_xxx(rcu_dereference(tsk->parent), user_ns), > > > > task_uid(tsk)); > > > > rcu_read_unlock(); > > > > > > > > > Still wrong because that access fundamentally depends upon the > > > task_list_lock no the rcu_read_lock. Things need to be consistent for > > > longer than the rcu_read_lock is held. > > > > > Okay, then how about something like rcu_dereference_protected(tsk->parent, lockdep_is_held(&tasklist_lock))? > > Let me know if this looks fine to you. > > But then there are several other ->parent accesses in the function. What > about something like the following? It removes the confusion Eric is > referring to and fixes the sparse errors you mentioned. Thoughts? > Yes, I agree this should remove the confusion. Thank you, Madhuparna > ---8<----------------------- > > diff --git a/kernel/signal.c b/kernel/signal.c > index bcd46f547db39..92f0b7bf70bf3 100644 > --- a/kernel/signal.c > +++ b/kernel/signal.c > @@ -1909,6 +1909,7 @@ bool do_notify_parent(struct task_struct *tsk, int sig) > struct sighand_struct *psig; > bool autoreap = false; > u64 utime, stime; > + struct task_struct *tsk_parent; > > BUG_ON(sig == -1); > > @@ -1918,6 +1919,9 @@ bool do_notify_parent(struct task_struct *tsk, int sig) > BUG_ON(!tsk->ptrace && > (tsk->group_leader != tsk || !thread_group_empty(tsk))); > > + tsk_parent = rcu_dereference_protected(tsk->parent, > + lockdep_is_held(&tasklist_lock)); > + > /* Wake up all pidfd waiters */ > do_notify_pidfd(tsk); > > @@ -1926,7 +1930,7 @@ bool do_notify_parent(struct task_struct *tsk, int sig) > * This is only possible if parent == real_parent. > * Check if it has changed security domain. > */ > - if (tsk->parent_exec_id != tsk->parent->self_exec_id) > + if (tsk->parent_exec_id != tsk_parent->self_exec_id) > sig = SIGCHLD; > } > > @@ -1945,8 +1949,8 @@ bool do_notify_parent(struct task_struct *tsk, int sig) > * correct to rely on this > */ > rcu_read_lock(); > - info.si_pid = task_pid_nr_ns(tsk, task_active_pid_ns(tsk->parent)); > - info.si_uid = from_kuid_munged(task_cred_xxx(tsk->parent, user_ns), > + info.si_pid = task_pid_nr_ns(tsk, task_active_pid_ns(tsk_parent)); > + info.si_uid = from_kuid_munged(task_cred_xxx(tsk_parent, user_ns), > task_uid(tsk)); > rcu_read_unlock(); > > @@ -1964,7 +1968,7 @@ bool do_notify_parent(struct task_struct *tsk, int sig) > info.si_status = tsk->exit_code >> 8; > } > > - psig = tsk->parent->sighand; > + psig = tsk_parent->sighand; > spin_lock_irqsave(&psig->siglock, flags); > if (!tsk->ptrace && sig == SIGCHLD && > (psig->action[SIGCHLD-1].sa.sa_handler == SIG_IGN || > @@ -1989,8 +1993,8 @@ bool do_notify_parent(struct task_struct *tsk, int sig) > sig = 0; > } > if (valid_signal(sig) && sig) > - __group_send_sig_info(sig, &info, tsk->parent); > - __wake_up_parent(tsk, tsk->parent); > + __group_send_sig_info(sig, &info, tsk_parent); > + __wake_up_parent(tsk, tsk_parent); > spin_unlock_irqrestore(&psig->siglock, flags); > > return autoreap; > -- > 2.25.0.341.g760bfbb309-goog >