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.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED 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 038BDC2D0EC for ; Tue, 7 Apr 2020 20:17:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A8A5C20748 for ; Tue, 7 Apr 2020 20:17:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="AestyY1v" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A8A5C20748 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 491F18E0014; Tue, 7 Apr 2020 16:17:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 41BA28E0001; Tue, 7 Apr 2020 16:17:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 30C728E0014; Tue, 7 Apr 2020 16:17:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0081.hostedemail.com [216.40.44.81]) by kanga.kvack.org (Postfix) with ESMTP id 145548E0001 for ; Tue, 7 Apr 2020 16:17:08 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id C02CF4995E4 for ; Tue, 7 Apr 2020 20:17:07 +0000 (UTC) X-FDA: 76682168094.03.sense95_5b48ed44ad833 X-HE-Tag: sense95_5b48ed44ad833 X-Filterd-Recvd-Size: 5099 Received: from mail-lj1-f195.google.com (mail-lj1-f195.google.com [209.85.208.195]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Tue, 7 Apr 2020 20:17:07 +0000 (UTC) Received: by mail-lj1-f195.google.com with SMTP id p10so5234315ljn.1 for ; Tue, 07 Apr 2020 13:17:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=tqNU/lPOQShoDviss5cOicvqhvwtlk4dqmmrGpr1nC4=; b=AestyY1vTqwruS2SjIrVNUtcv5M8Rgu+CcoXa2Ec6+EMfNUym7BLVuLaqMEg4Qo83h Qnr6k3woR88ywv52t7EjGWsxUFiyzpMnJQ7/9g74RK12uuMuQBryg8i26qgkAh6zrbEf bvModrsMiA1tyaJ0cX/reQrpKDKOb9pKz3p18= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=tqNU/lPOQShoDviss5cOicvqhvwtlk4dqmmrGpr1nC4=; b=b+Z4mUkgdK4HaUnrN8X197nuho/zhOKciGFubadab0LJdf595xgvzJCkbkZ2sKkcoG V37X27YF1BJZwR2U+MYxA/S1noWE8VjGOBikw6PtPh5/E9e0VeVnC7ukiHgGFwEFy70V U4k8fEEkRg3BcLWvQHNGVgPXXRmxMMlt9mHfP6bpbKrMrPTvWUFWV8LHj/6YGbJPzPL+ B9Cue4l+XHk7fh75Zaa8DoXJFiUmMHUvVkUhiLlkwcjF0Aw4g0wfpwPrkkqr0jNhGf7Y uq0mNwU8YaY+DjCNLvsrXdQFpjGyFIcsox3KIu533qWSkkHzcVTJ2cGJhMiKnHBpxDOW j7ug== X-Gm-Message-State: AGi0PuaGVGpEgO38KM1kiz6Qg7YPePxacVXbBN+y26o/qZANAvTyiBFS gMWh7eZ/QhiP+Q1f3xfihTjSOZFrvf4= X-Google-Smtp-Source: APiQypJNUekgcBprls+Bt3moDAVv7cHH5VfIVQj5hCiOsc9VEFvsbdK1J4FAhdCrGyPnyh3NrxhawA== X-Received: by 2002:a2e:8914:: with SMTP id d20mr2694155lji.148.1586290625275; Tue, 07 Apr 2020 13:17:05 -0700 (PDT) Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com. [209.85.167.47]) by smtp.gmail.com with ESMTPSA id r21sm12961609ljp.29.2020.04.07.13.17.04 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 07 Apr 2020 13:17:04 -0700 (PDT) Received: by mail-lf1-f47.google.com with SMTP id m19so1379060lfq.13 for ; Tue, 07 Apr 2020 13:17:04 -0700 (PDT) X-Received: by 2002:a19:9109:: with SMTP id t9mr2511760lfd.10.1586290623763; Tue, 07 Apr 2020 13:17:03 -0700 (PDT) MIME-Version: 1.0 References: <20200406185827.22249-1-longman@redhat.com> In-Reply-To: From: Linus Torvalds Date: Tue, 7 Apr 2020 13:16:47 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2] mm: Add kvfree_sensitive() for freeing sensitive data objects To: Joe Perches Cc: Waiman Long , Andrew Morton , David Howells , Jarkko Sakkinen , James Morris , "Serge E. Hallyn" , Linux-MM , keyrings@vger.kernel.org, Linux Kernel Mailing List , Matthew Wilcox , David Rientjes Content-Type: text/plain; charset="UTF-8" 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 Mon, Apr 6, 2020 at 12:40 PM Joe Perches wrote: > > 2.1.44 changed kfree(void *) to kfree(const void *) but > I didn't find a particular reason why. Because "free()" should always have been const (and volatile, for that matter, but the kernel doesn't care since we eschew volatile data structures). It's a bug in the C library standard. Think of it this way: free() doesn't really change the data, it kills the lifetime of it. You can't access it afterwards - you can neither read it nor write it validly. That is a completely different - and independent - operation from writing to it. And more importantly, it's perfectly fine to have a const data structure (or a volatile one) that you free. The allocation may have done something like this: struct mystruct { const struct dictionary *dictionary; ... }; and it was allocated and initialized before it was assigned to that "dictionary" pointer. That's _good_ code. So it wasn't const before the allocation, but it turned const afterwards, and freeing it doesn't change that, it just kills the lifetime entirely. So "free()" should take a const pointer without complaining, and saying free(mystruct->dictionary); free(mystruct); is a sensible an correct thing to do. Warning about - or requiring that dictionary pointer to be cast to be freed - is fundamentally wrong. We're not bound by the fact that the C standard library got their rules wrong, so we can fix it in the kernel. Linus