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: <20191216110539.2b268d86@gandalf.local.home>
Date:   Mon, 16 Dec 2019 11:05:39 -0500
From:   Steven Rostedt <rostedt@...dmis.org>
To:     David Laight <David.Laight@...LAB.COM>
Cc:     'Tom Zanussi' <zanussi@...nel.org>,
        Sven Schnelle <svens@...ckframe.org>,
        "linux-trace-devel@...r.kernel.org" 
        <linux-trace-devel@...r.kernel.org>,
        LKML <linux-kernel@...r.kernel.org>
Subject: Re: ftrace histogram sorting broken on BE architecures

On Mon, 16 Dec 2019 15:47:12 +0000
David Laight <David.Laight@...LAB.COM> wrote:

> > From: Tom Zanussi
> > Sent: 12 December 2019 19:17
> > On Wed, 2019-12-11 at 11:09 -0500, Steven Rostedt wrote:  
> > > On Wed, 11 Dec 2019 10:35:57 -0500
> > > Steven Rostedt <rostedt@...dmis.org> wrote:
> > >  
> > > > > Any thoughts on how to fix this? I'm not sure whether i fully
> > > > > understand the
> > > > > ftrace maps... ;-)  
> > > >
> > > > Your analysis makes sense. I'll take a deeper look at it.  
> > >
> > > Sven,
> > >
> > > Does this patch fix it for you?
> > >
> > > Tom,
> > >
> > > Correct me if I'm wrong, from what I can tell, all sums and keys are
> > > u64 unless they are a string. Thus, I believe this patch should not
> > > have any issues.  
> ...
> > > --- a/kernel/trace/tracing_map.c
> > > +++ b/kernel/trace/tracing_map.c
> > > @@ -148,8 +148,8 @@ static int tracing_map_cmp_atomic64(void *val_a,
> > > void *val_b)
> > >  #define DEFINE_TRACING_MAP_CMP_FN(type) 	\
> > >  static int tracing_map_cmp_##type(void *val_a, void *val_b) \
> > >  { \
> > > -	type a = *(type *)val_a; \
> > > -	type b = *(type *)val_b; \
> > > +	type a = (type)(*(u64 *)val_a); 	\
> > > +	type b = (type)(*(u64 *)val_b); 	\
> > > \
> > >  	return (a > b) ? 1 : ((a < b) ? -1 : 0); \
> > >  }  
> 
> That looks so horrid/wrong it can't be right on both BE and LE.

Well, the original is obviously not right for both BE and LE, but the
fix is:

	type a = (type)(*(u64 *)val_a);

Which breaks down to:

		(u64 *)val_a - make val_a a pointer to a u64 number

all values were written as u64.

	u64 data = (u64)original_val_a

Where original_val_a could be a byte, short, int, long or long long.

Now that we have (u64 *)val_a, we dereference it:

		*(u64 *)val_a - which gives us a u64 number.

This u64 number should be the same as the u64 data.

Then we convert this as:

		(type)(*(u64 *)val_a)

Taking the u64 number we retrieved and converted it back to the
original type that was recorded.

In other words, if the following should work:


	type a = x;
	u64 data = (u64)a;
	u64 *ptr = &data;
	u64 b_data = *ptr;
	type b = (type)b_data;

If b == a above, then there should be nothing wrong with this patch.

The compiler should know how to map those type conversions properly for
both BE and LE.

-- Steve

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ