From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6BA08C433F5 for ; Fri, 8 Oct 2021 10:46:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DFEBD60FF2 for ; Fri, 8 Oct 2021 10:46:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org DFEBD60FF2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 3D1D36B0071; Fri, 8 Oct 2021 06:46:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 35ADB6B0072; Fri, 8 Oct 2021 06:46:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1FB7C6B0073; Fri, 8 Oct 2021 06:46:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0033.hostedemail.com [216.40.44.33]) by kanga.kvack.org (Postfix) with ESMTP id 09E4D6B0071 for ; Fri, 8 Oct 2021 06:46:22 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id A9D4B1802030C for ; Fri, 8 Oct 2021 10:46:21 +0000 (UTC) X-FDA: 78672940962.21.CA7B3DB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf27.hostedemail.com (Postfix) with ESMTP id 34CAC7016DB2 for ; Fri, 8 Oct 2021 10:46:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633689980; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1ZrmeghbzDGDCRJyBgnjXu1u/BJe351JSfBE0ppWVUo=; b=Ua9IIyVbrLWZuE0S7KvoSL1mC/1cGJ1122efGD0wkT57ir7dz9o4m92Ld1YweiMBn/sK8h ZWau+6rQsXR9HPXVMYEpGjP7XG5+UICIwix5MU8WG33dEqiuob7q4xIayDx+kg57JkWpD7 KKTndx4HDEVZLcdkabL1yqwoAujYL4o= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-546-q3se9w8EO1COySGLQRtryw-1; Fri, 08 Oct 2021 06:46:19 -0400 X-MC-Unique: q3se9w8EO1COySGLQRtryw-1 Received: by mail-wr1-f71.google.com with SMTP id d13-20020adfa34d000000b00160aa1cc5f1so6981690wrb.14 for ; Fri, 08 Oct 2021 03:46:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=1ZrmeghbzDGDCRJyBgnjXu1u/BJe351JSfBE0ppWVUo=; b=FSfwBcaxph6nhzwtviYxbqWZg2so1bMuiSL20eC7WQAEGUMDYTFmqEEUndeu0khlqS zEKa8nUxcnU9IoabsTR3tQGeHHLIyGpdQXtEQ7GWciV4khcacfZWb5n69i8mEGqH3818 w0d6wPapZa5EpUwLcS/k6Xk+Yk+skjcr0SMPtEbvVmaKfBHsvi0rMBqcdz/MW+Z1edTB nhmiU7fyvzUWslnq/S6g2dtqk5WkGwUujk+26X2HNr4lfJwEaAD7tugGzHJgid3rGZZd QdYj0yhSPpGRvedJiSajvTG+CNmeBVFcHCpeDJf64KfbnY1IYg39xL1sXKGTd6RCZbJN vftQ== X-Gm-Message-State: AOAM53016lj4JDgknJbX40uVazWOWT2Cb1R0L3gNwUkjnG8xM362SJC3 NxUw9l4pMHuQ5WmkcsWGQU8RpYyGtbBON5OOxYxRovay0OE8nC7DsySxx8A1UYABp6HziyXrJ6d aniYOprddOtc= X-Received: by 2002:adf:f486:: with SMTP id l6mr2975689wro.375.1633689978350; Fri, 08 Oct 2021 03:46:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVvuDmQ2o7F+mPEUTq3C3d/JQl5S2sLgkDYkW1Y8AZnZBRM8c8KvitOhZtnoqmbIA0u2nEPg== X-Received: by 2002:adf:f486:: with SMTP id l6mr2975673wro.375.1633689978156; Fri, 08 Oct 2021 03:46:18 -0700 (PDT) Received: from [192.168.3.132] (p5b0c676e.dip0.t-ipconnect.de. [91.12.103.110]) by smtp.gmail.com with ESMTPSA id f16sm2169829wrr.53.2021.10.08.03.46.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 08 Oct 2021 03:46:17 -0700 (PDT) Subject: Re: [PATCH] mm: Fix NULL page->mapping dereference in page_is_secretmem() To: Sean Christopherson , Andrew Morton Cc: linux-kernel@vger.kernel.org, Mike Rapoport , linux-mm@kvack.org, "Darrick J . Wong" , Stephen References: <20211007231502.3552715-1-seanjc@google.com> From: David Hildenbrand Organization: Red Hat Message-ID: <97f7ae02-3124-8de5-f614-a2f7891645a5@redhat.com> Date: Fri, 8 Oct 2021 12:46:17 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20211007231502.3552715-1-seanjc@google.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 34CAC7016DB2 X-Stat-Signature: 9m7nw88eronbtja78fzmjfftekaarkcr Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ua9IIyVb; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf27.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com X-HE-Tag: 1633689981-19962 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 08.10.21 01:15, Sean Christopherson wrote: > Check for a NULL page->mapping before dereferencing the mapping in > page_is_secretmem(), as the page's mapping can be nullified while gup() > is running, e.g. by reclaim or truncation. > > BUG: kernel NULL pointer dereference, address: 0000000000000068 > #PF: supervisor read access in kernel mode > #PF: error_code(0x0000) - not-present page > PGD 0 P4D 0 > Oops: 0000 [#1] PREEMPT SMP NOPTI > CPU: 6 PID: 4173897 Comm: CPU 3/KVM Tainted: G W > RIP: 0010:internal_get_user_pages_fast+0x621/0x9d0 > Code: <48> 81 7a 68 80 08 04 bc 0f 85 21 ff ff 8 89 c7 be > RSP: 0018:ffffaa90087679b0 EFLAGS: 00010046 > RAX: ffffe3f37905b900 RBX: 00007f2dd561e000 RCX: ffffe3f37905b934 > RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffffe3f37905b900 > ... > CR2: 0000000000000068 CR3: 00000004c5898003 CR4: 00000000001726e0 > Call Trace: > get_user_pages_fast_only+0x13/0x20 > hva_to_pfn+0xa9/0x3e0 > try_async_pf+0xa1/0x270 > direct_page_fault+0x113/0xad0 > kvm_mmu_page_fault+0x69/0x680 > vmx_handle_exit+0xe1/0x5d0 > kvm_arch_vcpu_ioctl_run+0xd81/0x1c70 > kvm_vcpu_ioctl+0x267/0x670 > __x64_sys_ioctl+0x83/0xa0 > do_syscall_64+0x56/0x80 > entry_SYSCALL_64_after_hwframe+0x44/0xae > > Cc: Mike Rapoport > Cc: linux-mm@kvack.org > Reported-by: Darrick J. Wong > Reported-by: Stephen > Tested-by: Darrick J. Wong > Signed-off-by: Sean Christopherson > --- > include/linux/secretmem.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/include/linux/secretmem.h b/include/linux/secretmem.h > index 21c3771e6a56..988528b5da43 100644 > --- a/include/linux/secretmem.h > +++ b/include/linux/secretmem.h > @@ -23,7 +23,7 @@ static inline bool page_is_secretmem(struct page *page) > mapping = (struct address_space *) > ((unsigned long)page->mapping & ~PAGE_MAPPING_FLAGS); > > - if (mapping != page->mapping) > + if (!mapping || mapping != page->mapping) > return false; > > return mapping->a_ops == &secretmem_aops; > I assume we want to add Fixes: 1507f51255c9 ("mm: introduce memfd_secret system call to create "secret" memory areas") Cc: # v5.14 Reviewed-by: David Hildenbrand -- Thanks, David / dhildenb