Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1668337imm; Sat, 16 Jun 2018 00:12:12 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKC6teIf8AYyqat7ap+SCcN5A0jy5/dgJLdLtMr+qxS8rYMY1aDrMj23UOeaSanRU28paAD X-Received: by 2002:a17:902:7896:: with SMTP id q22-v6mr5402355pll.243.1529133132166; Sat, 16 Jun 2018 00:12:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529133132; cv=none; d=google.com; s=arc-20160816; b=Q/klU20bQvV8U4QtIDpF7MTKrhmuxC36AoQGos0Rd1hv9AIduQvXq1/ORqKYs0hikR 8lOYDCipBRfDjgkjkSqPWKhaQDD9+ueOObZ3FCV3xcvgebIWpC0sc7F0MSCIY+DGsYAO HbjE3wzuDFzrgr3tTCdaCqASmjADV3w/rsJR8gSftfDwicztRduPez/lncInoSAr3fst bgcMZMt10c7WEPNh1warpXlFXptmYma8hKZoOKGC5/yYt8yNHWukJAK0/Ohz4fgDdfV0 Jjboxoy+W8amkXergbIpGzB3GusFQv5uVGuf5AlCVQHmYqr/1zCIa/W0jLLV8mgpCzCf 89DQ== 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:from:date:dkim-signature:arc-authentication-results; bh=+yJdkEyoZsfogWZbD4NAzBfiu9rzD9Z/VAsQOfQohUs=; b=DT+GR9X+YKZsK5J22Jm6xaXbvkcF6jotPOZAMazVrOstWVoQ5rBUp98ujk7j8OsklD IKfOvH8pHQP7y/FCeiuRznl4zIJOwb6SYi3LNR1Ta8oCfgyXc4S3sMRKytBq4vKFzZxQ /JriAQEWxXLBvX2iai89bcodKEIQl/sSgpnuTOt6A7Xfc3dv8hx/kzd1vSV71ogWVcgE RdMMvf2taeTWkauFinIdChhhST+KQNP7E7HmHZt3VJRNhuVnBw995g1H2iHIwwvSqu6p 50gA0i547nUsPDzmPbdbx0sBnuKn4fW8+BzUF1lhAKV1tGBaZaht9PkDWqtC1M+e3HPz NQSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nXYyk9x3; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z7-v6si7930920pgz.284.2018.06.16.00.11.57; Sat, 16 Jun 2018 00:12:12 -0700 (PDT) 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=@kernel.org header.s=default header.b=nXYyk9x3; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756852AbeFPHLc (ORCPT + 99 others); Sat, 16 Jun 2018 03:11:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:60260 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754015AbeFPHLb (ORCPT ); Sat, 16 Jun 2018 03:11:31 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D902720896; Sat, 16 Jun 2018 07:11:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1529133091; bh=qKcbbHNGs48M46Nr7op7MZ57jID9CQXoxJF+2ujhERs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=nXYyk9x3Ox6WeAFszciwEZaR+w+A/Iwa+T4q0y6YBhYREBTvdJBNORGBsIpLWTTsA n8k0xX/sBW1WwB2nfXBvephoZ1IZ/781oN97AKiK12qgpAybfL4xGInsFfN4J7CyON GBflab5YW43dA0WMW/srzUMvCv5+rOItACAr+9jc= Date: Sat, 16 Jun 2018 09:11:08 +0200 From: Greg Kroah-Hartman To: Rajat Jain Cc: linux-kernel@vger.kernel.org, rajatxjain@gmail.com Subject: Re: [PATCH] sysfs: Fix internal_create_group() for named group updates Message-ID: <20180616071108.GB30558@kroah.com> References: <20180616012910.152694-1-rajatja@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180616012910.152694-1-rajatja@google.com> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 15, 2018 at 06:29:10PM -0700, Rajat Jain wrote: > There are a couple of problems with named group updates in the code > today: > > * sysfs_update_group() will always fail for a named group, because > internal_create_group() will try to create a new sysfs directory > unconditionally, which will ofcourse fail with -EEXIST. > > * We can leak the kernfs_node for grp->name if some one tries to: > - rename a group (change grp->name), or > - update a named group, to an unnamed group > > It appears that the whole purpose of sysfs_update_group() was to > allow changing the permissions or visibility of attributes and not > the names. So make it clear in the comments, and allow it to update > an existing named group. Who uses sysfs_update_group() today that has these problems? Or do you want to use it in new code? How can it be broken today so badly that it does not work? > Signed-off-by: Rajat Jain > --- > fs/sysfs/group.c | 26 +++++++++++++++++++------- > 1 file changed, 19 insertions(+), 7 deletions(-) > > diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c > index 4802ec0e1e3a..8bd10dc730ae 100644 > --- a/fs/sysfs/group.c > +++ b/fs/sysfs/group.c > @@ -119,12 +119,23 @@ static int internal_create_group(struct kobject *kobj, int update, > return -EINVAL; > } > if (grp->name) { > - kn = kernfs_create_dir(kobj->sd, grp->name, > - S_IRWXU | S_IRUGO | S_IXUGO, kobj); > - if (IS_ERR(kn)) { > - if (PTR_ERR(kn) == -EEXIST) > - sysfs_warn_dup(kobj->sd, grp->name); > - return PTR_ERR(kn); > + if (update) { > + kn = kernfs_find_and_get(kobj->sd, grp->name); > + if (!kn) { > + WARN(1, > + "Can't update unknown attr grp name: %s/%s\n", > + kobj->name, grp->name); > + return -EINVAL; This is going to cause the syzbot to bug the heck out of us, as people do run with panic-on-warning. Just make this a "normal" error message and dump the stack if you want that. But maybe we should just get rid of this function entirely, it feels very ackward and I can't remember why we added it... thanks, greg k-h