Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1287778ybk; Thu, 14 May 2020 05:24:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyVrP7LYTIgYJy2yIi5U8zUxYQNDi+9P4RisZT7bsf/rbPjIXnXIRR6mISpft0L6lsRAl7z X-Received: by 2002:a17:906:3048:: with SMTP id d8mr3568032ejd.97.1589459040037; Thu, 14 May 2020 05:24:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589459040; cv=none; d=google.com; s=arc-20160816; b=EKd0aih1klSGqGtcbFMl5FKSwdp3GFozv2gxmSaHlkbSZlnZXw31pVT8sG8e2/eTX+ OiAZfbsJyhwNz/UUcESJkwsfJZsY97kzK+hPEpibhfwUc+8t/3djXsvQXWgnGznoqoIP HTi2a+KZoW9sf5cm1BdbyIkcoesE1We/Llm8agDq5QJMqb2DmvfuCPoR634NgxMK+V54 rL4ZQHtMYkv0s5V+pIyfZwRew+3bMqlzvn5gPMdss+TUowrX09L91n7Xm3STrbPVtlCf 4PeXgAqyEt7bRyvGJKS07oIdaA2p0WEZvmpX0jaUk9H1JURVQhffpySzvSwF5S+vDYMI 9C1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=nF6vAAaP1cfceYeXNm1y8xNSuJkqKIzjNDIfaM3hC6U=; b=0zOkUZjDnOAbCejauUQ9nLp/2ttdfn/TaV3Vaa3+jgr53G13lnS2FQ3P+G7oT0yxiz JSS5cVBZdWO7jrou1I7dy02xWA8lY16BGQgfmQLjm5bSwKfa/7RORS9k/mu9sAAW/Eh0 GtbOcz9YgUjwYwstlvBjXbMov1xOriL82KOTyhqrbUnmBWBW8OS/uuvp72/x/e8e2vnB RRGmEw7Hc9TYjCkqsn4ZrAyJhNJ0nzxP1vy18kzDT8zL4cFPaRg0WK1Yav+gt5gJxgM4 YLuaB2D7OqAPRTb60C3703Q6dCc+DQsC4KKF/4ZAKe8gz0UW2lEtiAjoLxAXlsimUkiB SWCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=i5amiZT4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id me17si1784256ejb.410.2020.05.14.05.23.37; Thu, 14 May 2020 05:24:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=i5amiZT4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727119AbgENMWN (ORCPT + 99 others); Thu, 14 May 2020 08:22:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725955AbgENMWM (ORCPT ); Thu, 14 May 2020 08:22:12 -0400 Received: from mail-oi1-x242.google.com (mail-oi1-x242.google.com [IPv6:2607:f8b0:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67EA2C061A0C; Thu, 14 May 2020 05:22:12 -0700 (PDT) Received: by mail-oi1-x242.google.com with SMTP id 19so24335479oiy.8; Thu, 14 May 2020 05:22:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=nF6vAAaP1cfceYeXNm1y8xNSuJkqKIzjNDIfaM3hC6U=; b=i5amiZT4SYTxnRSl42OFApQUVQWMEMCzpzva6IzJpZUA8ComrOQCQAsHjrgthqm5Ti GtsNDdoRqE46Qt9PLanUT5TY2Bl0VFqUiHu5M0QIg6duIlNkLuQe8qJr+kir6XgqdVfD 5/SOQWjTz2Km5dz+pfxkh7zPj9KPJ94r2/Ag3If3AMmreLm/vSOzM8UVd2wlUJy4XxrC Y3Y61W6yaKPCDHY9edStqeGLglJrTL68OjZ0vcd54XZi+j9Fq2kDYMrFFSRcy9rIFy7A nX7z+uQKUg5PTswBiYuT5Cmq5JDIibyvxwL2OfL1jJvso9rIPZInZKoazLpB6dSHSd6h W5UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=nF6vAAaP1cfceYeXNm1y8xNSuJkqKIzjNDIfaM3hC6U=; b=MQ39zqs14DLM3VQ7p9t3vbeDNtDHsjP6cG6wPaQU5ko4EVj8OPCrHURZVqvqJZQEjR xYFgZ2IHvhWma5FQqpAnV/Auyzgc7ILvAQ2nYevjUrnzWr/cDAFGtbYUolo+E2j01GUF e2lEpZ1KrfPvlD2e8f+bP65sGvaKS8+UQXWTLK84mbeOFHgRVE85XxbCHGCGzw30CWQh yem5UVEt62yF1arUIeUNjmwpGPXKLro6CufBLwA7cdv6uv9WHGj+12gpUkNgD4nFIfRI tvMv5eZYLJjVeYeA9Ju67ZOnuNEUz6W8Y2//VKgFgMoCUex96nprviL315pGovXOm5lq XTYg== X-Gm-Message-State: AGi0PuaX/OaN7e36MsaFOlucejx2OLsJjDL54UsicGOfEsLCxRv7i0Jl Lm++Po43m1hTJZZDxaSx5Ys41VLkHD7tOIKyJK4= X-Received: by 2002:aca:5e0b:: with SMTP id s11mr28839792oib.160.1589458931895; Thu, 14 May 2020 05:22:11 -0700 (PDT) MIME-Version: 1.0 References: <20200505153156.925111-1-mic@digikod.net> <20200505153156.925111-4-mic@digikod.net> <202005131525.D08BFB3@keescook> <202005132002.91B8B63@keescook> In-Reply-To: <202005132002.91B8B63@keescook> From: Stephen Smalley Date: Thu, 14 May 2020 08:22:01 -0400 Message-ID: Subject: Re: [PATCH v5 3/6] fs: Enable to enforce noexec mounts or file exec through O_MAYEXEC To: Kees Cook Cc: =?UTF-8?B?TWlja2HDq2wgU2FsYcO8bg==?= , linux-kernel , Aleksa Sarai , Alexei Starovoitov , Al Viro , Andy Lutomirski , Christian Heimes , Daniel Borkmann , Deven Bowers , Eric Chiang , Florian Weimer , James Morris , Jan Kara , Jann Horn , Jonathan Corbet , Lakshmi Ramasubramanian , Matthew Garrett , Matthew Wilcox , Michael Kerrisk , =?UTF-8?B?TWlja2HDq2wgU2FsYcO8bg==?= , Mimi Zohar , =?UTF-8?Q?Philippe_Tr=C3=A9buchet?= , Scott Shell , Sean Christopherson , Shuah Khan , Steve Dower , Steve Grubb , Thibaut Sautereau , Vincent Strubel , kernel-hardening@lists.openwall.com, linux-api@vger.kernel.org, linux-integrity@vger.kernel.org, LSM List , Linux FS Devel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 13, 2020 at 11:05 PM Kees Cook wrote: > > On Wed, May 13, 2020 at 04:27:39PM -0700, Kees Cook wrote: > > Like, couldn't just the entire thing just be: > > > > diff --git a/fs/namei.c b/fs/namei.c > > index a320371899cf..0ab18e19f5da 100644 > > --- a/fs/namei.c > > +++ b/fs/namei.c > > @@ -2849,6 +2849,13 @@ static int may_open(const struct path *path, int acc_mode, int flag) > > break; > > } > > > > + if (unlikely(mask & MAY_OPENEXEC)) { > > + if (sysctl_omayexec_enforce & OMAYEXEC_ENFORCE_MOUNT && > > + path_noexec(path)) > > + return -EACCES; > > + if (sysctl_omayexec_enforce & OMAYEXEC_ENFORCE_FILE) > > + acc_mode |= MAY_EXEC; > > + } > > error = inode_permission(inode, MAY_OPEN | acc_mode); > > if (error) > > return error; > > > > FYI, I've confirmed this now. Effectively with patch 2 dropped, patch 3 > reduced to this plus the Kconfig and sysctl changes, the self tests > pass. > > I think this makes things much cleaner and correct. I think that covers inode-based security modules but not path-based ones (they don't implement the inode_permission hook). For those, I would tentatively guess that we need to make sure FMODE_EXEC is set on the open file and then they need to check for that in their file_open hooks.