Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp1043322ybm; Fri, 29 May 2020 19:46:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOieLK7R+iZXf8J/r2JBh1TX9Kk92RGTxVTU+GBG/zMUZLz37bfDZypT0jUzqgx1VF89sm X-Received: by 2002:a50:f60a:: with SMTP id c10mr9216965edn.295.1590806813711; Fri, 29 May 2020 19:46:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590806813; cv=none; d=google.com; s=arc-20160816; b=rqbUXinHYpnsaK8zvPjH1LalEACDtNy+ZF+7YO6el+3C+y1lRCDpp7pyJfcjTNWjBO saebGRSfkfO9ATttuNIlLaDGiLDOrdNeRyon0B/8RuFus5XAEjFOLm9l1fPEKL2bdE0q jdsBRfHJFjZeTY1pKrrp2XW/l1ENpBXur6CTN0mAf7nsqLsHRjSDL/qppSk6rVyVMzjM jy6SYnul+7ErU8DHLPzc0eOM+gSvejM8p+WmtHZGUb20+sGn6i9b0nJXTElI1Rq4aoNN sHrXeG6gxlCwiipw0Zqk38hvaNavTcSa78+2xqXBft3FQrqegE1tEpevFJV5eJ3p7CPe NCeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=tqT1Z0ZKvBSM+e8jvFBLBJcZZOZwowJYeHajnRMlUKw=; b=Dl9WoQFFwTaVhSZMdnW6jjYHrTcn0fRONbAmXpsdKKrT3CFzGTogxKRl7i0u74Y03C 98Xuz9WOuPxAaJJUf81JDHLLDN2+wKa8fhNThjt/xE2OAmFDz1bOA5fQBAZyCf/1Gq7D x8m0ykHEF/tO+XJMKTBO1EioRETHlnkXZmCxtn6SPMsMCqAUcYmnwMtcbxgvKByQwX1o YxaEpFAudxUmHPP3rGK4EaDa4NXqY9OMFc1I3ZqPWlhRcj2LRtZO7ewipnGJ+ba/+UuZ foSwZslZl5rIv1t1A/esMwO2dwG2MJvGaRM+pctjiuFvNiRNeElkHzasG3LqpnwX0+wz gHJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="SItPDO/h"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t22si5462385edr.207.2020.05.29.19.45.58; Fri, 29 May 2020 19:46:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="SItPDO/h"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728682AbgE3Clf (ORCPT + 99 others); Fri, 29 May 2020 22:41:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728349AbgE3Cle (ORCPT ); Fri, 29 May 2020 22:41:34 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8318DC03E969; Fri, 29 May 2020 19:41:33 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id i17so1926510pli.13; Fri, 29 May 2020 19:41:33 -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; bh=tqT1Z0ZKvBSM+e8jvFBLBJcZZOZwowJYeHajnRMlUKw=; b=SItPDO/hGImCOttd+gN5ppN+DRMAeCNL4jZVy5Z0nr1r8x7igPj7Sm9yzgP6X4cILJ 1b8IMbbsWMwHH9jvSN26vyG8t6SUqCuGUz4xtbnTYPUGsnffWvGXEz/ynJnGXvcIonOo bAs5hXz2jMIYUvl6XjDCKFU+0AcN9Mws+ybHm556YV8IxUH97wZX1uWDXqJWLIwXJuvO Tg0QGCAwtHfriMyBvfMaRswvrkH6E+GeIhGdWVlUmlh9ihNG16DyuzlomXwmX1Y0yoI/ Ki0RRiS6ly3+IHH4/HwDRTZArC0ngQpDbLR1eDNtOpiIZz2f5J3GVVr/40nvxwv85knr vpEw== 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; bh=tqT1Z0ZKvBSM+e8jvFBLBJcZZOZwowJYeHajnRMlUKw=; b=Cu1t+Du9IASTWL8wsD+28Mo9gfNVRa+cY7LE45GkAl7WivKd+QgNdQJha1Msn5UGl4 Qs6P/Pg6Npfe6Bv0pHDOYqGeANP+PWac2Z/DdY0u87R4wruE+72PxEqI6mM1NO2NfauK cAzT4YCCjUew0hlhN34ih6xGkkbTjrPFwKppbGBJF5DBqz06S3jw+zWtY6x4N8L/4lII AVIUpQY0UbVAMv1xrVr2elT4IWJkuZ9VuBoGgjRf958MPsvgtHTrJGrXcRXOYyYtRyvg e0GR+LM4Lx59E34I8yRbJehPjuN8XP4ECv1+ncbbQfNInRqzUlcxYcRg876AVUTBTLZf 3e9A== X-Gm-Message-State: AOAM532BaGlNW9IYM1eTarWBWpdUQCx2p9h/YgJXSfIAW0DQbBuh3moG i6wWkMojPIBMkKOPQ/xshG0= X-Received: by 2002:a17:902:c808:: with SMTP id u8mr11172343plx.135.1590806493090; Fri, 29 May 2020 19:41:33 -0700 (PDT) Received: from oslab.tsinghua.edu.cn ([166.111.139.172]) by smtp.gmail.com with ESMTPSA id n2sm8291365pfe.161.2020.05.29.19.41.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2020 19:41:32 -0700 (PDT) From: Jia-Ju Bai To: stanimir.varbanov@linaro.org, agross@kernel.org, bjorn.andersson@linaro.org, mchehab@kernel.org Cc: linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] media: venus: fix possible buffer overlow casued bad DMA value in venus_sfr_print() Date: Sat, 30 May 2020 10:41:17 +0800 Message-Id: <20200530024117.24613-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The value hdev->sfr.kva is stored in DMA memory, and it is assigned to sfr, so sfr->buf_size can be modified at anytime by malicious hardware. In this case, a buffer overflow may happen when the code "sfr->data[sfr->buf_size - 1]" is executed. To fix this possible bug, sfr->buf_size is assigned to a local variable, and then this variable is checked before being used. Signed-off-by: Jia-Ju Bai --- drivers/media/platform/qcom/venus/hfi_venus.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/qcom/venus/hfi_venus.c b/drivers/media/platform/qcom/venus/hfi_venus.c index 0d8855014ab3..4251a9e47a1b 100644 --- a/drivers/media/platform/qcom/venus/hfi_venus.c +++ b/drivers/media/platform/qcom/venus/hfi_venus.c @@ -960,18 +960,23 @@ static void venus_sfr_print(struct venus_hfi_device *hdev) { struct device *dev = hdev->core->dev; struct hfi_sfr *sfr = hdev->sfr.kva; + u32 buf_size; void *p; if (!sfr) return; - p = memchr(sfr->data, '\0', sfr->buf_size); + buf_size = sfr->buf_size; + if (buf_size > 1) + return; + + p = memchr(sfr->data, '\0', buf_size); /* * SFR isn't guaranteed to be NULL terminated since SYS_ERROR indicates * that Venus is in the process of crashing. */ if (!p) - sfr->data[sfr->buf_size - 1] = '\0'; + sfr->data[buf_size - 1] = '\0'; dev_err_ratelimited(dev, "SFR message from FW: %s\n", sfr->data); } -- 2.17.1