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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMn1gO55p_Vz0wrSqHxJ0nw_bncEyja8=mBedY29=8UdC3ejww@mail.gmail.com>
Date:   Tue, 16 May 2023 19:13:40 -0700
From:   Peter Collingbourne <pcc@...gle.com>
To:     David Hildenbrand <david@...hat.com>
Cc:     Catalin Marinas <catalin.marinas@....com>,
        Qun-wei Lin (林群崴) 
        <Qun-wei.Lin@...iatek.com>, linux-arm-kernel@...ts.infradead.org,
        linux-mm@...ck.org, linux-kernel@...r.kernel.org,
        "surenb@...gle.com" <surenb@...gle.com>,
        Chinwen Chang (張錦文) 
        <chinwen.chang@...iatek.com>,
        "kasan-dev@...glegroups.com" <kasan-dev@...glegroups.com>,
        Kuan-Ying Lee (李冠穎) 
        <Kuan-Ying.Lee@...iatek.com>,
        Casper Li (李中榮) <casper.li@...iatek.com>,
        "gregkh@...uxfoundation.org" <gregkh@...uxfoundation.org>,
        vincenzo.frascino@....com,
        Alexandru Elisei <alexandru.elisei@....com>, will@...nel.org,
        eugenis@...gle.com, Steven Price <steven.price@....com>,
        stable@...r.kernel.org
Subject: Re: [PATCH 1/3] mm: Move arch_do_swap_page() call to before swap_free()

On Tue, May 16, 2023 at 5:40 AM David Hildenbrand <david@...hat.com> wrote:
>
> On 16.05.23 02:16, Peter Collingbourne wrote:
> > On Sat, May 13, 2023 at 05:29:53AM +0200, David Hildenbrand wrote:
> >> On 13.05.23 01:57, Peter Collingbourne wrote:
> >>> Commit c145e0b47c77 ("mm: streamline COW logic in do_swap_page()") moved
> >>> the call to swap_free() before the call to set_pte_at(), which meant that
> >>> the MTE tags could end up being freed before set_pte_at() had a chance
> >>> to restore them. One other possibility was to hook arch_do_swap_page(),
> >>> but this had a number of problems:
> >>>
> >>> - The call to the hook was also after swap_free().
> >>>
> >>> - The call to the hook was after the call to set_pte_at(), so there was a
> >>>     racy window where uninitialized metadata may be exposed to userspace.
> >>>     This likely also affects SPARC ADI, which implements this hook to
> >>>     restore tags.
> >>>
> >>> - As a result of commit 1eba86c096e3 ("mm: change page type prior to
> >>>     adding page table entry"), we were also passing the new PTE as the
> >>>     oldpte argument, preventing the hook from knowing the swap index.
> >>>
> >>> Fix all of these problems by moving the arch_do_swap_page() call before
> >>> the call to free_page(), and ensuring that we do not set orig_pte until
> >>> after the call.
> >>>
> >>> Signed-off-by: Peter Collingbourne <pcc@...gle.com>
> >>> Suggested-by: Catalin Marinas <catalin.marinas@....com>
> >>> Link: https://linux-review.googlesource.com/id/I6470efa669e8bd2f841049b8c61020c510678965
> >>> Cc: <stable@...r.kernel.org> # 6.1
> >>> Fixes: ca827d55ebaa ("mm, swap: Add infrastructure for saving page metadata on swap")
> >>> Fixes: 1eba86c096e3 ("mm: change page type prior to adding page table entry")
> >>
> >> I'm confused. You say c145e0b47c77 changed something (which was after above
> >> commits), indicate that it fixes two other commits, and indicate "6.1" as
> >> stable which does not apply to any of these commits.
> >
> > Sorry, the situation is indeed a bit confusing.
> >
> > - In order to make the arch_do_swap_page() hook suitable for fixing the
> >    bug introduced by c145e0b47c77, patch 1 addresses a number of issues,
> >    including fixing bugs introduced by ca827d55ebaa and 1eba86c096e3,
> >    but we haven't fixed the c145e0b47c77 bug yet, so there's no Fixes:
> >    tag for it yet.
> >
> > - Patch 2, relying on the fixes in patch 1, makes MTE install an
> >    arch_do_swap_page() hook (indirectly, by making arch_swap_restore()
> >    also hook arch_do_swap_page()), thereby fixing the c145e0b47c77 bug.
> >
>
> Oh. That's indeed confusing. Maybe that should all be squashed to have
> one logical fix for the overall problem. It's especially confusing
> because this patch here fixes the other two issues touches code moved by
> c145e0b47c77.

Maybe. It can sometimes be hard to reconcile "one logical change per
patch" with "bug requires more than one logical change to fix" though.
Fortunately in this case I think we have an approach that fixes the
bug in one logical change, with some followup patches to clean things
up.

> > - 6.1 is the first stable version in which all 3 commits in my Fixes: tags
> >    are present, so that is the version that I've indicated in my stable
> >    tag for this series. In theory patch 1 could be applied to older kernel
> >    versions, but it wouldn't fix any problems that we are facing with MTE
> >    (because it only fixes problems relating to the arch_do_swap_page()
> >    hook, which older kernel versions don't hook with MTE), and there are
> >    some merge conflicts if we go back further anyway. If the SPARC folks
> >    (the previous only user of this hook) want to fix these issues with ADI,
> >    they can propose their own backport.
>
> Sometimes, it's a good idea to not specify a stable version and rather
> let the Fixes: tags imply that.

Yeah, but sometimes it's hard to say which way would be more
efficient. Either we spend time discussing why the version is
necessary or Greg spends time trying to apply patches to the wrong
trees because I wasn't more explicit...

Peter

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ