Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2026644pxa; Mon, 24 Aug 2020 03:01:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKH5mSrf2fFmlKeo8B/m/mcWmCEC0CTbbVzUJQP/X7Ew6e93kGlN2v95OrmIWnyHRf6IaS X-Received: by 2002:a50:9fe2:: with SMTP id c89mr4421041edf.292.1598263264577; Mon, 24 Aug 2020 03:01:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598263264; cv=none; d=google.com; s=arc-20160816; b=nQm9hhljmtlFYEtuxRGgJ4Tm10WHLv0CzZjwzDDY0FLsTQxrhp/7lDuFr4FdHK7P5d 5giSCJ1fKXfSBtiG0iTNBSnq3q3RGX4Bsy8BtSnEQiWXiyI0D9wzDUwC9HfdPFKunmAn Ks3PfQ4j1fykMJzwxkU3oJG0mdV+HooZaoIMjbAsNKQU16TjNAXmuWgr1dK1wml1rMU2 7Vx41mvtiSq1wXd/XY2evHtv9vazNEFHdkTETcSIMb2VrzB7aPQ/r/1eXPDnk3lPbTxb sfIPcuLcS7Yg21UnuGy4wb8UaXQboRkzM7Fwu9m1ed8dZIyt7vhnN1lFb73dJPEosnuk YT5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dWrKP4WE+9kUUXdx00ebkEGOnCYdlUmTT3nYi8v6Zvg=; b=H1ZrO5nQf/y+jd8f3vO0wlz98HNToTjZq7Y9gRXxvl+As1MmvSARZKJLXDp5iDYr1e +aq9PelRlICkzYpRs9kE2AFM+OJfo+/h7WoZoWq+YmH2UWjeGfA3n4qdl2Y1sbpcueWH NetV0SUbmqCNLZQsr8c99jVTnWo8RMCtipiBU5eoIssQNe9IwPCkx0YQ7CmPKkYvCksJ xVsRdEudNghtBAapczeD4rcao2Y6MTrSCd4w5hGuImZZEFNP5otEenFPuqI23t5FGlTm yhuErnmuowoosC+W1elsN4zOWhx4mO/aF5LNj59K8ynDctR0wXFQuVssla7/N7/YruaO V6ZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xA44E3Ra; 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 bs4si6210878edb.568.2020.08.24.03.00.41; Mon, 24 Aug 2020 03:01:04 -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=@kernel.org header.s=default header.b=xA44E3Ra; 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 S1726843AbgHXIcv (ORCPT + 99 others); Mon, 24 Aug 2020 04:32:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:39976 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726802AbgHXIct (ORCPT ); Mon, 24 Aug 2020 04:32:49 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 916A9206F0; Mon, 24 Aug 2020 08:32:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598257969; bh=1I0FJfJlkGo4/bQRz+yIbSTD2q6adynUdm/vCXmFolc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xA44E3Ra9DIKcTEpaxUYWL2PliAiahbbNhuyMuphPfWyxpalGcN5E0X2DzP6aRg6H jQhERAshrb3LqwOVtotVDIYz1S68/BeCDQ3ugOFWI6mZFIvnDynPdLiy96g7LX592e zGjJJvIecX2qtb2gVMOpe7sToF2ThOXiZ5C6DMxU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+5322482fe520b02aea30@syzkaller.appspotmail.com, Oleksij Rempel , Marc Kleine-Budde Subject: [PATCH 5.8 009/148] can: j1939: transport: j1939_session_tx_dat(): fix use-after-free read in j1939_tp_txtimer() Date: Mon, 24 Aug 2020 10:28:27 +0200 Message-Id: <20200824082414.396969214@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200824082413.900489417@linuxfoundation.org> References: <20200824082413.900489417@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Oleksij Rempel commit cd3b3636c99fcac52c598b64061f3fe4413c6a12 upstream. The current stack implementation do not support ECTS requests of not aligned TP sized blocks. If ECTS will request a block with size and offset spanning two TP blocks, this will cause memcpy() to read beyond the queued skb (which does only contain one TP sized block). Sometimes KASAN will detect this read if the memory region beyond the skb was previously allocated and freed. In other situations it will stay undetected. The ETP transfer in any case will be corrupted. This patch adds a sanity check to avoid this kind of read and abort the session with error J1939_XTP_ABORT_ECTS_TOO_BIG. Reported-by: syzbot+5322482fe520b02aea30@syzkaller.appspotmail.com Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol") Cc: linux-stable # >= v5.4 Signed-off-by: Oleksij Rempel Link: https://lore.kernel.org/r/20200807105200.26441-3-o.rempel@pengutronix.de Signed-off-by: Marc Kleine-Budde Signed-off-by: Greg Kroah-Hartman --- net/can/j1939/transport.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) --- a/net/can/j1939/transport.c +++ b/net/can/j1939/transport.c @@ -787,6 +787,18 @@ static int j1939_session_tx_dat(struct j if (len > 7) len = 7; + if (offset + len > se_skb->len) { + netdev_err_once(priv->ndev, + "%s: 0x%p: requested data outside of queued buffer: offset %i, len %i, pkt.tx: %i\n", + __func__, session, skcb->offset, se_skb->len , session->pkt.tx); + return -EOVERFLOW; + } + + if (!len) { + ret = -ENOBUFS; + break; + } + memcpy(&dat[1], &tpdat[offset], len); ret = j1939_tp_tx_dat(session, dat, len + 1); if (ret < 0) { @@ -1120,6 +1132,9 @@ static enum hrtimer_restart j1939_tp_txt * cleanup including propagation of the error to user space. */ break; + case -EOVERFLOW: + j1939_session_cancel(session, J1939_XTP_ABORT_ECTS_TOO_BIG); + break; case 0: session->tx_retry = 0; break;