From patchwork Mon Oct 24 11:31:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8781 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp430722wru; Mon, 24 Oct 2022 05:42:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6SCx3rD+9txy0yZP4/yHX8rMlozrHnwN34ZtIGE1KIzb6CwFhTNZ3EC/xAfhJHISohsxgN X-Received: by 2002:a05:6a00:80e:b0:563:4ad2:9d39 with SMTP id m14-20020a056a00080e00b005634ad29d39mr33536724pfk.66.1666615329768; Mon, 24 Oct 2022 05:42:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666615329; cv=none; d=google.com; s=arc-20160816; b=ZbBayDNm+tXLDQeS1326Lc/gOS8GhPdXQOyzGaDEwnVdDI6zqQKI26sWZanmFLPYyS kptn8gLHCFOPlipzyYkeO04dR9EyCIAbblOcuKZ1/fk7SOPOWx1EWca+T2c4YWfaCQ8m rK5nMFlYCfb6KufZ2Z3yQ/IqXdhUEcAYrzgdAbe5gBlzFYD+S8urs8J5fyuPHIZ8Bogh D4qLJzI1gtBecXnzyIQr9gU1Dnwqp7gK6hYohUNnuJl9o54NAMQQcOV9aMQHDeEHwqxt vnKk5gVbLvsT2iAqtW73f2sZ1NrdEZZFnq8us6o/VRHML0bW3YLS8dG5QCZQBnneJQVb teiQ== 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=WeHYePugxGs9gQOjoxAM3s7tFisdkeMS3AyP+ihM314=; b=k9AN3fz5TxCyPE7uPyWKXMuFPEaIuz5oo5IoWkavEuTyBekNdyhDU/fC12doBkRgrr BzP0RdAB4Rz3MHwnX5gFkC6v10hCgQRSb5g+dEaXvqg/fwQExNVptKdFVVsZNvaCc2Nt Ac20GB9AOvJiduLENfAo66jycGbU3SyXi5Lhk6eAlRVjlfDATnLMEmNUTiP/soCOcOn5 T36IENDcspyLEVxd3QAeT7VBKee+ox9BsBcSs2HrRgReJNldRLmbFrgjqqGEV9geWliL ye2fbIGOEDrYc/a5RAmqAupG1Mf41IK+6uxWPezvRGcTtbgOuAAKGtA2E2nEAfw20Rro mP9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Pel7MsoB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ng10-20020a17090b1a8a00b0020d2d8c9a84si18053493pjb.137.2022.10.24.05.41.54; Mon, 24 Oct 2022 05:42:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Pel7MsoB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234039AbiJXMcx (ORCPT + 99 others); Mon, 24 Oct 2022 08:32:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234001AbiJXM3K (ORCPT ); Mon, 24 Oct 2022 08:29:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0114887FBF; Mon, 24 Oct 2022 05:03:09 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 4E599612C4; Mon, 24 Oct 2022 11:52:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64F93C433D6; Mon, 24 Oct 2022 11:52:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612331; bh=oyLbuAvGHpzGiRHM5PDQER02O7OkAB/aDBnlGorzYC8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pel7MsoBY88CfxhsUOozHg2vE8lBkYC+oVEALgkBWBhUpuMwbIRoLlhy4JMnipMFz dcZnuKtAyIZC0OIPtGbmXqj51A2VUuuIZR80lik812ff5AtWGzjBdRWssjX+DiOoLD OBFEVc3lpp5DXClx0ycVg1yt/udkf+e8zUCzsnZw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Robin Murphy , Laurent Pinchart , Joerg Roedel , Sasha Levin Subject: [PATCH 4.14 157/210] iommu/omap: Fix buffer overflow in debugfs Date: Mon, 24 Oct 2022 13:31:14 +0200 Message-Id: <20221024113002.070661190@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112956.797777597@linuxfoundation.org> References: <20221024112956.797777597@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747572835667536945?= X-GMAIL-MSGID: =?utf-8?q?1747572835667536945?= From: Dan Carpenter [ Upstream commit 184233a5202786b20220acd2d04ddf909ef18f29 ] There are two issues here: 1) The "len" variable needs to be checked before the very first write. Otherwise if omap2_iommu_dump_ctx() with "bytes" less than 32 it is a buffer overflow. 2) The snprintf() function returns the number of bytes that *would* have been copied if there were enough space. But we want to know the number of bytes which were *actually* copied so use scnprintf() instead. Fixes: bd4396f09a4a ("iommu/omap: Consolidate OMAP IOMMU modules") Signed-off-by: Dan Carpenter Reviewed-by: Robin Murphy Reviewed-by: Laurent Pinchart Link: https://lore.kernel.org/r/YuvYh1JbE3v+abd5@kili Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- drivers/iommu/omap-iommu-debug.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/omap-iommu-debug.c b/drivers/iommu/omap-iommu-debug.c index cec33e90e399..a15c4d99b888 100644 --- a/drivers/iommu/omap-iommu-debug.c +++ b/drivers/iommu/omap-iommu-debug.c @@ -35,12 +35,12 @@ static inline bool is_omap_iommu_detached(struct omap_iommu *obj) ssize_t bytes; \ const char *str = "%20s: %08x\n"; \ const int maxcol = 32; \ - bytes = snprintf(p, maxcol, str, __stringify(name), \ + if (len < maxcol) \ + goto out; \ + bytes = scnprintf(p, maxcol, str, __stringify(name), \ iommu_read_reg(obj, MMU_##name)); \ p += bytes; \ len -= bytes; \ - if (len < maxcol) \ - goto out; \ } while (0) static ssize_t