Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2041821ybb; Sat, 4 Apr 2020 20:12:54 -0700 (PDT) X-Google-Smtp-Source: APiQypKo5UcM9inAr6WOFWzVDhF9tYoxVO7HELMuF5cI0MJPdseTt3YoPvAHel7T+w+z9fo3Qmbp X-Received: by 2002:a05:6830:1bca:: with SMTP id v10mr13153558ota.286.1586056373909; Sat, 04 Apr 2020 20:12:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586056373; cv=none; d=google.com; s=arc-20160816; b=Z4BKDr9h71Ud3x3SP9TyBlKoKpOVzbUYrO6er9SzPkH3knwmaXU8ikrLqrueghgfwx 1pTAQJ7TuonGjTBeEL9u4YekiVqRyMay6QHWrZbBS3q2dJ+h6CNyJtoOP1SsNTd+g618 2JWya3nCrOk1uSHLNtY6mCEVL9ejOnJ6pnNf7ScWNafzta9tRA2zcKHGaDhwbWtDluSh sc3nzvYN59mGO4icNk8F9xqiLiY4BDgkX7HQ8nlUOPY1ggbVPjgPorQZhCxXsP6uJTx8 ZQNeLCP9eyUwxoiANqojGjLRuijsvc8YpKseapKovZZM+fTzYXEqw9AY9jyQXm/L+6FK Gj0w== 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=EG5ytn3q4cjrK4N/hwUftqYJUijBPztWPiSrSQnYoRI=; b=xUNta8OU1J8uG/cfP+NqR7v46unfZfYbhFZL49OnIcHMMItzQJGuZGn09lqplWU0MX K1L/iFz3qfC7M3frzA6Arput3c+1KbOgLkWd8ObhzUwxisdtNfqyn+0VZrOmeJA0hiUC qYgh5yE/cmMRe1PPOcgTXDeCvEvvcz3MjFJwRXQOc3UN1+X708svtAon1V5NA786tm3+ Lbodzh0D6hvsfwPjPJBtDYB29/iM7R9fhADYfV4BJdhEO6DZOZwDobskYNfqzCzz2PMa YdTWNi9XCnbQMKUkH5yHk2RubFaLxQYC+Z1LzQhn3lMaxenm7arzlHZp/o+5oE4ga22q PYdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OA7iB1Dm; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m2si5839074oof.17.2020.04.04.20.12.41; Sat, 04 Apr 2020 20:12:53 -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=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OA7iB1Dm; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726474AbgDEDLE (ORCPT + 99 others); Sat, 4 Apr 2020 23:11:04 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:50452 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726388AbgDEDLE (ORCPT ); Sat, 4 Apr 2020 23:11:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586056263; 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=EG5ytn3q4cjrK4N/hwUftqYJUijBPztWPiSrSQnYoRI=; b=OA7iB1Dm1pXRGyEi5r57zEPfUlGkNIVURBO68AK6OP9XW7XyzKh1jaQdKC/OBCqPFqvGt8 zyhnA3XQCHgLMdsleZqr/QTVx74fTDmiY2DmFr+cHy2yVL4s/A2K7PDFlJwHPblA4K0WJm w/bCvGQKylxwrzONxZyhVgcX5hVFw9g= 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-400-5rHQ2HdINEyC9VBzDOicDQ-1; Sat, 04 Apr 2020 23:11:01 -0400 X-MC-Unique: 5rHQ2HdINEyC9VBzDOicDQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C3A9A100551A; Sun, 5 Apr 2020 03:10:59 +0000 (UTC) Received: from llong.remote.csb (ovpn-112-153.rdu2.redhat.com [10.10.112.153]) by smtp.corp.redhat.com (Postfix) with ESMTP id D4B2D1001B09; Sun, 5 Apr 2020 03:10:57 +0000 (UTC) Subject: Re: [GIT PULL] keys: Fix key->sem vs mmap_sem issue when reading key To: Linus Torvalds , David Howells , Johannes Weiner , Herbert Xu Cc: Jarkko Sakkinen , keyrings@vger.kernel.org, LSM List , Linux Kernel Mailing List References: <1437197.1585570598@warthog.procyon.org.uk> From: Waiman Long Organization: Red Hat Message-ID: <78ff6e5d-9643-8798-09cb-65b1415140be@redhat.com> Date: Sat, 4 Apr 2020 23:10:57 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/4/20 4:00 PM, Linus Torvalds wrote: > On Mon, Mar 30, 2020 at 5:16 AM David Howells wrote: >> security/keys/internal.h | 12 ++++ > This isn't so much about this pull (which I have taken), as about the > fact that this code re-inforces bad behavior we already in the slub > layer, and now extends it further to kvfree. > > Doing this: > > > __kvzfree(const void *addr, size_t len) > .. > memset((void *)addr, 0, len); > kvfree(addr); > > is wrong to begin with. It's wrong because if the compiler ever knows > that kvfree is a freeing function (with something like > __attribute__((free)) - I don't think gcc is smart enough today), the > compiler might throw the memset away. > > Yeah, so far we've only seen that for automatic stack clearing, but > there are very much compilers that know that alloc/free are special > (both for warning about use-after-free issues, and for "improving" > code generation by blindly removing dead writes). > > We have a function for clearing sensitive information: it's called > "memclear_explicit()", and it's about forced (explicit) clearing even > if the data might look dead afterwards. > > The other problem with that function is the name: "__kvzfree()" is not > a useful name for this function. We use the "__" format for internal > low-level helpers, and it generally means that it does *less* than the > full function. This does more, not less, and "__" is not following any > sane naming model. > > So the name should probably be something like "kvfree_sensitive()" or > similar. Or maybe it could go even further, and talk about _why_ it's > sensitive, and call it "kvfree_cleartext()" or something like that. > > Because the clearing is really not what even matters. It might choose > other patterns to overwrite things with, but it might do other things > too, like putting special barriers for data leakage (or flags to tell > return-to-user-mode to do so). > > And yes, kzfree() isn't a good name either, and had that same > memset(), but at least it doesn't do the dual-underscore mistake. > > Including some kzfree()/crypto people explicitly - I hope we can get > away from this incorrect and actively wrong pattern of thinking that > "sensitive data should be memset(), and then we should add a random > 'z' in the name somewhere to 'document' that". > > Linus > Thanks for the suggestion, I will post a patch to rename the function to kvzfree_explicit() and use memzero_explicit() for clearing memory. Cheers, Longman