From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73838C28D13 for ; Mon, 22 Aug 2022 09:17:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234391AbiHVJRR (ORCPT ); Mon, 22 Aug 2022 05:17:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234401AbiHVJRN (ORCPT ); Mon, 22 Aug 2022 05:17:13 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E3CF11166 for ; Mon, 22 Aug 2022 02:17:11 -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 sin.source.kernel.org (Postfix) with ESMTPS id 62802CE103C for ; Mon, 22 Aug 2022 09:17:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40BBBC433C1; Mon, 22 Aug 2022 09:17:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661159827; bh=ucGu0zl+LL4+ob8dqLVujqfyxzKTs9CzMudFzYxmK0Q=; h=Subject:To:Cc:From:Date:From; b=xXZJ0EFTggb2gTSE8RA1ZcBdEffDSpcVkG3uyNthxso9/7c9yzv0XXqRgDAYq1E2a fVr/C3X0nxr+Z25iS0OxzBtS0/ydPo/gzouOzeCHx6Z1Y6yNVkV1yFYL6TEnwOQeEt Hj2ji3SdatqVsPy3LigDW6LJ5Q+Vyw2aGmfoEdo4= Subject: FAILED: patch "[PATCH] NTB: ntb_tool: uninitialized heap data in tool_fn_write()" failed to apply to 4.9-stable tree To: dan.carpenter@oracle.com, jdmason@kudzu.us Cc: From: Date: Mon, 22 Aug 2022 11:16:41 +0200 Message-ID: <1661159801168244@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org The patch below does not apply to the 4.9-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From 45e1058b77feade4e36402828bfe3e0d3363177b Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Wed, 20 Jul 2022 21:28:18 +0300 Subject: [PATCH] NTB: ntb_tool: uninitialized heap data in tool_fn_write() 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 diff --git a/drivers/ntb/test/ntb_tool.c b/drivers/ntb/test/ntb_tool.c index b7bf3f863d79..5ee0afa621a9 100644 --- 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_ctx *tc, 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;