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=-2.4 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 8E3B7C433E1 for ; Mon, 18 May 2020 02:39:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4DEDF207BB for ; Mon, 18 May 2020 02:39:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="cwEvrV8h" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4DEDF207BB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CCDF680006; Sun, 17 May 2020 22:39:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C7E99900002; Sun, 17 May 2020 22:39:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B6CFA80006; Sun, 17 May 2020 22:39:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0125.hostedemail.com [216.40.44.125]) by kanga.kvack.org (Postfix) with ESMTP id 97A2E900002 for ; Sun, 17 May 2020 22:39:49 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 2B79B283D for ; Mon, 18 May 2020 02:39:49 +0000 (UTC) X-FDA: 76828284498.27.group72_55a5b4c46604a X-HE-Tag: group72_55a5b4c46604a X-Filterd-Recvd-Size: 4183 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Mon, 18 May 2020 02:39:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589769587; 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=7BmqVj8mU9rcSdcf5+RisNrhRwO2BSlPP3QfZ4VXAm0=; b=cwEvrV8hNPR2zgNfHExM09iCW1bHLtNNuiqsln333ry3/h0Won+Pw1+u8g1jNbPyvpx405 qUn7YcyxE3Ce2r1JGws7NnSF3ty+l0UWG0yf9gFvwBZmemi8cMqCMypUsn/q8XgDF7SjU2 x3xfSh40Z+d6wuQYqAby0WADPwJLoK0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-208-ltZH9LsiM3eX2tKIFqX5iw-1; Sun, 17 May 2020 22:39:43 -0400 X-MC-Unique: ltZH9LsiM3eX2tKIFqX5iw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5F4711800D42; Mon, 18 May 2020 02:39:41 +0000 (UTC) Received: from llong.remote.csb (ovpn-112-120.rdu2.redhat.com [10.10.112.120]) by smtp.corp.redhat.com (Postfix) with ESMTP id 260985C1B2; Mon, 18 May 2020 02:39:39 +0000 (UTC) Subject: Re: [PATCH v3] mm: Add kvfree_sensitive() for freeing sensitive data objects To: Balbir Singh , Matthew Wilcox Cc: 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 References: <20200407200318.11711-1-longman@redhat.com> <1158ff38-c65d-379f-8ae7-6f507d9fc8dd@gmail.com> <20200514120018.GA16070@bombadil.infradead.org> From: Waiman Long Organization: Red Hat Message-ID: <365c8e0c-5d92-f032-b9ff-f64a8d314dfe@redhat.com> Date: Sun, 17 May 2020 22:39:38 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 5/16/20 8:27 PM, 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. We can't disable preemption like that. The vfree() call may potentially sleep. It could be a mess to keep track of the preemption state to make that works. The purpose of this API is to make sure that a newly allocated memory block won't contain secret left behind from another task. There is no guarantee on how long the freeing process will take. Cheers, Longman