Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2158911pxb; Fri, 25 Mar 2022 12:08:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwowBR7ijMf8encdGrIFAepHIg9eNX0QuDCMlRt5mdfKJpDAW3mJyO9TKchnZhUBWa5MYQL X-Received: by 2002:a17:902:db0c:b0:154:1b36:6a7a with SMTP id m12-20020a170902db0c00b001541b366a7amr13439130plx.36.1648235294664; Fri, 25 Mar 2022 12:08:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648235294; cv=none; d=google.com; s=arc-20160816; b=zpFq9C08njWEXpkFuvXmzxzDdjHbw0Nf69QVbv2p8uduDdC9q2VNLPxSHppmd7XP2P 5dvL21cbmpeG3BJ5gek7XuyPviBxtjrjzknlWWSLULriZveq1DSLNsG6H8kb2VS+zdNl f7y6J/xXBhORilMsiUM+CT5cUIJ1tqS0dOSSsqV6yUsfZU/tM3NwQL2DNYyR5nERPceW 5SNU6G7+YkN2qL7dlrIW6aFw67NDnQj0kHayHfJ7wW6rZYE3guBV4J0sXxNgFrgwqNm8 e4VUPO2P2xOEa/MgohRx/wZ3iz4iFLgDPRPh+uY3Eo2TvTgb+VhAtQnnnAV3wme7rFlU 37oA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=G5VkRxphoDlEffob+x1mTjn2V5jLAaYh4z6lIZRAV4w=; b=it3z3QFEB6JxyLjjscnzCKfP07pIHw6aVzeZFY7N3uXAaAKIWp+0D2T8Zgdbo2gRbt LT/de0rnEo6Tl0YSZu0rsSrhDAvCKCQ4SN8gut7MBes/v2JJqmoVWHMccnx/Nd2IpXxM Y2YOWZTn6Wqea1v3J1cnBR5+UeHGCW+UpAU9Q4kxEQaOmtnzSJeNm7IssKgM/puOuD/u dkbd2OLo9h3GthIY0pyeF2Ju3qbTK16OPoUracAn5tia4wvM48zTJKk7y0GHm5JLzhPW znzNWJOkz3LD7pldz1UFY5Ow4BP7KtGTqYa/+wgam8KCCbbCCJUUpaRljEzjEbJSKPLe nBkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=SztdccuZ; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id e8-20020a170903240800b00153b2d16482si3382169plo.138.2022.03.25.12.08.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 12:08:14 -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=@gmail.com header.s=20210112 header.b=SztdccuZ; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0BC7F223872; Fri, 25 Mar 2022 11:19:56 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348782AbiCXIDJ (ORCPT + 99 others); Thu, 24 Mar 2022 04:03:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348765AbiCXIDH (ORCPT ); Thu, 24 Mar 2022 04:03:07 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0911799ED5; Thu, 24 Mar 2022 01:01:36 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id f3so2138299pfe.2; Thu, 24 Mar 2022 01:01:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=G5VkRxphoDlEffob+x1mTjn2V5jLAaYh4z6lIZRAV4w=; b=SztdccuZGsYitnp5O37Adv5pazKmREdg7yYTtTI5xjFfB2W40ez4XslXUEH3pu/mYj RhRIF2YdKKb3eFfRvGh+Pay83BAw65hM1ekzuqwDufB1/2RO5XcZGMWa7W/kSzjA3kRk rSnGlKgFN6wyC+bCk+ESrtaRh1wi6/8UOwT6racfe1nLtcGOqkkCZ4xAnJen+Pf30fwg zfqnr1xf53dILmn9XJ/t5tEDUtul0BlM3grhvHrWKerziMlm1YV3yFbH209OEhv5+be+ FZDXWsrgKubV6CftoDY6yWKLWMj2uzNqAs6aHUkhj1VN0JA585cRLSJzOQjd67OaVZqJ Of6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=G5VkRxphoDlEffob+x1mTjn2V5jLAaYh4z6lIZRAV4w=; b=Y/ODXh4ALtgwMVdKqyBZdgBeD7A6dabe/0ZDsQ5XSammCl/97+Bh+YMcxL22gNJX9g cENictvQZn5ElaOTrTcGH9z/abwEhApSLNM180oQLGqwxgUOIqJMv867fzGmBhm+kT70 NebiAmdWpBMyKjpd5WaNIJ81cuyr+9xgtudbxYB0uuV6X2LoVfBKUQmyDWWkSyeK8juF rUdGGVL/alpXDxOfFxxjKyo9rvABpxjPlfzUjfXBq9r/Q1n+QXLQYsdeMbNpYU7UqIBV OI3AfQjS7hij1983bmQxJDCU4wRGC25gPmt6XX5lwDfGo91I9E3w2ArKJga27hAYrYsg V7Qg== X-Gm-Message-State: AOAM533M5zromZzUMHNpSkPcRaoFKJiDRkF+jOebsOS6m3riPwR3zBPz MTpMbDDqlXG11FdIvp4hHF0= X-Received: by 2002:a63:3e01:0:b0:386:3916:182f with SMTP id l1-20020a633e01000000b003863916182fmr2071130pga.435.1648108895546; Thu, 24 Mar 2022 01:01:35 -0700 (PDT) Received: from slim.das-security.cn ([103.84.139.54]) by smtp.gmail.com with ESMTPSA id j14-20020a056a00174e00b004f776098715sm2443851pfc.68.2022.03.24.01.01.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Mar 2022 01:01:35 -0700 (PDT) From: Hangyu Hua To: mchehab@kernel.org, senozhatsky@chromium.org, caihuoqing@baidu.com, hverkuil-cisco@xs4all.nl Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Hangyu Hua Subject: [PATCH] media: dvb_vb2: fix possible out of bound access Date: Thu, 24 Mar 2022 16:01:19 +0800 Message-Id: <20220324080119.40133-1-hbh25y@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 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"); + return -EINVAL; + } vb2_core_querybuf(&ctx->vb_q, b->index, b); dprintk(3, "[%s] index=%d\n", ctx->name, b->index); 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, -- 2.25.1