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: <20191014130247.rag2g7qz54uiw54z@pathway.suse.cz>
Date:   Mon, 14 Oct 2019 15:02:47 +0200
From:   Petr Mladek <pmladek@...e.com>
To:     Rasmus Villemoes <linux@...musvillemoes.dk>
Cc:     Uwe Kleine-König <uwe@...ine-koenig.org>,
        Joe Perches <joe@...ches.com>,
        Andy Shevchenko <andy.shevchenko@...il.com>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Jonathan Corbet <corbet@....net>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v4 1/1] printf: add support for printing symbolic error
 names

On Fri 2019-10-11 15:36:17, Rasmus Villemoes wrote:
> It has been suggested several times to extend vsnprintf() to be able
> to convert the numeric value of ENOSPC to print "ENOSPC". This
> implements that as a %p extension: With %pe, one can do

Reviewed-by: Petr Mladek <pmladek@...e.com>

I like the patch. There are only two rather cosmetic things.

> diff --git a/lib/errname.c b/lib/errname.c
> new file mode 100644
> index 000000000000..30d3bab99477
> --- /dev/null
> +++ b/lib/errname.c
> +const char *errname(int err)
> +{
> +	bool pos = err > 0;
> +	const char *name = __errname(err > 0 ? err : -err);
> +
> +	return name ? name + pos : NULL;

This made me to check C standard. It seems that "true" really has
to be "1".

But I think that I am not the only one who is not sure.
I would prefer to make it less tricky and use, for example:

	const char *name = __errname(err > 0 ? err : -err);
	if (!name)
		return NULL;

	return err > 0 ? name + 1 : name;

> +}
> diff --git a/lib/test_printf.c b/lib/test_printf.c
> index 5d94cbff2120..4fa0ccf58420 100644
> --- a/lib/test_printf.c
> +++ b/lib/test_printf.c
> @@ -593,6 +593,29 @@ flags(void)
>  	kfree(cmp_buffer);
>  }
>  
> +static void __init
> +errptr(void)
> +{
> +	char buf[PLAIN_BUF_SIZE];
> +
> +	test("-1234", "%pe", ERR_PTR(-1234));
> +
> +	/* Check that %pe with a non-ERR_PTR gets treated as ordinary %p. */
> +	BUILD_BUG_ON(IS_ERR(PTR));
> +	snprintf(buf, sizeof(buf), "(%p)", PTR);
> +	test(buf, "(%pe)", PTR);

There is a small race. "(____ptrval____)" is used for %p before
random numbers are initialized. The switch is done via workqueue
work, see enable_ptr_key_workfn(). It means that it can be done
in parallel.

I doubt that anyone would ever hit the race. But it could be very confusing
and hard to debug. I would replace it with:

	test_hashed("%pe", PTR);


If would like to have the two things fixed. I am not sure if you want
to send one more revision. Or I could also change it by follow
up patch when pushing. What is your preference, please?

Best Regards,
Petr

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ