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 X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78579C433B4 for ; Fri, 14 May 2021 09:29:30 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C8E23613F6 for ; Fri, 14 May 2021 09:29:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C8E23613F6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:Cc:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ALvCqGKZ0b4meFf+MLbXjvd0GUKgW0Il8VXxMVIg5wo=; b=XEeCcVU0y440454C+md+mc0RN k/oTyx/yudO7j7vLUurllebRsVYbOAGF/CB4ZJcn9U1cPIOr+Rre047GWrQ1hWcck6666AdN599ec 1t1FocbNEfkHo8Xq3P4T/YbVc9p6SOYRSdDVsl6Ln05F11bwXs9a5X/gyZEkpIROUZSCZBxeaIx6S s2DE6+y/V+NWfe7wzVWXZCSUVSJyg5jBwHV3mDvlakQWQcpJ+CRAE7GkyQIadekzKydkSUaVJACWu z7WSNhm++WgXA0HVIRdBMepJc+qKio010jIzqbQuF25Dd4zZ1NFQ6hyQ6YNGRyozwM3LZUNNPFxSN f3ihIc/wQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lhU6O-007d0Y-2R; Fri, 14 May 2021 09:27:24 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lhU6J-007cyq-V1 for linux-arm-kernel@desiato.infradead.org; Fri, 14 May 2021 09:27:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: Content-Type:In-Reply-To:MIME-Version:Date:Message-ID:From:References:Cc:To: Subject:Sender:Reply-To:Content-ID:Content-Description; bh=yW2asbdUagGat2ijahWn20ew93BwpmErRmbUGUDMNcY=; b=d1eEDp+yorkXdxcEX+xcb3jfel RltwxvsSUW2rwU0AvOIZdSxlfY8Ipq69UCCYj4zmB1TcHoDJp+Y64RpL4tWbZkcNQ7TuvYFHYYqC+ ujxrpp07hcx9FzzUpYQl3Vyo8AX6mnTm6iJUgJ/SzMLTQigvnF99FpY41hTO+22DZwTKBZiMm5qeM ionchFv0nIi9o6jYHZ0t/T7L0RDszH9XkdYnsWPXG4cdNDnWFYgNtJv5ZSLhbQA7R1i05LtGPnKL+ hqU3mUlV1+HZ8fRd/UnTH/vEYLLqlhoCm6eTjO9tinEu5lI95TqWZCVB5Kv9DRgwiCrldTb/SmE0g Y9+AKrKw==; Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lhU6H-00BrGq-5q for linux-arm-kernel@lists.infradead.org; Fri, 14 May 2021 09:27:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620984436; 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=yW2asbdUagGat2ijahWn20ew93BwpmErRmbUGUDMNcY=; b=PesLttMemUFfXv4leFnnycKMR7EyGaoYpAU0v/r5JNdfxLgHyxhvVKxVgyPgmx44r89nP9 10WPakKrV9JVSb8BKJGMMsZ+hUub63RAcAXtv+PL123B+nE0AfDbP39bZ241uPW4lmE0XM 6e/IqPFzISJ2mkN1o9bFvg2F3HLhM5c= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-64-9tqvb9ZXNwW7BohJUgN-SQ-1; Fri, 14 May 2021 05:27:14 -0400 X-MC-Unique: 9tqvb9ZXNwW7BohJUgN-SQ-1 Received: by mail-ed1-f71.google.com with SMTP id d8-20020a0564020008b0290387d38e3ce0so16075606edu.1 for ; Fri, 14 May 2021 02:27:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; 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=yW2asbdUagGat2ijahWn20ew93BwpmErRmbUGUDMNcY=; b=J8E1R5/hiODk8iUod2szvekPBqGL/vj6EFuPZ1b9gyr484QvGT/ASAYFZLH2VBNR8x ZIvdmxj7QsF6t0vr9kGw1vM+toFx5KyweF/ssZo31GBN8qfpqfZYEk0SLv378M2L6ZxT irRrvMCabyx82dfsMu6z/qLIgYWz611CFIMNl0qv8KlCo9JGCrx3scs0KMk4LnlW5pnx MuUqksX8KTeBdgKuh919dXCp+zaZOePJM5HOCZzDs+FHyRn1i8NR7WNfjICg/T+Pwq4T 56ENFI2bhezd1/Mg8vgYOJfJIcHCDx1/BWS2OvEtbvpHTLCLivSiVUggeO1HGxZxfd1x pbUQ== X-Gm-Message-State: AOAM531UTghZzo6Of3RWtRj6mPamOMg1j3rr/NLARUYsA9AQx9nxU5rx BvKJQh0eWk2EGHj2IN6VQ7aOINBKa8+e3wCbDRQiWBGxMVNahQBuKf8OSoLiyAQqkKb5geu2SNQ o8+W2RazN6jimIQSDzKQSohia8MtYrphVcIQ= X-Received: by 2002:a05:6402:10c6:: with SMTP id p6mr55735289edu.241.1620984433538; Fri, 14 May 2021 02:27:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEtOCv5Ls17oMjk/nlAqkQoSV5N2CP4kQHSOXjzJBX9acMLtoFBB9xjtabyDhiKP+sEIswPA== X-Received: by 2002:a05:6402:10c6:: with SMTP id p6mr55735269edu.241.1620984433367; Fri, 14 May 2021 02:27:13 -0700 (PDT) Received: from [192.168.3.132] (p5b0c6501.dip0.t-ipconnect.de. [91.12.101.1]) by smtp.gmail.com with ESMTPSA id m9sm3510728ejj.53.2021.05.14.02.27.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 14 May 2021 02:27:13 -0700 (PDT) Subject: Re: [PATCH v19 6/8] PM: hibernate: disable when there are active secretmem users To: Mike Rapoport , Andrew Morton Cc: Alexander Viro , Andy Lutomirski , Arnd Bergmann , Borislav Petkov , Catalin Marinas , Christopher Lameter , Dan Williams , Dave Hansen , Elena Reshetova , "H. Peter Anvin" , Hagen Paul Pfeifer , Ingo Molnar , James Bottomley , Kees Cook , "Kirill A. Shutemov" , Matthew Wilcox , Matthew Garrett , Mark Rutland , Michal Hocko , Mike Rapoport , Michael Kerrisk , Palmer Dabbelt , Palmer Dabbelt , Paul Walmsley , Peter Zijlstra , "Rafael J. Wysocki" , Rick Edgecombe , Roman Gushchin , Shakeel Butt , Shuah Khan , Thomas Gleixner , Tycho Andersen , Will Deacon , Yury Norov , linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-nvdimm@lists.01.org, linux-riscv@lists.infradead.org, x86@kernel.org References: <20210513184734.29317-1-rppt@kernel.org> <20210513184734.29317-7-rppt@kernel.org> From: David Hildenbrand Organization: Red Hat Message-ID: Date: Fri, 14 May 2021 11:27:11 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210513184734.29317-7-rppt@kernel.org> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210514_022717_332204_D591B234 X-CRM114-Status: GOOD ( 32.05 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 13.05.21 20:47, Mike Rapoport wrote: > From: Mike Rapoport > > It is unsafe to allow saving of secretmem areas to the hibernation > snapshot as they would be visible after the resume and this essentially > will defeat the purpose of secret memory mappings. > > Prevent hibernation whenever there are active secret memory users. > > Signed-off-by: Mike Rapoport > Cc: Alexander Viro > Cc: Andy Lutomirski > Cc: Arnd Bergmann > Cc: Borislav Petkov > Cc: Catalin Marinas > Cc: Christopher Lameter > Cc: Dan Williams > Cc: Dave Hansen > Cc: David Hildenbrand > Cc: Elena Reshetova > Cc: Hagen Paul Pfeifer > Cc: "H. Peter Anvin" > Cc: Ingo Molnar > Cc: James Bottomley > Cc: "Kirill A. Shutemov" > Cc: Mark Rutland > Cc: Matthew Wilcox > Cc: Michael Kerrisk > Cc: Palmer Dabbelt > Cc: Palmer Dabbelt > Cc: Paul Walmsley > Cc: Peter Zijlstra > Cc: Rick Edgecombe > Cc: Roman Gushchin > Cc: Shakeel Butt > Cc: Shuah Khan > Cc: Thomas Gleixner > Cc: Tycho Andersen > Cc: Will Deacon > --- > include/linux/secretmem.h | 6 ++++++ > kernel/power/hibernate.c | 5 ++++- > mm/secretmem.c | 15 +++++++++++++++ > 3 files changed, 25 insertions(+), 1 deletion(-) > > diff --git a/include/linux/secretmem.h b/include/linux/secretmem.h > index e617b4afcc62..21c3771e6a56 100644 > --- a/include/linux/secretmem.h > +++ b/include/linux/secretmem.h > @@ -30,6 +30,7 @@ static inline bool page_is_secretmem(struct page *page) > } > > bool vma_is_secretmem(struct vm_area_struct *vma); > +bool secretmem_active(void); > > #else > > @@ -43,6 +44,11 @@ static inline bool page_is_secretmem(struct page *page) > return false; > } > > +static inline bool secretmem_active(void) > +{ > + return false; > +} > + > #endif /* CONFIG_SECRETMEM */ > > #endif /* _LINUX_SECRETMEM_H */ > diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c > index da0b41914177..559acef3fddb 100644 > --- a/kernel/power/hibernate.c > +++ b/kernel/power/hibernate.c > @@ -31,6 +31,7 @@ > #include > #include > #include > +#include > #include > > #include "power.h" > @@ -81,7 +82,9 @@ void hibernate_release(void) > > bool hibernation_available(void) > { > - return nohibernate == 0 && !security_locked_down(LOCKDOWN_HIBERNATION); > + return nohibernate == 0 && > + !security_locked_down(LOCKDOWN_HIBERNATION) && > + !secretmem_active(); > } > > /** > diff --git a/mm/secretmem.c b/mm/secretmem.c > index 1ae50089adf1..7c2499e4de22 100644 > --- a/mm/secretmem.c > +++ b/mm/secretmem.c > @@ -40,6 +40,13 @@ module_param_named(enable, secretmem_enable, bool, 0400); > MODULE_PARM_DESC(secretmem_enable, > "Enable secretmem and memfd_secret(2) system call"); > > +static atomic_t secretmem_users; > + > +bool secretmem_active(void) > +{ > + return !!atomic_read(&secretmem_users); > +} > + > static vm_fault_t secretmem_fault(struct vm_fault *vmf) > { > struct address_space *mapping = vmf->vma->vm_file->f_mapping; > @@ -94,6 +101,12 @@ static const struct vm_operations_struct secretmem_vm_ops = { > .fault = secretmem_fault, > }; > > +static int secretmem_release(struct inode *inode, struct file *file) > +{ > + atomic_dec(&secretmem_users); > + return 0; > +} > + > static int secretmem_mmap(struct file *file, struct vm_area_struct *vma) > { > unsigned long len = vma->vm_end - vma->vm_start; > @@ -116,6 +129,7 @@ bool vma_is_secretmem(struct vm_area_struct *vma) > } > > static const struct file_operations secretmem_fops = { > + .release = secretmem_release, > .mmap = secretmem_mmap, > }; > > @@ -202,6 +216,7 @@ SYSCALL_DEFINE1(memfd_secret, unsigned int, flags) > file->f_flags |= O_LARGEFILE; > > fd_install(fd, file); > + atomic_inc(&secretmem_users); > return fd; > > err_put_fd: > It looks a bit racy, but I guess we don't really care about these corner cases. Acked-by: David Hildenbrand -- Thanks, David / dhildenb _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel