Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1677106pxu; Sun, 6 Dec 2020 03:44:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJxwsrXjaS2FV9oNbaRjOlvD7m3k+gRQCYkhON8zb+/riR0VJuIMAZQJJbjIxe/I4UeE4Exc X-Received: by 2002:a17:907:94c6:: with SMTP id dn6mr14927167ejc.13.1607255050497; Sun, 06 Dec 2020 03:44:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607255050; cv=none; d=google.com; s=arc-20160816; b=eeBHSOesuvmCig/pMU8AO1YX3o52SogFhvmpNLzOxmrvHU5BhU+78rOW4T9OxQRSoK 7IfbB614OhJO8CU1PLY5eWH7zf0I+Y3/4E9eEPlk7Vf9UvcalgosfEuRcBEwSLGDt4eB +laAsX+oiH3FN7p34ikps0PsTwCjBRxSNau6pVQWeLDZ60HT4lxNDPry4cQsQDuqyU0x TK0dM5+YL3lz6Xi3cMn6GknlEcMqVXXaFGH5tWG3qeYB6byJem+Wa0Lj0dxwFrD4kED4 Yvku2nDepza/dprgL2GbbuKPTwhgItQELJQLX1vZd0epcs4p2khbfS92PEYmHp6mZant fZKQ== 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=g84i6XJEddOX4JoGklirTTujxujis3ERITrUF8QIBmnXi0PpmudoRgAhjkTBLlp5SZ a+NIyMmQUZo1JDE86J8a8m24ybG0L3rGtgk8JdB9prt3HSqCRBbxdoREBwrtawNvYuji iT6QK992f+VG6/2skcachcVslvJlMHHNBtDBcmtM/FWOS11qRBCTSjTUeCLWeNxvlBwS fpGKD6dNo0mWThpbFvui1BlXvLlpyuMPBUaLBSUboOJSEIjbXXelBhugn68ZKaw5ACp0 Lb+GIo8PEmd+luv8kTXTVaN5kD1ioBTuu+BDKsBk+uTmWuhuoqQ5X/WUzKb1ulq6Y26N 16zQ== 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 x5si6266993edv.585.2020.12.06.03.43.48; Sun, 06 Dec 2020 03:44:10 -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 S1728215AbgLFLjv (ORCPT + 99 others); Sun, 6 Dec 2020 06:39:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:36708 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728197AbgLFLju (ORCPT ); Sun, 6 Dec 2020 06:39:50 -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.14 12/20] net/x25: prevent a couple of overflows Date: Sun, 6 Dec 2020 12:17:15 +0100 Message-Id: <20201206111556.136858754@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201206111555.569713359@linuxfoundation.org> References: <20201206111555.569713359@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;