All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@kernel.org>
To: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	linux-api@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] mm/hugetlb: Fix NULL-pointer dereference on 5-level paging machine
Date: Wed, 22 Nov 2017 13:47:23 +0100	[thread overview]
Message-ID: <20171122124723.pr2yazh2g3zqjula@dhcp22.suse.cz> (raw)
In-Reply-To: <20171122121921.64822-1-kirill.shutemov@linux.intel.com>

On Wed 22-11-17 15:19:21, Kirill A. Shutemov wrote:
> I've made mistake during converting hugetlb code to 5-level paging:
> in huge_pte_alloc() we have to use p4d_alloc(), not p4d_offset().
> Otherwise it leads to crash -- NULL-pointer dereference in pud_alloc()
> if p4d table is not yet allocated.

Ups, I have completely missed that when reviewing the patch. Sorry about
that.
 
> It only can happen in 5-level paging mode. In 4-level paging mode
> p4d_offset() always returns pgd, so we are fine.
> 
> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Fixes: c2febafc6773 ("mm: convert generic code to 5-level paging")
> Cc: <stable@vger.kernel.org> # v4.11+

Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  mm/hugetlb.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 2d2ff5e8bf2b..94a4c0b63580 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -4617,7 +4617,9 @@ pte_t *huge_pte_alloc(struct mm_struct *mm,
>  	pte_t *pte = NULL;
>  
>  	pgd = pgd_offset(mm, addr);
> -	p4d = p4d_offset(pgd, addr);
> +	p4d = p4d_alloc(mm, pgd, addr);
> +	if (!p4d)
> +		return NULL;
>  	pud = pud_alloc(mm, p4d, addr);
>  	if (pud) {
>  		if (sz == PUD_SIZE) {
> -- 
> 2.15.0

-- 
Michal Hocko
SUSE Labs

WARNING: multiple messages have this Message-ID (diff)
From: Michal Hocko <mhocko@kernel.org>
To: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	linux-api@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] mm/hugetlb: Fix NULL-pointer dereference on 5-level paging machine
Date: Wed, 22 Nov 2017 13:47:23 +0100	[thread overview]
Message-ID: <20171122124723.pr2yazh2g3zqjula@dhcp22.suse.cz> (raw)
In-Reply-To: <20171122121921.64822-1-kirill.shutemov@linux.intel.com>

On Wed 22-11-17 15:19:21, Kirill A. Shutemov wrote:
> I've made mistake during converting hugetlb code to 5-level paging:
> in huge_pte_alloc() we have to use p4d_alloc(), not p4d_offset().
> Otherwise it leads to crash -- NULL-pointer dereference in pud_alloc()
> if p4d table is not yet allocated.

Ups, I have completely missed that when reviewing the patch. Sorry about
that.
 
> It only can happen in 5-level paging mode. In 4-level paging mode
> p4d_offset() always returns pgd, so we are fine.
> 
> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Fixes: c2febafc6773 ("mm: convert generic code to 5-level paging")
> Cc: <stable@vger.kernel.org> # v4.11+

Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  mm/hugetlb.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 2d2ff5e8bf2b..94a4c0b63580 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -4617,7 +4617,9 @@ pte_t *huge_pte_alloc(struct mm_struct *mm,
>  	pte_t *pte = NULL;
>  
>  	pgd = pgd_offset(mm, addr);
> -	p4d = p4d_offset(pgd, addr);
> +	p4d = p4d_alloc(mm, pgd, addr);
> +	if (!p4d)
> +		return NULL;
>  	pud = pud_alloc(mm, p4d, addr);
>  	if (pud) {
>  		if (sz == PUD_SIZE) {
> -- 
> 2.15.0

-- 
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  parent reply	other threads:[~2017-11-22 12:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-22 12:19 [PATCH] mm/hugetlb: Fix NULL-pointer dereference on 5-level paging machine Kirill A. Shutemov
2017-11-22 12:19 ` Kirill A. Shutemov
2017-11-22 12:36 ` Vlastimil Babka
2017-11-22 12:36   ` Vlastimil Babka
2017-11-22 12:47 ` Michal Hocko [this message]
2017-11-22 12:47   ` Michal Hocko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171122124723.pr2yazh2g3zqjula@dhcp22.suse.cz \
    --to=mhocko@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.