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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED5B9C4332F for ; Tue, 26 Oct 2021 00:02:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 83049610A6 for ; Tue, 26 Oct 2021 00:02:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 83049610A6 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=kvack.org Received: by kanga.kvack.org (Postfix) id 0976494000B; Mon, 25 Oct 2021 20:02:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 04656940007; Mon, 25 Oct 2021 20:02:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E50F394000B; Mon, 25 Oct 2021 20:02:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0079.hostedemail.com [216.40.44.79]) by kanga.kvack.org (Postfix) with ESMTP id D21DD940007 for ; Mon, 25 Oct 2021 20:02:38 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 86BF1183E6016 for ; Tue, 26 Oct 2021 00:02:38 +0000 (UTC) X-FDA: 78736637196.30.8774793 Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) by imf25.hostedemail.com (Postfix) with ESMTP id 4DEF8B000187 for ; Tue, 26 Oct 2021 00:02:32 +0000 (UTC) Received: by mail-lj1-f179.google.com with SMTP id u5so15311751ljo.8 for ; Mon, 25 Oct 2021 17:02:38 -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=+mnm+OfMKcKUtkfqrC5M97FE+bDqSMISDz0T80M6Naw=; b=Zr8T+v06R2K3WXZXA/rUZs6WfYMvfmtXk94m5JBLVuXUlLBJpGx736SF8nwtXTYl0c kU+TL3h/XLlQCjRn5C6XVoEDuOrGftxepbTasP56kMLo/Bz0I51EmdYXyfWQ96Odv9SC q6xT7IH8kr9CoZttMVB4amc+2gZey1z7kz+VE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+mnm+OfMKcKUtkfqrC5M97FE+bDqSMISDz0T80M6Naw=; b=vqqww17CGu4/WxqW480wo6wWvszJHjMxZ7dWG+iJtUH6+2C+FNgDQOaGtEXN8Zr5vu Xt3axvdcREcCNeveW9LPSSkK2Cx1swDuzzAz2jWr0uzjVjMDHMaCGkd4aePbnC+QL3Fe E3ODDO5/77k1WYiCjaCzMqwuUxoeNaPAjcnVuJH70qD/zzTCwXmgxeyqC3NJY4O3YuO2 MABZcLQdLhj0D76GYuj87gwZFXF2hkQCroJbgZim4Vg1Lomoift//awzWFSPSH5soSlE Qouoih4GkdptCopr9TzGCxunNA98g9dtZ5lmKCSV4OfgVjDr2PJ0bbR+W16BDH/LHN10 FJzQ== X-Gm-Message-State: AOAM533Le1KSh7B2yD+c8XaPp9/QisARQ+qBJoZkFjx0rdJihfZHMlWr reNbXjWt/A0nHKYfFrWfP+NQBuDO/XC4gA== X-Google-Smtp-Source: ABdhPJzWlmwVHBIddoIGMIAzC/XhplGjZMO0NpZt2XFxcMEUWHrNQHPcQhLJisFCdzJXw/wZ8W2/4g== X-Received: by 2002:a2e:7308:: with SMTP id o8mr21741211ljc.360.1635206556341; Mon, 25 Oct 2021 17:02:36 -0700 (PDT) Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com. [209.85.167.43]) by smtp.gmail.com with ESMTPSA id x10sm1457065lfa.177.2021.10.25.17.02.35 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 Oct 2021 17:02:35 -0700 (PDT) Received: by mail-lf1-f43.google.com with SMTP id u11so7350294lfs.1 for ; Mon, 25 Oct 2021 17:02:35 -0700 (PDT) X-Received: by 2002:a19:ad0c:: with SMTP id t12mr19319386lfc.173.1635206555059; Mon, 25 Oct 2021 17:02:35 -0700 (PDT) MIME-Version: 1.0 References: <20211025181634.3889666-1-willy@infradead.org> <202110251225.D01841AE67@keescook> <202110251402.ADFA4D41BF@keescook> <202110251438.1762406A5@keescook> In-Reply-To: From: Linus Torvalds Date: Mon, 25 Oct 2021 17:02:18 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] secretmem: Prevent secretmem_users from wrapping to zero To: Kees Cook Cc: Matthew Wilcox , Linux Kernel Mailing List , Linux-MM , Jordy Zomer , James Bottomley , Mike Rapoport , Andrew Morton Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: 1eh6fqzarxhu8achgkexosd7rd43tf4e X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 4DEF8B000187 Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=google header.b=Zr8T+v06; dmarc=none; spf=pass (imf25.hostedemail.com: domain of torvalds@linuxfoundation.org designates 209.85.208.179 as permitted sender) smtp.mailfrom=torvalds@linuxfoundation.org X-HE-Tag: 1635206552-462102 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, Oct 25, 2021 at 4:37 PM Linus Torvalds wrote: > > Stop thinking that refcount_t is a good type. Start realizing the > downsides. Start understanding that saturation is a HORRENDOUSLY BAD > solution, and horrible QoI. Basically, refcount_t should be used purely for internal kernel data structures - it makes perfect sense for things like the 'struct device' resource handling, for example. In fact, there it is good for two reasons: - it's not counting some user resource, so users shouldn't have any way to trigger overflow and saturation which causes problems - it's used by random driver stuff, which is often where kernel bugs happen and testing is fundamentally limited by hw availability etc but in general, anything that is user-accountable needs to have _limits_, not saturation. It's why the page count is a "atomic_t" even if the name of the field is "_refcount". Because refcount_t is the INFERIOR TYPE. Using an atomic_t properly is actually the much better option. It's just that "properly" might be a bit more code, involving actual limit checking. 'refcount_t' is basically a shorthand for "I didn't bother doing this right, so I'm using this type that adds debugging, warns and stops working and might DoS the kernel". It's a crutch. It's not the alpha and the omega of counting types. It has its place, but I really want to stress how people should ABSOLUTELY not think "oh, refcount_t is better than atomic_t". Linus