Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2378857ybk; Sun, 17 May 2020 19:43:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPQLCQ4NsLmo+N2RwwdPzT2sq7Ql788n+F9ZE3QiCtn+BarcDKGakomtYjhxwPzFg3NR3H X-Received: by 2002:aa7:c0d1:: with SMTP id j17mr11990283edp.308.1589769836689; Sun, 17 May 2020 19:43:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589769836; cv=none; d=google.com; s=arc-20160816; b=Ke3gWt75i7da/5A95CLwy5E0GuB8f1bzYumsfW8xyzU4CwEvD0JK30zpn1w3ORg87N O0MyOHWuMkJVJc9rc1FhXGjEgWzt/2lIT3T4iHEz6OsMr21MQrrmubOPmLGt5Cl9Z53a VY9wDUIccTwenQCuAcuVw8CJHV192LIugAFT7ELZ81j4ps/BBvSyvjSuNy6WFlJMPSBp x2NEAsySN/GwrjhcYEew3VoQ6GtcstDQ8kk2tudcFDJTzIiyBsT00raFbChePrgYZBLB cYmX/+Mxj8eslOB1eFluM4PcT0jmBJVG4EQY44+LmHLxLYmzeMNmMTqbsuolybI/Ay9S elXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject :dkim-signature; bh=7BmqVj8mU9rcSdcf5+RisNrhRwO2BSlPP3QfZ4VXAm0=; b=YchO9yKOOnOiDgJUaBUBr3wPqqRMUuNkw18L6N6+UsxDWOs27dBjgmcCmZevrBkkPw FgaDjNYTr0k8VjIi/V5iOeQ64PUcN+0EkzdfYvtoh9TOV5qSh+AV7UxgiFMhBJp1r/Xn 0l7BG/z6n+kYIPFxVbO4RnqxIVsw9Q57fmCjfZeW4EIH/AUiBXXfYiapWWH3Mu1gEAC0 RJaHNNEpWO9xEBxRtYq4L6gih3xNioNaXplN1Vv9uF5Y2mhwhYyFnfGbvTmaGDR1n2dk kVt1iIKI4N+3bkw9f9ZHmXBjhHE9RZwc0hnK42U1ezr8KIryQ6f5wP4w4f6aZRtFJZvW PP3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cwEvrV8h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z3si5511498eda.578.2020.05.17.19.43.32; Sun, 17 May 2020 19:43:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cwEvrV8h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726729AbgERCjs (ORCPT + 99 others); Sun, 17 May 2020 22:39:48 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:22855 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726680AbgERCjs (ORCPT ); Sun, 17 May 2020 22:39:48 -0400 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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