Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp230798pxb; Wed, 13 Jan 2021 02:06:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJzrcUnpCHTvVSthRBES7NBjKxHKaNtT39v5qtWMoUD+OW+Hl1bxbvHMCc71Kd4ewKeN//GP X-Received: by 2002:a05:6402:1748:: with SMTP id v8mr1187481edx.136.1610532388665; Wed, 13 Jan 2021 02:06:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610532388; cv=none; d=google.com; s=arc-20160816; b=0zrA8FLL2QqIT8lmMEsX3LHK3L1Ps+7oSzA71VmHMtVH1frhrypV85u3Dvl/aCyV39 MXN0QgUZL6jdfSlEWv3JDLpC1k5O6AXjf36IyCopcPI+ggGBSf25j+M8FXfJx2WNYyON pNW7kFTwTP5vfU/aCR1bB7dHnvsX4UY33fPHHllZBQUk7WqASd2rigVYoSNHhBxB/OBy 2+wDOi810iDzEhma6r3Y0kj95GswstHUEKUPQxRc6hfYqwRrvEFQNztdaYUX1JRKZ74B k47au4DL9L0EARHoMdIAam0o3hOameyiDOg//PvjWEow+L/4jcTXRCxBix0+xfFprYuC /tAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=jp+K+7j7YaTFi7y42TbbGWkVcjfUldJ+Q6gh/Vz/KO0=; b=fBIBv4KYMXhwgmI69QrsJ/JpxB4ILLdUtXG1/Dl9tG3+AY7MOt5DtTrgt3AgCV2uKV LEcAq/tFa/mjF3fm9jm26+9ToAOWH8NTFMqQtnSLFRJhHCme7vxnh3gJz6ctTEWqNYii THZOGbsMSbsbzyWu1cYBWbnn1D9LkrD2WbXjj6ylFc398BucbaXjLXwidVOp1lW5h9Td y1S/6SgOYW11NO05J+7WHmhVbTNBNBAktLulE42pHhIODsOFqDyNZ7bFozOYTVZi85W0 VXVyibgzcSjYp1ALGZGA+skQBDFH60VWrJgC0HC/TJ44SCONO7ZSs+F3QpN6wPd8qWql TOzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=ZZ8X1e64; 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=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hd18si703532ejc.712.2021.01.13.02.05.54; Wed, 13 Jan 2021 02:06:28 -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; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=ZZ8X1e64; 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=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726202AbhAMKDc (ORCPT + 99 others); Wed, 13 Jan 2021 05:03:32 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:54986 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725843AbhAMKDb (ORCPT ); Wed, 13 Jan 2021 05:03:31 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10DA03cm171319; Wed, 13 Jan 2021 10:02:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : content-transfer-encoding : in-reply-to; s=corp-2020-01-29; bh=jp+K+7j7YaTFi7y42TbbGWkVcjfUldJ+Q6gh/Vz/KO0=; b=ZZ8X1e646+qAmJx3SzdWEx7Llk9LUFEMoxWVChX6ahP1rYSImKMKePv6UXCtXvHy5tAb 5szQqOzbECyvaU0zyR0vQJ9TqEXhbfbKE+/jFZviYBqxHuyGyJsauvyHpNUd/obinRwG ir+1MMst1IqefH+TLEIxTcijgKG5uSsc4Wobp7QBw8v4SKTkUdv3G5icrV6K/QOeq0X/ 01RTWyHey6ZHOEuMQ3vCf6ZRuUOa618sY81WjBaEufbpxk2csGKZmMRMj1t8mxO7EDlX E0ccWDSOzUceYpQZoVmqFouGMqxAS3FNjtf40RSyNw/K7ld8+Qylw4cH9UIFAzneIKTV sg== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 360kcytn6v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Jan 2021 10:02:39 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10DA1eRV041372; Wed, 13 Jan 2021 10:02:38 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 360ke836fm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Jan 2021 10:02:38 +0000 Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 10DA2Z68019379; Wed, 13 Jan 2021 10:02:35 GMT Received: from kadam (/102.36.221.92) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 13 Jan 2021 02:02:35 -0800 Date: Wed, 13 Jan 2021 13:02:24 +0300 From: Dan Carpenter To: =?utf-8?B?5oWV5Yas5Lqu?= Cc: linux-kernel , linux-media@vger.kernel.org, mchehab@kernel.org, sean@mess.org, anant.thazhemadam@gmail.com, syzkaller-bugs , Greg KH , Dmitry Vyukov Subject: Re: "UBSAN: shift-out-of-bounds in mceusb_dev_recv" should share the same root cause with "UBSAN: shift-out-of-bounds in mceusb_dev_printdata" Message-ID: <20210113100224.GH5083@kadam> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9862 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101130058 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9862 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 impostorscore=0 bulkscore=0 adultscore=0 suspectscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1011 mlxlogscore=999 mlxscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101130058 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 13, 2021 at 01:04:44PM +0800, 慕冬亮 wrote: > Hi developers, > > I found that "UBSAN: shift-out-of-bounds in mceusb_dev_recv" and > "UBSAN: shift-out-of-bounds in mceusb_dev_printdata" should share the > same root cause. > The reason is that the PoCs after minimization has a high similarity > with the other. And their stack trace only diverges at the last > function call. The following is some analysis for this bug. > > The following code in the mceusb_process_ir_data is the vulnerable > -------------------------------------------------------------------------------------------------------------------------- > for (; i < buf_len; i++) { > switch (ir->parser_state) { > case SUBCMD: > ir->rem = mceusb_cmd_datasize(ir->cmd, ir->buf_in[i]); > mceusb_dev_printdata(ir, ir->buf_in, buf_len, i - 1, > ir->rem + 2, false); > if (i + ir->rem < buf_len) > mceusb_handle_command(ir, &ir->buf_in[i - 1]); > -------------------------------------------------------------------------------------------------------------------------- > > The first report crashes at a shift operation(1<<*hi) in mceusb_handle_command. > -------------------------------------------------------------------------------------------------------------------------- > static void mceusb_handle_command(struct mceusb_dev *ir, u8 *buf_in) > { > u8 *hi = &buf_in[2]; /* read only when required */ > if (cmd == MCE_CMD_PORT_SYS) { > switch (subcmd) { > case MCE_RSP_GETPORTSTATUS: > if (buf_in[5] == 0) > ir->txports_cabled |= 1 << *hi; > -------------------------------------------------------------------------------------------------------------------------- > > The second report crashes at another shift operation (1U << data[0]) > in mceusb_dev_printdata. > -------------------------------------------------------------------------------------------------------------------------- > static void mceusb_dev_printdata(struct mceusb_dev *ir, u8 *buf, int buf_len, > int offset, int len, bool out) > { > data = &buf[offset] + 2; > > period = DIV_ROUND_CLOSEST((1U << data[0] * 2) * > (data[1] + 1), 10); > -------------------------------------------------------------------------------------------------------------------------- > > >From the analysis, we can know the data[0] and *hi access the same > memory cell - ``ir->buf_in[i+1]``. So the root cause should be that it > misses the check of ir->buf_in[i+1]. > > For the patch of this bug, there is one from anant.thazhemadam@gmail.com: > -------------------------------------------------------------------------------------------------------------------------- > diff --git a/drivers/media/rc/mceusb.c b/drivers/media/rc/mceusb.c > index f1dbd059ed08..79de721b1c4a 100644 > --- a/drivers/media/rc/mceusb.c > +++ b/drivers/media/rc/mceusb.c > @@ -1169,7 +1169,7 @@ static void mceusb_handle_command(struct > mceusb_dev *ir, u8 *buf_in) > switch (subcmd) { > /* the one and only 5-byte return value command */ > case MCE_RSP_GETPORTSTATUS: > - if (buf_in[5] == 0) > + if ((buf_in[5] == 0) && (*hi <= 32)) This should be < instead of <=. Shifting by 32 is undefined. Also this patch can't be applied at all so it's hard to review. Read the two paragraphs of Documentation/process/email-clients.rst There are some other bugs: ir->num_txports = *hi; If "ir->num_txports" is over 31 then it will lead to undefined behavior in mceusb_set_tx_mask(). It not totally clear to me what the correct limit is. So search through the code a bit more I guess and try find the remaining bugs and what the limits should be. regards, dan carpenter