Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp6576724ybx; Mon, 11 Nov 2019 11:13:17 -0800 (PST) X-Google-Smtp-Source: APXvYqykAhQbsdpKdfiGnQsiOQ4Rf5FmIHWCP6zZlq/YZbO4HK/wB6RXGYZEJLu8/hl2muTyKkpW X-Received: by 2002:a50:fd95:: with SMTP id o21mr28892754edt.283.1573499596953; Mon, 11 Nov 2019 11:13:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573499596; cv=none; d=google.com; s=arc-20160816; b=qbuj6lRnIeH7Uq+DX0DduXuYT6IxlC2jOQ0z67whxLlIrH7z8cLc23Snq/NxwqIJxr reo2sFQROAdvAbE0iNoZvtKpMQ8rslmN3fZnE9G1E5e466NIbyhCIwqQ62rIRD3WnhFQ YOVtCUYMY7PF2wjee8DlrIxgynVIVW3+EwZzTNFZiG9omZyMSmfjA68qutTrGUMtARdS ZVAxKg5U3UtHEbxeAjJaSVXW3tKvOZD+s+U92Y2TF/Q/SsZmQf8LplnDIbnzHnujAdpg FA53milzzpTr8/uOcSc9FUnkKJ+XT1IgJJy8kPcrXW1Z6SA5zFQt5Bp5A1/KxUhZ4WYO heyg== 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=YlInBsy3kOnCwfl0J3dOe9663cw5a8WtSUvNk74TVO8=; b=0VMq5eB6gAFg6RoAr0BaqtnultbHFBGPEmlO699aLex5s+Yl8shiKhbVd+iPk7MZLs aTKjcEje+pYGOGkj/ElPGzX7qJSGG0hXNlHBbxBaViGY6yUNvmy8uGvazmyXoJw9PpT3 DHwF1QARfSpJmkZBLtX0dOb2LbL+YJJ8PD+S3dcCpSU31mailclS9J+Qi5J4l+AeGI/S 0PiVxOEmH+BBG3OP8OpMKbqdANyDLuErkGE43UaqiN8EIiR3xWF7iKnRHdR2JZfdR2RF hLG1cfEUu5BN/8WhMpkZykWkt6Zs5EKNvlK1fAikZwX+Sn8BdA4MzVQdC5pSQfu8I6ba 9Z+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="1p/5TybS"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bi17si12685678edb.430.2019.11.11.11.12.52; Mon, 11 Nov 2019 11:13:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="1p/5TybS"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728027AbfKKTKK (ORCPT + 99 others); Mon, 11 Nov 2019 14:10:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:50046 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727999AbfKKScl (ORCPT ); Mon, 11 Nov 2019 13:32:41 -0500 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 A1FA020674; Mon, 11 Nov 2019 18:32:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573497161; bh=27fDGEpqKQPn9KccCyYX91hENaUtYZICVPP1diLkpYY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1p/5TybSN2SAUm9pg4zGEBEbv/zt0E1HpFD0XAEP9mtl86VQsV1idUtSylTQFegOW J6Z9gc/BcO1/wirGJtd2wSiQHGoAPFrXISnipWUwbA+EMRE2RNQsRKvYtgpYS+JhqQ Ae1dKfH69+NvxPT1OIxTYzXX/NwODUCdp3YDCBn0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stephane Grosjean , Marc Kleine-Budde Subject: [PATCH 4.9 24/65] can: peak_usb: fix a potential out-of-sync while decoding packets Date: Mon, 11 Nov 2019 19:28:24 +0100 Message-Id: <20191111181345.547015472@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191111181331.917659011@linuxfoundation.org> References: <20191111181331.917659011@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: Stephane Grosjean commit de280f403f2996679e2607384980703710576fed upstream. When decoding a buffer received from PCAN-USB, the first timestamp read in a packet is a 16-bit coded time base, and the next ones are an 8-bit offset to this base, regardless of the type of packet read. This patch corrects a potential loss of synchronization by using a timestamp index read from the buffer, rather than an index of received data packets, to determine on the sizeof the timestamp to be read from the packet being decoded. Signed-off-by: Stephane Grosjean Fixes: 46be265d3388 ("can: usb: PEAK-System Technik PCAN-USB specific part") Cc: linux-stable Signed-off-by: Marc Kleine-Budde Signed-off-by: Greg Kroah-Hartman --- drivers/net/can/usb/peak_usb/pcan_usb.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) --- a/drivers/net/can/usb/peak_usb/pcan_usb.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb.c @@ -108,7 +108,7 @@ struct pcan_usb_msg_context { u8 *end; u8 rec_cnt; u8 rec_idx; - u8 rec_data_idx; + u8 rec_ts_idx; struct net_device *netdev; struct pcan_usb *pdev; }; @@ -552,10 +552,15 @@ static int pcan_usb_decode_status(struct mc->ptr += PCAN_USB_CMD_ARGS; if (status_len & PCAN_USB_STATUSLEN_TIMESTAMP) { - int err = pcan_usb_decode_ts(mc, !mc->rec_idx); + int err = pcan_usb_decode_ts(mc, !mc->rec_ts_idx); if (err) return err; + + /* Next packet in the buffer will have a timestamp on a single + * byte + */ + mc->rec_ts_idx++; } switch (f) { @@ -638,10 +643,13 @@ static int pcan_usb_decode_data(struct p cf->can_dlc = get_can_dlc(rec_len); - /* first data packet timestamp is a word */ - if (pcan_usb_decode_ts(mc, !mc->rec_data_idx)) + /* Only first packet timestamp is a word */ + if (pcan_usb_decode_ts(mc, !mc->rec_ts_idx)) goto decode_failed; + /* Next packet in the buffer will have a timestamp on a single byte */ + mc->rec_ts_idx++; + /* read data */ memset(cf->data, 0x0, sizeof(cf->data)); if (status_len & PCAN_USB_STATUSLEN_RTR) { @@ -695,7 +703,6 @@ static int pcan_usb_decode_msg(struct pe /* handle normal can frames here */ } else { err = pcan_usb_decode_data(&mc, sl); - mc.rec_data_idx++; } }