Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3418196rwa; Tue, 23 Aug 2022 04:34:22 -0700 (PDT) X-Google-Smtp-Source: AA6agR5umWq+qippAQSTjfNyNpM7P7SdrytnGOwPthJyRYeaTFOPk/a+XeObiNtFowY4Wg691Kir X-Received: by 2002:a05:6402:5252:b0:43e:14ec:46f with SMTP id t18-20020a056402525200b0043e14ec046fmr3242227edd.398.1661254461905; Tue, 23 Aug 2022 04:34:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661254461; cv=none; d=google.com; s=arc-20160816; b=pD1AW8hzXUD+nxVWDsDhDDg+HWZOtMtr6VXbT+YMpGVpx/sc06gKMzYE0mRS2ECBav B5RsAPDeUYtc3/BqajKCvywlJ+kt/WBDv2g1MausOQVYHN6PdErK8YLFEPLSKr58bhrf 9ARwjgcf5Wxp4CKTLk2Tt1REv7JMn0muF8uVyhB7E651CkKm3BBrfLb8YNM6ZmyXRJtn sWCvldhvikZOoj+WSJ1nsysficx8h5qrHwZzYaTjUZ0Ib38R4i3J5XhR+37/jwfJmTBR Y8QjhLCrIyaGH0DA3dV4HptMRYKxyRX4WAgosxYjdU/qXTUWGPB+ITuGPWpJ+Wu+x3KY US7g== 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=dlRCBSj2rWqCcxN7Q8/SjYrr3PFYcfZft0hXpPGOdgp+vyBvqBR03TmPRNEZCAaG7v 6sOYCvI4S8GSrMIiJyhU2FZQeLlDRKdlvVJcPdhcJqVFv5h85f9NQEb3tLV1i4IQbBA/ 4voqmJXa8EJql9z/CS3p/qpCd5e8kHG9Lozp8ky6ffthxtl3NjX+g6Wg6FTgEFtVRB8p aLdbJ+My1dl6jazYH1lEosnXT+YF+QofkJXsN0fDp/2xI19VICfkq4EQg5z6OZuGzCdR 9rlFR6UKfjdshQ+MF80xj9eBpxGmI0BE71hiJ8HFPTp+YKH2PihznYG9mcc8YvdfQkMx 4Mow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="C7m1iUZ/"; 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 dd15-20020a1709069b8f00b00734804bb362si331400ejc.568.2022.08.23.04.33.55; Tue, 23 Aug 2022 04:34:21 -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="C7m1iUZ/"; 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 S1356823AbiHWLED (ORCPT + 99 others); Tue, 23 Aug 2022 07:04:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356962AbiHWLAn (ORCPT ); Tue, 23 Aug 2022 07:00:43 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B894AE21B; Tue, 23 Aug 2022 02:14:15 -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 31E28B81C4E; Tue, 23 Aug 2022 09:14:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61AC4C433C1; Tue, 23 Aug 2022 09:14:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661246047; bh=UfA2D+Yn9Vkzxi9TLQAdixu5obpAF7LAI9CvtDbERPU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C7m1iUZ/fUwODqUfFKgm3/PvrScXCqrRPiMiIhr+VfPS8dRQLfZ6U64X7r3QsyLmY wpLJe18yH4OV8bp+6c5z9uV7/3daQQ913SRu7od7j6yTemW6LqQFdXoz67eMRQ9WRd DkoOG6TBM4K0phJOGQ1RU02igltH9G0ITCBkGgcM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Jon Mason Subject: [PATCH 4.19 241/287] NTB: ntb_tool: uninitialized heap data in tool_fn_write() Date: Tue, 23 Aug 2022 10:26:50 +0200 Message-Id: <20220823080109.204439326@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080100.268827165@linuxfoundation.org> References: <20220823080100.268827165@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;