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] [day] [month] [year] [list]
Date: Sat, 2 Mar 2024 00:17:42 +1300
From: Barry Song <21cnbao@...il.com>
To: Herbert Xu <herbert@...dor.apana.org.au>
Cc: David Miller <davem@...emloft.net>, linux-crypto@...r.kernel.org, 
	Andrew Morton <akpm@...ux-foundation.org>, LKML <linux-kernel@...r.kernel.org>, 
	Johannes Weiner <hannes@...xchg.org>, Chris Li <chriscli@...gle.com>, Chris Li <chrisl@...nel.org>, 
	Seth Jennings <sjenning@...hat.com>, Vitaly Wool <vitaly.wool@...sulko.com>, 
	Barry Song <v-songbaohua@...o.com>, Nhat Pham <nphamcs@...il.com>, 
	Yosry Ahmed <yosryahmed@...gle.com>, Chengming Zhou <zhouchengming@...edance.com>, 
	Matthew Wilcox <willy@...radead.org>, Kent Overstreet <kent.overstreet@...ux.dev>, 
	"Darrick J. Wong" <djwong@...nel.org>, Christoph Hellwig <hch@....de>, Al Viro <viro@...iv.linux.org.uk>
Subject: Re: [PATCH v6] crypto: scompress: remove memcpy if sg_nents is 1 and
 pages are lowmem

On Fri, Mar 1, 2024 at 11:28 PM Herbert Xu <herbert@...dor.apana.org.au> wrote:
>
> On Thu, Feb 22, 2024 at 03:06:17PM +1300, Barry Song wrote:
> >
> > -     scatterwalk_map_and_copy(scratch->src, req->src, 0, req->slen, 0);
> > +     if (sg_nents(req->src) == 1 && !PageHighMem(sg_page(req->src))) {
> > +             src = page_to_virt(sg_page(req->src)) + req->src->offset;
>
> Incidentally this made me look at other uses of PageHighMem in
> the kernel.
>
> The one in copy_page_from_iter_atomic looks buggy because it assumes
> that the kmap never maps a page if PageHighMem is false, which is not
> the case for CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP.

You are right. This needs to be fixed.

>
> > @@ -152,8 +165,12 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir)
> >                       ret = -ENOSPC;
> >                       goto out;
> >               }
> > -             scatterwalk_map_and_copy(scratch->dst, req->dst, 0, req->dlen,
> > -                                      1);
> > +             if (dst == scratch->dst) {
> > +                     scatterwalk_map_and_copy(scratch->dst, req->dst, 0,
> > +                                              req->dlen, 1);
> > +             } else {
> > +                     flush_dcache_page(sg_page(req->dst));
>
> I think this is still wrong for the > PAGE_SIZE case.  The existing
> code flushes each page sequentially  but the new code only flushes the
> first page.

right, can it be fixed like the below?

diff --git a/crypto/scompress.c b/crypto/scompress.c
index 185d2359f28b..d85f0318f273 100644
--- a/crypto/scompress.c
+++ b/crypto/scompress.c
@@ -169,7 +169,11 @@ static int scomp_acomp_comp_decomp(struct
acomp_req *req, int dir)
                        scatterwalk_map_and_copy(scratch->dst, req->dst, 0,
                                                 req->dlen, 1);
                } else {
-                       flush_dcache_page(sg_page(req->dst));
+                       int nr_pages = DIV_ROUND_UP(req->dst->offset +
req->dlen, PAGE_SIZE);
+                       int i;
+
+                       for (i = 0; i < nr_pages; i++)
+                               flush_dcache_page(sg_page(req->dst) + i);
                }
        }
 out:

>
> Thanks,
> --
> Email: Herbert Xu <herbert@...dor.apana.org.au>
> Home Page: http://gondor.apana.org.au/~herbert/
> PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
>

Thanks
Barry

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ