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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8386BC433EF for ; Wed, 18 May 2022 17:46:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BC2C06B0072; Wed, 18 May 2022 13:46:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B71186B0073; Wed, 18 May 2022 13:46:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A601E6B0074; Wed, 18 May 2022 13:46:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 9823C6B0072 for ; Wed, 18 May 2022 13:46:04 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 6E4EE120482 for ; Wed, 18 May 2022 17:46:04 +0000 (UTC) X-FDA: 79479592248.04.991CC65 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf08.hostedemail.com (Postfix) with ESMTP id 134DB160009 for ; Wed, 18 May 2022 17:45:45 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DEEAB6171C; Wed, 18 May 2022 17:46:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13BB6C385A5; Wed, 18 May 2022 17:46:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1652895962; bh=RHuQvfGJad+0pY5yu6xwPWnVxtuvlO9bjRDUb1H5LiI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=sAgWV3VlrxHOfFBNTBtOCBslOzTBkY3S4OqCsCTg+o9kqhiukopfAMkmA37kes29I jxrQyedjJrJ7oifewXYzkO5A31I5YWPwZL1OK5PgIE3Cv3opBGj38hqFCkhxi45j2S hjCnG+wSs5tauK0ydMYgyTzlJvFQcWrI7nADmsdw= Date: Wed, 18 May 2022 10:46:01 -0700 From: Andrew Morton To: Zhihao Cheng Cc: , , , , , Subject: Re: [PATCH -next] exec: Remove redundant check in do_open_execat/uselib Message-Id: <20220518104601.fc21907008231b60a0e54a8e@linux-foundation.org> In-Reply-To: <20220518081227.1278192-1-chengzhihao1@huawei.com> References: <20220518081227.1278192-1-chengzhihao1@huawei.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Stat-Signature: trpso9zo1ka5iqw9o7937iusqww8b7yq X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 134DB160009 X-Rspam-User: Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=sAgWV3Vl; dmarc=none; spf=pass (imf08.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-HE-Tag: 1652895945-583105 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 Wed, 18 May 2022 16:12:27 +0800 Zhihao Cheng wrote: > There is a false positive WARNON happening in execve(2)/uselib(2) > syscalls with concurrent noexec-remount. > > execveat remount > do_open_execat(path/bin) > do_filp_open > path_openat > do_open > may_open > path_noexec() // PASS > remount(path->mnt, MS_NOEXEC) > WARNON(path_noexec(&file->f_path)) // path_noexec() checks fail You're saying this is a race condition? A concurrent remount causes this warning? > Since may_open() has already checked the same conditions, fix it by > removing 'S_ISREG' and 'path_noexec' check in do_open_execat()/uselib(2). > > ... > > --- a/fs/exec.c > +++ b/fs/exec.c > @@ -141,16 +141,6 @@ SYSCALL_DEFINE1(uselib, const char __user *, library) > if (IS_ERR(file)) > goto out; > > - /* > - * may_open() has already checked for this, so it should be > - * impossible to trip now. But we need to be extra cautious > - * and check again at the very end too. > - */ > - error = -EACCES; > - if (WARN_ON_ONCE(!S_ISREG(file_inode(file)->i_mode) || > - path_noexec(&file->f_path))) > - goto exit; > - Maybe we should retain the `goto exit'. The remount has now occurred, so the execution attempt should be denied. If so, the comment should be updated to better explain what's happening. I guess we'd still be racy against `mount -o exec', but accidentally denying something seems less serious than accidentally permitting it.