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 0655FC433FE for ; Fri, 22 Oct 2021 02:53:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B13CC61503 for ; Fri, 22 Oct 2021 02:53:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B13CC61503 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 26EDD900004; Thu, 21 Oct 2021 22:53:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F5F4900002; Thu, 21 Oct 2021 22:53:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0BDFA900004; Thu, 21 Oct 2021 22:53:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0147.hostedemail.com [216.40.44.147]) by kanga.kvack.org (Postfix) with ESMTP id EDDE9900002 for ; Thu, 21 Oct 2021 22:53:14 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 8993E8249980 for ; Fri, 22 Oct 2021 02:53:14 +0000 (UTC) X-FDA: 78722551908.22.8792ABB Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf06.hostedemail.com (Postfix) with ESMTP id 3474A801A8A3 for ; Fri, 22 Oct 2021 02:53:13 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id B5D266135E; Fri, 22 Oct 2021 02:53:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1634871193; bh=ZOyHbxAA1KVGEYcWxP49OLWHjX0kWfehynxD5OBUUVw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=MYl6fk548La85NrwC/69S4sKIJvdsbVdNXs9wgOfrX7zVeEh/JVjMuVJBaPLdbpOv yHO9iNYMoEIeXZ4Knv8ctrzbhv+1IHA7gfgUii2lsO4Z1rDVMBq+9Vt7vQ5kaYqlcd ZuG4B+l/nqSUKKafT4TqvA0ZbCZUdliClZeG8epA= Date: Thu, 21 Oct 2021 19:53:11 -0700 From: Andrew Morton To: Kees Cook 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: <20211021195311.6058b90f573641542605dae4@linux-foundation.org> In-Reply-To: <20211021154046.880251-1-keescook@chromium.org> References: <20211021154046.880251-1-keescook@chromium.org> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 3474A801A8A3 X-Stat-Signature: yioumbfu7papqukmrb6hjicdhez655zg Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=MYl6fk54; dmarc=none; spf=pass (imf06.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-HE-Tag: 1634871193-279960 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 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?