From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by passt.top (Postfix, from userid 1000) id AC5825A026D; Mon, 27 Feb 2023 10:59:41 +0100 (CET) From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH 3/3] tcp: Avoid (theoretical) resource leak (CWE-772) Coverity warning Date: Mon, 27 Feb 2023 10:59:41 +0100 Message-Id: <20230227095941.225672-4-sbrivio@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230227095941.225672-1-sbrivio@redhat.com> References: <20230227095941.225672-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: NPMOV4EKC65PHXGHZDL5GATPJ6E22VLU X-Message-ID-Hash: NPMOV4EKC65PHXGHZDL5GATPJ6E22VLU X-MailFrom: sbrivio@passt.top X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: If tcp_timer_ctl() gets a socket number greater than SOCKET_MAX (2 ^ 24), we return error but we don't close the socket. This is a rather formal issue given that, at least on Linux, socket numbers are monotonic and we're in general not allowed to open so many sockets. Signed-off-by: Stefano Brivio --- tcp.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tcp.c b/tcp.c index 561064e..b674311 100644 --- a/tcp.c +++ b/tcp.c @@ -702,6 +702,9 @@ static void tcp_timer_ctl(const struct ctx *c, struct tcp_tap_conn *conn) fd = timerfd_create(CLOCK_MONOTONIC, 0); if (fd == -1 || fd > SOCKET_MAX) { debug("TCP: failed to get timer: %s", strerror(errno)); + if (fd > -1) + close(fd); + conn->timer = -1; return; } conn->timer = fd; -- 2.39.1