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 9D98AC4332F for ; Fri, 22 Oct 2021 03:39:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 23CB0619EE for ; Fri, 22 Oct 2021 03:39:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 23CB0619EE 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 C0188940010; Thu, 21 Oct 2021 23:39:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BAFB7900002; Thu, 21 Oct 2021 23:39:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A7746940010; Thu, 21 Oct 2021 23:39:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0190.hostedemail.com [216.40.44.190]) by kanga.kvack.org (Postfix) with ESMTP id 9B02E900002 for ; Thu, 21 Oct 2021 23:39:06 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 55D1C1808737A for ; Fri, 22 Oct 2021 03:39:06 +0000 (UTC) X-FDA: 78722667492.04.28C580D Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf17.hostedemail.com (Postfix) with ESMTP id F38AFF000392 for ; Fri, 22 Oct 2021 03:39:05 +0000 (UTC) Received: by mail-pl1-f175.google.com with SMTP id e10so1792979plh.8 for ; Thu, 21 Oct 2021 20:39:05 -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=Yy5rRpKo2fw53nbqx7qopu8aspq5/Q7NCCnnOq+gk3c=; b=Cn2Xsk7upRNROV5qt7FnTqWCajekr42FLh6s8J2a0aJQ836/Z3uSQ4Vk6PVWjRrdkg 2fwCtanYMpNbn6R6rA6TPEAd6mvvkyZ7K5BDsCm3l2i5KHjSU6q31Qlh+Swh10NBpXpd wRVPrLAKa+et+O/gGLSt0NR6gkxStW4ptwf0k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Yy5rRpKo2fw53nbqx7qopu8aspq5/Q7NCCnnOq+gk3c=; b=WZQERKsxIujmvPzeExUvOvuoQTQIO1vey/VTtCY0euHSp/jM5GUv1kZ1P3mn6VghHq JpGBUlGqzge6UElVo1PEcqpauV/KCkZ0Us1DPfjiRkycMvXWc8+I8RtZ5z2g8t+TXqg1 O6w6mLS3RYBSrbNb0gLSAGsa9TKTj4h3UjLYNyEU1/aV9BYWAEPZhLlMZtCUELGXLNc4 0iILLa9OSsP7cDUpyXITgGG3P6aWNycjKX6aJqDanBb6AvIPYHyE9F09gKyuHf/DGFB3 r2zIRcKF4ulfn0ncD3gttJxNUyJWzY4fpQ5Mahm53jBeTdDp4hE42WqAVFXHsTIi0gUG kgeg== X-Gm-Message-State: AOAM532S3JsxfjEI/YW5GUwqyHAnMJAA+xFeyNOTCAeMQBo7ZuA11yH9 SRo5IgsRS3bE8VatRuEdAvCINA== X-Google-Smtp-Source: ABdhPJyTM8I19F2FqzotuNQUV0QBtp7k6bw9s+ngwQ75RmF0tNa9jRPSOazWUsPVmZ5KB0k4z3J6jw== X-Received: by 2002:a17:90b:3886:: with SMTP id mu6mr11450646pjb.40.1634873944883; Thu, 21 Oct 2021 20:39:04 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id d137sm8200122pfd.72.2021.10.21.20.39.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Oct 2021 20:39:04 -0700 (PDT) Date: Thu, 21 Oct 2021 20:39:03 -0700 From: Kees Cook To: Andrew Morton Cc: Mike Rapoport , Jordy Zomer , linux-mm@kvack.org, Dmitry Vyukov , James Bottomley , David Hildenbrand , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] mm/secretmem: Avoid letting secretmem_users drop to zero Message-ID: <202110212037.E18CD404@keescook> References: <20211021154046.880251-1-keescook@chromium.org> <20211021195311.6058b90f573641542605dae4@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211021195311.6058b90f573641542605dae4@linux-foundation.org> X-Stat-Signature: 35b1s46h7jkh99p473984jfk31gxnj5m Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=Cn2Xsk7u; spf=pass (imf17.hostedemail.com: domain of keescook@chromium.org designates 209.85.214.175 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: F38AFF000392 X-HE-Tag: 1634873945-526110 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Oct 21, 2021 at 07:53:11PM -0700, Andrew Morton wrote: > On Thu, 21 Oct 2021 08:40:46 -0700 Kees Cook wrote: > > > Quoting Dmitry: "refcount_inc() needs to be done before fd_install(). > > After fd_install() finishes, the fd can be used by userspace and we can > > have secret data in memory before the refcount_inc(). > > > > A straightforward mis-use where a user will predict the returned fd > > in another thread before the syscall returns and will use it to store > > secret data is somewhat dubious because such a user just shoots themself > > in the foot. > > > > But a more interesting mis-use would be to close the predicted fd and > > decrement the refcount before the corresponding refcount_inc, this way > > one can briefly drop the refcount to zero while there are other users > > of secretmem." > > > > Move fd_install() after refcount_inc(). > > I added cc:stable. Or doesn't the benefit/risk ratio justify that? I hadn't because commit 110860541f44 ("mm/secretmem: use refcount_t instead of atomic_t") wasn't, and this would build on top of it. I think the exposure is very small in both places, so probably best to avoid the churn, but I'm not _opposed_ to it. -- Kees Cook