Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2145526iof; Tue, 7 Jun 2022 21:15:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzp7YC7KPgybUu7l7fHVew11I/P19QUSwtpv6q/9yJyCWahdmNFCXmRemL3zEZzWx41yceV X-Received: by 2002:a05:6a00:1901:b0:518:916e:4a85 with SMTP id y1-20020a056a00190100b00518916e4a85mr32530085pfi.65.1654661759482; Tue, 07 Jun 2022 21:15:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654661759; cv=none; d=google.com; s=arc-20160816; b=sUYLNOTW5u5or7iorhlz/zZsgTJ40F+0J2HfvyOt/ltTqLLWN/S7k/tt8fjrM2DCG9 lvDQO+dceO2zbFk+l4ltgUs4kRiGEO1HaybqdRsYNRT3mqq2+tGFOsPBfMtcy86Q3AsW cDiIwGg/1ChjO7QP2zWcZouvAnOSTKKkUuNMrxO1paRccKJmQn5Grbbbt76kCOCqobgU mm2kpYU8t70hTCVrYGETzdWejdUluTjg2l1QniCB29y5qbK4zBB/3u6UPSPuKh/VPMRQ 9zghwEYjoBDucctaAjfrmuH0OCFnBelS1J35IZ9hyW/dm9f+4jBBqCDUMxy5wy0/a6nM AuVA== 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=/fSqIzuHbnZRiXK5zEeNjRtVR7YyCQbE/Ao3Rw7pmzg=; b=ak6SNxww4DUUTffDfvwuHUUU5G2lS3VaeMHFo19C6/vzXIDB7V9wq99DrplscXQxjx byEOcRSyM4+OUzbNk3h7yy3DVXasK/CTCzrbeubEEsHxASipFYhM4UNdia5keB13LLx3 aFBEVQD6u7BgPLO/6ZdEZCdxmedTlLJGGrgEguLbqm2cu8sdY1YyWNaPNOzIddz+XZzm dSDoU0VtvIn58/DX6Yo/RZIqMvRomisJ3z1LRWndrjBPiD1/jgWNgp6+xSFti+Vr9j4H I/qJgjj5mcZxz3isSBFCACjGKL5uTJKBum8UpyKK7hJxqn/NWEkD+0udpmL/Dswgb2mE ZySg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=S3qxI0BW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id h190-20020a6383c7000000b003fe2e6495easi1461813pge.409.2022.06.07.21.15.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 21:15:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=S3qxI0BW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id ABE2122FE51; Tue, 7 Jun 2022 20:47:20 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349652AbiFGSHZ (ORCPT + 99 others); Tue, 7 Jun 2022 14:07:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349103AbiFGRqp (ORCPT ); Tue, 7 Jun 2022 13:46:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A77462FD; Tue, 7 Jun 2022 10:36:48 -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 7BE58615F5; Tue, 7 Jun 2022 17:36:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8894DC341C8; Tue, 7 Jun 2022 17:36:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654623406; bh=1fLzDA9P3oPmWoVT/PenFt81kH0oQvPzFPy+yKour2I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S3qxI0BWKokBh/OMH5ekxFoUKQFjZ3C/bXO/rFAKiy4A/FxzpUiA/YW8xmJXk5cVV e/5/OuzdHRgKhcFmFAHISyT8IX0dW63SfPOloJrjA+N5fXaFNuGiZs5hmqWp4jRiqI 8A9FMzjCvn1bBVEW/E56p0EihHVQ0tHMZivPVmsU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yi Yang , Max Filippov Subject: [PATCH 5.10 405/452] xtensa/simdisk: fix proc_read_simdisk() Date: Tue, 7 Jun 2022 19:04:22 +0200 Message-Id: <20220607164920.628334952@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607164908.521895282@linuxfoundation.org> References: <20220607164908.521895282@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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: Yi Yang commit b011946d039d66bbc7102137e98cc67e1356aa87 upstream. The commit a69755b18774 ("xtensa simdisk: switch to proc_create_data()") split read operation into two parts, first retrieving the path when it's non-null and second retrieving the trailing '\n'. However when the path is non-null the first simple_read_from_buffer updates ppos, and the second simple_read_from_buffer returns 0 if ppos is greater than 1 (i.e. almost always). As a result reading from that proc file is almost always empty. Fix it by making a temporary copy of the path with the trailing '\n' and using simple_read_from_buffer on that copy. Cc: stable@vger.kernel.org Fixes: a69755b18774 ("xtensa simdisk: switch to proc_create_data()") Signed-off-by: Yi Yang Signed-off-by: Max Filippov Signed-off-by: Greg Kroah-Hartman --- arch/xtensa/platforms/iss/simdisk.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) --- a/arch/xtensa/platforms/iss/simdisk.c +++ b/arch/xtensa/platforms/iss/simdisk.c @@ -213,12 +213,18 @@ static ssize_t proc_read_simdisk(struct struct simdisk *dev = PDE_DATA(file_inode(file)); const char *s = dev->filename; if (s) { - ssize_t n = simple_read_from_buffer(buf, size, ppos, - s, strlen(s)); - if (n < 0) - return n; - buf += n; - size -= n; + ssize_t len = strlen(s); + char *temp = kmalloc(len + 2, GFP_KERNEL); + + if (!temp) + return -ENOMEM; + + len = scnprintf(temp, len + 2, "%s\n", s); + len = simple_read_from_buffer(buf, size, ppos, + temp, len); + + kfree(temp); + return len; } return simple_read_from_buffer(buf, size, ppos, "\n", 1); }