From nobody Fri Mar 07 07:00:57 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Z8HHt1C1Rzt5Ht; Fri, 07 Mar 2025 07:00:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Z8HHs3sp1z3h94; Fri, 07 Mar 2025 07:00:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1741330857; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=o8SnTKqvSeTLIXhFa02Lrh/F7Ht6kedfuT4kyToZBSQ=; b=x0xioRrLsLsquioopcJ4NYC3/2RK/kXCBKKaPuUDmvlG6tTucQXSB7JVbNGlCHI8F9Ro25 sqfVU3QleeCjZxvYKJm6n7Gtg83uZeV1i6KM+E54nzeqb/JAs1ZSnm6iIMb8A/Oew89l/3 RG9LjBvE63taePYyx9pSpCMbXO6kvexLQu7XU2Mz0xpgtCr36y2Kfa27mNA9GpAig6VlNj qTdR5iQq+qPyqDUsoAE0dOuC+xarmJNMsOlclZgcxHR9GjVnhenyPIs8I5Zj9KQtHPrxyt OYZadUDFl7k6I3WJT9jWBv+xkUMVRKnxlh5preE+J9xc3L7oz2wGHuyECxI2iw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1741330857; a=rsa-sha256; cv=none; b=iUrHd8Qx7itmyyhbeFOeIHf5E6D07mbYl4pyMLNpHytTv0JenqGFpKLqyU8GTZAeOatUHZ D/aMmAoYs83uR1H+rZpS3UuQEWt8Ow9tcDOxzQH1Fi92lI6fAc/iKiFRL1Nx1FSzQStBUL R1NXopdgmlfBlfof0BbmjQOdP2+1xD0gG8lEGfeC8LQmY9NL9evmmkh2je5XtnXYA2+h3+ K8JxqTE8AaV1P2qeetPWuUlPLyAf+8gjkmxcNcjEfWn3ZNS06P+JYNKmy27xr4Jkiptuak +bJncMZxnGeZaCQnYfv616Nb4VPu/+3Hb74D+cBjMTAUs65YpQI+EmUf1p4vwg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1741330857; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=o8SnTKqvSeTLIXhFa02Lrh/F7Ht6kedfuT4kyToZBSQ=; b=jFARA0yaTMVrkQ181nSD4h4Dlw40UtXIoZ+xESQKbYnoPoYHzsW/lLv1+L/2SryQTrrmx/ OxS4qI08VK/cSJE0bpx7SFJbWCDKPQMWPTbb1HXOkwl/N23DrJ7460nL09Z1da5FSAFim8 cQPKkQUD0PFEcOopYxlcDm1ekFySRTDwhbb+PaPLFZiUewlEUxZGOEa4epa+4IIzaFES06 T3swrWefZsyqKecr7m4N7kBowX67xFcH8YZA9hokoz7lJ9CQpkFDgwUDCzklGOCVvkydYL O2Z3bmbIMT2HKdwPY1QJIvkWYALhEWK4QXLqadHDJ2A7+qpGfV+75+EP3bwtsA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Z8HHs2wmbzBBZ; Fri, 07 Mar 2025 07:00:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 52770vcF063471; Fri, 7 Mar 2025 07:00:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 52770vnb063468; Fri, 7 Mar 2025 07:00:57 GMT (envelope-from git) Date: Fri, 7 Mar 2025 07:00:57 GMT Message-Id: <202503070700.52770vnb063468@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: 136c5e17b61a - main - inpcb: return ENOMEM if bind(2) fails to allocate lbgroup List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 136c5e17b61a16482c696d4ba417e02563a7e465 Auto-Submitted: auto-generated The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=136c5e17b61a16482c696d4ba417e02563a7e465 commit 136c5e17b61a16482c696d4ba417e02563a7e465 Author: Gleb Smirnoff AuthorDate: 2025-03-07 06:59:46 +0000 Commit: Gleb Smirnoff CommitDate: 2025-03-07 06:59:46 +0000 inpcb: return ENOMEM if bind(2) fails to allocate lbgroup The SO_REUSEPORT_LB isn't a standard option, neither ENOMEM is a specified return code from bind(2), but it definitely is more appropriate than EAGAIN or the masked ENOBUFS. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D49153 --- sys/netinet/in_pcb.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 8a99297f3818..47852a8cda4b 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -435,7 +435,7 @@ in_pcbinslbgrouphash(struct inpcb *inp, uint8_t numa_domain) inp->inp_lport, &inp->inp_inc.inc_ie.ie_dependladdr, INPCBLBGROUP_SIZMIN, numa_domain, fib); if (grp == NULL) - return (ENOBUFS); + return (ENOMEM); in_pcblbgroup_insert(grp, inp); CK_LIST_INSERT_HEAD(hdr, grp, il_list); } else if (grp->il_inpcnt + grp->il_pendcnt == grp->il_inpsiz) { @@ -449,7 +449,7 @@ in_pcbinslbgrouphash(struct inpcb *inp, uint8_t numa_domain) /* Expand this local group. */ grp = in_pcblbgroup_resize(hdr, grp, grp->il_inpsiz * 2); if (grp == NULL) - return (ENOBUFS); + return (ENOMEM); in_pcblbgroup_insert(grp, inp); } else { in_pcblbgroup_insert(grp, inp); @@ -732,11 +732,12 @@ in_pcbbind(struct inpcb *inp, struct sockaddr_in *sin, int flags, &inp->inp_lport, flags, cred); if (error) return (error); - if (in_pcbinshash(inp) != 0) { + if (__predict_false((error = in_pcbinshash(inp)) != 0)) { + MPASS(inp->inp_socket->so_options & SO_REUSEPORT_LB); inp->inp_laddr.s_addr = INADDR_ANY; inp->inp_lport = 0; inp->inp_flags &= ~INP_BOUNDFIB; - return (EAGAIN); + return (error); } if (anonport) inp->inp_flags |= INP_ANONPORT; @@ -2611,6 +2612,10 @@ _in6_pcbinshash_wild(struct inpcbhead *pcbhash, struct inpcb *inp) /* * Insert PCB onto various hash lists. + * + * With normal sockets this function shall not fail, so it could return void. + * But for SO_REUSEPORT_LB it may need to allocate memory with locks held, + * that's the only condition when it can fail. */ int in_pcbinshash(struct inpcb *inp)