From patchwork Sat Oct 22 07:26:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7539 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1105873wrr; Sat, 22 Oct 2022 01:36:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7rnLcFPdAJwQX+8YBdgXiywY3Z3GqGGMmJesMv+NPhl8/UWH/LIrpK8DvxQJmLSkQV1KGI X-Received: by 2002:a05:6402:1906:b0:45d:db20:7709 with SMTP id e6-20020a056402190600b0045ddb207709mr20796707edz.406.1666427784837; Sat, 22 Oct 2022 01:36:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666427784; cv=none; d=google.com; s=arc-20160816; b=mibeCTYWJfkQjVJhRbyhFdWtnelL1JNAZRt3wWbJ7cX8kQIqFd+n/n/mulxazNh4Hq udHMS8+NEpDkpdZv3lAarxfPAdBnnq/uXJcOoCCh8vrMxooDSMo9r3R2G2fGY2XveUc/ N1xxChn/v6BF4hxmX9vnyeDjN9Nhn/xTLPMJ35vbbiRR4fDYl+UUM5h1JOwLNHnP7CBy dFneM+WY3Is4h+i+ZCEMZCWSBIQN0D178MrwrRy2edFvdFKoqf116KlKDbOsaWXpA7Ol EbXWu9m/LvAG6FxJPFrJZ2NImR3oSYbEUMPbQ/45ndrjd0vEToDBEqnTm2DeoA+zl9Qc IVeA== 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=Re463ur1U2wiu9FBcNtMjBkF7WpIaychu4lKxQTsQLs=; b=OF/LgUaHBoYw0ijWbyMzUD4OLgS4b6JtUM5a45wFgPIe8L2j1+ua4Ie9sG7IGyfxdB MDGSyfBnBfvJxtspTbFlAt9MiypFkKcCJ1Q6nTeuwQD6ZpS/ktsYU6rwhMlDizW4+7No mLMDjH0rzQu8zlolCOvOEW2HOK+86sApz0Z9F5DLYpKXHMBTy+ueIVvqXKvk3s337wEK /JXpgbkfrKNuv/iQ6i/szi+/I6DVmmWTg+FQ6lOd9NzmcP2luxI9g7qWGhy9QElRAv2l JllrqXUNCHfAXAqpi9g6uKwtWZPPjgEyVBkTVxV/ue8LpNRp90c+lPFwoJnSJzX3zZwZ vAfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=M5QaGctB; 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 y14-20020a50ce0e000000b0045745ecd5a1si17988968edi.304.2022.10.22.01.35.55; Sat, 22 Oct 2022 01:36:24 -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=M5QaGctB; 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 S233750AbiJVIW1 (ORCPT + 99 others); Sat, 22 Oct 2022 04:22:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233655AbiJVIUe (ORCPT ); Sat, 22 Oct 2022 04:20:34 -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 9F6332B5BAC; Sat, 22 Oct 2022 00:58:36 -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 A172960ADC; Sat, 22 Oct 2022 07:58:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A1443C433C1; Sat, 22 Oct 2022 07:58:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666425485; bh=AlKGxA5oHb1mhMs88++LuDXBhLryEnVpofotGpHubyE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M5QaGctB2iYXQx0I2xwiGTzTqFv1pW/xRQkkMp2dj6iiEdiJpEzWvpRYlbZcyTCUN W7vZc4c6sd47WzGeMEi0GfjoiASPDFW0/Ukh30Z7fVf5B7x/w7/jO7n9/uQbObjO9I mB1g528tgRA1C6jmKfCrGcvGax+ZNj9By2rosJC4= 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 5.19 516/717] iommu/omap: Fix buffer overflow in debugfs Date: Sat, 22 Oct 2022 09:26:35 +0200 Message-Id: <20221022072521.109506096@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 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?1747376180841660088?= X-GMAIL-MSGID: =?utf-8?q?1747376180841660088?= 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 a99afb5d9011..259f65291d90 100644 --- a/drivers/iommu/omap-iommu-debug.c +++ b/drivers/iommu/omap-iommu-debug.c @@ -32,12 +32,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