Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp358216iob; Wed, 18 May 2022 03:53:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxg+rasd1a7SIswrWxyF8bK6xXHQGfEldvx7IJIoLidbkxRPI2Rv2F9GIh3RRNyb0cbzRwi X-Received: by 2002:a63:34a:0:b0:3f5:ef54:ec6c with SMTP id 71-20020a63034a000000b003f5ef54ec6cmr3737473pgd.41.1652871211712; Wed, 18 May 2022 03:53:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652871211; cv=none; d=google.com; s=arc-20160816; b=MtxhGxe9ftoBhM8xjciVPlDY84GmUlpnCIbpQ19ChNstkxmgjCsH92JstgK4cuj7uO Xt9nGR4UwU/jdfbMjjx3K4rB4bww83KrQVwEt75932R3xQO1MxYSRZRzfVwnl00TeO+4 L0YKj3ujXCDyd9rPlVwTza9dN9CY8IhdBrCMBXPsek+UAnd8Y9SwRgEUMmudGmMVX1g1 E9lbSvJoT59TlToUmI7HCLv1PdBFcbryEFDKlge29YLK+3egTF7q22G/93EfW7/Z3dMS Mjis/fCENBiFCzpV1syRFa7cy/jmng+50EsyYZITWHaZsJqlf0ZhgL1IvJuUL4DrPyLH BA4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=ph+3ct6X1QyZ21KvhAxnKnqhAWD9kkeqIPmnuWsoKAs=; b=T6daSOnKOSVTIP7/WeIAcwUaeixNx+3TLFHMygTldf65/oYbOzHfE3QPU3y6hqbXLW tf5c8RrEb2WysJnyUGEZAWX3F+m5NuJtmOym7Y1jNvjRd+G8/cZ2gUwhv0Bw6+VIptOZ 7IAUnrHmL05rxXme6TEzOC3O04JhvgZMiZe9T87i8HmsK/2J1Lmk6sdYDtT63K+1jkbC 33pDj4tOsykVOYgEfT1NO6J932Cs9IPwZTfTXHjIceb6jYLDrsCMZi+etKidtwzSDKiB SZzarMPda1nUSvAYsfqSQs4lai0zqTa66vCowMb+CiXMqSTRnOYaqF9lES/Rq8zhi4Wl EIrQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id l23-20020a63da57000000b003ab35377352si2330186pgj.662.2022.05.18.03.53.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 03:53:31 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B7E0C54BED; Wed, 18 May 2022 03:44:39 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235225AbiERKob (ORCPT + 99 others); Wed, 18 May 2022 06:44:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235206AbiERKo0 (ORCPT ); Wed, 18 May 2022 06:44:26 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 915FE527E1; Wed, 18 May 2022 03:44:25 -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 4D5E2B81F06; Wed, 18 May 2022 10:44:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C0BABC385A5; Wed, 18 May 2022 10:44:21 +0000 (UTC) Message-ID: <32fac87b-0e57-8cf1-ac1e-38e2bee82af2@xs4all.nl> Date: Wed, 18 May 2022 12:44:20 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: Re: [PATCH] media: dvb_vb2: fix possible out of bound access Content-Language: en-US To: Hangyu Hua , mchehab@kernel.org, senozhatsky@chromium.org, caihuoqing@baidu.com Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org References: <20220324080119.40133-1-hbh25y@gmail.com> From: Hans Verkuil In-Reply-To: <20220324080119.40133-1-hbh25y@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Hi Hangyu, It appears this patch fell through the cracks. It's certainly useful to have. On 3/24/22 09:01, Hangyu Hua wrote: > vb2_core_qbuf and vb2_core_querybuf don't check the range of b->index > controlled by the user. > > Fix this by adding range checking code before using them. > > Signed-off-by: Hangyu Hua > --- > drivers/media/dvb-core/dvb_vb2.c | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/drivers/media/dvb-core/dvb_vb2.c b/drivers/media/dvb-core/dvb_vb2.c > index a1bd6d9c9223..f410800b92e7 100644 > --- a/drivers/media/dvb-core/dvb_vb2.c > +++ b/drivers/media/dvb-core/dvb_vb2.c > @@ -354,6 +354,12 @@ int dvb_vb2_reqbufs(struct dvb_vb2_ctx *ctx, struct dmx_requestbuffers *req) > > int dvb_vb2_querybuf(struct dvb_vb2_ctx *ctx, struct dmx_buffer *b) > { > + struct vb2_queue *q = &ctx->vb_q; > + > + if (b->index >= q->num_buffers) { > + dprintk(q, 1, "buffer index out of range\n"); However, this patch doesn't compile: dprintk in this source doesn't have a 'q' argument! > + return -EINVAL; > + } > vb2_core_querybuf(&ctx->vb_q, b->index, b); > dprintk(3, "[%s] index=%d\n", ctx->name, b->index); Also, to help debugging it prefixes the warnings with the ctx-name. Can you post a v2 of this patch? Regards, Hans > return 0; > @@ -378,8 +384,13 @@ int dvb_vb2_expbuf(struct dvb_vb2_ctx *ctx, struct dmx_exportbuffer *exp) > > int dvb_vb2_qbuf(struct dvb_vb2_ctx *ctx, struct dmx_buffer *b) > { > + struct vb2_queue *q = &ctx->vb_q; > int ret; > > + if (b->index >= q->num_buffers) { > + dprintk(q, 1, "buffer index out of range\n"); > + return -EINVAL; > + } > ret = vb2_core_qbuf(&ctx->vb_q, b->index, b, NULL); > if (ret) { > dprintk(1, "[%s] index=%d errno=%d\n", ctx->name,