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=-0.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 6AB6CC433E0 for ; Sun, 17 May 2020 00:44:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0DB51206F4 for ; Sun, 17 May 2020 00:44:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="qAKXBD7I" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0DB51206F4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A4F8D900002; Sat, 16 May 2020 20:44:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A019E8E0001; Sat, 16 May 2020 20:44:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F005900002; Sat, 16 May 2020 20:44:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0129.hostedemail.com [216.40.44.129]) by kanga.kvack.org (Postfix) with ESMTP id 765B98E0001 for ; Sat, 16 May 2020 20:44:50 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 3DCAD180AD807 for ; Sun, 17 May 2020 00:44:50 +0000 (UTC) X-FDA: 76824365940.14.hand59_29ecb37337f19 X-HE-Tag: hand59_29ecb37337f19 X-Filterd-Recvd-Size: 3574 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Sun, 17 May 2020 00:44:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=oXEwYMh56jP/jhXSylitEbrYxOmXJzOOvEwzfWzqxsY=; b=qAKXBD7IRVa5nZGnQMYp7EAHiS QHFpaF2P1IVwaqinpvrE797uhAPmiooSzWNW6DLG0iVscFGcXXrfhWHtWiLxWf9WKnYYZX09j8GKd N9/um3djtTvFtOW9I4vj7jCkKZMKmLkNLhFHE4q5FuAOBA5m5IvCHZqN9SN4PwIvmtMfb0I1BX+yg Zrqc6/XeNs+SHPvs0JIMfcUS7zvVxwdp8J/jeeh0TP0kI1QDOvgvS15/TKc04HnMXO/0kxj+h9lhu ZU8I6fv8ZSjXvNJAiYKZ9oESe5BiihA7RGH76iy5krBASPeFxB02doNP1BdoOpBtu01hQmczm8iJw 5tlBWcfA==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1ja7Px-0005su-Jb; Sun, 17 May 2020 00:44:37 +0000 Date: Sat, 16 May 2020 17:44:37 -0700 From: Matthew Wilcox To: Balbir Singh Cc: Waiman Long , Andrew Morton , David Howells , Jarkko Sakkinen , James Morris , "Serge E. Hallyn" , linux-mm@kvack.org, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, Linus Torvalds , Joe Perches , David Rientjes Subject: Re: [PATCH v3] mm: Add kvfree_sensitive() for freeing sensitive data objects Message-ID: <20200517004437.GN16070@bombadil.infradead.org> References: <20200407200318.11711-1-longman@redhat.com> <1158ff38-c65d-379f-8ae7-6f507d9fc8dd@gmail.com> <20200514120018.GA16070@bombadil.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Sun, May 17, 2020 at 10:27:39AM +1000, Balbir Singh wrote: > On 14/5/20 10:00 pm, Matthew Wilcox wrote: > > On Thu, May 14, 2020 at 09:00:40PM +1000, Balbir Singh wrote: > >> I wonder if the right thing to do is also to disable pre-emption, just so that the thread does not linger on with sensitive data. > >> > >> void kvfree_sensitive(const void *addr, size_t len) > >> { > >> preempt_disable(); > >> if (likely(!ZERO_OR_NULL_PTR(addr))) { > >> memzero_explicit((void *)addr, len); > >> kvfree(addr); > >> } > >> preempt_enable(); > >> } > >> EXPORT_SYMBOL(kvfree_sensitive); > > > > If it's _that_ sensitive then the caller should have disabled preemption. > > Because preemption could otherwise have occurred immediately before > > kvfree_sensitive() was called. > > > > May be, but the callers of the API have to be explictly aware of the contract. > I don't disagree with you on what you've said, but I was referring to the > intent of freeing sensitive data vs the turn around time for doing so. It's the caller's information. They should be aware of their own requirements. If they do something like: p = kmalloc(); preempt_disable(); construct(p); use(p); preempt_enable(); kvfree_sensitive(p); there's really nothing we can do to help them inside kvfree_sensitive(). Actually, can you come up with a scenario where disabling preemption inside kvfree_sensitive() will help with anything?