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] [day] [month] [year] [list]
Message-ID: <202112021134.7ECC69C1@keescook>
Date:   Thu, 2 Dec 2021 11:35:59 -0800
From:   Kees Cook <keescook@...omium.org>
To:     Yang Guang <cgel.zte@...il.com>
Cc:     Yang Guang <yang.guang5@....com.cn>,
        Zeal Robot <zealci@....com.cn>,
        linux-hardening@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] gcc-plugins: use swap() to make code cleaner

On Thu, Oct 28, 2021 at 12:35:26AM +0000, Yang Guang wrote:
> Using swap() make it more readable.
> 
> Reported-by: Zeal Robot <zealci@....com.cn>
> Signed-off-by: Yang Guang <yang.guang5@....com.cn>
> ---
>  scripts/gcc-plugins/randomize_layout_plugin.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/scripts/gcc-plugins/randomize_layout_plugin.c b/scripts/gcc-plugins/randomize_layout_plugin.c
> index 334741a31d0a..feee5ba8fa2b 100644
> --- a/scripts/gcc-plugins/randomize_layout_plugin.c
> +++ b/scripts/gcc-plugins/randomize_layout_plugin.c
> @@ -244,11 +244,8 @@ static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state
>  	unsigned long i, randnum;
>  
>  	for (i = length - 1; i > 0; i--) {
> -		tree tmp;
>  		randnum = ranval(prng_state) % (i + 1);
> -		tmp = newtree[i];
> -		newtree[i] = newtree[randnum];
> -		newtree[randnum] = tmp;
> +		swap(newtree[i], newtree[randnum]);
>  	}
>  }

Hmm, I don't think you compile-tested this? The gcc plugins are build in
userspace without the kernel headers (i.e. no "swap" macro). I'd be
happy to avoid open-coding this, but that would require a new macro
specific to the gcc plugins (to avoid std::swap). Also, there are two
other open-coded swaps in here that could be changed too. :)

-Kees

-- 
Kees Cook

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ