Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2095513pxb; Mon, 12 Apr 2021 14:21:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwiHX48n7q8EwVeOfk372bJqHFci268lUH1TMgonrrxLVxiK6GhStISec7TZQigaS+YFv8x X-Received: by 2002:a17:906:8288:: with SMTP id h8mr14154722ejx.75.1618262482542; Mon, 12 Apr 2021 14:21:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618262482; cv=none; d=google.com; s=arc-20160816; b=rHy7qc95XgQgzBLjFvU5Pu4TIo1RgmQeqnKC+FE66ZqGSnEb6v19kFgavA3ZJeioxB rb7neDkijU/pvng0sQAfiREc1Lyyaye4gLpM5J4+oWN6Ts48imKAyUXb4KAs62idihJn Xj9FXkb9eH7Brx/nhhSaBOgtDa6WpbUqMK1HI+McVFbYWJIrjlzTUZ6EXVbQSkWAHbJM alwWvjjdVzy033WpananK++Fc0G7Rkmew7TjwgyJO5fq4k9B3KWfNimVeH8I4gfWtBxz c8R4gZ2pdrzeL8RefP4ivcIKSQ4NRbzLPwkHQb8bUdCGdWMYSr9rzf5SzGUnvVJQgEwp oQvg== 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:dkim-signature; bh=Pe7ws9R4sOvBFLx+QzE51ha9YX49r2eVH8s1WGUiDok=; b=jT3junlWYgkGR6BpLlIDLD9NnuCih9qMMxZZZgbZiXJFqKFQmHxrW1yyc+I00ujhfM 1B/5IBuMb1qqSaPMgc1bVOa4zgPrSSBGG66qeoFFb6dR77focE6443TZLOXmPkQhpIDc qa/rmS7qBuDf3qRm3zj0Xtc9llYY2iDw88wvOr73U1TGummO4KFfrfq3pGB1AAGLGa5k 30s5xwX4EsX4HwJjLi03ONH42XNPZFk/RtZeoiOjfwcunVy30cSSBTYFVcUeAl+MYijR iMIYqeJiotQjZ+TYrWcQtIf27hPFRBuVKMY+t+bjQ3GZOH29yEK8X4IoS1/3M7dD3mzo 1JAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=abWuzW6g; 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=pass (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 ss2si5046665ejb.370.2021.04.12.14.20.59; Mon, 12 Apr 2021 14:21:22 -0700 (PDT) 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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=abWuzW6g; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240497AbhDLJKW (ORCPT + 99 others); Mon, 12 Apr 2021 05:10:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:44694 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239039AbhDLIz3 (ORCPT ); Mon, 12 Apr 2021 04:55:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 48F33611F0; Mon, 12 Apr 2021 08:55:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618217710; bh=kxJ0YnO73BloS+aKac4i5xoe12tE1J3Ux0Qz1aii0Lo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=abWuzW6gUK30TGI+w03LIjDQ0njyluoxOIT/7KEbj77IzvlscOXxT+WXD0e5lyYGM oksck9RrWRMGEDXyz+gInfmM1ZfIHjmIKWU7hPK7N4KStQHVU6QAGvvX02VBqp+8z2 8ROORl1zl6LYFbpQFDJaQ5r/Bd2CsHhSoP0jB3OE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Richard Weinberger , Kurt Van Dijck , Oliver Hartkopp , Marc Kleine-Budde , Sasha Levin Subject: [PATCH 5.10 117/188] can: isotp: fix msg_namelen values depending on CAN_REQUIRED_SIZE Date: Mon, 12 Apr 2021 10:40:31 +0200 Message-Id: <20210412084017.545729083@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210412084013.643370347@linuxfoundation.org> References: <20210412084013.643370347@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: Oliver Hartkopp [ Upstream commit f522d9559b07854c231cf8f0b8cb5a3578f8b44e ] Since commit f5223e9eee65 ("can: extend sockaddr_can to include j1939 members") the sockaddr_can has been extended in size and a new CAN_REQUIRED_SIZE macro has been introduced to calculate the protocol specific needed size. The ABI for the msg_name and msg_namelen has not been adapted to the new CAN_REQUIRED_SIZE macro for the other CAN protocols which leads to a problem when an existing binary reads the (increased) struct sockaddr_can in msg_name. Fixes: e057dd3fc20f ("can: add ISO 15765-2:2016 transport protocol") Reported-by: Richard Weinberger Acked-by: Kurt Van Dijck Link: https://lore.kernel.org/linux-can/1135648123.112255.1616613706554.JavaMail.zimbra@nod.at/T/#t Link: https://lore.kernel.org/r/20210325125850.1620-2-socketcan@hartkopp.net Signed-off-by: Oliver Hartkopp Signed-off-by: Marc Kleine-Budde Signed-off-by: Sasha Levin --- net/can/isotp.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/net/can/isotp.c b/net/can/isotp.c index ea1e227b8e54..d5780ab29e09 100644 --- a/net/can/isotp.c +++ b/net/can/isotp.c @@ -77,6 +77,8 @@ MODULE_LICENSE("Dual BSD/GPL"); MODULE_AUTHOR("Oliver Hartkopp "); MODULE_ALIAS("can-proto-6"); +#define ISOTP_MIN_NAMELEN CAN_REQUIRED_SIZE(struct sockaddr_can, can_addr.tp) + #define SINGLE_MASK(id) (((id) & CAN_EFF_FLAG) ? \ (CAN_EFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG) : \ (CAN_SFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG)) @@ -981,7 +983,8 @@ static int isotp_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, sock_recv_timestamp(msg, sk, skb); if (msg->msg_name) { - msg->msg_namelen = sizeof(struct sockaddr_can); + __sockaddr_check_size(ISOTP_MIN_NAMELEN); + msg->msg_namelen = ISOTP_MIN_NAMELEN; memcpy(msg->msg_name, skb->cb, msg->msg_namelen); } @@ -1050,7 +1053,7 @@ static int isotp_bind(struct socket *sock, struct sockaddr *uaddr, int len) int err = 0; int notify_enetdown = 0; - if (len < CAN_REQUIRED_SIZE(struct sockaddr_can, can_addr.tp)) + if (len < ISOTP_MIN_NAMELEN) return -EINVAL; if (addr->can_addr.tp.rx_id == addr->can_addr.tp.tx_id) @@ -1136,13 +1139,13 @@ static int isotp_getname(struct socket *sock, struct sockaddr *uaddr, int peer) if (peer) return -EOPNOTSUPP; - memset(addr, 0, sizeof(*addr)); + memset(addr, 0, ISOTP_MIN_NAMELEN); addr->can_family = AF_CAN; addr->can_ifindex = so->ifindex; addr->can_addr.tp.rx_id = so->rxid; addr->can_addr.tp.tx_id = so->txid; - return sizeof(*addr); + return ISOTP_MIN_NAMELEN; } static int isotp_setsockopt(struct socket *sock, int level, int optname, -- 2.30.2