Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3408278rwa; Tue, 23 Aug 2022 04:24:07 -0700 (PDT) X-Google-Smtp-Source: AA6agR55FU86FFzUX3qmFucngAIs7KFUDq/NXHrgnqWy0qmU745UfU8cr1u99Omi12WSXHpVDKfp X-Received: by 2002:a17:90b:3e8b:b0:1f5:8706:18a1 with SMTP id rj11-20020a17090b3e8b00b001f5870618a1mr2952580pjb.112.1661253846996; Tue, 23 Aug 2022 04:24:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661253846; cv=none; d=google.com; s=arc-20160816; b=oKzqoS49cU45REBC47zgmEMB+tzHlLHTvaW9jHEqz4uVy7PLRcTPsiCDtyq7chSl31 hM5pzz43GYY3ZhtOn3lILJTPG34nb6eOHF+cBRExv8jA+irQ0dSOWfUZoTIFN6gl4x8P Z1I6yF8Z+4Lp20SW7w4FmG924QjBg41MrqbHfc88UasSrDTkD6yGn85GaDw58/JlQur5 ZXFPdHLeuYdOj0zXhllJFzRY89C5JombmtKIQAtL/UMZtaWsv7UgVLg38sykBofHUBoa kqM1nj8rAR/QUpQ88hmYTjT18cYoyPiNjiNmM6HEsC7A8tkqdZBK+QEmam/+2HB1RHV2 2x0A== 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=EmEVRCcPYKzcF+d7h+p2vhfFnJMP3D/jHjtBGizrbq8=; b=cpi+ksTETJLPQRVKOIFUMf3b2ryAGTEdEXa2BjXVxSudrdRcHTSutk6XdegpciqF5+ 94RtEJQ41ekPu+wjuClwbM7tvLbxmZVp+5ve9PyPvlqZ305lwq4wbDXh0pq+z6NAB1Oq qSfMhvh3OSW/atuibgbbcslJd67JsX/0zUbBY9FznlQd1xvb7oLkEnIrMqgKmhvFxY01 8xIwFZM26Y2RHpbELcWux9vJXHM6BdPHY/2/FutAhGLXDqIy+TISGRyBBq0lpccrLUAP TGJPMCG0Otj3DXSuSQ1do/YrH2fLUb/Um8PMSwNcwsMmbXHRvy0Y1lGliw70kJyiV1an ifLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nDjcuwdC; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n9-20020aa78a49000000b005366b1b5a2csi7800727pfa.202.2022.08.23.04.23.55; Tue, 23 Aug 2022 04:24:06 -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=nDjcuwdC; 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 S1351859AbiHWKAp (ORCPT + 99 others); Tue, 23 Aug 2022 06:00:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352257AbiHWJ4i (ORCPT ); Tue, 23 Aug 2022 05:56:38 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 927B0A0623; Tue, 23 Aug 2022 01:47:25 -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 ams.source.kernel.org (Postfix) with ESMTPS id BBED9B8105C; Tue, 23 Aug 2022 08:47:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF3C1C433D6; Tue, 23 Aug 2022 08:47:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661244440; bh=UfA2D+Yn9Vkzxi9TLQAdixu5obpAF7LAI9CvtDbERPU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nDjcuwdCmyEEQjkB/ceny7EllUW79t+JIsYv0JEFHgjSgU/NuHYHt3oskFLEI4yPK CIogs6uviDmP2NQCpJEnXDGBj/v0TouudXcjfJHb5cJ8YZ+FAWaseWR1rudZcnFMZu MDeQKiKEFGjwzCoZqd1/oA6UQ9gKdoMbD5QGswDU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Jon Mason Subject: [PATCH 5.15 094/244] NTB: ntb_tool: uninitialized heap data in tool_fn_write() Date: Tue, 23 Aug 2022 10:24:13 +0200 Message-Id: <20220823080102.157740388@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080059.091088642@linuxfoundation.org> References: <20220823080059.091088642@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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,T_SCC_BODY_TEXT_LINE 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 From: Dan Carpenter commit 45e1058b77feade4e36402828bfe3e0d3363177b upstream. The call to: ret = simple_write_to_buffer(buf, size, offp, ubuf, size); will return success if it is able to write even one byte to "buf". The value of "*offp" controls which byte. This could result in reading uninitialized data when we do the sscanf() on the next line. This code is not really desigined to handle partial writes where *offp is non-zero and the "buf" is preserved and re-used between writes. Just ban partial writes and replace the simple_write_to_buffer() with copy_from_user(). Fixes: 578b881ba9c4 ("NTB: Add tool test client") Signed-off-by: Dan Carpenter Signed-off-by: Jon Mason Signed-off-by: Greg Kroah-Hartman --- drivers/ntb/test/ntb_tool.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) --- a/drivers/ntb/test/ntb_tool.c +++ b/drivers/ntb/test/ntb_tool.c @@ -367,14 +367,16 @@ static ssize_t tool_fn_write(struct tool u64 bits; int n; + if (*offp) + return 0; + buf = kmalloc(size + 1, GFP_KERNEL); if (!buf) return -ENOMEM; - ret = simple_write_to_buffer(buf, size, offp, ubuf, size); - if (ret < 0) { + if (copy_from_user(buf, ubuf, size)) { kfree(buf); - return ret; + return -EFAULT; } buf[size] = 0;