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 BA14AC433F5 for ; Sun, 24 Oct 2021 15:31:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4174860F70 for ; Sun, 24 Oct 2021 15:31:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4174860F70 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 29A2B6B006C; Sun, 24 Oct 2021 11:31:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 249D0940007; Sun, 24 Oct 2021 11:31:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 138756B0072; Sun, 24 Oct 2021 11:31:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0154.hostedemail.com [216.40.44.154]) by kanga.kvack.org (Postfix) with ESMTP id 055856B006C for ; Sun, 24 Oct 2021 11:31:41 -0400 (EDT) Received: from smtpin35.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id ABA8B2CFFE for ; Sun, 24 Oct 2021 15:31:40 +0000 (UTC) X-FDA: 78731720760.35.8F53937 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf29.hostedemail.com (Postfix) with ESMTP id 4DF3590001BC for ; Sun, 24 Oct 2021 15:31:40 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 4E10C60F21; Sun, 24 Oct 2021 15:31:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1635089499; bh=rCLmnOPDWbzvIdvUEGs6ZnW1xYqd22FSEv9wsc2itJY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=cBcEA4Iom2lpL3bff2odUoc04Gx3+KHo8bEori5CKeAvCvO57hUPcrNB6H2IJTIpt FNYjgmtCfzRmho3pY1LhiPPBdLhoQqO/nydyFll32daFOxQLL3FCOLTNFJWyjFApxD zwvaSb2zteXOECzgXA4Ey/o1W/xhTcmznu4Oj6WTLQzOJ+hNuLafG0sEMd3Du3MupE G2WIDLDXlYSEl9cZc0fikIt1mOXWgoNpuma9OCjGUiGT9PWN+eepBS9+F63FO6bqtO CXl4XHxNc5IVT/p+HsmPnzuozoA+fJT90uSZBW+oFOkDQk11o7S3tArIdiGC2GimBZ OarueG4wDVPSw== Date: Sun, 24 Oct 2021 18:31:30 +0300 From: Mike Rapoport To: Matthew Wilcox Cc: Kees Cook , Dmitry Vyukov , syzbot , Jordy Zomer , akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, syzkaller-bugs@googlegroups.com Subject: Re: [syzbot] WARNING: refcount bug in sys_memfd_secret Message-ID: References: <00000000000062d0fc05cef24c57@google.com> <088FF23B-CD8E-4E53-B702-53E2C2382062@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: scrxhygtnuakywhkpjonz48jiz6cecb7 Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=cBcEA4Io; spf=pass (imf29.hostedemail.com: domain of rppt@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 4DF3590001BC X-HE-Tag: 1635089500-900570 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 Sun, Oct 24, 2021 at 11:57:02AM +0100, Matthew Wilcox wrote: > On Sun, Oct 24, 2021 at 08:37:59AM +0300, Mike Rapoport wrote: > > On Sat, Oct 23, 2021 at 11:46:18PM +0100, Matthew Wilcox wrote: > > > On Sat, Oct 23, 2021 at 10:03:11AM -0700, Kees Cook wrote: > > > > On October 23, 2021 8:27:28 AM PDT, Mike Rapoport wrote: > > > > >and my first reaction was to send a revert the untested commit 110860541f44 > > > > >("mm/secretmem: use refcount_t instead of atomic_t"). > > > > > > I think you should. This isn't a real problem. > > > > Do you mean that creation of 4 billion of file descriptors is not feasible? > > On a sufficiently large machine, it is. But then we have the same > problem with other atomic_t. If you really care, just check whether > secretmem_users has gone negative, and return -ENFILE. It doesn't > even have to be all that exact; you've got 2 billion values of slop > to use before you hit the wrap from negative to 0 which is the actual > problem. > > ie this: > > +++ b/mm/secretmem.c > @@ -203,6 +203,8 @@ SYSCALL_DEFINE1(memfd_secret, unsigned int, flags) > > if (flags & ~(SECRETMEM_FLAGS_MASK | O_CLOEXEC)) > return -EINVAL; > + if (atomic_read(&secretmem_users) < 0) > + return -ENFILE; So you suggest to prevent creation of the file descriptor to ensure there is no overflow of secretmem_users. I don't feel it's a clean and elegant solution. > > fd = get_unused_fd_flags(flags & O_CLOEXEC); > if (fd < 0) > > > Also, why does secretmem depend on !EMBEDDED? There was a request from tiny-config maintainers to keep this code outside tiny-config and the best option I could find to make secretmem depend on !EMBEDDED. -- Sincerely yours, Mike.