Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1326725rdb; Mon, 19 Feb 2024 11:22:49 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUndji/kBOxct1P+q1fjYFrMxlGViGytJFSBgvszcwVAt8BhLvZnTFQWysP4oOgjEmIZl3buAQyr/RBGzz2JqBvh9lP4VXNj4ldQSvNZA== X-Google-Smtp-Source: AGHT+IElf3POQ4fVv/dxSzz8vJUYB393Szl5oCitFP8CBMVA+LiivOQ69V4RsbTMncWoFSU2YkQ6 X-Received: by 2002:a05:6a20:43a0:b0:1a0:849a:45be with SMTP id i32-20020a056a2043a000b001a0849a45bemr13125869pzl.46.1708370569172; Mon, 19 Feb 2024 11:22:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708370569; cv=pass; d=google.com; s=arc-20160816; b=kwcETMsJQk+bloqQ67tJuM844shLG4ywuIEwzsGLfIcA0o7WxWHU9cCy5YOThk1GJS ITxoFjHoYVL6XUYkgEHyLrCPkwr7AxavvwtFeTt0pPR9rKudqJLb1XK1ybx67k8JRITF 58CUyj6DlUmBSTEc+Cp6SppnpZ8jY2aTlVaJNXb4DReg7KkftTGg7tEApY9BRaPNySsg rYk8qKJegdQGHWZ6JkDpLknZGcr2kdhPi3ZcFjDh3sxM8M0GoiCLfTxKEwYbJBXjiA2Z ngS0LzreHFAWpivW5xr2qisFRgjBOjy0gtKLg63vVqOf/WMDRc9sYNNx2YrSlTbGRMqt 2Osw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=lStFc/jOLXluSDksA1X2bwl745EY+ayYp77myY2/f+s=; fh=RD9RXf5W8TUhgnEUGDkhSw4CBQCC7N8cn5VDBQJJCm4=; b=GO5/jgrJxgG07VFAb08e5v5JGTbRsZQYYBZVcF/DkARcujmZu6MN5KyH5djwdLAeoA 4EiDi5SOsFS79SKYv+R0xN2Yz8kUSol9aolI5ih4HWqzhkmF/KROXXdJ79r+SyKy/Awz pUeDdauTksiDiOppkdLi386SoguLPSPjgE4Z+rOs0GuG7ka1uXE8REs09RaE52ut5QE6 dNkrOgTpfdAV5g9g/qE/2hiF6XVFeKd9oH2fd8EUrBksBsm2Mu6KP/ER2UIEwswu5GlX +reVnvW8Yg2y7FLR9EncaoAWzWSfOwsPcZOkElixzVwdJyXlUAFabgAqcmnigElNHs9k lxdw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b=oYEBpSyH; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-71862-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71862-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id b14-20020a170902650e00b001dbd677a910si3592784plk.500.2024.02.19.11.22.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 11:22:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71862-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b=oYEBpSyH; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-71862-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71862-linux.lists.archive=gmail.com@vger.kernel.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id AE1ADB220CA for ; Mon, 19 Feb 2024 19:22:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 603F050A6B; Mon, 19 Feb 2024 19:22:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b="oYEBpSyH" Received: from smtp-190a.mail.infomaniak.ch (smtp-190a.mail.infomaniak.ch [185.125.25.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F17944C86 for ; Mon, 19 Feb 2024 19:22:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.25.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708370532; cv=none; b=GjigZix2Jl3kFEkF3onLDbC5DsOgh0PSeR/D1sWciGsMQE4siR6qdJXIqbB00tJ0gxOYZkTWNSrklXA2ALgSGXiE0Qr445D6cSlLWSsAQTnPShjrjUEfHiixfg2WNSc8/fTZsdy6zv7IChNc6hPegzEcTc58zy962MtvzQGbTgA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708370532; c=relaxed/simple; bh=2Hj9UWhrDgzjOkOL5rsGTh1N6ZOemj+WfIpokHEQmEQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=jSjpXxn65YcPbjjU0q81G88ZY02mVxftFXMWNADPgzxT8ZFkoDAwYPnZI2GU1GV++9B+nsd74LeKTKMYBxVQIvhbjRpRfb1evSxUq5MXz2qLDyoDtBzTJDgT1BoNOZAnfzbt6WRZsvinJxPT3dLtp5cnfBeQS+WnFWTs9j1qm4E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=digikod.net; spf=pass smtp.mailfrom=digikod.net; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b=oYEBpSyH; arc=none smtp.client-ip=185.125.25.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=digikod.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=digikod.net Received: from smtp-4-0001.mail.infomaniak.ch (unknown [10.7.10.108]) by smtp-3-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4TdsQN4czSzMq2jt; Mon, 19 Feb 2024 20:03:56 +0100 (CET) Received: from unknown by smtp-4-0001.mail.infomaniak.ch (Postfix) with ESMTPA id 4TdsQM6BKYzHc4; Mon, 19 Feb 2024 20:03:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=digikod.net; s=20191114; t=1708369436; bh=2Hj9UWhrDgzjOkOL5rsGTh1N6ZOemj+WfIpokHEQmEQ=; h=From:To:Cc:Subject:Date:From; b=oYEBpSyHPf3yCOV1oKVMu8oMFvPoQCSBIkNLD+IxvPoRrocGTlH6/8tVFY6grA/4c HrGPkpJHLNPY4iMEKl0tx04ZbxKvFox0qZDC43+cqxrcm7kdx5k9AWmXmBj0QePO/+ gDw7Cba472cs3BaH1+HVVVML+M4YsWMtlhVpbagM= From: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= To: Arnd Bergmann , Christian Brauner , =?UTF-8?q?G=C3=BCnther=20Noack?= , Jann Horn Cc: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Kees Cook , Konstantin Meskhidze , Paul Moore , "Serge E . Hallyn" , Shervin Oloumi , linux-fsdevel@vger.kernel.org, linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH] landlock: Fix asymmetric private inodes referring Date: Mon, 19 Feb 2024 20:03:45 +0100 Message-ID: <20240219190345.2928627-1-mic@digikod.net> 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=UTF-8 Content-Transfer-Encoding: 8bit X-Infomaniak-Routing: alpha When linking or renaming a file, if only one of the source or destination directory is backed by an S_PRIVATE inode, then the related set of layer masks would be used as uninitialized by is_access_to_paths_allowed(). This would result to indeterministic access for one side instead of always being allowed. This bug could only be triggered with a mounted filesystem containing both S_PRIVATE and !S_PRIVATE inodes, which doesn't seem possible. The collect_domain_accesses() calls return early if is_nouser_or_private() returns false, which means that the directory's superblock has SB_NOUSER or its inode has S_PRIVATE. Because rename or link actions are only allowed on the same mounted filesystem, the superblock is always the same for both source and destination directories. However, it might be possible in theory to have an S_PRIVATE parent source inode with an !S_PRIVATE parent destination inode, or vice versa. To make sure this case is not an issue, explicitly initialized both set of layer masks to 0, which means to allow all actions on the related side. If at least on side has !S_PRIVATE, then collect_domain_accesses() and is_access_to_paths_allowed() check for the required access rights. Cc: Arnd Bergmann Cc: Christian Brauner Cc: Günther Noack Cc: Jann Horn Cc: Shervin Oloumi Cc: stable@vger.kernel.org Fixes: b91c3e4ea756 ("landlock: Add support for file reparenting with LANDLOCK_ACCESS_FS_REFER") Signed-off-by: Mickaël Salaün --- security/landlock/fs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/security/landlock/fs.c b/security/landlock/fs.c index 90f7f6db1e87..f243c6a392ee 100644 --- a/security/landlock/fs.c +++ b/security/landlock/fs.c @@ -1093,8 +1093,8 @@ static int current_check_refer_path(struct dentry *const old_dentry, bool allow_parent1, allow_parent2; access_mask_t access_request_parent1, access_request_parent2; struct path mnt_dir; - layer_mask_t layer_masks_parent1[LANDLOCK_NUM_ACCESS_FS], - layer_masks_parent2[LANDLOCK_NUM_ACCESS_FS]; + layer_mask_t layer_masks_parent1[LANDLOCK_NUM_ACCESS_FS] = {}, + layer_masks_parent2[LANDLOCK_NUM_ACCESS_FS] = {}; if (!dom) return 0; -- 2.43.0