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: <ZVTTbuviH9/RWYyI@casper.infradead.org>
Date:   Wed, 15 Nov 2023 14:19:26 +0000
From:   Matthew Wilcox <willy@...radead.org>
To:     José Pekkarinen <jose.pekkarinen@...hound.fi>
Cc:     akpm@...ux-foundation.org, skhan@...uxfoundation.org,
        linux-mm@...ck.org, linux-kernel@...r.kernel.org,
        linux-kernel-mentees@...ts.linux.dev,
        syzbot+89edd67979b52675ddec@...kaller.appspotmail.com,
        Hugh Dickins <hughd@...gle.com>
Subject: Re: [PATCH] mm/pgtable: return null if no ptl in
 __pte_offset_map_lock

On Wed, Nov 15, 2023 at 08:55:05AM +0200, José Pekkarinen wrote:
> Documentation of __pte_offset_map_lock suggest there is situations where

You should have cc'd Hugh who changed all this code recently.

> a pmd may not have a corresponding page table, in which case it should
> return NULL without changing ptlp. Syzbot found its ways to produce a
> NULL dereference in the function showing this case. This patch will
> provide the exit path suggested if this unlikely situation turns up. The
> output of the kasan null-ptr-report follows:

There's no need to include all this nonsense in the changelog.

>  spin_lock include/linux/spinlock.h:351 [inline]
>  __pte_offset_map_lock+0x154/0x360 mm/pgtable-generic.c:373
>  pte_offset_map_lock include/linux/mm.h:2939 [inline]
>  filemap_map_pages+0x698/0x11f0 mm/filemap.c:3582

This was the only interesting part.

> +++ b/include/linux/mm.h
> @@ -2854,7 +2854,7 @@ void ptlock_free(struct ptdesc *ptdesc);
>  
>  static inline spinlock_t *ptlock_ptr(struct ptdesc *ptdesc)
>  {
> -	return ptdesc->ptl;
> +	return (likely(ptdesc)) ? ptdesc->ptl : NULL;
>  }

I don't think we should be changing ptlock_ptr().

> +++ b/mm/pgtable-generic.c
> @@ -370,6 +370,8 @@ pte_t *__pte_offset_map_lock(struct mm_struct *mm, pmd_t *pmd,
>  	if (unlikely(!pte))
>  		return pte;
>  	ptl = pte_lockptr(mm, &pmdval);
> +	if (unlikely(!ptl))
> +		return NULL;
>  	spin_lock(ptl);

I don't understand how this could possibly solve the problem.  If there's
no PTE level, then __pte_offset_map() should return NULL and we'd already
return due to the check for !pte.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ