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=-6.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 F391BC4320A for ; Fri, 20 Aug 2021 16:05:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A387761251 for ; Fri, 20 Aug 2021 16:05:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A387761251 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 445F18D0002; Fri, 20 Aug 2021 12:05:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F37D8D0001; Fri, 20 Aug 2021 12:05:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E2928D0002; Fri, 20 Aug 2021 12:05:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0137.hostedemail.com [216.40.44.137]) by kanga.kvack.org (Postfix) with ESMTP id 14E758D0001 for ; Fri, 20 Aug 2021 12:05:10 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id B8AAC26DFB for ; Fri, 20 Aug 2021 16:05:09 +0000 (UTC) X-FDA: 78495933138.30.36A3CB0 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf22.hostedemail.com (Postfix) with ESMTP id 6FEBF192C for ; Fri, 20 Aug 2021 16:05:09 +0000 (UTC) Received: by mail-pl1-f179.google.com with SMTP id j2so1786953pll.1 for ; Fri, 20 Aug 2021 09:05:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=9RSxFZuikPY0+6WkzucAxhDl/Af7QYt1ZT+jZ731aVs=; b=C51vSheFGqvRaMzd78bsgYL+KckqPd7LdgQ1wxeWTkI06dNiE8mq/SN0h9cLyjDSKp XecYIk+Up2Oo2FQuvAXsBO9g4mcC8iEiR/5e9c6esL0PPyBiG6ucXN8K0+ek6epZ01uO MjScRZDErFj/SkOc0WQTvNyH+tea3ac7xNVzc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=9RSxFZuikPY0+6WkzucAxhDl/Af7QYt1ZT+jZ731aVs=; b=TOzOFjBLlPErb8A24hzw+tlGsmTpUHbKLixgTjHEbOa3+XNjQAo6hp9BMgBucQ0vvS RMaIUWinxcsFRQK1r1btkolDFdP6Ds62q9oZ2AJUwCOhNTyDreQqVB7rr/daZbfAx1tZ 8/4i+XiitY+N3N3UADphTcFjicbdewTzenXjDOzXzrD9MOH20xUjMonszps6FMlGM2MG 9DnIdwA76iTgOs9ITn80qP2rM1olvg5eob51q27xzZdEDW57t2Hz7II/6UO8JLsPx17l CFYHy09mUXv0KwuNZicKpugEBdg9RDWXo4OE7gO2Ui+aIom7gaIiLjtPQta+OPI8zKCY do/Q== X-Gm-Message-State: AOAM531rBn4tmP84+7kexhgRQw0F+DlegWF37mhcN9C/2sJ8xStciTzI dQwSON9B2jaoeWLT0hARf58uHw== X-Google-Smtp-Source: ABdhPJx1Wpa6EBam0RYtT/6mZ8dD8eoIueMBE+WIU9ng87w+5uPAP4mmMdGc1ciQ717B/aGft7Osow== X-Received: by 2002:a17:902:7681:b0:12d:8f52:3d55 with SMTP id m1-20020a170902768100b0012d8f523d55mr16786637pll.70.1629475507362; Fri, 20 Aug 2021 09:05:07 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id i24sm7377171pfo.208.2021.08.20.09.05.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Aug 2021 09:05:06 -0700 (PDT) Date: Fri, 20 Aug 2021 09:05:05 -0700 From: Kees Cook To: James Bottomley Cc: Jordy Zomer , linux-kernel@vger.kernel.org, Andrew Morton , linux-mm@kvack.org, Mike Rapoport Subject: Re: [PATCH] mm/secretmem: use refcount_t instead of atomic_t Message-ID: <202108200904.81ED4AA52@keescook> References: <20210820043339.2151352-1-jordy@pwning.systems> <0874a50b61cfaf7c817cab7344c49c1641c1fd10.camel@HansenPartnership.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0874a50b61cfaf7c817cab7344c49c1641c1fd10.camel@HansenPartnership.com> Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=C51vSheF; spf=pass (imf22.hostedemail.com: domain of keescook@chromium.org designates 209.85.214.179 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 6FEBF192C X-Stat-Signature: mcbhfdqctc7pf1w1mczyyka45n6ucucr X-HE-Tag: 1629475509-492081 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 Fri, Aug 20, 2021 at 07:57:25AM -0700, James Bottomley wrote: > On Fri, 2021-08-20 at 06:33 +0200, Jordy Zomer wrote: > > As you can see there's an `atomic_inc` for each `memfd` that is > > opened in the `memfd_secret` syscall. If a local attacker succeeds to > > open 2^32 memfd's, the counter will wrap around to 0. This implies > > that you may hibernate again, even though there are still regions of > > this secret memory, thereby bypassing the security check. > > This isn't a possible attack, is it? secret memory is per process and > each process usually has an open fd limit of 1024. That's not to say > we shouldn't have overflow protection just in case, but I think today > we don't have a problem. But it's a _global_ setting, so it's still possible, though likely impractical today. But refcount_t mitigates it and is a trivial change. :) -- Kees Cook