Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp251646pxu; Fri, 11 Dec 2020 01:12:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJwJ0fe7UFZwm5tD/j6QJ9FRmdt4PJ9wFY0Avvn6jKpohdLeqTMjX7Ka3yRs49hQrxUavAUK X-Received: by 2002:a17:906:68c4:: with SMTP id y4mr10299685ejr.332.1607677954080; Fri, 11 Dec 2020 01:12:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607677954; cv=none; d=google.com; s=arc-20160816; b=gncm2QkeF4d2WNBbyTebc5V/rWYzUbC5zK4LWMv9oA4QSJxSwoBcunNaenGAbDiPFx t7ajAR0dfivIfmXyPcozSardsIlfFLlNEafEytq5HI1c3Ii1KT8WFSk6K7pbeSVdfGfz F8yaBTbEND6twFMT6bkMqJHnHU2PLvjv8FvtZ9D+l+R1lr5jNOGIjYz+hyNnNtAN+Auy Npaps29k3GATBY/I22gBx+Qj1z0DR+xhU/kxBNfa2zuwIvOghrnxuMc/Jn5N9e/GdhyI ajgjpsUTRNhWoinv0fZB1GIhpYqoRBxMgImJiklspK94bQcXXVCGw7Nd6itugse6PIfe f6pg== 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=Xi0Xye8qS9fkr7Jo+ax6GqDfdrpS2Ytvs2ofmRHtkQenG4ziFBH7jB0x3BM8RZV2rO fDick9z2fWHEjV4p5UqXGMNRKVMH4502FK3o/K6SYSHVJVlw9Agtn978476zcohGOJYG jyJSYuwObn+IRh3vYSKzXx4pwD/lqsFVBs+xlMsjQFEOKnlliY8VRoUnuD/pJKGsg5ij tdF73OBMGCRlaihbnKZk1CLlPn7sbRkD5Eq/kQFyqtKqRC/hprwbT20UXK+/DtDXYKRR jYXfSQXkWFbVYyvKDLG9UV4ErHfIc/jqRcY9eoaLcM/HF1lt9a4Ik/DZrwmQIbnsotoc 5BuQ== 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 r27si4479248edx.124.2020.12.11.01.12.11; Fri, 11 Dec 2020 01:12:34 -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 S2393444AbgLJTlT (ORCPT + 99 others); Thu, 10 Dec 2020 14:41:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:36916 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390172AbgLJO2r (ORCPT ); Thu, 10 Dec 2020 09:28:47 -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.4 06/39] net/x25: prevent a couple of overflows Date: Thu, 10 Dec 2020 15:26:17 +0100 Message-Id: <20201210142601.203768202@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201210142600.887734129@linuxfoundation.org> References: <20201210142600.887734129@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;