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 X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 888FEC433E1 for ; Sat, 15 Aug 2020 00:30:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 44B8122B45 for ; Sat, 15 Aug 2020 00:30:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="gR7BEoRu" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 44B8122B45 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=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id DB39A6B000D; Fri, 14 Aug 2020 20:30:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D3C686B000E; Fri, 14 Aug 2020 20:30:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C553E6B0010; Fri, 14 Aug 2020 20:30:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0047.hostedemail.com [216.40.44.47]) by kanga.kvack.org (Postfix) with ESMTP id AB22E6B000D for ; Fri, 14 Aug 2020 20:30:16 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 6F1A475AA for ; Sat, 15 Aug 2020 00:30:16 +0000 (UTC) X-FDA: 77150921232.21.smoke56_270795927001 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id 47976180442C0 for ; Sat, 15 Aug 2020 00:30:16 +0000 (UTC) X-HE-Tag: smoke56_270795927001 X-Filterd-Recvd-Size: 2853 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Sat, 15 Aug 2020 00:30:15 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B7AC2221E2; Sat, 15 Aug 2020 00:30:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597451415; bh=QBXzTQcMnoIh0FsmTT777HtmQhovmOY+Gre/6iajyjQ=; h=Date:From:To:Subject:In-Reply-To:From; b=gR7BEoRuMT/2lqlBaWe1qK3fzQfzjgUqlopmugyKrRZ1oiXevSLnYTAE53P00aEMH 8cg2K+XpFrcoqsDJu0gvyYVtr8dMVPC33gslRMe+1gb/vR8KNoQv8/solUrngnkqbM qPErV37clTVoNQ2SacH+LruFmJ16kYwN9IUPSGnQ= Date: Fri, 14 Aug 2020 17:30:14 -0700 From: Andrew Morton To: akpm@linux-foundation.org, gregkh@android.com, gregkh@google.com, keescook@chromium.org, linux-mm@kvack.org, maz@kernel.org, mm-commits@vger.kernel.org, torvalds@linux-foundation.org Subject: [patch 04/39] exec: restore EACCES of S_ISDIR execve() Message-ID: <20200815003014.DWF4Lqhri%akpm@linux-foundation.org> In-Reply-To: <20200814172939.55d6d80b6e21e4241f1ee1f3@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Rspamd-Queue-Id: 47976180442C0 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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: From: Kees Cook Subject: exec: restore EACCES of S_ISDIR execve() Patch series "Fix S_ISDIR execve() errno". Fix an errno change for execve() of directories, noticed by Marc Zyngier. Along with the fix, include a regression test to avoid seeing this return in the future. This patch (of 2): The return code for attempting to execute a directory has always been EACCES. Adjust the S_ISDIR exec test to reflect the old errno instead of the general EISDIR for other kinds of "open" attempts on directories. Link: http://lkml.kernel.org/r/20200813231723.2725102-2-keescook@chromium.org Link: https://lore.kernel.org/lkml/20200813151305.6191993b@why Fixes: 633fb6ac3980 ("exec: move S_ISREG() check earlier") Signed-off-by: Kees Cook Reported-by: Marc Zyngier Reviewed-by: Greg Kroah-Hartman Tested-by: Greg Kroah-Hartman Signed-off-by: Andrew Morton --- fs/namei.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/fs/namei.c~exec-restore-eacces-of-s_isdir-execve +++ a/fs/namei.c @@ -2849,8 +2849,10 @@ static int may_open(const struct path *p case S_IFLNK: return -ELOOP; case S_IFDIR: - if (acc_mode & (MAY_WRITE | MAY_EXEC)) + if (acc_mode & MAY_WRITE) return -EISDIR; + if (acc_mode & MAY_EXEC) + return -EACCES; break; case S_IFBLK: case S_IFCHR: _