From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752007AbdFOBz3 (ORCPT ); Wed, 14 Jun 2017 21:55:29 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:7873 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750768AbdFOBz1 (ORCPT ); Wed, 14 Jun 2017 21:55:27 -0400 Message-ID: <5941E8BF.2070304@huawei.com> Date: Thu, 15 Jun 2017 09:54:07 +0800 From: zhong jiang User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 MIME-Version: 1.0 To: Jeff Layton CC: , , , , , Subject: Re: [PATCH] fs/fcntl: return -ESRCH in f_setown when pid/pgid can't be found References: <20170614145255.7767-1-jlayton@redhat.com> In-Reply-To: <20170614145255.7767-1-jlayton@redhat.com> Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.29.68] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020206.5941E8E4.0072,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: fb6be270adf47394f146ac7649f0a50b Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org yes, look good to me. but I found the another issue. if the pass argument is -1. by the spec describe, type should be assigned to PIDTYPE_MAX, Do you think that it deserve another patch ? Thanks zhongjiang On 2017/6/14 22:52, Jeff Layton wrote: > The current implementation of F_SETOWN doesn't properly vet the argument > passed in. It never returns an error. If the argument doesn't specify a > valid pid/pgid, then we just end up cleaning out the file->f_owner > structure. > > What we really want is to only clean that out only in the case where > userland passed in an argument of 0. For anything else, we want to > return ESRCH if it doesn't refer to a valid pid. > > The relevant POSIX spec page is here: > > http://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html > > Cc: Jiri Slaby > Cc: zhong jiang > Signed-off-by: Jeff Layton > --- > fs/fcntl.c | 18 +++++++++++++----- > 1 file changed, 13 insertions(+), 5 deletions(-) > > diff --git a/fs/fcntl.c b/fs/fcntl.c > index 693322e28751..afed3b364979 100644 > --- a/fs/fcntl.c > +++ b/fs/fcntl.c > @@ -112,8 +112,9 @@ EXPORT_SYMBOL(__f_setown); > int f_setown(struct file *filp, unsigned long arg, int force) > { > enum pid_type type; > - struct pid *pid; > - int who = arg; > + struct pid *pid = NULL; > + int who = arg, ret = 0; > + > type = PIDTYPE_PID; > if (who < 0) { > /* avoid overflow below */ > @@ -123,12 +124,19 @@ int f_setown(struct file *filp, unsigned long arg, int force) > type = PIDTYPE_PGID; > who = -who; > } > + > rcu_read_lock(); > - pid = find_vpid(who); > - __f_setown(filp, pid, type, force); > + if (who) { > + pid = find_vpid(who); > + if (!pid) > + ret = -ESRCH; > + } > + > + if (!ret) > + __f_setown(filp, pid, type, force); > rcu_read_unlock(); > > - return 0; > + return ret; > } > EXPORT_SYMBOL(f_setown); >