Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2163ybb; Tue, 7 Apr 2020 15:25:31 -0700 (PDT) X-Google-Smtp-Source: APiQypIDrJsSqTs+Ogy6vyU0i3kc+49Fea3Fr9PN8QQQ+J44/BWwW56dUIb3Tsulrtx/fxlNgdRU X-Received: by 2002:a9d:75d5:: with SMTP id c21mr3268959otl.223.1586298331218; Tue, 07 Apr 2020 15:25:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586298331; cv=none; d=google.com; s=arc-20160816; b=N6/5S/PSdQe185h8/KtWuYggqCmmIap7sXXtrN+8a17Rkt3z2gzGCZmx+Cr279SeVP LgQZ6AdahmluywQPlnyMB82OMx9Bo3xTQ2YO7nSxKKDLr3uhg+2SWKUYN/sH7SDaNuna Jy80/PRY+AhwsUostyt3uI6y3d7HqC/PaAWp+GIih8KI+QaGigUHTruLqE3B4xrZ1WzK 0OLHjctEFnE1rXSnPk0Yx2ggbHuA0k0oQOvm7iXSnj4fgnlFESQH7k4Y15/1pjDx6cW0 FxKSmG32/12Oj0Pi6y4CaZVt3pCD0I9Dy3ddKRNEI7losP8mulQH0wMyGz6ukzcjDwNE wwUA== 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=ilWPxxADWa3Mhatef/EKw7rS7FCyC/3gxiDqFnp+HLE=; b=0NjySvcnK9Ko4iITuswhr7s8AYVV5lHYp+RUWYPMhwOsHQ4qKwFGvU3ecs6DfybW8V +cG5i5IG549Sg9PJQHyYEzv+5luh7tW2PBoyxCG/WD1f8Q56tbJPevr6UmJUiAIubNtS KpoSDadbi3kO2sKVwRB2UvzWDWUc27sY/hWoPh4Jj0xTuRLecSdXjOCkl5hPTnILyohN a0EXxWFIfFJ7XXQHCTeVoqpoJkbZl8v/mLc5Knhz6EKaYfrMm28Ip80rwzNV+11BuM0t 0HFWzw3cx0KG+sXf1+yCB2R1MGOXrfa/vZcmDEo+GRHlNm5N20qKdiinXBatc9HY5OoF dacw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=BBZlsBLP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s27si1748376otg.229.2020.04.07.15.25.16; Tue, 07 Apr 2020 15:25:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=BBZlsBLP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726395AbgDGWYT (ORCPT + 99 others); Tue, 7 Apr 2020 18:24:19 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:52206 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726421AbgDGWYR (ORCPT ); Tue, 7 Apr 2020 18:24:17 -0400 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=ilWPxxADWa3Mhatef/EKw7rS7FCyC/3gxiDqFnp+HLE=; b=BBZlsBLPC3Z7Ym7P4pCyL1Km26 xO+SsFOTryXTlbDB71tkCxYVEjbXDJJ0n534EO5JJxADwCKc65ekQsrica4ogN2t5qYlsPP3clZcP ER5Putst3MeTijN9yhRletEkRPQqm96I6AM/PWFsLHSfZSn5+kYYymH9CfizhshKlxxYzUHXHWvFl trx7Z2YsT/VBmtmD5GzSukdKaD8S68A9c7n24Fx51B9Co3SkpTAYotIf5jA/P3iQ5bynWCqgCNk0V lUHsqJjoCXVEz/mXHh6NZ83c/OHmH1xQLSRNiHpE5250zTCFBo7GoCLiDmAmKitnkVi1GWIufMqSu 8q8KZ6vg==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jLwdf-0002jz-SO; Tue, 07 Apr 2020 22:24:11 +0000 Date: Tue, 7 Apr 2020 15:24:11 -0700 From: Matthew Wilcox To: David Howells Cc: Linus Torvalds , Joe Perches , Waiman Long , Andrew Morton , Jarkko Sakkinen , James Morris , "Serge E. Hallyn" , Linux-MM , keyrings@vger.kernel.org, Linux Kernel Mailing List , David Rientjes Subject: Re: [PATCH v2] mm: Add kvfree_sensitive() for freeing sensitive data objects Message-ID: <20200407222411.GN21484@bombadil.infradead.org> References: <20200406185827.22249-1-longman@redhat.com> <699292.1586294051@warthog.procyon.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <699292.1586294051@warthog.procyon.org.uk> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 07, 2020 at 10:14:11PM +0100, David Howells wrote: > Linus Torvalds wrote: > > > So the _real_ prototype for 'free()'-like operations should be something like > > > > void free(const volatile killed void *ptr); > > > > where that "killed" also tells the compiler that the pointer lifetime > > is dead, so that using it afterwards is invalid. So that the compiler > > could warn us about some of the most trivial use-after-free cases. > > It might be worth asking the compiler folks to give us an __attribute__ for > that - even if they don't do anything with it immediately. So we might have > something like: > > void free(const volatile void *ptr) __attribute__((free(1))); > > There are some for allocation functions, some of which we use, though I'm not > sure we do so as consistently as we should (should inline functions like > kcalloc() have them, for example?). GCC recognises free() as being a __builtin. I don't know if there's an __attribute__ for it. gcc/builtins.def:DEF_LIB_BUILTIN (BUILT_IN_FREE, "free", BT_FN_VOID_PTR, ATTR_NOTHROW_LEAF_LIST) It looks like the only two things this really does is warn you if you try to free a pointer that gcc can prove isn't in the heap, and elide the call if gcc can prove it's definitely NULL. Which are both things that a compiler should do, but aren't all that valuable.