From patchwork Mon Mar 13 12:53:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 9620775 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 01A7B60244 for ; Mon, 13 Mar 2017 12:55:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E53E82848B for ; Mon, 13 Mar 2017 12:55:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D787228498; Mon, 13 Mar 2017 12:55:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D4EB2848B for ; Mon, 13 Mar 2017 12:55:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752561AbdCMMzU (ORCPT ); Mon, 13 Mar 2017 08:55:20 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:36574 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750927AbdCMMyg (ORCPT ); Mon, 13 Mar 2017 08:54:36 -0400 Received: by mail-lf0-f68.google.com with SMTP id g70so11735196lfh.3; Mon, 13 Mar 2017 05:54:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=SNuHHpGsDfhflejzjy02/PuKzQL8lwnIU/6O2Nihrc8=; b=WKLf6Q8o5xN0WiphBLuJ/pUJfVIILm2HVfdSO3M+s6vzTc8euXlrgqPZkxf8DHSrMY XrxC58It6Fqy7qu+NllZuqquCPJHBk5vETyVwZWVGAEd/1bcynvEbGCSPCb7yjhx3IMt zJKgPv0fDselSOWriCkULT6Rcbbv8Fwl1voIcFp9NgQwNCbLINbzspRA3/D8Zfigc5wF DypOVFslxsTrF4irxOzpKJGpoGRyq6AUU97LQkUMtE/heNOf4r90FnuBdlJMgZGUlvUe QBKS18aEP3oMHpTBWEgfdevEttpyr09KYJ/oLIJDKm5xvewbHo+ALMtB4YXHDCwtFrdO 5qFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=SNuHHpGsDfhflejzjy02/PuKzQL8lwnIU/6O2Nihrc8=; b=GsZkfxzsLq7sOqdQkTxWcaLxqPuXiq7fRNEwKn0xvO+2GR1M4nPUVY2iXQAaxYU+wb qDDupAY6ktgM9f0cxO3hvdzz8RfwpS/ggG3XQD9SlkGjrDEv4SGFpQhvzQijkWvMclvl yiN5ROhdqsxmvPF+Fe32yAn6i3UiaDqdYcMGIAThA1xz8kNgctBllwoz9rN3A9QXR/k4 YTlMvZNOvsfynogk5FC0j0XEll5VSELaLay9bPtDYlIhuJftwu+RrvK/IhbJ7XCumwP+ 4ENyQtSgw1/PX3L9z+a3l2a/GaVn2NeV14+ENZDI2h3kohwNAwSKmrfcqscbK6zKuuUY doSA== X-Gm-Message-State: AMke39nm7UgH4Qv/k77vtXXl4sZvN802fH8IDJGZKiUW0O962TTRJq1W8IqhQZIHN9as0g== X-Received: by 10.25.151.196 with SMTP id z187mr8179667lfd.126.1489409673653; Mon, 13 Mar 2017 05:54:33 -0700 (PDT) Received: from xi.terra ([84.216.234.102]) by smtp.gmail.com with ESMTPSA id l78sm3585494lfl.59.2017.03.13.05.54.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Mar 2017 05:54:31 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.89) (envelope-from ) id 1cnPUU-0007fF-C7; Mon, 13 Mar 2017 13:54:22 +0100 From: Johan Hovold To: Mauro Carvalho Chehab Cc: Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , stable , Sri Deevi Subject: [PATCH 5/6] [media] cx231xx-audio: fix NULL-deref at probe Date: Mon, 13 Mar 2017 13:53:58 +0100 Message-Id: <20170313125359.29394-6-johan@kernel.org> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170313125359.29394-1-johan@kernel.org> References: <20170313125359.29394-1-johan@kernel.org> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Make sure to check the number of endpoints to avoid dereferencing a NULL-pointer or accessing memory beyond the endpoint array should a malicious device lack the expected endpoints. Fixes: e0d3bafd0258 ("V4L/DVB (10954): Add cx231xx USB driver") Cc: stable # 2.6.30 Cc: Sri Deevi Signed-off-by: Johan Hovold --- drivers/media/usb/cx231xx/cx231xx-audio.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/cx231xx/cx231xx-audio.c b/drivers/media/usb/cx231xx/cx231xx-audio.c index f3729d6eb46a..a050d125934c 100644 --- a/drivers/media/usb/cx231xx/cx231xx-audio.c +++ b/drivers/media/usb/cx231xx/cx231xx-audio.c @@ -697,6 +697,11 @@ static int cx231xx_audio_init(struct cx231xx *dev) hs_config_info[0].interface_info. audio_index + 1]; + if (uif->altsetting[0].desc.bNumEndpoints < isoc_pipe + 1) { + err = -ENODEV; + goto err_free_card; + } + adev->end_point_addr = uif->altsetting[0].endpoint[isoc_pipe].desc. bEndpointAddress; @@ -712,8 +717,14 @@ static int cx231xx_audio_init(struct cx231xx *dev) } for (i = 0; i < adev->num_alt; i++) { - u16 tmp = - le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].desc. + u16 tmp; + + if (uif->altsetting[i].desc.bNumEndpoints < isoc_pipe + 1) { + err = -ENODEV; + goto err_free_pkt_size; + } + + tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].desc. wMaxPacketSize); adev->alt_max_pkt_size[i] = (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); @@ -724,6 +735,8 @@ static int cx231xx_audio_init(struct cx231xx *dev) return 0; +err_free_pkt_size: + kfree(adev->alt_max_pkt_size); err_free_card: snd_card_free(card);