Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2924522rwb; Mon, 15 Aug 2022 14:09:30 -0700 (PDT) X-Google-Smtp-Source: AA6agR7Sw5f+IhrBAyd0qzQFH3JNxjLYkLgKgFF+m3to46e+PdA1L7oWueglNLSvQfrlBFDRnOHO X-Received: by 2002:a05:6402:26c5:b0:43e:2f1b:31c2 with SMTP id x5-20020a05640226c500b0043e2f1b31c2mr15824829edd.424.1660597770428; Mon, 15 Aug 2022 14:09:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660597770; cv=none; d=google.com; s=arc-20160816; b=FeIl8OCnl/OaWqc1imWAvFYbNbOUuO+RamilbgkmRg/KG5/93pdNV8dEL23Mc0zxX1 oHvleb6Gt41JSSlKeT1e7UXjJ580lM1ZgRR3U1fisRba2GKgtGW3EBwLHC8QDouZ7k90 fDl0rgYA6mVQ20ByS4YatDb0sq7wcx9OKtcjJB5CjQ02gs3+Y3lHh8lx4jFr6TPOHzaM vlh2KZrQUF72q8oTLYXCn0FfFwkL2vzC3vx9YI8j23tkYgcBZnLSMiC8tmUESfq4FMwW apSBqU4E812Oq5EftBJqwtl2AinbTqrwgwMtaW94awkDaxyHpahESjBpbiRS2fGCJUkL Tlug== 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=aFTX+NQch5m5oF6bI7gjvNaSMplCJ708tz+QWknOs3C1pc+IfNNsDlOD4ko3TP/Gnu PigKWSJ3NkN5ocfKvw0L6UT3Qo05OhcBTLJsyeJlY9YmxQrsyVvfM+gqW49f4vraZrSG akPcRaxTn4ZD5jcodksPTxwoHUJDaI8MHBRzCiY9RUO4k97t+E9La3dK91dvZFQ1OFol 71tGmimVRFlicz4vZbVRI7gEoYvioiNPAeDk2eUvkUPiewR8fQBN47FXY+nUCte9gpFV g2xJkmcuZae901dZ+NlT0QLlp7Q00a07m5I5NX0zzhQ2QKpEnGTTUoe1a57j/EqIOc+m PIvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QgGRwVDa; 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 b8-20020aa7c6c8000000b0043f543f68ccsi8161627eds.287.2022.08.15.14.09.05; Mon, 15 Aug 2022 14:09:30 -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=QgGRwVDa; 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 S244637AbiHOTYS (ORCPT + 99 others); Mon, 15 Aug 2022 15:24:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344772AbiHOTVi (ORCPT ); Mon, 15 Aug 2022 15:21:38 -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 7673C326D2; Mon, 15 Aug 2022 11:40:29 -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 7D810B8108E; Mon, 15 Aug 2022 18:40:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BBE69C433D6; Mon, 15 Aug 2022 18:40:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660588826; bh=imMcvGzzPpr3rWTwGM7Bb11ZJvZPVZIPQT6qdLY3okI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QgGRwVDaooqf8DiQKtQYlFkuAJuL6t/Idse9qy1MRDyQ7y2wausnk0x32go4XpQED hIZ1HprnyPbUvVVTyXp+SABhlabQ4B8PmkOEyu+nql4RPgrob0WaE8APq90Bt7/GNY i34bb0pDmLfR2SRz5gxU1E6oSPCkTqIHZpz+oUtE= 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.15 495/779] eeprom: idt_89hpesx: uninitialized data in idt_dbgfs_csr_write() Date: Mon, 15 Aug 2022 20:02:19 +0200 Message-Id: <20220815180358.445525049@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@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