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:   Sat, 12 Mar 2022 16:14:34 -0800
From:   Joe Perches <joe@...ches.com>
To:     Alexey Dobriyan <adobriyan@...il.com>, x86@...nel.org
Cc:     tglx@...utronix.de, mingo@...hat.com, bp@...en8.de,
        dave.hansen@...ux.intel.com, hpa@...or.com,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/5] x86/alternative: simplify DUMP_BYTES macro

On Sat, 2022-03-12 at 08:36 -0800, Joe Perches wrote:
> On Fri, 2022-03-11 at 17:43 +0300, Alexey Dobriyan wrote:
> > Avoid zero length check with clever whitespace placement in the format
> > string.
> []
> > diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
> []
> > @@ -66,13 +66,10 @@ do {									\
> >  	if (unlikely(debug_alternative)) {				\
> >  		int j;							\
> >  									\
> > -		if (!(len))						\
> > -			break;						\
> > -									\
> >  		printk(KERN_DEBUG pr_fmt(fmt), ##args);			\
> > -		for (j = 0; j < (len) - 1; j++)				\
> > -			printk(KERN_CONT "%02hhx ", buf[j]);		\
> > -		printk(KERN_CONT "%02hhx\n", buf[j]);			\
> > +		for (j = 0; j < (len); j++)				\
> > +			printk(KERN_CONT " %02hhx", buf[j]);		\
> > +		printk(KERN_CONT "\n");					\
> >  	}								\
> 
> This could also use %02x and not %02hhx
> 
> And MAX_PATCH_LEN is 255 but is that really possible?
> 
> Maybe if the actual patch length is always <= 64 this could use
> 	printk(KERN_CONT "%*ph\n", (int)len, buf);
> instead and avoid all possible interleaving?

Another possibility would be to raise the arbitrary 64 byte
limit on %*ph to 256.
---
 Documentation/core-api/printk-formats.rst | 6 +++---
 lib/vsprintf.c                            | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/Documentation/core-api/printk-formats.rst b/Documentation/core-api/printk-formats.rst
index 5e89497ba314e..39f787e9b26e1 100644
--- a/Documentation/core-api/printk-formats.rst
+++ b/Documentation/core-api/printk-formats.rst
@@ -289,9 +289,9 @@ Raw buffer as a hex string
 	%*phD	00-01-02- ... -3f
 	%*phN	000102 ... 3f
 
-For printing small buffers (up to 64 bytes long) as a hex string with a
-certain separator. For larger buffers consider using
-:c:func:`print_hex_dump`.
+For printing small buffers (up to 256 bytes long) as a hex string with a
+certain separator. For buffers larger than 64 bytes consider using
+:c:func:`print_hex_dump` as its output can be more easily counted.
 
 MAC/FDDI addresses
 ------------------
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 2a6c767cc2709..be6fa9fab1be8 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1194,7 +1194,7 @@ char *hex_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
 	}
 
 	if (spec.field_width > 0)
-		len = min_t(int, spec.field_width, 64);
+		len = min_t(int, spec.field_width, 256);
 
 	for (i = 0; i < len; ++i) {
 		if (buf < end)


Powered by blists - more mailing lists