Received: by 2002:a05:7412:a9a3:b0:f9:327e:43ab with SMTP id o35csp104581rdh; Mon, 18 Dec 2023 05:47:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IFWWSYYqfeGq5pnpAtf1CVIUKvv0bdPVds4JpJRZ6bz33UR6G2OBLSXPzkGTTHLrqX9cdUy X-Received: by 2002:a05:620a:2401:b0:77f:684:5b1 with SMTP id d1-20020a05620a240100b0077f068405b1mr26780567qkn.47.1702907240384; Mon, 18 Dec 2023 05:47:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702907240; cv=none; d=google.com; s=arc-20160816; b=OLAWtmAcOfXmMo9uzajJ9AmKShYmOfAaZkl7ObfIHVEO9ILnNgQPlu8gjrvD0ZJF9A wR2/9btoVz+9fvUxTLltEEf8H+oelQ6yw10ji4pxtcWywz11y2KTlg4b8CLnVWmd+NFU Zv3apa/5im1ZYhYyqqYSOSY+8WacJpNNsie9UMXYKop6r4A3lntpxMKC+grI3iDU11MZ 53LSuGrRMgrdHxtWE45czQmMz25JOAZh5ZSA4Tkqvgg7Gv286Ycp0LOOLlDijt0Saz8g LspHL6fHE21CjIg1UH7olJSKQ4wncPpVag121FsG1r/R9ZiYcHqXc7ZM2lUskIqYybyM vNgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=h4k4Fh/TASWn1uJrItxeFdHWOjIQFIOHIcCI80h3IYQ=; fh=i/8NkxMDeWOy8pqwFbMJmGA0QiDAIkK6bY5oMPmvo7U=; b=NcUMsr7XN04tf/H+PEEag1pZStlKuG8nfLek3gr/L0VGsR32Njzj/tOAE52705upvU 6PbnYtUuejWLJZ6fvRuMuBCYL3no/7X0qC6LzduPXJa05yvGwdWpSG1dgkw5KmZaCOzh 5Pn5yoB9oqkC63agGsPBmAcclfx/1rp2d5rk3gazhG5o9aa/6vHb4C3V4dVNJLq+sLfW QxYJ2IbAtbB+1b8EXex3HlDozk0bohdNs4Xx8bytVHVPowrYwM+bD/PVVeQwMgs72gGM 9EPjS+pk4FpbbWs6KiDECBzAOVnfrpJCQe9+H9Sd+cuiqaDJDsH71T7YqVVIBPsVqMyh Y1Pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=itDeCEwX; spf=pass (google.com: domain of linux-kernel+bounces-3772-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3772-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id v13-20020a05620a0f0d00b007742e8f217asi552871qkl.450.2023.12.18.05.47.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 05:47:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3772-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=itDeCEwX; spf=pass (google.com: domain of linux-kernel+bounces-3772-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3772-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 EDBB61C233F0 for ; Mon, 18 Dec 2023 13:47:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8838E1D12A; Mon, 18 Dec 2023 13:47:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="itDeCEwX" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (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 8145A129EF7; Mon, 18 Dec 2023 13:47:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-5cd86e3a9afso1056696a12.1; Mon, 18 Dec 2023 05:47:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702907230; x=1703512030; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=h4k4Fh/TASWn1uJrItxeFdHWOjIQFIOHIcCI80h3IYQ=; b=itDeCEwXhrSLykXNxA9lV5oC4zcQV1hHC28ibq9gUITlXIFkeI8Y523mo2HGlGPxRf XsBlbNMhwOZxaA47RD7a9UJ/srIowUzKEm6lIzXyOAoudD2p7TJhDZXzlpBqRdlYB7P1 1jGNxLnJnXTWx6Xlp0QzjZHzMFkE+L/N1VrhpEPL+7GCQtLR6n71Md1Qnhcrn+nlbUCQ zc3HPRNzty/Rs5LTznQb3eofz2RAqqURESogAUcj3AL18dttGa7n/TMEjgFg+FUOVTGf AflqSAav7JT6jG81H/SZdKfgZRxzZnzvHzd5oe7P50a86gWoEwvfB+hZZSTbTwS8uXba LQYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702907230; x=1703512030; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=h4k4Fh/TASWn1uJrItxeFdHWOjIQFIOHIcCI80h3IYQ=; b=LZz1YaR2keoMwHZPT5Ozlg77hG4rX+J5Bzd1knDHQ2j3FH81B6G5Tk+nEXjpJioDWz k01gkPYGSjsP32mUzXYFz1kzvVLPJPgph+i9KDa+EeuddmDk+J2AIZrQ6SzDW1kjrPiw UkqzAAIzOZ/hz/Rt9kVsia9LXlSVo76s8ehWQD2ksOyUFhA4/hsjwvk/G4fcFxRuI+Rz lx/4OTjl8Cdnjd2FDlGA8M4zMEcz5/Vn7T5kkSzUNm4GJsvrtBNvGuvwTaTIm0bze/ra B7vyE2OW4Cs58K71Nhy0v01kbUX1/zpYZUmirdQ6srbfmy/MviSpZOGMnjxcFnrDsHtQ 5y+w== X-Gm-Message-State: AOJu0YzLVdHO8m2q5Jz0hJU8UHrHudqB8xCJLH8yjZUyywvdlyFwEH+2 Ag1tmHtHAdZmNya3bFTNX/ObqIPa3LhC62suHqg= X-Received: by 2002:a05:6a20:65b0:b0:190:6d:1c5a with SMTP id p48-20020a056a2065b000b00190006d1c5amr15311555pzh.56.1702907229671; Mon, 18 Dec 2023 05:47:09 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20230906102557.3432236-1-alpic@google.com> <20231218124137.2476015-1-alpic@google.com> In-Reply-To: <20231218124137.2476015-1-alpic@google.com> From: Stephen Smalley Date: Mon, 18 Dec 2023 08:46:58 -0500 Message-ID: Subject: Re: [PATCH] SELinux: Introduce security_file_ioctl_compat hook To: Alfred Piccioni Cc: Paul Moore , Eric Paris , stable@vger.kernel.org, selinux@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Dec 18, 2023 at 7:43=E2=80=AFAM Alfred Piccioni = wrote: > > Some ioctl commands do not require ioctl permission, but are routed to > other permissions such as FILE_GETATTR or FILE_SETATTR. This routing is > done by comparing the ioctl cmd to a set of 64-bit flags (FS_IOC_*). > > However, if a 32-bit process is running on a 64-bit kernel, it emmits s/emmits/emits/ > 32-bit flags (FS_IOC32_*) for certain ioctl operations. These flags are > being checked erroneously, which leads to these ioctl operations being > routed to the ioctl permission, rather than the correct file > permissions. > > This was also noted in a RED-PEN finding from a while back - > "/* RED-PEN how should LSM module know it's handling 32bit? */". > > This patch introduces a new hook, security_file_ioctl_compat, that > replaces security_file_ioctl if the CONFIG_COMPAT flag is on. All > current LSMs have been changed to hook into the compat flag. It doesn't (or shouldn't) replace security_file_ioctl, and the hook doesn't appear to be conditional on CONFIG_COMPAT per se. It is a new hook that is called from the compat ioctl syscall. The old hook continues to be used from the regular ioctl syscall and elsewhere. > Reviewing the three places where we are currently using > security_file_ioctl, it appears that only SELinux needs a dedicated > compat change; TOMOYO and SMACK appear to be functional without any > change. > > Fixes: 0b24dcb7f2f7 ("Revert "selinux: simplify ioctl checking"") > Signed-off-by: Alfred Piccioni > Cc: stable@vger.kernel.org > --- > diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c > index 83ef66644c21..170687b5985b 100644 > --- a/fs/overlayfs/inode.c > +++ b/fs/overlayfs/inode.c > @@ -751,7 +751,11 @@ static int ovl_security_fileattr(const struct path *= realpath, struct fileattr *f > else > cmd =3D fa->fsx_valid ? FS_IOC_FSGETXATTR : FS_IOC_GETFLA= GS; > > +#ifdef CONFIG_COMPAT > + err =3D security_file_ioctl_compat(file, cmd, 0); > +# else > err =3D security_file_ioctl(file, cmd, 0); > +#endif I don't understand why you made this change, possibly a leftover of an earlier version of the patch that tried to replace security_file_ioctl() everywhere?