Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1384091rdb; Wed, 24 Jan 2024 13:35:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IHYpH3LH5ZyFvXnHPsQKISOnN+8KF3zYU/nNyPIgxrJzlTcZtiLk49yuoggPVNouGvzt9pL X-Received: by 2002:a05:620a:2995:b0:783:7695:1d32 with SMTP id r21-20020a05620a299500b0078376951d32mr50171qkp.17.1706132139874; Wed, 24 Jan 2024 13:35:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706132139; cv=pass; d=google.com; s=arc-20160816; b=U5eOg+Tg5H68G6b5TnePmrvEzbiDjeHxCsSx/PExnaXIsfxw2dVtK42eCs4Ir0vPhD h/duLLzWjAbYPHZpB+WSZogZbcHA45ZzVLpiYvLng8q9RgkiaUUdwiynbc4MhyleYBUU 2RELqzmzno7c0w7EVj1A9iMdbhaij+zxVnEUAHjPNp+ggAQFPBzx2VCaxdJWLU3T+JAc CBVB5d1/Y1q8wCGJGgxfASAX0yUp5YWlIYn1EwI/TyBtUFlwnfpvlmmf492BwxVNI7R0 ebcbW3EPKKD61ogwFigQKprxAsYq5GCmvqSHKRsQtckZLSYSDLvO2DIV2P0gIPndOp66 GXDA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=R02kkjm9zZZALeIAu8OyIiBbwYldvv1po8aujCvgxCc=; fh=FnKs2D+5+ibBL+N4acPZMbPk32lgU3/BrrfVIZsTUb8=; b=IanSCrJKAlqF0+d+UWyyYXxNJefaP4iAeuzkt3WHjAfWPxHl7zQQxNOvzW3vdM65lE /qYwNxxRmUT01UivtEzxvwsjTf5073GPayr2pkMEGq0h5LZKPomRNProlleIdV00UAqA yqcXCaQbIMagXAD+bsOHcsNdvWe91RN1GKKcxdvhYy6ctB0ulhWk0zf0abzqO2D+nGg7 po3wb8Zv4J5j/JJsllrkG9N0o/a5y8SIN636YDl1O4kituj7sqj8p1RSsUvIbPUaA+aJ 7IQ07n0NIa7nP6R5syDbAkgN9I8q6iuOanYqZ/KGQAMOLyNuBQ3TIT8io1mYHU8RpkIB pxjA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Lo+4DfvP; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-37698-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37698-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id f8-20020a05620a15a800b007833b7a1170si10982264qkk.588.2024.01.24.13.35.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 13:35:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37698-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Lo+4DfvP; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-37698-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37698-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 9E1331C2273A for ; Wed, 24 Jan 2024 21:35:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CB97A13540F; Wed, 24 Jan 2024 21:35:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Lo+4DfvP" Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96F4C1350F5 for ; Wed, 24 Jan 2024 21:35:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706132126; cv=none; b=egeGR9b0+Nh6k71k/YfzI3xcJ34c+HlikkMMZXCmZT+fcNuGyS3Rn+1LJDkoC+7FtnHiEAriYNDUOWeHi7O3PJb2Q642j7Z9XkMI7/hw76Gpeh5kQh1OHCS1Drkci2ZXo/YZDCHvbl8+uYukckKKOsa8/wo8kgE+pLQxwTiYWbY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706132126; c=relaxed/simple; bh=vy2eQcXuP8J+89WHubqOmUDL6fntpzonJvK8RD/C8Zo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Z2hQ/0t6CcBMFR9TQ/Eu4qqwrbKDM8S/JF4o7N9pW+mcBwFKw8qOXNCoElj88WDSKwuXWQdSrCqbDhjIqiigBTCMoS7xbMcUcAw/WdDh5LEG7uW+j6jbv2Q7G4CKC3lZXamuna5IIreHElJbfEEwyD0VrHLXaDDXOj2i4eW8smQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=Lo+4DfvP; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1d74045c463so28784765ad.3 for ; Wed, 24 Jan 2024 13:35:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1706132124; x=1706736924; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=R02kkjm9zZZALeIAu8OyIiBbwYldvv1po8aujCvgxCc=; b=Lo+4DfvPcbZAIp9UbKEWYLXIJIcEicEMgfszjEA+dHd4meIfvchp0cmxZPFJi4cdDC VvT1GBoOV/cELPKOvtssF0J0xP7v/Pxl0SlcC+YOxsJ+TUkS7cFz8PwzoQgwJmCFUSPG fXhWOnwqf7/ylOBk9aydYvu1MyYRXDIun8LRc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706132124; x=1706736924; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=R02kkjm9zZZALeIAu8OyIiBbwYldvv1po8aujCvgxCc=; b=B6I8eV0ZohsLcnppAs2yyv61Ev/NOMukZqREH/fq0BwzdEP89nAm9n9pHplmuGWc9T 97mfnZ7b8Ell3jor6bptm5aY/TF1bPrmAGLItQbC7AUkFuQSYtO4yc1P8NzSk5kBxpXE I1awsqyfYtN2L7j6vzxjBug11lRp74WxXpHc3XbgMloYjTKjrQlEoTzSrc5Ew7ZNCPFl E1Sxpz3GYYhYSF3l1uMo8xw1xgEkbVq7Ji77a+YghaGw8p8eC7sjvINLgBXHBcIFI4DU J9hytm2BljYClcsxQS5SJQLdiCmG6uiyCGQptnxi5wv7hJ9Oxh6yrFX8LTxwOraOWcAZ yK1A== X-Gm-Message-State: AOJu0YxUKW1fKLrikdhBWa+SlELI+a5KcYM8pN++z6bW2u7tER3KWkOg MHeUqUJO89CFYNJaLosCgBPuUclJsp0HgY8F4+hQgIaLMrTs1PW5lXkJW0sv9Q== X-Received: by 2002:a17:902:ee0c:b0:1d5:b82a:939 with SMTP id z12-20020a170902ee0c00b001d5b82a0939mr16459plb.125.1706132124053; Wed, 24 Jan 2024 13:35:24 -0800 (PST) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id mj11-20020a1709032b8b00b001d73a2acc2bsm6701572plb.142.2024.01.24.13.35.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 13:35:23 -0800 (PST) Date: Wed, 24 Jan 2024 13:35:23 -0800 From: Kees Cook To: Linus Torvalds Cc: Jann Horn , Josh Triplett , Kevin Locke , John Johansen , Paul Moore , James Morris , "Serge E. Hallyn" , Kentaro Takeda , Tetsuo Handa , Alexander Viro , Christian Brauner , Jan Kara , Eric Biederman , Andrew Morton , Sebastian Andrzej Siewior , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] exec: Check __FMODE_EXEC instead of in_execve for LSMs Message-ID: <202401241334.670AFDD@keescook> References: <20240124192228.work.788-kees@kernel.org> <202401241206.031E2C75B@keescook> <202401241310.0A158998@keescook> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202401241310.0A158998@keescook> On Wed, Jan 24, 2024 at 01:32:02PM -0800, Kees Cook wrote: > On Wed, Jan 24, 2024 at 12:47:34PM -0800, Linus Torvalds wrote: > > On Wed, 24 Jan 2024 at 12:15, Kees Cook wrote: > > > > > > Hmpf, and frustratingly Ubuntu (and Debian) still builds with > > > CONFIG_USELIB, even though it was reported[2] to them almost 4 years ago. > > For completeness, Fedora hasn't had CONFIG_USELIB for a while now. > > > Well, we could just remove the __FMODE_EXEC from uselib. > > > > It's kind of wrong anyway. > > Yeah. > > > So I think just removing __FMODE_EXEC would just do the > > RightThing(tm), and changes nothing for any sane situation. > > Agreed about these: > > - fs/fcntl.c is just doing a bitfield sanity check. > > - nfs_open_permission_mask(), as you say, is only checking for > unreadable case. > > - fsnotify would also see uselib() as a read, but afaict, > that's what it would see for an mmap(), so this should > be functionally safe. > > This one, though, I need some more time to examine: > > - AppArmor, TOMOYO, and LandLock will see uselib() as an > open-for-read, so that might still be a problem? As you > say, it's more of a mmap() call, but that would mean > adding something a call like security_mmap_file() into > uselib()... > > The issue isn't an insane "support uselib() under AppArmor" case, but > rather "Can uselib() be used to bypass exec/mmap checks?" > > This totally untested patch might give appropriate coverage: > > diff --git a/fs/exec.c b/fs/exec.c > index d179abb78a1c..0c9265312c8d 100644 > --- a/fs/exec.c > +++ b/fs/exec.c > @@ -143,6 +143,10 @@ SYSCALL_DEFINE1(uselib, const char __user *, library) > if (IS_ERR(file)) > goto out; > > + error = security_mmap_file(file, PROT_READ | PROT_EXEC, MAP_FIXED | MAP_SHARED); Actually, this should probably match was load_shlib() uses: PROT_READ | PROT_WRITE | PROT_EXEC, MAP_FIXED_NOREPLACE | MAP_PRIVATE, -- Kees Cook