Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1nyFj8-0001Ll-QE for mharc-grub-devel@gnu.org; Mon, 06 Jun 2022 12:37:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54620) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyFj6-0001LQ-UX for grub-devel@gnu.org; Mon, 06 Jun 2022 12:37:12 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]:36714) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nyFj2-0004Xi-9B for grub-devel@gnu.org; Mon, 06 Jun 2022 12:37:12 -0400 Received: by mail-pf1-x42d.google.com with SMTP id 15so13137214pfy.3 for ; Mon, 06 Jun 2022 09:37:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leblancnet-us.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Q7Tftdlj5Dmsbkq3fhJ0EVAt1xlJD+BUYE1rRyiOUjI=; b=gEu4NoEL823OQZCowqeruJzFKX5wTf0jPfxS7ZUuui0lHv+Lcz+VjY4uolIAioHUPz 2HLPPtSgNPySaq/kHxafAw58K/SBR9fg9EPG6+Ty+mHXW0gKhtUY2EobXFGCT0fHjSvM EBevqtFp0+bz7WPwZTtOqDyAOTBimJMScTOBh1zpHUjlZd0vC+g9la78Ou8aW26naCO9 edbze5lQYC7wp3Id0EulqxqETYirmLE4HXUOUqpjmUHo0XdOFKDyFQpTGTBQ5+WcvWEp bdD+thc0dAQ2BSpPeueUj+jWUqfQt07FXuMomKbLthML2sPKktJvG6IyMntYrw/My4ZN peEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Q7Tftdlj5Dmsbkq3fhJ0EVAt1xlJD+BUYE1rRyiOUjI=; b=Z0mq684tImzNLDJb49tKj1IlE3pGGnhxXhLY+p1w0y5/Jv38+9b0i6/lXNFYa8WRYF ufsnDS405mLeJHvfUTrFNv8aeFS7UEEh38ZI20uZD7sEWezxrre3iGncoF4oQ/OruXBX 29+v6lOWPLEgaZvv52DJ4PndAhm51iKlPZ0tBOBzfA6Mqz7ppA1UkI6dK20lUsCmhHxC 4CyfiaePoZV3zo0l43CzVemG+F4n8mUmvb8Twczb5WIKw6oeojjO+s92uQrlCnHbn4U0 Q6u6zJzULfjRiLIOxfmEBNQ3X5rpGQAsneCFVVH8pecyioek2L2yMJajX0/0V0N8rN5s MHGQ== X-Gm-Message-State: AOAM533Gj2pugXqb+/WNb+Lb/fUN3arfnsCi/EaIlvrq3LfITKuo46aj 8xrIwBRhKF3BrdGMbpbP3PVr4kCMvL1plA== X-Google-Smtp-Source: ABdhPJyzGchgJOqUH6G8JC2sWckXz4wiNFsDize3ILl0hIBGl5TBA4Pj5eMJKOU3Sg8l2zNB7hyPLg== X-Received: by 2002:a05:6a00:150f:b0:51b:e050:d36e with SMTP id q15-20020a056a00150f00b0051be050d36emr18522863pfu.44.1654533425874; Mon, 06 Jun 2022 09:37:05 -0700 (PDT) Received: from 2927-laptop.zooxlabs.com ([2001:470:4189:21:24f5:a2ff:0:2bc]) by smtp.googlemail.com with ESMTPSA id q12-20020a170902e30c00b00163f1831ddfsm10624756plc.40.2022.06.06.09.37.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jun 2022 09:37:04 -0700 (PDT) From: Robert LeBlanc To: grub-devel@gnu.org Cc: Robert LeBlanc Subject: [PATCH] Add some randomness to TCP source port selection. Date: Mon, 6 Jun 2022 10:36:56 -0600 Message-Id: <20220606163656.1044299-1-robert@leblancnet.us> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=robert@leblancnet.us; helo=mail-pf1-x42d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Jun 2022 16:37:13 -0000 GRUB uses a static source TCP port and increments for each new connection. When rapidly restarting GRUB this can cause issues with some firewalls that suspect that a reply attack is happening. In addition GRUB does not ACK the last FIN,ACK when booting the kernel and initrd from HTTP for example. This cause the remote HTTP server to keep the TCP session in TIME_WAIT and reject new connections from the same port combination when restarted quickly. This helps to work around both problems by shifting the source port by a small amount based on time. The missing final ACK should also be addressed, but I'm not sure how to resolve that. Signed-off-by: Robert LeBlanc --- grub-core/net/tcp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grub-core/net/tcp.c b/grub-core/net/tcp.c index 93dee0caa..2eefd3168 100644 --- a/grub-core/net/tcp.c +++ b/grub-core/net/tcp.c @@ -569,7 +569,7 @@ grub_net_tcp_open (char *server, struct grub_net_network_level_interface *inf; grub_net_network_level_address_t gateway; grub_net_tcp_socket_t socket; - static grub_uint16_t in_port = 21550; + grub_uint16_t in_port = 21550 + grub_get_time_ms () % 256; struct grub_net_buff *nb; struct tcphdr *tcph; int i; @@ -603,7 +603,7 @@ grub_net_tcp_open (char *server, socket->inf = inf; socket->out_nla = addr; socket->ll_target_addr = ll_target_addr; - socket->in_port = in_port++; + socket->in_port = in_port; socket->recv_hook = recv_hook; socket->error_hook = error_hook; socket->fin_hook = fin_hook; -- 2.35.1