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]
Date:   Wed, 9 Nov 2022 23:54:06 +0100
From:   Borislav Petkov <bp@...en8.de>
To:     Evgeniy Baskov <baskov@...ras.ru>
Cc:     Dave Hansen <dave.hansen@...ux.intel.com>,
        Ingo Molnar <mingo@...hat.com>,
        Thomas Gleixner <tglx@...utronix.de>,
        linux-kernel@...r.kernel.org, x86@...nel.org,
        Alexey Khoroshilov <khoroshilov@...ras.ru>
Subject: Re: [PATCH v7 2/5] x86: Add cmdline_prepare() helper

On Tue, Oct 04, 2022 at 03:48:21PM +0300, Evgeniy Baskov wrote:
> +static inline void cmdline_prepare(char *command_line,
> +				   const char *boot_command_line)
> +{
> +	if (!IS_ENABLED(CONFIG_CMDLINE_BOOL)) {
> +		strscpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
> +	} else if (!IS_ENABLED(CONFIG_CMDLINE_OVERRIDE)) {
> +		/* Append boot loader cmdline to builtin one. */
> +		strlcat(command_line, " ", COMMAND_LINE_SIZE);
> +		strlcat(command_line, boot_command_line, COMMAND_LINE_SIZE);
> +	}

Why can't we make this plain and simple and understandable at a quick
glance instead of putting parts of the string in some variable and then
still doing copying outside of the function?

IOW, simply put everything in a single function:

static inline void cmdline_prepare(char *dst,
                                   const char *builtin_cmdline,
                                   const char *boot_command_line)
{                                  
        /* Depends on CONFIG_CMDLINE_BOOL, overwrite with builtin cmdline */
        if (IS_ENABLED(CONFIG_CMDLINE_OVERRIDE))
                strscpy(dst, builtin_cmdline, COMMAND_LINE_SIZE);
        else if (IS_ENABLED(CONFIG_CMDLINE_BOOL)) {
                if (builtin_cmdline[0]) {
                        /* append boot loader cmdline to builtin */
                        srtlcat(dst, builtin_cmdline, COMMAND_LINE_SIZE)
                        strlcat(dst, " ", COMMAND_LINE_SIZE);
                        strlcat(dst, boot_command_line, COMMAND_LINE_SIZE);
                } else {
                        strscpy(dst, boot_command_line, COMMAND_LINE_SIZE);
                }
        }
}

which is then called like this:

	cmdline_prepare(command_line, builtin_cmdline, boot_command_line);

and when it returns command_line is ready. And before it, command_line
is the empty string:

static char __initdata command_line[COMMAND_LINE_SIZE];

And all the complexity is in one single function and that single
function does each case in an obvious manner and you don't have to go
look outside of the function body to understand what it does.

Hmmm?

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ