From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753028AbcHOQij (ORCPT ); Mon, 15 Aug 2016 12:38:39 -0400 Received: from smtprelay0094.hostedemail.com ([216.40.44.94]:37468 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752989AbcHOQii (ORCPT ); Mon, 15 Aug 2016 12:38:38 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::,RULES_HIT:41:152:355:379:541:599:800:960:973:982:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1543:1593:1594:1711:1730:1747:1777:1792:2197:2199:2393:2553:2559:2562:3138:3139:3140:3141:3142:3355:3622:3653:3867:3868:3871:4321:5007:7903:8957:10004:10400:10848:11026:11232:11473:11658:11783:11914:12043:12291:12295:12438:12517:12519:12555:12683:12740:13894:14110:14181:14659:14721:21080:21221:21451:30054:30070:30090:30091,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,LFtime:2,LUA_SUMMARY:none X-HE-Tag: boats24_10c75ff1e4a49 X-Filterd-Recvd-Size: 4070 Message-ID: <1471279114.4075.67.camel@perches.com> Subject: Re: [PATCH] checkpatch: Look for symbolic permissions and suggest octal instead From: Joe Perches To: Andrew Morton , Andy Whitcroft Cc: Linus Torvalds , linux-kernel@vger.kernel.org Date: Mon, 15 Aug 2016 09:38:34 -0700 In-Reply-To: <7232ef011d05a92f4caa86a5e9830d87966a2eaf.1470180926.git.joe@perches.com> References: <7232ef011d05a92f4caa86a5e9830d87966a2eaf.1470180926.git.joe@perches.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.18.5.2-0ubuntu3 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2016-08-02 at 16:39 -0700, Joe Perches wrote: > S_ uses should be avoided where octal is more intelligible. ping? Should CodingStyle and Documentation/filesystems change too? > Signed-off-by: Joe Perches > --- >  scripts/checkpatch.pl | 49 +++++++++++++++++++++++++++++++++++++++++++------ >  1 file changed, 43 insertions(+), 6 deletions(-) > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > index 1d5b09d..1140940 100755 > --- a/scripts/checkpatch.pl > +++ b/scripts/checkpatch.pl > @@ -541,6 +541,32 @@ our $mode_perms_world_writable = qr{ >   0[0-7][0-7][2367] >  }x; >   > +our %mode_permission_string_types = ( > + "S_IRWXU" => 0700, > + "S_IRUSR" => 0400, > + "S_IWUSR" => 0200, > + "S_IXUSR" => 0100, > + "S_IRWXG" => 0070, > + "S_IRGRP" => 0040, > + "S_IWGRP" => 0020, > + "S_IXGRP" => 0010, > + "S_IRWXO" => 0007, > + "S_IROTH" => 0004, > + "S_IWOTH" => 0002, > + "S_IXOTH" => 0001, > + "S_IRWXUGO" => 0777, > + "S_IRUGO" => 0444, > + "S_IWUGO" => 0222, > + "S_IXUGO" => 0111, > +); > + > +#Create a search pattern for all these strings to speed up a loop below > +our $mode_perms_string_search = ""; > +foreach my $entry (keys %mode_permission_string_types) { > + $mode_perms_string_search .= '|' if ($mode_perms_string_search ne ""); > + $mode_perms_string_search .= $entry; > +} > + >  our $allowed_asm_includes = qr{(?x: >   irq| >   memory| > @@ -5996,20 +6022,31 @@ sub process { >   $arg_pos--; >   $skip_args = "(?:\\s*$FuncArg\\s*,\\s*){$arg_pos,$arg_pos}"; >   } > - my $test = "\\b$func\\s*\\(${skip_args}([\\d]+)\\s*[,\\)]"; > + my $test = "\\b$func\\s*\\(${skip_args}($FuncArg(?:\\|\\s*$FuncArg)*)\\s*[,\\)]"; >   if ($line =~ /$test/) { >   my $val = $1; >   $val = $6 if ($skip_args ne ""); > - > - if ($val !~ /^0$/ && > -     (($val =~ /^$Int$/ && $val !~ /^$Octal$/) || > -      length($val) ne 4)) { > + if (($val =~ /^$Int$/ && $val !~ /^$Octal$/) || > +     ($val =~ /^$Octal$/ && length($val) ne 4)) { >   ERROR("NON_OCTAL_PERMISSIONS", >         "Use 4 digit octal (0777) not decimal permissions\n" . $herecurr); > - } elsif ($val =~ /^$Octal$/ && (oct($val) & 02)) { > + } > + if ($val =~ /^$Octal$/ && (oct($val) & 02)) { >   ERROR("EXPORTED_WORLD_WRITABLE", >         "Exporting writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr); >   } > + if ($val =~ /\b$mode_perms_string_search\b/) { > + my $to = 0; > + while ($val =~ /\b($mode_perms_string_search)\b(?:\s*\|\s*)?\s*/g) { > + $to |=  $mode_permission_string_types{$1}; > + } > + my $new = sprintf("%04o", $to); > + if (WARN("SYMBOLIC_PERMS", > +  "Symbolic permissions are not preferred. Consider using octal permissions $new.\n" . $herecurr) && > +     $fix) { > + $fixed[$fixlinenr] =~ s/\Q$val\E/$new/; > + } > + } >   } >   } >   }