From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-8fa9.mail.infomaniak.ch (smtp-8fa9.mail.infomaniak.ch [83.166.143.169]) (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 9F8C42FF147 for ; Thu, 2 Apr 2026 19:31:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=83.166.143.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775158311; cv=none; b=LOSZSslb5psHyuxtKrPnG/oLlciL2XsR0VbZ4V3X4jP6V1wI4ijj+CuwaQxSIgn3CzNSgWjpLjGHyLu/Ich+AURZgkCQs4tx4z5T3KPPohcFStoMOjNAnawC/csRe/rdNbWSLuEE2Y1luQlzyuTEC0P1/oMsDVTHe2SnnEhjHLE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775158311; c=relaxed/simple; bh=ZLPFmzVxTeoO3UlZmgJPRYil3LGxf2tKed38PwRRnzw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sHFVgj42140mnDA4xSmlgicG7hk5vsoA1Pae9fHrAv3GT3z+PJoTKhDyQIZY//WVA8n9BBdMhz97QUsjdkYlUC+x3HO4TABtIz5XZg31J3IrnQuQLjEZAUJLg1ZGtuS+1x/j0ZKml1/EZLjOeWrqaYA28NT3ctR7/LldcuUZ7cc= 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=jKZkAH1x; arc=none smtp.client-ip=83.166.143.169 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="jKZkAH1x" Received: from smtp-4-0000.mail.infomaniak.ch (unknown [IPv6:2001:1600:7:10::a6b]) by smtp-4-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4fmsKN2Q5KzJvr; Thu, 2 Apr 2026 21:26:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=digikod.net; s=20191114; t=1775157976; bh=0gLvNpHE+Gf58oSodBBF5EKIn7dLRrInQCSTksiP2hA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jKZkAH1xjaMPNuC/gZe5yutRyNaT6XZjqdl89DePO1liCCtLhdmcFDiaqjH2joRia elm4SHvKvID5HCvqOQVAQi7WJXJ2SKzcLefd5bfW2BQJ3aHK1vcxTcUmOAaLYA8bwe prhajC7NvzUlyiLSesEmnyiP60GxsQtfXT4blt08= Received: from unknown by smtp-4-0000.mail.infomaniak.ch (Postfix) with ESMTPA id 4fmsKM6pzTzDMt; Thu, 2 Apr 2026 21:26:15 +0200 (CEST) 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?= , linux-security-module@vger.kernel.org, Justin Suess , Tingmao Wang , stable@vger.kernel.org Subject: [PATCH v3 2/5] selftests/landlock: Fix socket file descriptor leaks in audit helpers Date: Thu, 2 Apr 2026 21:26:03 +0200 Message-ID: <20260402192608.1458252-3-mic@digikod.net> In-Reply-To: <20260402192608.1458252-1-mic@digikod.net> References: <20260402192608.1458252-1-mic@digikod.net> Precedence: bulk X-Mailing-List: linux-security-module@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 audit_init() opens a netlink socket and configures it, but leaks the file descriptor if audit_set_status() or setsockopt() fails. Fix this by jumping to an error path that closes the socket before returning. Apply the same fix to audit_init_with_exe_filter(), which leaks the file descriptor from audit_init() if audit_init_filter_exe() or audit_filter_exe() fails, and to audit_cleanup(), which leaks it if audit_init_filter_exe() fails in FIXTURE_TEARDOWN_PARENT(). Cc: Günther Noack Cc: stable@vger.kernel.org Fixes: 6a500b22971c ("selftests/landlock: Add tests for audit flags and domain IDs") Signed-off-by: Mickaël Salaün --- Changes since v1: https://lore.kernel.org/r/20260312100444.2609563-8-mic@digikod.net - New patch (split from the drain fix, extended to audit_init_with_exe_filter() and audit_cleanup()). --- tools/testing/selftests/landlock/audit.h | 26 +++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/landlock/audit.h b/tools/testing/selftests/landlock/audit.h index 1049a0582af5..6422943fc69e 100644 --- a/tools/testing/selftests/landlock/audit.h +++ b/tools/testing/selftests/landlock/audit.h @@ -379,19 +379,25 @@ static int audit_init(void) err = audit_set_status(fd, AUDIT_STATUS_ENABLED, 1); if (err) - return err; + goto err_close; err = audit_set_status(fd, AUDIT_STATUS_PID, getpid()); if (err) - return err; + goto err_close; /* Sets a timeout for negative tests. */ err = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &audit_tv_default, sizeof(audit_tv_default)); - if (err) - return -errno; + if (err) { + err = -errno; + goto err_close; + } return fd; + +err_close: + close(fd); + return err; } static int audit_init_filter_exe(struct audit_filter *filter, const char *path) @@ -441,8 +447,10 @@ static int audit_cleanup(int audit_fd, struct audit_filter *filter) filter = &new_filter; err = audit_init_filter_exe(filter, NULL); - if (err) + if (err) { + close(audit_fd); return err; + } } /* Filters might not be in place. */ @@ -468,11 +476,15 @@ static int audit_init_with_exe_filter(struct audit_filter *filter) err = audit_init_filter_exe(filter, NULL); if (err) - return err; + goto err_close; err = audit_filter_exe(fd, filter, AUDIT_ADD_RULE); if (err) - return err; + goto err_close; return fd; + +err_close: + close(fd); + return err; } -- 2.53.0