From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.197 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795998977; b=g5mAQxQW4VvXJ86x0FKUgTraYJL1HnCMVKu1ILBaut6khK9Rifp8Ri4GIXgUvDvQH1/P UCnxAkzst9Daeo3XwWYsI5/ER5AYFfSATaXWJsUCVEXq72qC7PVejCoPWAD5fpqFSUWWZ s7txUM045oG+mlYvI1ReJcrCBwI81eLa/+ogFt6sVfd6G6Z1sMXMbf/XHTl0uvBIBTzas 6V6pxAdzUDYJAekeL4lU0k1Fujs5JgECWdzO+k7GtjzkDicEHH8KBDxDm4gvkduXjYgmu y8RTfwHrrWcyJ05L7/xdPA6KtxqFBynnL6Lj8UKziaJrInabX5zz4wvJrM1ogUeFvgg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795998977; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:Message-ID:Subject:From:To:Cc:Content-Type; bh=gxBWlxtX9TRJujIxLd+D/ruiXZmHAb7W20JbMK02NuU=; b=CrK9Z2Lh4bmxFjlHKVovuJStqg7rHsIWdytbZ8GWqziIGTGYEGMXN2S/maeJWTjv7xSX X4Qboqw7ihGHXP8TvMuRyn2xJ3UJxQtNAV1+s0nnoNdX3qBDFtfKO0EqnXIdHKMl0LyyQ fcB0CcjGVhEf9oKIG/16oSYIaAQ7jMY/v/GIaN46SDpiCqPyayM3RQSc8IYDG0AJxUTc6 82gtm7ZWKm4G6y9Ad1dyu8QTbrNOc1L46VkXFYEUXAfN29TssJkk1QVMH/7/Ft6mUe6F/ CBRRmndp3MLOMIHzrX4bmQ10qFV/mQVGaDQy8EWwc14/Y+RSbelsZCk/mIWlIuqLRxA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--kuniyu.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=DAxAMlkN; arc=none smtp.remote-ip=209.85.214.197 Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66EB2606A31C for ; Mon, 30 Nov 2026 00:36:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 66EB2606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kuniyu.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=DAxAMlkN Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-2f045e399acso88470805ad.2 for ; Sun, 29 Nov 2026 16:36:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1795998977; x=1796603777; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=gxBWlxtX9TRJujIxLd+D/ruiXZmHAb7W20JbMK02NuU=; b=DAxAMlkNS9El3DeD/adZrZ+DAnBqMikw8zZMrAzW3t+DDzaMSRgsbmVNcmwya2J6Kr P26J6BIylTgLAPsG71FqVqubaUnLpNUJABHlDDxulCyqK4baraP1rIULRimLCeMiMEbQ cCLtvo1SqVMHapEAqWntd849Re6K8M1d7YkxpoJBO7wpPbCZNDedtF8DkDDIiN+E01ju zeqfj1rJ2PCSB1YHORVquq3zuyvm6icYG1igG6EoYjEH4opXin3gCto+jS58pL7PdTLg w7kbNklw2toe5Sw+12gX+13mpL+JSzv/17kmgAm3gtfgs2tJ1X5BnK0Sm50MEcmm5Yrv gxXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795998977; x=1796603777; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=gxBWlxtX9TRJujIxLd+D/ruiXZmHAb7W20JbMK02NuU=; b=YLJmi7VZWa9tLz5MACir2mms4TDGOPy6/ffB7HFRYQS1kL2665CfOU/jBzYuL/Sx0j WaG0K3Fwv+D0HrJ8l3vUKg/LOsu57addIzAUWhltBZ/72RMzsAWkmg3qi1gGXLZZEu0b TjfpdG4DTF6IHEmpH8Hkq22+AkbWkdE9tAjkU/jYjnhshx/jfYpr6GVUJkdlj+X+ak4G 60h4MPe39yTtihCRMoNFIOPCOzAGVGEM/tjVeohE7eN2qIlgXsXYAMvQpsB2aPlqjkpp wf7QVtKKZOsbncZiW7GYu4v4cfYR9kFDrU51+y7FbbY9Tizk+ZByFWEZLIiPAx8h+lt/ 0w8Q== X-Forwarded-Encrypted: i=1; AL+hErGTPLajXao0aayEd8WPK8lvY8DqFJcq8fUSbWlAcvINMu6QNWPXa9Jyn5oP8kwNR6De1kGuti4=@vger.kernel.org X-Gm-Message-State: APuU4Z8C1xUEmaj8aeYby6KVcmrqjtdUCilTfwI4cd8CYauXLmOWp7E5 gQ49CJ1g/ckEx8oDcNNDmgCh73qXjkTpAvMXUFEjlqXQ1/WpK1mtfApsaKDi684qp2bleku4ZA0 zxSNtCA== X-Received: from ploh18.prod.google.com ([2002:a17:902:f712:b0:2ef:f5cd:c465]) (user=kuniyu job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:2409:b0:2f0:436d:bdce with SMTP id d9443c01a7336-2f0436dc520mr303432045ad.46.1795998976362; Sun, 29 Nov 2026 16:36:16 -0800 (PST) Date: Mon, 30 Nov 2026 00:36:15 +0000 In-Reply-To: <20261124180600.71138-1-dmnk@google.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261124180600.71138-1-dmnk@google.com> Message-ID: Subject: Re: [PATCH net v2] inet: release newly acquired port on inet_csk_listen_start() hash error From: Kuniyuki Iwashima To: Dominik Maier Cc: Eric Dumazet , Neal Cardwell , Jakub Kicinski , Joanne Koong , netdev@vger.kernel.org, dmnk+artist@google.com Content-Type: text/plain; charset="us-ascii" On Tue, 24 Nov 2026 18:06:00 +0000, Dominik Maier wrote: > When inet_csk_listen_start() is called on a socket that has not been > explicitly bound, sk->sk_prot->get_port() allocates an ephemeral port > and links the socket into bhash and bhash2 without setting > SOCK_BINDPORT_LOCK. If sk->sk_prot->hash() then fails (for example, when > a prior failed connect() left icsk->unhashed_state set to TCP_SYN_SENT > so inet_hash() returns -EINVAL), inet_csk_listen_start() resets sk_state > to TCP_CLOSE and returns the error without releasing the newly acquired > port. > > Because inet->inet_num remains non-zero while SOCK_BINDPORT_LOCK is > unset, a subsequent Fast Open connect on a dual-stack AF_INET6 socket > can update sk_v6_rcv_saddr via tcp_v4_connect() without rehashing the > bhash2 entry. Disconnecting with AF_UNSPEC then invokes > __inet_put_port(), which locks the new address's bhash2 bucket while > unlinking and freeing tb2 from the original bhash2 bucket without > holding its spinlock. > > Record whether icsk->icsk_bind_hash was already populated before > get_port(). If sk->sk_prot->hash() fails on a newly bound socket, call > inet_put_port(sk) and clear inet->inet_sport before transitioning back > to TCP_CLOSE. Explicitly bound sockets retain their port. > > Fixes: 28044fc1d495 ("net: Add a bhash2 table hashed by port and address") > Cc: stable@vger.kernel.org > Signed-off-by: Dominik Maier Reviewed-by: Kuniyuki Iwashima