From patchwork Fri Apr 18 01:26:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 14056488 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-80008.amazon.com (smtp-fw-80008.amazon.com [99.78.197.219]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 696CE19C54B for ; Fri, 18 Apr 2025 01:28:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=99.78.197.219 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744939713; cv=none; b=QSoG6veJUGcovdlKSV5TRqsQaX8jIonF2VyS3kWeeFp75hncUAcbo5MTysJxYgv6UMCkO1hqiOoNYf7Qrebtl4XIw0Oy7oa4QGK5XloYZmztoslTiIS44nBKPc2t6a7uoCbYXjO1Mpe5p1yQsb1j6z80uH1QwcKqvDXh5bJK5kE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744939713; c=relaxed/simple; bh=BZe0Wq/jz/KH2m5SVTQQLqu4+LS09O9k/r6ibU5xNKU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qaRMQxCi9P0+KCjhQXJIPECo+Qy0BJjCULxYsehYSVshbYeV5M4TUMd3gAAdJ9PeK40WZTkZWTY0Efc0Gv1StziVYESc0NuVoWNEfaHOT2y0wAfDTR4agVmgpgRA36QIE4Gwrh6vu2LNcWguHpap/vkc3Sn8nXyysQpouvHDBmI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=iorkz1w7; arc=none smtp.client-ip=99.78.197.219 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="iorkz1w7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1744939712; x=1776475712; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mHRGH5Xu3F6wFyDoOnyhlmKmHj8rj6l62Zxlo6R/g/A=; b=iorkz1w7dx6MhrRx2CfgbPuRrPaJxKxFuVjVulaI07UyTbPOkMu2+QKJ F8Vn91OuhRckwqnKnp3jzLa+ylh6gAFYgC6DC/rNp3o/+7KRIcGr+H/Gs OHAYnBrO5B8osj7cb6DhRYhQQzln9FFx5GwdTrVvHLRMdvUyqwAlV7Uob s=; X-IronPort-AV: E=Sophos;i="6.15,220,1739836800"; d="scan'208";a="188428038" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.214]) by smtp-border-fw-80008.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2025 01:28:30 +0000 Received: from EX19MTAUWC002.ant.amazon.com [10.0.38.20:24182] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.59.110:2525] with esmtp (Farcaster) id 4c342591-ec9f-46ed-b241-bc277bf10cb0; Fri, 18 Apr 2025 01:28:29 +0000 (UTC) X-Farcaster-Flow-ID: 4c342591-ec9f-46ed-b241-bc277bf10cb0 Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWC002.ant.amazon.com (10.250.64.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Fri, 18 Apr 2025 01:28:27 +0000 Received: from 6c7e67bfbae3.amazon.com (10.94.49.59) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Fri, 18 Apr 2025 01:28:24 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni CC: Simon Horman , Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v2 net-next 2/7] neighbour: Move two validations from neigh_get() to neigh_valid_get_req(). Date: Thu, 17 Apr 2025 18:26:54 -0700 Message-ID: <20250418012727.57033-3-kuniyu@amazon.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250418012727.57033-1-kuniyu@amazon.com> References: <20250418012727.57033-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D039UWA002.ant.amazon.com (10.13.139.32) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org We will remove RTNL for neigh_get() and run it under RCU instead. neigh_get() returns -EINVAL in the following cases: * NDA_DST is not specified * Both ndm->ndm_ifindex and NTF_PROXY are not specified These validations do not require RCU. Let's move them to neigh_valid_get_req(). Signed-off-by: Kuniyuki Iwashima --- v2: Fix ERR_PTR(0) paths --- net/core/neighbour.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/net/core/neighbour.c b/net/core/neighbour.c index e1b0d9177270..29f3d5e31901 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -2874,6 +2874,12 @@ static struct ndmsg *neigh_valid_get_req(const struct nlmsghdr *nlh, goto err; } + if (!(ndm->ndm_flags & NTF_PROXY) && !ndm->ndm_ifindex) { + NL_SET_ERR_MSG(extack, "No device specified"); + err = -EINVAL; + goto err; + } + err = nlmsg_parse_deprecated_strict(nlh, sizeof(struct ndmsg), tb, NDA_MAX, nda_policy, extack); if (err < 0) @@ -2887,11 +2893,14 @@ static struct ndmsg *neigh_valid_get_req(const struct nlmsghdr *nlh, } for (i = 0; i <= NDA_MAX; ++i) { - if (!tb[i]) - continue; - switch (i) { case NDA_DST: + if (!tb[i]) { + NL_SET_ERR_MSG(extack, "Network address not specified"); + err = -EINVAL; + goto err; + } + if (nla_len(tb[i]) != (int)(*tbl)->key_len) { NL_SET_ERR_MSG(extack, "Invalid network address in neighbor get request"); err = -EINVAL; @@ -2900,6 +2909,9 @@ static struct ndmsg *neigh_valid_get_req(const struct nlmsghdr *nlh, *dst = nla_data(tb[i]); break; default: + if (!tb[i]) + continue; + NL_SET_ERR_MSG(extack, "Unsupported attribute in neighbor get request"); err = -EINVAL; goto err; @@ -2995,11 +3007,6 @@ static int neigh_get(struct sk_buff *in_skb, struct nlmsghdr *nlh, } } - if (!dst) { - NL_SET_ERR_MSG(extack, "Network address not specified"); - return -EINVAL; - } - if (ndm->ndm_flags & NTF_PROXY) { struct pneigh_entry *pn; @@ -3012,11 +3019,6 @@ static int neigh_get(struct sk_buff *in_skb, struct nlmsghdr *nlh, nlh->nlmsg_seq, tbl); } - if (!dev) { - NL_SET_ERR_MSG(extack, "No device specified"); - return -EINVAL; - } - neigh = neigh_lookup(tbl, dst, dev); if (!neigh) { NL_SET_ERR_MSG(extack, "Neighbour entry not found");