From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754831AbbCNPmP (ORCPT ); Sat, 14 Mar 2015 11:42:15 -0400 Received: from smtprelay0196.hostedemail.com ([216.40.44.196]:36112 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751732AbbCNPmM (ORCPT ); Sat, 14 Mar 2015 11:42:12 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 64,4,0,,d41d8cd98f00b204,joe@perches.com,:::::::::,RULES_HIT:41:355:379:541:599:800:901:960:967:968:973:982:988:989:1260:1263:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2332:2393:2525:2553:2561:2564:2682:2685:2693:2828:2859:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3354:3622:3653:3657:3865:3866:3867:3868:3870:3871:3872:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:4605:5007:6261:7903:9025:9388:10004:10049:10400:10848:11026:11232:11233:11473:11658:11914:12043:12262:12296:12438:12517:12519:12555:12679:12740:13149:13230:14094:14096:21080,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0 X-HE-Tag: lift38_6a4592aa85c53 X-Filterd-Recvd-Size: 3572 Message-ID: <1426347729.2744.3.camel@perches.com> Subject: Re: [PATCH] checkpatch: match more world writable permissions From: Joe Perches To: Guenter Roeck Cc: Nicholas Mc Guire , Andrew Morton , Andy Whitcroft , linux-kernel@vger.kernel.org Date: Sat, 14 Mar 2015 08:42:09 -0700 In-Reply-To: <20150314143200.GA19645@roeck-us.net> References: <1426274602-21196-1-git-send-email-hofrat@osadl.org> <1426290223.11459.62.camel@perches.com> <20150314143200.GA19645@roeck-us.net> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.12.10-0ubuntu1~14.10.1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 2015-03-14 at 07:32 -0700, Guenter Roeck wrote: > On Fri, Mar 13, 2015 at 04:43:43PM -0700, Joe Perches wrote: > > Currently checkpatch will fuss if one uses world writable > > settings in debugfs files and DEVICE_ATTR uses by testing > > S_IWUGO but not testing S_IWOTH, S_IRWXUGO or S_IALLUGO. > > > > Extend the check to catch all cases exporting world writable > > permissions including octal values. > > > > Original-patch-by: Nicholas Mc Guire > > Signed-off-by: Joe Perches > > --- > > scripts/checkpatch.pl | 12 ++++++++++-- > > 1 file changed, 10 insertions(+), 2 deletions(-) > > > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > > index 6b79beb..4f07d50 100755 > > --- a/scripts/checkpatch.pl > > +++ b/scripts/checkpatch.pl > > @@ -443,6 +443,14 @@ foreach my $entry (@mode_permission_funcs) { > > $mode_perms_search .= $entry->[0]; > > } > > > > +$our $mode_perms_world_writable = qr{ > > + S_IWUGO | > > + S_IWOTH | > > + S_IRWXUGO | > > + S_IALLUGO | > > + 0[0-7][0-7][2367] > > +}x; > > + > > our $allowed_asm_includes = qr{(?x: > > irq| > > memory| > > @@ -5356,8 +5364,8 @@ sub process { > > } > > } > > > > - if ($line =~ /debugfs_create_file.*S_IWUGO/ || > > - $line =~ /DEVICE_ATTR.*S_IWUGO/ ) { > > + if ($line =~ /debugfs_create_\w+.*\b$mode_perms_world_writable\b/ || > > + $line =~ /DEVICE_ATTR.*\b$mode_perms_world_writable\b/) { > > WARN("EXPORTED_WORLD_WRITABLE", > > "Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr); > > With https://lkml.org/lkml/2015/3/12/412 in mind, maybe this should be > marked as error, at least for sysfs attributes. Maybe it's time for the debate this commit referenced: commit 58f86cc89c3372d3e61d5b71e5513ec5a0b02848 Author: Rusty Russell Date: Mon Mar 24 12:00:34 2014 +1030 VERIFY_OCTAL_PERMISSIONS: stricter checking for sysfs perms. Summary of http://lkml.org/lkml/2014/3/14/363 : Ted: module_param(queue_depth, int, 444) Joe: 0444! Rusty: User perms >= group perms >= other perms? Joe: CLASS_ATTR, DEVICE_ATTR, SENSOR_ATTR and SENSOR_ATTR_2? Side effect of stricter permissions means removing the unnecessary S_IFREG from several callers. Note that the BUILD_BUG_ON_ZERO((perm) & 2) test was removed: a fair number of drivers fail this test, so that will be the debate for a future patch.