From patchwork Mon Oct 24 11:31:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8955 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp436113wru; Mon, 24 Oct 2022 05:56:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM47SLq+FLNVkxrH26EN/R8V90YD7z3SsQtkFDhKWXUltN4ijhoh6zQNjljOMA0hGencpeKg X-Received: by 2002:a17:902:db0b:b0:185:51cc:811a with SMTP id m11-20020a170902db0b00b0018551cc811amr33168854plx.85.1666616177501; Mon, 24 Oct 2022 05:56:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666616177; cv=none; d=google.com; s=arc-20160816; b=hZX/0ecjvhYbpF4jYIdZ+MAkTykjMa619wMelb2BBMXdByPB57yRHDX+yPdMSFbh3d VxP20hIIGXZ6xM1fZ48WWkW+XSWjqDob9yQDcvQ+RxZQKuaLhaITFY5izsTGg2p8LQMQ I3OGKpbb55BZMbHuCdK2kOTER1oomnEsQKhLV0FgWRdptOaMwTZ7xXhLF1/ZvpEjtX+Y lqZKdS9nHu00AReg8ij2r2Vx7nFfEkSJ33NzBYqnViPSoEJTVsFq7YTcWtKpTrFOHhuC rR3T+ehP29/HvZKiD9HaXgKKD0SthezZMOsIPm0oivsQEwCvy+FYR49Y6bG2xBU9jCXu NbJg== 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=QFcPds9eeMzt18VznIZOjzkm08R01QCjPvwedHkmQaU4OxEiY5V4PsKMnqkJ6Be7W1 UnhEOBuoPYtPGLXmZaIkz93qSQdQ8FPqMZgWmdAotjddY3bYkFeEVxzmL4pQqQPjtr04 WodhVHXCVfPSqnEI/8+uDuC1UPESRNdw3FgJDIf1Ijsq4j2psgfe6CS6JmBO1cDP1YcQ RfULEGb1l+VTsQ8ixEBGbITl+ygGju34fR3SwApSxsq7/0j5RwuFf6GGMZTYXJnmJfct MYX39p/346CGvop6jobEqGT9pSfZ4dsxefdzipYHsafBM3EjD3ciXGoDRQNVOklsMvPG +yWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pbfIA83K; 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 cr7-20020a056a000f0700b0056bc627dbeesi3268829pfb.124.2022.10.24.05.56.04; Mon, 24 Oct 2022 05:56:17 -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=pbfIA83K; 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 S234455AbiJXMya (ORCPT + 99 others); Mon, 24 Oct 2022 08:54:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234523AbiJXMxE (ORCPT ); Mon, 24 Oct 2022 08:53:04 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48294326D0; Mon, 24 Oct 2022 05:14:16 -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 24727612FF; Mon, 24 Oct 2022 12:12:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38E0DC433D6; Mon, 24 Oct 2022 12:12:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613547; bh=AlKGxA5oHb1mhMs88++LuDXBhLryEnVpofotGpHubyE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pbfIA83KIIxpBwWK3zzg0448uAACtnfj2RRDQqt6WR92AL/++gjC+JhYRV6rH7pxa /uHc9sSmnELJ+F1tZ04qyKql+OZxcutofNtWjlxkXZnMViYISlxJmGyLKomoy0TTQT ++okFCTuoBpcU+k3NjK8dmaiUfxz5aw+u6c88TDc= 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.4 178/255] iommu/omap: Fix buffer overflow in debugfs Date: Mon, 24 Oct 2022 13:31:28 +0200 Message-Id: <20221024113008.763948658@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113002.471093005@linuxfoundation.org> References: <20221024113002.471093005@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?1747573724814827290?= X-GMAIL-MSGID: =?utf-8?q?1747573724814827290?= 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