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:   Mon, 29 Apr 2019 12:44:14 +0200
From:   Nicholas Mc Guire <der.herr@...r.at>
To:     Edward Cree <ecree@...arflare.com>
Cc:     Nicholas Mc Guire <hofrat@...dl.org>,
        Jamal Hadi Salim <jhs@...atatu.com>,
        Cong Wang <xiyou.wangcong@...il.com>,
        Jiri Pirko <jiri@...nulli.us>,
        "David S. Miller" <davem@...emloft.net>, netdev@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH] net_sched: force endianness annotation

On Mon, Apr 29, 2019 at 11:11:20AM +0100, Edward Cree wrote:
> On 28/04/2019 06:54, Nicholas Mc Guire wrote:
> > While the endiannes is being handled correctly sparse was unhappy with
> > the missing annotation as be16_to_cpu()/be32_to_cpu() expects a __be16
> > respectively __be32.
> [...]
> > diff --git a/net/sched/em_cmp.c b/net/sched/em_cmp.c
> > index 1c8360a..3045ee1 100644
> > --- a/net/sched/em_cmp.c
> > +++ b/net/sched/em_cmp.c
> > @@ -41,7 +41,7 @@ static int em_cmp_match(struct sk_buff *skb, struct tcf_ematch *em,
> >  		val = get_unaligned_be16(ptr);
> >  
> >  		if (cmp_needs_transformation(cmp))
> > -			val = be16_to_cpu(val);
> > +			val = be16_to_cpu((__force __be16)val);
> >  		break;
> There should probably be a comment here to explain what's going on.  TBH
>  it's probably a good general rule that any use of __force should have a
>  comment explaining why it's needed.
> AFAICT, get_unaligned_be16(ptr) is (barring alignment) equivalent to
>  be16_to_cpu(*(__be16 *)ptr).  But then calling be16_to_cpu() again on
>  val is bogus; it's already CPU endian.  There's a distinct lack of
>  documentation around as to the intended semantics of TCF_EM_CMP_TRANS,
>  but it would seem either (__force u16)cpu_to_be16(val); (which preserves
>  the existing semantics, that trans is a no-op on BE) or swab16(val);
>  would make more sense.
>
be16_to_cpu((__force __be16)val) should be a NOP on big-endian as well - 
atleast that is how I understood it (usr/include/linux/byteorder/big_endian.h).

The problem with using swab16 is that it is impating the binary significantly
so I'm not sure if the change is really side-effect free - while the somewhat
brute force solution is evaluatable simply by diffing.
The swab16() solution seems cleaner than adding another layer of casting - 
but I just am unsure if
-                   val = be16_to_cpu(val);
+                   val = swab16(val);
is actually equivalent. For the original patch this can be checked

-rw-r--r-- 1 hofrat hofrat 2984 Apr 28 01:49 /tmp/em_cmp_force.o
-rw-r--r-- 1 hofrat hofrat 2984 Apr 28 01:49 /tmp/em_cmp_org.o
-rw-r--r-- 1 hofrat hofrat 3392 Apr 29 06:25 /tmp/em_cmp_swab.o
hofrat@...ian:~/linux-next$ diff /tmp/em_cmp_force.o /tmp/em_cmp_org.o
hofrat@...ian:~/linux-next$

which is why I prefered that solution. if swab16() is equivalent I' resend
a V2

thx!
hofrat

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ