Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3018787rwb; Mon, 15 Aug 2022 16:15:38 -0700 (PDT) X-Google-Smtp-Source: AA6agR7VCfQHt83WwbQBSEf9jwr2GXpp0aCLhn4gikLgui8vqOsGHR0H+nJKKnDQBAcRAxM4Sr+Z X-Received: by 2002:a17:907:94d6:b0:730:bfe6:8352 with SMTP id dn22-20020a17090794d600b00730bfe68352mr11621750ejc.348.1660605337986; Mon, 15 Aug 2022 16:15:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605337; cv=none; d=google.com; s=arc-20160816; b=DmOt1cMNheRRpeuCBhw/e7sNf845tTxxFZ5a2hRc0r23rB3xbeKZJ5qm4FotEWm/GT EFKkpxlNR41hDDEav2poMEDemsW//z++r3PcjIefz0jW1ixDywTleCud8kr3kLsXIxiM bGg5i00aAxMjlJZm417b6iBy6hobw5YUftZzJHw7ooMOWxuzu07s3nKFqY+oe8TPUHHb ef77LH08Z/PQN4HHcLownzf+PCjcW2KTK47KVQooHHdOI9GavjRypWEY+ZPxdr3syMRs mdG6/jXUmFiIjgSe/dJ/pzbkKZ4s5s8ZBUPaA5rmohZTCMx8kQicJFjnv8Q3aF2eoaE6 NlDg== 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=6yfmLvp6Xg4bG+MHPyJaxhQvVoQl0nSw2eBRsXD0bcc=; b=FSNY7k28l5akwrv21UMOqbX1TepjBgNwEpnw+u8/SK9OptO5vaw39L/9P2svZuHaV4 vJrvPA4RLVSQtEQRhxONNCqRsQAPQcVUn8F3ivjxISt5Q7RbpbiM3LEyQhwLU+7qy+Sd 5Vt69fMDsJIpWXahvHPjyyQOlJ8+rb4cruRkUH1kPHLoYeI0iMkqbjCbbikN5VDOg9dp cwlSkGRUpS+Qpz/WqL0h/SS7TrKpcvpaY+2k9rdPbOL3kCFN2Qkmy+95SdSWSiDY5jE/ qxMrkdyDcfOgWu9XTw2NaiV3equz/N6hF7BrE1LHdCkll4M8RXX067VmAMk0TTPw0uhg vYAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GhK17yXV; 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 nc15-20020a1709071c0f00b0072a72bb6f80si8876744ejc.744.2022.08.15.16.15.12; Mon, 15 Aug 2022 16:15:37 -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=GhK17yXV; 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 S1348406AbiHOWXl (ORCPT + 99 others); Mon, 15 Aug 2022 18:23:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350768AbiHOWS3 (ORCPT ); Mon, 15 Aug 2022 18:18:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 553274198D; Mon, 15 Aug 2022 12:41:26 -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 CE38E61089; Mon, 15 Aug 2022 19:41:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD6DDC433C1; Mon, 15 Aug 2022 19:41:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660592485; bh=imMcvGzzPpr3rWTwGM7Bb11ZJvZPVZIPQT6qdLY3okI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GhK17yXVuBDxC8btGuf57XAG4txiCajNNbOdd6tjVDvpR0430JrbwwaOzXLd8OKbo 59AZJk/czkjg9gaWyAU6+L2PpJyVa4fwnUZKRVR/SUg0Tqn76TBAffZSvJBJZCXhAO P/EwCDQWoKxE3R75H9s22HSZ1JIpVJfInTmhisNo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Serge Semin , Dan Carpenter , Sasha Levin Subject: [PATCH 5.18 0759/1095] eeprom: idt_89hpesx: uninitialized data in idt_dbgfs_csr_write() Date: Mon, 15 Aug 2022 20:02:38 +0200 Message-Id: <20220815180500.682064472@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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 [ Upstream commit 71d46f1ff2212ced4852c7e77c5176382a1bdcec ] The simple_write_to_buffer() function will return positive/success if it is able to write a single byte anywhere within the buffer. However that potentially leaves a lot of the buffer uninitialized. In this code it's better to return 0 if the offset is non-zero. This code is not written to support partial writes. And then return -EFAULT if the buffer is not completely initialized. Fixes: cfad6425382e ("eeprom: Add IDT 89HPESx EEPROM/CSR driver") Reviewed-by: Serge Semin Signed-off-by: Dan Carpenter Link: https://lore.kernel.org/r/Ysg1Pu/nzSMe3r1q@kili Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/misc/eeprom/idt_89hpesx.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/misc/eeprom/idt_89hpesx.c b/drivers/misc/eeprom/idt_89hpesx.c index b0cff4b152da..7f430742ce2b 100644 --- a/drivers/misc/eeprom/idt_89hpesx.c +++ b/drivers/misc/eeprom/idt_89hpesx.c @@ -909,14 +909,18 @@ static ssize_t idt_dbgfs_csr_write(struct file *filep, const char __user *ubuf, u32 csraddr, csrval; char *buf; + if (*offp) + return 0; + /* Copy data from User-space */ buf = kmalloc(count + 1, GFP_KERNEL); if (!buf) return -ENOMEM; - ret = simple_write_to_buffer(buf, count, offp, ubuf, count); - if (ret < 0) + if (copy_from_user(buf, ubuf, count)) { + ret = -EFAULT; goto free_buf; + } buf[count] = 0; /* Find position of colon in the buffer */ -- 2.35.1