From patchwork Fri Jan 10 15:39:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micka=C3=ABl_Sala=C3=BCn?= X-Patchwork-Id: 13935045 Received: from smtp-bc0b.mail.infomaniak.ch (smtp-bc0b.mail.infomaniak.ch [45.157.188.11]) (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 F18B3211701 for ; Fri, 10 Jan 2025 15:39:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.157.188.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736523574; cv=none; b=F6l664PIRrdFoAg6OU+CfW9R/1dHl4BsKd0OK0DuA4fCIp7JHi1tsZR/tFMt6JWTZrp5yyp/hXyHhOtyWYMEgpTBwgzFkI9/yy8P/59E/+XczmA3LnXIkvl7FOmWjUz7Tp2cLyQxcEf6mP07Mp1R+H4rvq9AdHvA0dLoY+HACSs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736523574; c=relaxed/simple; bh=V1yAhAaw7cF8jS7hyOsRxEsq7v6QEh7ic+3H0uTdT3o=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=p5R5PslcX4EIZcCWTIFlxgQuQZIBkVVxzLv0lQYTU2CsWgbLUf46Ajoz2JdVgusc1DlX6djgnHgoJznMRHuQvrcl1CqKVDI0nsMcSjbfmJpgQZsm4okYx6qyWW5shEV4PHLlw61xYxhaWSmkZU/Ewry4//AN2ytvSfz89cKpIcw= 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=BeVDgVwJ; arc=none smtp.client-ip=45.157.188.11 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="BeVDgVwJ" Received: from smtp-4-0001.mail.infomaniak.ch (unknown [IPv6:2001:1600:7:10:40ca:feff:fe05:1]) by smtp-4-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4YV5Ry5z60zLQg; Fri, 10 Jan 2025 16:39:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=digikod.net; s=20191114; t=1736523566; bh=JwMC7dDoGc9u/Z/aQtgLAFpqqY+jSE/ZJsPCOI3W4G8=; h=From:To:Cc:Subject:Date:From; b=BeVDgVwJKKzuQT5k2gA5zpnese2Vq1YA5NAjLifF4F0qXv4gOhvbYerZAmi1qzIad J7Xv6iVsld5ZAocmbhT9dN5KwFFRBHBtm1uWO0mHpALZElesk+wmLZSCN9Mn/82SC4 Bwa2lWIPLibEP3inyoHAnFLlmOIWYGFe0H3gsVwE= Received: from unknown by smtp-4-0001.mail.infomaniak.ch (Postfix) with ESMTPA id 4YV5Rx6CZHz6L2; Fri, 10 Jan 2025 16:39:25 +0100 (CET) From: =?utf-8?q?Micka=C3=ABl_Sala=C3=BCn?= To: =?utf-8?q?G=C3=BCnther_Noack?= Cc: =?utf-8?q?Micka=C3=ABl_Sala=C3=BCn?= , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, Paul Moore , Dave Chinner , Kent Overstreet , syzbot+34b68f850391452207df@syzkaller.appspotmail.com, syzbot+360866a59e3c80510a62@syzkaller.appspotmail.com, Ubisectech Sirius Subject: [PATCH v1 1/2] landlock: Handle weird files Date: Fri, 10 Jan 2025 16:39:13 +0100 Message-ID: <20250110153918.241810-1-mic@digikod.net> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Infomaniak-Routing: alpha A corrupted filesystem (e.g. bcachefs) might return weird files. Instead of throwing a warning and allowing access to such file, treat them as regular files. Cc: Dave Chinner Cc: Günther Noack Cc: Kent Overstreet Cc: Paul Moore Reported-by: syzbot+34b68f850391452207df@syzkaller.appspotmail.com Closes: https://lore.kernel.org/r/000000000000a65b35061cffca61@google.com Reported-by: syzbot+360866a59e3c80510a62@syzkaller.appspotmail.com Closes: https://lore.kernel.org/r/67379b3f.050a0220.85a0.0001.GAE@google.com Reported-by: Ubisectech Sirius Closes: https://lore.kernel.org/r/c426821d-8380-46c4-a494-7008bbd7dd13.bugreport@ubisectech.com Fixes: cb2c7d1a1776 ("landlock: Support filesystem access-control") Signed-off-by: Mickaël Salaün Reviewed-by: Günther Noack --- security/landlock/fs.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/security/landlock/fs.c b/security/landlock/fs.c index e31b97a9f175..7adb25150488 100644 --- a/security/landlock/fs.c +++ b/security/landlock/fs.c @@ -937,10 +937,6 @@ static access_mask_t get_mode_access(const umode_t mode) switch (mode & S_IFMT) { case S_IFLNK: return LANDLOCK_ACCESS_FS_MAKE_SYM; - case 0: - /* A zero mode translates to S_IFREG. */ - case S_IFREG: - return LANDLOCK_ACCESS_FS_MAKE_REG; case S_IFDIR: return LANDLOCK_ACCESS_FS_MAKE_DIR; case S_IFCHR: @@ -951,9 +947,12 @@ static access_mask_t get_mode_access(const umode_t mode) return LANDLOCK_ACCESS_FS_MAKE_FIFO; case S_IFSOCK: return LANDLOCK_ACCESS_FS_MAKE_SOCK; + case S_IFREG: + case 0: + /* A zero mode translates to S_IFREG. */ default: - WARN_ON_ONCE(1); - return 0; + /* Treats weird files as regular files. */ + return LANDLOCK_ACCESS_FS_MAKE_REG; } } From patchwork Fri Jan 10 15:39:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micka=C3=ABl_Sala=C3=BCn?= X-Patchwork-Id: 13935044 Received: from smtp-42aa.mail.infomaniak.ch (smtp-42aa.mail.infomaniak.ch [84.16.66.170]) (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 AC45C21149C for ; Fri, 10 Jan 2025 15:39:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=84.16.66.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736523573; cv=none; b=rWB4J0m7zHfi3kL8rqKlSxGi6Vap8ypP9C1x3tSKGrxHYPYzhknzQwDT9IBSUBqrOmMUhw4y3l3G6C2HVXHdnTBJsRD9EBE5Mmaeanf8e25hTysFLHRNRRMwVdjKgpsLsy42E1+j0m++fKkTCEeCiA1bqmXTtK9iodQ1yq9vF8U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736523573; c=relaxed/simple; bh=/PlasUUg+tCGz3EHMvkEX/mc5natk/yUYrZEcdMowco=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=buSfOEF/+hs/WKGBYOWFg+jQSuZvnkguGr9n6CjJbHFdyN+qWbDLKvJEjXeaG8GB2o3rOWj0uO7NINRU2Z4RDGKGQGgEDevcz4awfYAZxboZK+lB/Ku+ihh86VyyqrhrB9DMxdQV2N/KxyYkTV5iYwVRzjZONYW0P06uYc3Ubh4= 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=P2meaDr+; arc=none smtp.client-ip=84.16.66.170 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="P2meaDr+" Received: from smtp-3-0001.mail.infomaniak.ch (unknown [IPv6:2001:1600:4:17::246c]) by smtp-3-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4YV5S00bF7z48X; Fri, 10 Jan 2025 16:39:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=digikod.net; s=20191114; t=1736523567; bh=AsHxtaI/j0xAJpUvjMF5GGxk6M6C8AwNGet+DOF16/Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P2meaDr+yvTyyWxF4mFKaRzgKZwGy+K3iASGZUsDnRCyTmnC7qiUh70RhIoeS6r8e 7u9+vjel70PKagbJGyaR929v7mZtAJbcsdpgpOF+OTxMWQ6NQ2kUOu+IZeQc/CnKFW BjJDgD6nBK2cfkesZHTXwWkRVTGu1zysxHyV1V4Y= Received: from unknown by smtp-3-0001.mail.infomaniak.ch (Postfix) with ESMTPA id 4YV5Rz3J9ZzKnD; Fri, 10 Jan 2025 16:39:27 +0100 (CET) From: =?utf-8?q?Micka=C3=ABl_Sala=C3=BCn?= To: =?utf-8?q?G=C3=BCnther_Noack?= Cc: =?utf-8?q?Micka=C3=ABl_Sala=C3=BCn?= , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, Paul Moore Subject: [PATCH v1 2/2] landlock: Constify get_mode_access() Date: Fri, 10 Jan 2025 16:39:14 +0100 Message-ID: <20250110153918.241810-2-mic@digikod.net> In-Reply-To: <20250110153918.241810-1-mic@digikod.net> References: <20250110153918.241810-1-mic@digikod.net> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Infomaniak-Routing: alpha Use __attribute_const__ for get_mode_access(). Cc: Günther Noack Signed-off-by: Mickaël Salaün Reviewed-by: Günther Noack --- security/landlock/fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/security/landlock/fs.c b/security/landlock/fs.c index 7adb25150488..f81d0335b825 100644 --- a/security/landlock/fs.c +++ b/security/landlock/fs.c @@ -932,7 +932,7 @@ static int current_check_access_path(const struct path *const path, return check_access_path(dom, path, access_request); } -static access_mask_t get_mode_access(const umode_t mode) +static __attribute_const__ access_mask_t get_mode_access(const umode_t mode) { switch (mode & S_IFMT) { case S_IFLNK: