From nobody Tue Nov 26 03:29:02 2024 Received: from smtp-8fa8.mail.infomaniak.ch (smtp-8fa8.mail.infomaniak.ch [83.166.143.168]) (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 B37FB1B14FA for ; Tue, 22 Oct 2024 16:10:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=83.166.143.168 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729613433; cv=none; b=S0p4FUdjrTPrRWmwbJrO1F3CJIRo8pKE+IkUpJAdAJGloGz46AAprm5PLF78DjwuVBpvnXQH3tEF+CtfYnrDFSm2oLt0GsLcXjF97PkbJk0lI8j5LAQh6QAtR7NKhNKTzI6bKlilob3xYlOiT5sT3kGZZDSZ7AtSb0HzphrK02s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729613433; c=relaxed/simple; bh=gKRPBSv5tRdn0WhX8XTWlq6SJW7sHsXoiZHnw6l3YeE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=APcCkIBptxZdTMBnj8cNLYiuGX5/2nteWC4/VXvTCAFHImJHRfMZfVHeboWReQEANxeZXVZ+zfQZh9QAJ1GVtCMeHmoiEuA1wPE5vIpkjjnfx2baztksTqOljGohWyEji1ribdjn6+7CIYC+0Ji0BwzYNHqHl/DQB9pNiT/oqe8= 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=d85gjLzQ; arc=none smtp.client-ip=83.166.143.168 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b="d85gjLzQ" Received: from smtp-3-0000.mail.infomaniak.ch (smtp-3-0000.mail.infomaniak.ch [10.4.36.107]) by smtp-3-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4XXxwb27ngzMZV; Tue, 22 Oct 2024 18:10:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=digikod.net; s=20191114; t=1729613423; bh=KiJAI6pzo/lR1j3ha++zSLq7VEjNzvmIBz7wSSyQs+A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d85gjLzQ0Yh9evyPoI84SlDBOBY24w/2YvFinONBukFG9wcckRuUv2a63QyteCogX je+JU/UDduA4izmDb5d6bl4AT81L9hzvuz4iPyuhSPBuKifqTrhwEkjqM2+Wye6H2f S7Xgx1fOfRNz3a7AZ1ULRVIlDlboGLvaTLSa5i9c= Received: from unknown by smtp-3-0000.mail.infomaniak.ch (Postfix) with ESMTPA id 4XXxwZ35zvzn8l; Tue, 22 Oct 2024 18:10:22 +0200 (CEST) From: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= To: Eric Paris , Paul Moore , =?UTF-8?q?G=C3=BCnther=20Noack?= , "Serge E . Hallyn" Cc: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Ben Scarlato , Casey Schaufler , Charles Zaffery , James Morris , Jann Horn , Jeff Xu , Jorge Lucangeli Obes , Kees Cook , Konstantin Meskhidze , Matt Bobrowski , Mikhail Ivanov , Praveen K Paladugu , Robert Salvet , Shervin Oloumi , Song Liu , Tahera Fahimi , audit@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org Subject: [RFC PATCH v2 03/14] landlock: Factor out check_access_path() Date: Tue, 22 Oct 2024 18:09:58 +0200 Message-ID: <20241022161009.982584-4-mic@digikod.net> In-Reply-To: <20241022161009.982584-1-mic@digikod.net> References: <20241022161009.982584-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: quoted-printable X-Infomaniak-Routing: alpha Merge check_access_path() into current_check_access_path() and make hook_path_mknod() use it. Cc: G=C3=BCnther Noack Signed-off-by: Micka=C3=ABl Sala=C3=BCn Link: https://lore.kernel.org/r/20241022161009.982584-4-mic@digikod.net --- Changes since v1: * Rebased on the TCP patch series. * Remove inlining removal which was merged. --- security/landlock/fs.c | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/security/landlock/fs.c b/security/landlock/fs.c index dd9a7297ea4e..698a623a8184 100644 --- a/security/landlock/fs.c +++ b/security/landlock/fs.c @@ -907,28 +907,22 @@ static bool is_access_to_paths_allowed( return allowed_parent1 && allowed_parent2; } =20 -static int check_access_path(const struct landlock_ruleset *const domain, - const struct path *const path, - access_mask_t access_request) -{ - layer_mask_t layer_masks[LANDLOCK_NUM_ACCESS_FS] =3D {}; - - access_request =3D landlock_init_layer_masks( - domain, access_request, &layer_masks, LANDLOCK_KEY_INODE); - if (is_access_to_paths_allowed(domain, path, access_request, - &layer_masks, NULL, 0, NULL, NULL)) - return 0; - return -EACCES; -} - static int current_check_access_path(const struct path *const path, - const access_mask_t access_request) + access_mask_t access_request) { const struct landlock_ruleset *const dom =3D get_current_fs_domain(); + layer_mask_t layer_masks[LANDLOCK_NUM_ACCESS_FS] =3D {}; =20 if (!dom) return 0; - return check_access_path(dom, path, access_request); + + access_request =3D landlock_init_layer_masks( + dom, access_request, &layer_masks, LANDLOCK_KEY_INODE); + if (is_access_to_paths_allowed(dom, path, access_request, &layer_masks, + NULL, 0, NULL, NULL)) + return 0; + + return -EACCES; } =20 static access_mask_t get_mode_access(const umode_t mode) @@ -1413,11 +1407,7 @@ static int hook_path_mknod(const struct path *const = dir, struct dentry *const dentry, const umode_t mode, const unsigned int dev) { - const struct landlock_ruleset *const dom =3D get_current_fs_domain(); - - if (!dom) - return 0; - return check_access_path(dom, dir, get_mode_access(mode)); + return current_check_access_path(dir, get_mode_access(mode)); } =20 static int hook_path_symlink(const struct path *const dir, --=20 2.47.0