Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1623576ybk; Sat, 16 May 2020 17:50:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPNMKUdgtIOt/qSCxze7iXtNPRsDJnTWKQf7JclqzrUbIyhYMxR0FLXj90NDbnUICgaf3u X-Received: by 2002:a17:906:7e56:: with SMTP id z22mr9063330ejr.60.1589676609155; Sat, 16 May 2020 17:50:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589676609; cv=none; d=google.com; s=arc-20160816; b=Lexl17lRTIlxIJceC2QRXTf+B3IjYQwiOqJg80AMM2vReB4Foc4esTpgCoXliG77Q6 VnQZk06aKHrUAXekGe1Vg4U9wFdmhrM74xIKgzvW2p3/mpdGsPr0JBEiqsX8uXmAEyXR xPhvTPg250aHGFw1h8UxrgZ1r58JevrPjAjvPNTwRMLAkGNipjiL8FJB+JS/gk/55ycB K0eh/wgQR6eG6T5Y3IItL/88xpzwtgTzYhZhcflduhPz0yZJ5Wo01yQceoIEYnPN1KNo rzUcUJASoNvrhGJmsl1c8mDvvt0mJezm+Ns/yULg5gakcQ+RKxwDB0dP8TlK/5sJQiRw 7d4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=oXEwYMh56jP/jhXSylitEbrYxOmXJzOOvEwzfWzqxsY=; b=nSD4CxhSs6a6dLnQevPokiEYhgIs9T8el3a1Ekk8kjxhdEvbGQ2lCP8MAyI64A+33g NflSbRyq427fAOAM0iY4PGKtcFGjhqgyGOvl4W9JH9fFY8GKPP0Pj3G7Vk9soFFUkJW2 g6JjNqC8JOaB7HPibLqevyl7PlqlBGWBtEBlh1kyaM3tKdCTIrW/S2resOFE+k4HocoN n2/02Y8TTLRqV+M2MWMTbVto2b24xvEbAvbVN11Rtk5FolI4M7zWalG9NiGFQiTdb3Vl ESv3EDWiWjlXtC1AerItKGRWKpcdJ/jVbL6IesIFVtCNu+dSLD/T8eLoFXM5MdMk8Rgj CaGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=qAKXBD7I; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q24si3112736ejc.399.2020.05.16.17.49.34; Sat, 16 May 2020 17:50:09 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=qAKXBD7I; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726834AbgEQAoy (ORCPT + 99 others); Sat, 16 May 2020 20:44:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726295AbgEQAoy (ORCPT ); Sat, 16 May 2020 20:44:54 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C368C061A0C; Sat, 16 May 2020 17:44:54 -0700 (PDT) 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: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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?