Received: by 10.192.165.156 with SMTP id m28csp73914imm; Tue, 10 Apr 2018 16:43:54 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/DbpEZjxklO1BB090AkVSdMg9ZFE5lwrjlS0WUUmKHSxxMj6nhgrgbzRinZwVKvcpqv7FI X-Received: by 10.98.247.15 with SMTP id h15mr1960421pfi.165.1523403834396; Tue, 10 Apr 2018 16:43:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523403834; cv=none; d=google.com; s=arc-20160816; b=QRfGVG+faUwFLAT8NlYJIx4rcLlaa+5pGAmXAG3X18yuviR8Gwk42EdNFQuu2n6StH OeCq+OvPuLvg0twfBSjCYXWs01moTbdnfg79QsJdus8cpknjqgeYwUfj6NikV/o3wWYB QHfgsg+Xyl8tNd/aS+rZi1cxbo4ZGIAAkXz2jIxIGqoXbziBB4LO9NaIORLgNR8K4qzx /f5dzOORC+lbzgelhMhEOgqvzu/vkhgYqa0IrksxkCDEpekErDSOK2wrRPOc79gXY79k xvWitjsN5rilHAjF8QzziuKzPf4PdPQgLcMbtTmynBni2nm3kst6lfdYBaPYCg1wUa3D yoVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=qdpYN8eG4ECDyZUdpfefGiGurB9MX7TW8xpZodwympE=; b=HqdqspoCnul7K9TlyuQMEU54TT/9t+ZzE/iRVhSg1PaGTBEF28/XWndUSPQLr7zZ1w FVCYId/Ay3V6L3nw1wx2/HVZGyAy3WtAIG1/xWXIix7bIo8Hle+kBhCBn6tXr418rJT3 bqdMsmuUxIBdPNwMP9sUPBhiSuO6xjL8p+9EQcpqusxYW8Tr0adh4LDhTASlBtrvPKLV /4wjCGqvumJiygupy/6Q2roVFStS1VW/Q7Ql38lykV9nGJQtW+NLzWOAMC1yWYkrHCdM rYPhXq4jVh0o/8n94S34tNZNwYS7p1AO7QtlH6OnAEa6DJ+mURXKPCsuzHK/Th2nI032 Iu7w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r8si2428873pgq.593.2018.04.10.16.43.17; Tue, 10 Apr 2018 16:43:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753353AbeDJW05 (ORCPT + 99 others); Tue, 10 Apr 2018 18:26:57 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:37648 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753241AbeDJW0x (ORCPT ); Tue, 10 Apr 2018 18:26:53 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id F1CD3CDA; Tue, 10 Apr 2018 22:26:52 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sowmini Varadhan , Willem de Bruijn , "David S. Miller" , Sasha Levin Subject: [PATCH 4.15 027/168] selftests/net: fix bugs in address and port initialization Date: Wed, 11 Apr 2018 00:22:49 +0200 Message-Id: <20180410212801.355499320@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180410212800.144079021@linuxfoundation.org> References: <20180410212800.144079021@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sowmini Varadhan [ Upstream commit d36f45e5b46723cf2d4147173e18c52d4143176d ] Address/port initialization should work correctly regardless of the order in which command line arguments are supplied, E.g, cfg_port should be used to connect to the remote host even if it is processed after -D, src/dst address initialization should not require that [-4|-6] be specified before the -S or -D args, receiver should be able to bind to *. Achieve this by making sure that the address/port structures are initialized after all command line options are parsed. Store cfg_port in host-byte order, and use htons() to set up the sin_port/sin6_port before bind/connect, so that the network system calls get the correct values in network-byte order. Signed-off-by: Sowmini Varadhan Acked-by: Willem de Bruijn Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- tools/testing/selftests/net/msg_zerocopy.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) --- a/tools/testing/selftests/net/msg_zerocopy.c +++ b/tools/testing/selftests/net/msg_zerocopy.c @@ -259,22 +259,28 @@ static int setup_ip6h(struct ipv6hdr *ip return sizeof(*ip6h); } -static void setup_sockaddr(int domain, const char *str_addr, void *sockaddr) + +static void setup_sockaddr(int domain, const char *str_addr, + struct sockaddr_storage *sockaddr) { struct sockaddr_in6 *addr6 = (void *) sockaddr; struct sockaddr_in *addr4 = (void *) sockaddr; switch (domain) { case PF_INET: + memset(addr4, 0, sizeof(*addr4)); addr4->sin_family = AF_INET; addr4->sin_port = htons(cfg_port); - if (inet_pton(AF_INET, str_addr, &(addr4->sin_addr)) != 1) + if (str_addr && + inet_pton(AF_INET, str_addr, &(addr4->sin_addr)) != 1) error(1, 0, "ipv4 parse error: %s", str_addr); break; case PF_INET6: + memset(addr6, 0, sizeof(*addr6)); addr6->sin6_family = AF_INET6; addr6->sin6_port = htons(cfg_port); - if (inet_pton(AF_INET6, str_addr, &(addr6->sin6_addr)) != 1) + if (str_addr && + inet_pton(AF_INET6, str_addr, &(addr6->sin6_addr)) != 1) error(1, 0, "ipv6 parse error: %s", str_addr); break; default: @@ -603,6 +609,7 @@ static void parse_opts(int argc, char ** sizeof(struct tcphdr) - 40 /* max tcp options */; int c; + char *daddr = NULL, *saddr = NULL; cfg_payload_len = max_payload_len; @@ -627,7 +634,7 @@ static void parse_opts(int argc, char ** cfg_cpu = strtol(optarg, NULL, 0); break; case 'D': - setup_sockaddr(cfg_family, optarg, &cfg_dst_addr); + daddr = optarg; break; case 'i': cfg_ifindex = if_nametoindex(optarg); @@ -638,7 +645,7 @@ static void parse_opts(int argc, char ** cfg_cork_mixed = true; break; case 'p': - cfg_port = htons(strtoul(optarg, NULL, 0)); + cfg_port = strtoul(optarg, NULL, 0); break; case 'r': cfg_rx = true; @@ -647,7 +654,7 @@ static void parse_opts(int argc, char ** cfg_payload_len = strtoul(optarg, NULL, 0); break; case 'S': - setup_sockaddr(cfg_family, optarg, &cfg_src_addr); + saddr = optarg; break; case 't': cfg_runtime_ms = 200 + strtoul(optarg, NULL, 10) * 1000; @@ -660,6 +667,8 @@ static void parse_opts(int argc, char ** break; } } + setup_sockaddr(cfg_family, daddr, &cfg_dst_addr); + setup_sockaddr(cfg_family, saddr, &cfg_src_addr); if (cfg_payload_len > max_payload_len) error(1, 0, "-s: payload exceeds max (%d)", max_payload_len);