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=-3.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED 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 DAC73C433DF for ; Thu, 14 May 2020 12:22:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B626120722 for ; Thu, 14 May 2020 12:22:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="i5amiZT4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727832AbgENMWN (ORCPT ); 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-Google-Smtp-Source: APiQypKvnbVkSBLslf8tuVKDqGZ9R3qBIciw1yU8Il1eGXOPA175sNtg+n/Z5A2Hq8fDCIabdLt9q9wcWPA/Ns3WUPQ= 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.