lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20180218130520.3mmosubvt443756v@gmail.com>
Date:   Sun, 18 Feb 2018 14:05:20 +0100
From:   Ingo Molnar <mingo@...nel.org>
To:     Thomas Gleixner <tglx@...utronix.de>
Cc:     Josh Poimboeuf <jpoimboe@...hat.com>, x86@...nel.org,
        linux-kernel@...r.kernel.org, Steven Rostedt <rostedt@...dmis.org>,
        Linus Torvalds <torvalds@...ux-foundation.org>,
        Peter Zijlstra <peterz@...radead.org>,
        Jason Baron <jbaron@...mai.com>, Borislav Petkov <bp@...e.de>
Subject: Re: [PATCH v2 1/2] jump_label: Explicitly disable jump labels in
 __init code


* Thomas Gleixner <tglx@...utronix.de> wrote:

> On Sat, 17 Feb 2018, Josh Poimboeuf wrote:
> > On Sat, Feb 17, 2018 at 11:38:48AM +0100, Ingo Molnar wrote:
> > > 
> > > * Josh Poimboeuf <jpoimboe@...hat.com> wrote:
> > > 
> > > > +/* Disable any jump label entries in __init code */
> > > > +void __init jump_label_invalidate_init(void)
> > > > +{
> > > > +	struct jump_entry *iter_start = __start___jump_table;
> > > > +	struct jump_entry *iter_stop = __stop___jump_table;
> > > > +	struct jump_entry *iter;
> > > > +
> > > > +	for (iter = iter_start; iter < iter_stop; iter++)
> > > > +		if (iter->code >= (unsigned long)_sinittext &&
> > > > +		    iter->code < (unsigned long)_einittext)
> > > > +			iter->code = 0;
> > > > +}
> > > > +
> > > > +/* Disable any jump label entries in module init code */
> > > >  static void jump_label_invalidate_module_init(struct module *mod)
> > > >  {
> > > >  	struct jump_entry *iter_start = mod->jump_entries;
> > > >  	struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
> > > >  	struct jump_entry *iter;
> > > >  
> > > > -	for (iter = iter_start; iter < iter_stop; iter++) {
> > > > +	for (iter = iter_start; iter < iter_stop; iter++)
> > > >  		if (within_module_init(iter->code, mod))
> > > >  			iter->code = 0;
> > > > -	}
> > > 
> > > Why did you remove the curly braces? They are canonical kernel style for 
> > > multi-line statements.
> > 
> > Personally I prefer the more compact version, but I have no problem
> > changing it.
> 
> Yes, it's certainly a matter of taste. Here is the reason why myself and
> others prefer the version with braces:
> 
>        https://marc.info/?l=linux-kernel&m=148467980905537&w=2

Easier visual parsing is indeed one of the primary reasons, but there's 
two other reasons as well:

2) code robustness 

For example:

        for (i = 0; i < 10; i++)
                if (foo)
                        bar(i);
                baz(i);

Is probably buggy code, although technically it's valid syntax and will compile 
just fine.

If all multi-line statements have curly braces then this type of bug cannot occur:

        for (i = 0; i < 10; i++) {
                if (foo)
                        bar(i);
                baz(i);
	}

3) style consistency

Nothing is worse than randomly inconsistent coding style, and in arch/x86/ and 
core kernel code using curly braces is certainly the dominant style:

  # multi-line C statements without braces:
  $ find arch/x86/ kernel mm -name "*.[ch]" | xargs awk '/for \(.*[^{]$/ { line1=$0; 
    f=1; next } f == 1 && /if \(.*[^{]$/ { f=0; line2=$0; i=1; next } i == 1 { i=0; 
    line3=$0; j=1; next } j == 1 && /^$/{j=0; print line1; print line2; print line3; 
    print; next} { f=0; i=0; j=0; }' |grep 'for (' |wc -l
  
  55

  # multi-line C statements with braces:
  $ find arch/x86 kernel mm -name "*.[ch]" | xargs awk '/for \(.*{$/ { line1=$0; f=1; 
    next } f == 1 && /if \(.*[^{]$/ { f=0; line2=$0; i=1; next } i == 1 { i=0; 
    line3=$0; j=1; next } j == 1 && /}/{j=0; print line1; print line2; print line3; 
    print } { f=0; i=0; j=0; }' |grep 'for (' |wc -l

  116

Thanks,

	Ingo

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ