Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3294409rwa; Tue, 23 Aug 2022 02:09:58 -0700 (PDT) X-Google-Smtp-Source: AA6agR7tvOWNtXmR15cCs7HqYbIMVXt9J8BN1WgUFIAiKRucW39F85YbK0s3onSS83iqStzZ5E1u X-Received: by 2002:a05:6402:2206:b0:446:9bb7:a1c0 with SMTP id cq6-20020a056402220600b004469bb7a1c0mr2896027edb.344.1661245798454; Tue, 23 Aug 2022 02:09:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661245798; cv=none; d=google.com; s=arc-20160816; b=J32X1ZQsZnf4sHNPAi5FYbss13KEPBd22fnuoD72iMs5zKQTpa4L0+DxxF2J3GVms0 n5W3bBIGX1VPZB2rf9DAWlWlH7giA6Gtuefh+Y9XGv+oqvY3j9LUmIszdMTqOBp5MN2e 4pY5TJ0vyfvNCMykNpsbR73qvFmPZWotZSjjUCz8kgyCfPXNqP6TXeQzyCk7uOnmgNjQ wgMQNp8K+KtJZT2Qe/yuVqppuoekTywe5KtzxrfoQxFQfoHWqlduYQ1pveeyN1gDwtdj JljyAttQXSn4HDHqLsGDVjhrC7Ren514zC/GHpVRCct77j9HByCH5sNsnIH59Xfr9bSy a+hQ== 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=X+9kZMgJhW6AZvDks8rAb2hCzec4hszbTauiCm6OcViCfLw6AYdbtNeGbDyTVNmWmx pxWu1uKqXRnT0Og3iNkmZ0fPs9vLEz12SkhesjNAvBDHyniT41PhWHJqIBrY9JYjEryO WWaxb7B5UliiIFchP7txmhGGlaQnPto2kJcBxg1jpv64g+YtTngETszpxuuaMfOdAQNL UNmFuqDbXq8+od8f1LGEprOYzbAQfr8/B2ZT9lnFMy1LspTD2Vepz5WpNTm6oRVUJ80F 7SsE48jJRzLB9kqwuECdaUenjOXMyytw+cX3m7jurfgw+htsxEmGnkeCgKHP9HyhEvZ2 b0yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NA97XWWX; 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 gn35-20020a1709070d2300b0072642bbc8cfsi11273593ejc.914.2022.08.23.02.09.29; Tue, 23 Aug 2022 02:09:58 -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=NA97XWWX; 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 S237987AbiHWIjz (ORCPT + 99 others); Tue, 23 Aug 2022 04:39:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344922AbiHWIjR (ORCPT ); Tue, 23 Aug 2022 04:39:17 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1A4A636F; Tue, 23 Aug 2022 01:18:20 -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 7648EB81C29; Tue, 23 Aug 2022 08:17:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC99FC433C1; Tue, 23 Aug 2022 08:17:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661242627; bh=UfA2D+Yn9Vkzxi9TLQAdixu5obpAF7LAI9CvtDbERPU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NA97XWWXyydbDhhW+lCf1ejAfhoKo5ypaes5ng8cccyZs4uxMTmarr2nXTyWf9Ysv 4gJJrgTGHp7pjSjT6CK5CuRsJMPMzAOOmoRN7SvBhKypqLfobSa+y9JqQJSpKHsQWx iY1Uhs/giwVcEJKJ/z6Qpn0xsWFwXNK7AyZ/hfdE= 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.19 147/365] NTB: ntb_tool: uninitialized heap data in tool_fn_write() Date: Tue, 23 Aug 2022 10:00:48 +0200 Message-Id: <20220823080124.365784424@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080118.128342613@linuxfoundation.org> References: <20220823080118.128342613@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;