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: <20201113141542.GJ3576660@ZenIV.linux.org.uk>
Date:   Fri, 13 Nov 2020 14:15:42 +0000
From:   Al Viro <viro@...iv.linux.org.uk>
To:     Björn Töpel <bjorn.topel@...il.com>
Cc:     Jean-Philippe Brucker <jean-philippe@...aro.org>,
        Netdev <netdev@...r.kernel.org>, bpf <bpf@...r.kernel.org>,
        Tom Herbert <tom@...bertland.com>,
        Anders Roxell <anders.roxell@...il.com>,
        linux-riscv <linux-riscv@...ts.infradead.org>,
        linux-arm-kernel@...ts.infradead.org
Subject: Re: csum_partial() on different archs (selftest/bpf)

On Fri, Nov 13, 2020 at 02:22:16PM +0100, Björn Töpel wrote:

> Folding Al's input to this reply.
> 
> I think the bpf_csum_diff() is supposed to be used in combination with
> another helper(s) (e.g. bpf_l4_csum_replace) so I'd guess the returned
> __wsum should be seen as an opaque value, not something BPF userland
> can rely on.

Why not reduce the sucker modulo 0xffff before returning it?  Incidentally,
implementation is bloody awful:

        /* This is quite flexible, some examples:
         *
         * from_size == 0, to_size > 0,  seed := csum --> pushing data
         * from_size > 0,  to_size == 0, seed := csum --> pulling data
         * from_size > 0,  to_size > 0,  seed := 0    --> diffing data
         *
         * Even for diffing, from_size and to_size don't need to be equal.
         */
        if (unlikely(((from_size | to_size) & (sizeof(__be32) - 1)) ||
                     diff_size > sizeof(sp->diff)))
                return -EINVAL;

        for (i = 0; i < from_size / sizeof(__be32); i++, j++)
                sp->diff[j] = ~from[i];
        for (i = 0; i <   to_size / sizeof(__be32); i++, j++)
                sp->diff[j] = to[i];

        return csum_partial(sp->diff, diff_size, seed);

What the hell is this (copying, scratchpad, etc.) for?  First of all,
_if_ you want to use csum_partial() at all (and I'm not at all sure
that it won't be cheaper to just go over two arrays, doing csum_add()
and csum_sub() resp. - depends upon the realistic sizes), you don't
need to copy anything.  Find the sum of from, find the sum of to and
then subtract (csum_sub()) the old sum from the seed and and add the
new one...

And I would strongly recommend to change the calling conventions of that
thing - make it return __sum16.  And take __sum16 as well...

Again, exposing __wsum to anything that looks like a stable ABI is
a mistake - it's an internal detail that can be easily abused,
causing unpleasant compat problems.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ