From patchwork Mon Aug 10 05:05:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peilin Ye X-Patchwork-Id: 256213 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.1 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64220C433E1 for ; Mon, 10 Aug 2020 05:07:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 25E3F20734 for ; Mon, 10 Aug 2020 05:07:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UxHPO6Ru" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725849AbgHJFHu (ORCPT ); Mon, 10 Aug 2020 01:07:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725763AbgHJFHu (ORCPT ); Mon, 10 Aug 2020 01:07:50 -0400 Received: from mail-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBA71C061756; Sun, 9 Aug 2020 22:07:49 -0700 (PDT) Received: by mail-qt1-x844.google.com with SMTP id c12so5891897qtn.9; Sun, 09 Aug 2020 22:07:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=aPHXTL52nZ8TnYruo+TUHBbc33RfRH/y9aR6NOzaRVo=; b=UxHPO6Ru8IFAHFgMeMWp54jGqzTiCihLYmV0zJhgBUaAyfmPsEx2LJAwXw2fLA0KG5 D6OBIvkJn0g+qtixsVSWnsCjzrD17UtQ2vDuWxkusNN8VNYdgH97X2zs0vSgRxY+vWw3 tMSsgwW2UHXCGWh/Puol387O+IctIO//VkkPqRZO3JICdKshwUwWUnmnANxLqsyLekQl gsknh7pR3vmTc8F3jfQ9r6mVvmf23C+Y5fCPZpE1CshJsxvNrp7uScL24EwAEc7WWBFI yePF2V597Y8LZKSPYmP+DUJIFgT+djJL7a+ax7YwAIu6SUfPHDI05nrBN57WQE4Wgw8h KNzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=aPHXTL52nZ8TnYruo+TUHBbc33RfRH/y9aR6NOzaRVo=; b=Iru/vfuF21vxDMS2u2lBNwWmQjA9iZ8oQOC+FAhHuaff+/ep5SDgx9kE24X89dmcqv rjJEcfJd4BkEeSP0ulA6upi/1gucCBnYmu5/KpaclYXb0tHIw/Im65ISdrMNEdX+bXQU NvEquE/cBRLh2Mjv5EBxfbHClib7OwIk272zUrpnU5MXnyTverpemQohr0cC2WsKuJPg LY81iQ1x9MR23QWLV7ns5H0sNViOnuEdrh29lPt/fUd8LqGNfyD9s8vmy2HSPqtEa3ej bQ55unWDiNPZAdbLXSo+famSwZB2H3Mr9Ma0QipsTJFttL8bmGN7GCJL/al0EXIrgc5X mKXA== X-Gm-Message-State: AOAM531BzRwh0L5e6X+h9oX7UqJoOtFv+orLI3oVOKLNS41O8g5wL933 Sjl3U6hxUUKbz+xuYAOmug== X-Google-Smtp-Source: ABdhPJxeZ9jmhF6jSAkll2vnf9FoWW3KrIT9DdSlTQiwoFC7RC0e4phvSPS3a0ljAS4WeWvC0RiN9A== X-Received: by 2002:ac8:1382:: with SMTP id h2mr25882364qtj.228.1597036068667; Sun, 09 Aug 2020 22:07:48 -0700 (PDT) Received: from localhost.localdomain (146-115-88-66.s3894.c3-0.sbo-ubr1.sbo.ma.cable.rcncustomer.com. [146.115.88.66]) by smtp.gmail.com with ESMTPSA id w20sm13125325qki.108.2020.08.09.22.07.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Aug 2020 22:07:48 -0700 (PDT) From: Peilin Ye To: Mauro Carvalho Chehab Cc: Peilin Ye , Hans Verkuil , Greg Kroah-Hartman , linux-media@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, syzkaller-bugs@googlegroups.com, linux-kernel@vger.kernel.org Subject: [Linux-kernel-mentees] [PATCH] v4l2-tpg: Fix global-out-of-bounds read in precalculate_color() Date: Mon, 10 Aug 2020 01:05:32 -0400 Message-Id: <20200810050532.640075-1-yepeilin.cs@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org precalculate_color() is reading out of `sin` since `tpg->hue` is not being properly checked. Fix it. `cos` is safe, as long as `tpg->hue` is higher than or equal to -192. Fixes: 63881df94d3e ("[media] vivid: add the Test Pattern Generator") Reported-and-tested-by: syzbot+02d9172bf4c43104cd70@syzkaller.appspotmail.com Link: https://syzkaller.appspot.com/bug?id=db50123c788e2cc5a9d90de569c398b66293ee48 Signed-off-by: Peilin Ye --- drivers/media/common/v4l2-tpg/v4l2-tpg-core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c index 50f1e0b28b25..52205fe096f7 100644 --- a/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c +++ b/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c @@ -930,6 +930,9 @@ static void precalculate_color(struct tpg_data *tpg, int k) /* Implement these operations */ int tmp_cb, tmp_cr; + if (tpg->hue < -128 || tpg->hue > 128) + return; + /* First convert to YCbCr */ color_to_ycbcr(tpg, r, g, b, &y, &cb, &cr);