From nobody Thu Dec 18 11:45:15 2025 Received: from smtp-42a8.mail.infomaniak.ch (smtp-42a8.mail.infomaniak.ch [84.16.66.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 BE23220AF78 for ; Mon, 13 Jan 2025 16:11:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=84.16.66.168 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736784693; cv=none; b=tVn1Yx0CWp8EZUBoMiBoaa1KJPDQ6zLNMx6KpPjE7dHF7UkQ6z6PPsM+ltscw9sDQXZbBBT+vhoCj289+JOm7ikp0UqAFL4e2hXC4U6BCHCPV7cLDLym4EoQy5TOcyP+4rIgf8BDtqjyMHD4yDIl5A8xZBvcydWS51+EtbRoiEk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736784693; c=relaxed/simple; bh=e7EajQHBGxTlpsWtbyDOw7pIsgGDBwUT7WTk0sLggUE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AL99P1c3h6nNz6rcg9AEN1aRu4862cLP61QwxW3svKbZWF6MQU+Gwo5IlqP46nqnLcFrvpvvTs+3v2oQjFCoPkIP+K6D0TSeKNR8rn2Fo4pCx3jZ3D3G7c9NvADOxQIvmZNOA3uosDBd+/cdh/qigyLEJKmpai9l6Qvj084iwXw= 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=LkwwU1dF; arc=none smtp.client-ip=84.16.66.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="LkwwU1dF" Received: from smtp-3-0001.mail.infomaniak.ch (smtp-3-0001.mail.infomaniak.ch [10.4.36.108]) by smtp-3-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4YWy1P6695z12kn; Mon, 13 Jan 2025 17:11:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=digikod.net; s=20191114; t=1736784681; bh=aejfFX/wCqISAf4ObXFXZmBBY776r83KhR6yOC8AcQ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LkwwU1dFSVWTwo7QkKZpXioqyA0KUIWjz811gnY0mGTogVnVKyUmpBb217vQvb3xn xOAmal7mbxYjjokwMB+oVGPSBYdIOUX5vi/uq0bQg6vXyx8D06bMh/6Qc7T1BmVd8T hEHMm0t6df7Ob/KZt/fvyv8N2KcQSyY6pgeeSJzo= Received: from unknown by smtp-3-0001.mail.infomaniak.ch (Postfix) with ESMTPA id 4YWy1P2bL4zSVx; Mon, 13 Jan 2025 17:11:21 +0100 (CET) From: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= To: =?UTF-8?q?G=C3=BCnther=20Noack?= Cc: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Boqun Feng , Ingo Molnar , Konstantin Meskhidze , Matthieu Buffet , Mikhail Ivanov , Peter Zijlstra , Shervin Oloumi , Waiman Long , Will Deacon , linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org Subject: [PATCH v1 2/4] landlock: Use scoped guards for ruleset in landlock_add_rule() Date: Mon, 13 Jan 2025 17:11:10 +0100 Message-ID: <20250113161112.452505-3-mic@digikod.net> In-Reply-To: <20250113161112.452505-1-mic@digikod.net> References: <20250113161112.452505-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 Simplify error handling by replacing goto statements with automatic calls to landlock_put_ruleset() when going out of scope. This change depends on the TCP support. Cc: G=C3=BCnther Noack Cc: Konstantin Meskhidze Cc: Mikhail Ivanov Signed-off-by: Micka=C3=ABl Sala=C3=BCn Link: https://lore.kernel.org/r/20250113161112.452505-3-mic@digikod.net Reviewed-by: G=C3=BCnther Noack --- security/landlock/syscalls.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/security/landlock/syscalls.c b/security/landlock/syscalls.c index 5a7f1f77292e..a9760d252fc2 100644 --- a/security/landlock/syscalls.c +++ b/security/landlock/syscalls.c @@ -399,8 +399,7 @@ SYSCALL_DEFINE4(landlock_add_rule, const int, ruleset_f= d, const enum landlock_rule_type, rule_type, const void __user *const, rule_attr, const __u32, flags) { - struct landlock_ruleset *ruleset; - int err; + struct landlock_ruleset *ruleset __free(landlock_put_ruleset) =3D NULL; =20 if (!is_initialized()) return -EOPNOTSUPP; @@ -416,17 +415,12 @@ SYSCALL_DEFINE4(landlock_add_rule, const int, ruleset= _fd, =20 switch (rule_type) { case LANDLOCK_RULE_PATH_BENEATH: - err =3D add_rule_path_beneath(ruleset, rule_attr); - break; + return add_rule_path_beneath(ruleset, rule_attr); case LANDLOCK_RULE_NET_PORT: - err =3D add_rule_net_port(ruleset, rule_attr); - break; + return add_rule_net_port(ruleset, rule_attr); default: - err =3D -EINVAL; - break; + return -EINVAL; } - landlock_put_ruleset(ruleset); - return err; } =20 /* Enforcement */ --=20 2.47.1