Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp979465pxb; Wed, 6 Apr 2022 05:55:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygsIJtUlQtZJBmfLwp13iA0b1edVtYj1/oa7tJ5HcAm3hIn2K2nGmNKPNZteMWVSKkGQxH X-Received: by 2002:a17:903:246:b0:153:87f0:a93e with SMTP id j6-20020a170903024600b0015387f0a93emr8492617plh.171.1649249750338; Wed, 06 Apr 2022 05:55:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649249750; cv=none; d=google.com; s=arc-20160816; b=Kh4Goc3nJTW7YJiws5VikUNdDnPQffVxeOVPkGkrX/qWGdhBmhox9G9sKDeV+KQbwt ez5W72BzxIaVgWicEutOUq6mLdAD12EZblGH3ENKWv0DLBrm0DW4HclWrfKmyaHUv/LR 9ZHUyuLnMNsPqpwaXvX3ZNUaZ362/2DmQ5sDyQUQOJYbEqzfrQbL+/dhcwe9MmuTs4jA L9++s+JIzKw4wnojPYhIpEizGquCQmfCF0ZS2tfQe9BFWkqJSm/+C/aU1/YncTLWlVSB NRRfJEbBjB2IFFycmNyMKALWHLq5w0IuWMqdMUjHODlio44/GqYugEcAsyQ36KcOBXtb ScBw== 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=YEwcCVoaFbLDQ+NpteJ78WS2NVMlYqB3gd510cJcdzk=; b=xVDWw3QsnEKekkmpfu3K01AZKD7oVHZVHgeJd7l102mejbeOH+82SZuSDvDYMVcOqS xVt66PPsxeBaJyc+BiN8Vl8HFx1AFsdGFTcNXAuUz1+vtAmulLymeSJPH8zCI6wH5Vza Qd6hd4cLq05K/Mvw1B5axh1Ym2RhQEgp0VqE9EXiohvpAlcomVgVB1xsnLzwXjhCj/3B 3+H/8kTM4OH0PWN1WZ4/PCyaqPLejJ2XQ6GOXJDFEreEGAgw5sAZqccaKvnrHcXE8E46 nBA3p5fXn9u9og4pFEULubQHprEPilmany39F4fbOYSC5dremJSnvYqKJYHfBZY4iwRm v5IQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HJpMjeya; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id n4-20020a170903110400b00153b385c1a5si17661145plh.276.2022.04.06.05.55.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 05:55:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HJpMjeya; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C5A33629255; Wed, 6 Apr 2022 03:03:43 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1579756AbiDEXcq (ORCPT + 99 others); Tue, 5 Apr 2022 19:32:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351410AbiDEKCY (ORCPT ); Tue, 5 Apr 2022 06:02:24 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52E2A6D4E1; Tue, 5 Apr 2022 02:51:41 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id F29D3B818F3; Tue, 5 Apr 2022 09:51:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4440BC385A1; Tue, 5 Apr 2022 09:51:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649152298; bh=1mzmburc3X+szuNAEo1tXUhYMeph1aGhucbEOTahC2s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HJpMjeyalV/lhbM3/NYaLVeH8qDojrV/j94qB62wTAFbAgYM89PEC2Ft7XYoxV/fw jv+tLm0+9MC3JTgi+npS8+qfperGqZ5wOgzCvg0dha7MISMzhCIWvZKjMQj98tAwfX xg3bYRCkut1tjrlRsNdARjpJjaUL0xMAUln3aXBo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Corentin Labbe , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 5.15 726/913] media: staging: media: zoran: calculate the right buffer number for zoran_reap_stat_com Date: Tue, 5 Apr 2022 09:29:48 +0200 Message-Id: <20220405070401.593671596@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Corentin Labbe [ Upstream commit e3b86f4e558cea9eed71d894df2f19b10d60a207 ] On the case tmp_dcim=1, the index of buffer is miscalculated. This generate a NULL pointer dereference later. So let's fix the calcul and add a check to prevent this to reappear. Signed-off-by: Corentin Labbe Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/staging/media/zoran/zoran_device.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/staging/media/zoran/zoran_device.c b/drivers/staging/media/zoran/zoran_device.c index 5b12a730a229..fb1f0465ca87 100644 --- a/drivers/staging/media/zoran/zoran_device.c +++ b/drivers/staging/media/zoran/zoran_device.c @@ -814,7 +814,7 @@ static void zoran_reap_stat_com(struct zoran *zr) if (zr->jpg_settings.tmp_dcm == 1) i = (zr->jpg_dma_tail - zr->jpg_err_shift) & BUZ_MASK_STAT_COM; else - i = ((zr->jpg_dma_tail - zr->jpg_err_shift) & 1) * 2 + 1; + i = ((zr->jpg_dma_tail - zr->jpg_err_shift) & 1) * 2; stat_com = le32_to_cpu(zr->stat_com[i]); if ((stat_com & 1) == 0) { @@ -826,6 +826,11 @@ static void zoran_reap_stat_com(struct zoran *zr) size = (stat_com & GENMASK(22, 1)) >> 1; buf = zr->inuse[i]; + if (!buf) { + spin_unlock_irqrestore(&zr->queued_bufs_lock, flags); + pci_err(zr->pci_dev, "No buffer at slot %d\n", i); + return; + } buf->vbuf.vb2_buf.timestamp = ktime_get_ns(); if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) { -- 2.34.1