From patchwork Tue Jun 10 21:30:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eelco Chaudron X-Patchwork-Id: 2096421 X-Patchwork-Delegate: aconole@redhat.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=EW/1umi0; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4bH25J1q3Zz1yYd for ; Wed, 11 Jun 2025 07:30:26 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 5445F41F8A; Tue, 10 Jun 2025 21:30:38 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id Zd1oKpkikFSD; Tue, 10 Jun 2025 21:30:36 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=2605:bc80:3010:104::8cd3:938; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 9FA0641C99 Authentication-Results: smtp4.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=EW/1umi0 Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp4.osuosl.org (Postfix) with ESMTPS id 9FA0641C99; Tue, 10 Jun 2025 21:30:36 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 6C217C0AC5; Tue, 10 Jun 2025 21:30:36 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 09D29C0AC4 for ; Tue, 10 Jun 2025 21:30:35 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 006CD60804 for ; Tue, 10 Jun 2025 21:30:35 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 1KlQKKltX5-F for ; Tue, 10 Jun 2025 21:30:34 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.133.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=echaudro@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp3.osuosl.org 4AAF76070C Authentication-Results: smtp3.osuosl.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 4AAF76070C Authentication-Results: smtp3.osuosl.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=EW/1umi0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp3.osuosl.org (Postfix) with ESMTPS id 4AAF76070C for ; Tue, 10 Jun 2025 21:30:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749591032; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=wuK/x00mcNFjt2GvGpDL0bvRELw7thE90NWKUbGh2YU=; b=EW/1umi0syyToHgiEeFRA74rQWhM32yJpeOKUxOJbVVkf8VCgL90gzOTjjlsHDp/TLOoj9 /aYfs7JpKGMyypXmPPvGH73L7lVV8Yu9lAV2mv9ner1YEX4bRs41G1+lnQg8DP/gPyHUNC /JGMarffzz7guROO4Vks2oKZWIeD5M8= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-640-e7HclxBjNqGj4DLB0rFodw-1; Tue, 10 Jun 2025 17:30:31 -0400 X-MC-Unique: e7HclxBjNqGj4DLB0rFodw-1 X-Mimecast-MFC-AGG-ID: e7HclxBjNqGj4DLB0rFodw_1749591030 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3CC8619560AA for ; Tue, 10 Jun 2025 21:30:30 +0000 (UTC) Received: from ebuild.redhat.com (unknown [10.45.224.55]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 280CB195608D; Tue, 10 Jun 2025 21:30:28 +0000 (UTC) To: dev@openvswitch.org Date: Tue, 10 Jun 2025 23:30:24 +0200 Message-ID: <5fc35a2a983a93a88e44bde0492f37a717578d4d.1749591024.git.echaudro@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: lMtPhlTycRE28uxh_FlXi-E22FcCzaw8o4gVm3AjVaA_1749591030 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH v2] daemon-unix: Handle potential negative values from sysconf(). X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Eelco Chaudron via dev From: Eelco Chaudron Reply-To: Eelco Chaudron Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Coverity reports that daemon_set_new_user() may receive a large unsigned value from get_sysconf_buffer_size(), due to sysconf() returning -1 and being cast to size_t. Although this would likely lead to an allocation failure and abort, it's better to handle the error in place. Signed-off-by: Eelco Chaudron Acked-by: Aaron Conole --- v2: added comment to the code on -1 return reasons. --- lib/daemon-unix.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/daemon-unix.c b/lib/daemon-unix.c index 4fdc6e3c4..6d02aceeb 100644 --- a/lib/daemon-unix.c +++ b/lib/daemon-unix.c @@ -915,8 +915,9 @@ daemon_become_new_user(bool access_datapath, bool access_hardware_ports) static size_t get_sysconf_buffer_size(void) { - size_t bufsize, pwd_bs = 0, grp_bs = 0; const size_t default_bufsize = 1024; + long pwd_bs = 0, grp_bs = 0; + size_t bufsize; errno = 0; if ((pwd_bs = sysconf(_SC_GETPW_R_SIZE_MAX)) == -1) { @@ -924,14 +925,24 @@ get_sysconf_buffer_size(void) VLOG_FATAL("%s: Read initial passwordd struct size " "failed (%s), aborting. ", pidfile, ovs_strerror(errno)); + } else { + /* As per API documentation, sysconf(_SC_GETPW_R_SIZE_MAX) may + * return -1 without setting errno, indicating no recommended + * size. In that case, fall back to the default buffer size. */ + pwd_bs = default_bufsize; } } + errno = 0; if ((grp_bs = sysconf(_SC_GETGR_R_SIZE_MAX)) == -1) { if (errno) { VLOG_FATAL("%s: Read initial group struct size " "failed (%s), aborting. ", pidfile, ovs_strerror(errno)); + } else { + /* See above comment on _SC_GETPW_R_SIZE_MAX, as the same applies + * to _SC_GETGR_R_SIZE_MAX. */ + grp_bs = default_bufsize; } }