Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp35690pxu; Thu, 10 Dec 2020 17:28:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJyHwhx0g7qADr7eLVUB34Rmb/1UNWj94BXfpPf7Urbn1m3GUmXqoM8Ak0YhBQb6HwKwNzAG X-Received: by 2002:a50:9d04:: with SMTP id v4mr9569704ede.363.1607650104263; Thu, 10 Dec 2020 17:28:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607650104; cv=none; d=google.com; s=arc-20160816; b=JraWwH0zIofYzkkD/IH9hEA1tSRIcGxh8/nlhX8iLVT7lGWkOXbea2aozto+XLuSvO shfmvo1+BSp+hUzMmN0Nv0RoXfICELXSq6OoHW6MNolAw1ftM2Qe7spfOk+DCofpIuOZ sbCxP+BDZ8FGX/+3w32g8yak8EfT/T9n5YbZnypirlMKXhwHchIzqUo+khKWho1QCDwu eLRvKin218TTAd0Mrfm4udyf1NHUqj2n/10Gqdvf4gpdvCXETHSCo63WzslAUM4Taq4s 1ezpZ7pmG6sjQ1AUwiHaYphSkiVlPfI/oEO7/9K7cc7QTAhbS7okOc48W2DuYNLQDRwW ZGXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=bW2/89ccnUAOq9NfQcOeS/gij0dcJ8ryb0hRUJl4jJw=; b=WLTO2uW41Jg01rgo3jYswYqVWh0W7H1SSEt2d//V4FWN6mmtqNsP7ct8i1FizhLO2E kPsFnFJ0OSQzwJDOtoJvACcUu6SOqU+c2F9fJfLflPEB+tpK/0EcM+k2ma4ia6fLBvod 7Bvma7RdAFBn1zQrv8sNrhQU/RaeSRv7i6i8r7vl+34zJJsnRiBn06IKR+ieKgDkNp/C bywqsgW/LnJE/G1aB75iT0++wgLG2AvlMvBJHT3ZIRmEXrm6Pei94vRSvqASMPNk3Tr4 dH2ZKC/Yj3nRYki7idJkIsaFkxDMXVg93ZoVCHjekDtMnO4cN+sT4nFa47EcujXC0ntl +WNA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u7si3326315ejm.200.2020.12.10.17.27.44; Thu, 10 Dec 2020 17:28:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390401AbgLJOao (ORCPT + 99 others); Thu, 10 Dec 2020 09:30:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:36422 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728974AbgLJO3h (ORCPT ); Thu, 10 Dec 2020 09:29:37 -0500 From: Greg Kroah-Hartman Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?kiyin ?= , Dan Carpenter , Martin Schiller , Jakub Kicinski Subject: [PATCH 4.9 08/45] net/x25: prevent a couple of overflows Date: Thu, 10 Dec 2020 15:26:22 +0100 Message-Id: <20201210142602.776486521@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201210142602.361598591@linuxfoundation.org> References: <20201210142602.361598591@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Carpenter [ Upstream commit 6ee50c8e262a0f0693dad264c3c99e30e6442a56 ] The .x25_addr[] address comes from the user and is not necessarily NUL terminated. This leads to a couple problems. The first problem is that the strlen() in x25_bind() can read beyond the end of the buffer. The second problem is more subtle and could result in memory corruption. The call tree is: x25_connect() --> x25_write_internal() --> x25_addr_aton() The .x25_addr[] buffers are copied to the "addresses" buffer from x25_write_internal() so it will lead to stack corruption. Verify that the strings are NUL terminated and return -EINVAL if they are not. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Fixes: a9288525d2ae ("X25: Dont let x25_bind use addresses containing characters") Reported-by: "kiyin(尹亮)" Signed-off-by: Dan Carpenter Acked-by: Martin Schiller Link: https://lore.kernel.org/r/X8ZeAKm8FnFpN//B@mwanda Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/x25/af_x25.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/net/x25/af_x25.c +++ b/net/x25/af_x25.c @@ -679,7 +679,8 @@ static int x25_bind(struct socket *sock, int len, i, rc = 0; if (addr_len != sizeof(struct sockaddr_x25) || - addr->sx25_family != AF_X25) { + addr->sx25_family != AF_X25 || + strnlen(addr->sx25_addr.x25_addr, X25_ADDR_LEN) == X25_ADDR_LEN) { rc = -EINVAL; goto out; } @@ -773,7 +774,8 @@ static int x25_connect(struct socket *so rc = -EINVAL; if (addr_len != sizeof(struct sockaddr_x25) || - addr->sx25_family != AF_X25) + addr->sx25_family != AF_X25 || + strnlen(addr->sx25_addr.x25_addr, X25_ADDR_LEN) == X25_ADDR_LEN) goto out; rc = -ENETUNREACH;