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 5F592C433EF for ; Thu, 21 Oct 2021 15:50:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F2F9D6120C for ; Thu, 21 Oct 2021 15:50:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org F2F9D6120C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 94D89900002; Thu, 21 Oct 2021 11:50:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8FBC46B0071; Thu, 21 Oct 2021 11:50:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7EAEB900002; Thu, 21 Oct 2021 11:50:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0223.hostedemail.com [216.40.44.223]) by kanga.kvack.org (Postfix) with ESMTP id 705576B006C for ; Thu, 21 Oct 2021 11:50:24 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 366F81828001B for ; Thu, 21 Oct 2021 15:50:24 +0000 (UTC) X-FDA: 78720881568.18.1ABAA00 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf27.hostedemail.com (Postfix) with ESMTP id 593E170000B0 for ; Thu, 21 Oct 2021 15:50:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634831422; 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=wGNuVhi5Wfv6Y5HCVEAnOz4vrOFq78Ll27lC1Wx8arY=; b=P9ocbqOMPwGPDtcqSl8W3vS2APczBuW1ORWMZ6WH/XpkBQMgY6q7/+o4QRvIqNOqquJNia OOQwQ2kYYdQdwqzZUDIbEYFZrfe6zmukvZJ7W7vPYTz8XaW9dedia/H6EzIJ7D0itfnboZ q3pZmQyWMyy+1XWXupBnTQH45yhD0Os= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-26-p_g89RTmMf257Fuya8dSpw-1; Thu, 21 Oct 2021 11:50:18 -0400 X-MC-Unique: p_g89RTmMf257Fuya8dSpw-1 Received: by mail-wm1-f70.google.com with SMTP id s26-20020a7bc39a000000b0030d9db6c428so45496wmj.6 for ; Thu, 21 Oct 2021 08:50:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:organization:in-reply-to :content-transfer-encoding; bh=wGNuVhi5Wfv6Y5HCVEAnOz4vrOFq78Ll27lC1Wx8arY=; b=ZH94izqN4YHS39+eS/AmYbHUWF3tqvxSoFYLQhBeQ32jSdK6p0hMNjOHZwFyB7jqjo mwSxnxwxJNdCxLNCOJGonedm5VjVp2m3SEbFvKS2uOUz+VpG7xVh4qXecu2YKE3LDdMM OxaJVkOsW69TQtDLTbMCV6Tqz7V3sz1BVrSZfVMBpdBqPkqSruskhQ0OLlo7fOwN+ChV jRHU1AE9B5ZEZFt38t+7fNrev11GUPICmiGIxRgBnFR6UZKQZTODox6pBIeBM08+bvMo hppVdqnMv+PYHbyBPEWYLPGEq30WpVJZhXRn4JrtKsvtPX5Zg8WDCzjBEr3epdBeTCYj pGGQ== X-Gm-Message-State: AOAM5334ATrgX9HI8MqUaCTM13ibOECuYVYFRZNYr5tAW1pQSimvlZ9d f9nAZqAbu+Nt0HJghtWcT9vXIn4ccPaemPDIPZ3GLpiK5wjna3LnVa9n0a0/W9vPaZ8juyMtRuu 05bcF+04vLyY= X-Received: by 2002:adf:bb08:: with SMTP id r8mr8428738wrg.247.1634831417842; Thu, 21 Oct 2021 08:50:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgRmpVw7GQoX5QS0ErkShGxQ4LBQKq9b//e8IAFwGPYgHiV4rJyKGUD+AIXN67lgBoTTfX1A== X-Received: by 2002:adf:bb08:: with SMTP id r8mr8428696wrg.247.1634831417574; Thu, 21 Oct 2021 08:50:17 -0700 (PDT) Received: from [192.168.3.132] (p4ff23aba.dip0.t-ipconnect.de. [79.242.58.186]) by smtp.gmail.com with ESMTPSA id r17sm6082878wmq.47.2021.10.21.08.50.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Oct 2021 08:50:17 -0700 (PDT) Message-ID: Date: Thu, 21 Oct 2021 17:50:15 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.0 Subject: Re: [PATCH] mm/secretmem: Avoid letting secretmem_users drop to zero To: Kees Cook , Andrew Morton Cc: Mike Rapoport , Jordy Zomer , linux-mm@kvack.org, Dmitry Vyukov , James Bottomley , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org References: <20211021154046.880251-1-keescook@chromium.org> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20211021154046.880251-1-keescook@chromium.org> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 593E170000B0 Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=P9ocbqOM; spf=none (imf27.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: 87zdkycxmcimb4yidt71rryt3j9tidqk X-Rspamd-Server: rspam06 X-HE-Tag: 1634831421-967456 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 21.10.21 17:40, 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(). > > Cc: Mike Rapoport > Cc: Jordy Zomer > Cc: linux-mm@kvack.org > Reported-by: Dmitry Vyukov > Link: https://lore.kernel.org/lkml/CACT4Y+b1sW6-Hkn8HQYw_SsT7X3tp-CJNh2ci0wG3ZnQz9jjig@mail.gmail.com > Fixes: 9a436f8ff631 ("PM: hibernate: disable when there are active secretmem users") > Signed-off-by: Kees Cook > --- > mm/secretmem.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/mm/secretmem.c b/mm/secretmem.c > index 1fea68b8d5a6..924d84ba481f 100644 > --- a/mm/secretmem.c > +++ b/mm/secretmem.c > @@ -217,8 +217,8 @@ SYSCALL_DEFINE1(memfd_secret, unsigned int, flags) > > file->f_flags |= O_LARGEFILE; > > - fd_install(fd, file); > refcount_inc(&secretmem_users); > + fd_install(fd, file); > return fd; > > err_put_fd: > Reviewed-by: David Hildenbrand -- Thanks, David / dhildenb