Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2199919iof; Tue, 7 Jun 2022 23:01:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8GDNy0pqpbYMBttHh3kTiYY0JQ+QqPJLg2EQr5SVK8Hl2v50W1PJiFXe37Bt9jkVhTtIM X-Received: by 2002:a17:903:1247:b0:156:25b4:4206 with SMTP id u7-20020a170903124700b0015625b44206mr32761520plh.146.1654668072169; Tue, 07 Jun 2022 23:01:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654668072; cv=none; d=google.com; s=arc-20160816; b=JHQuyakhxu7L+tYbfYFM0qvNg6MYTlRL9utSfn0LU4k+UBGXJq1iYeynJf7gy8K6Gt jtLWaTbA7fc4jBLTJeqogLZ+wOk6JJusEXLKy1Mrb4mIQlZ1lbefCTTiYhvPy5xzlbc1 0AvLES05FOdhRrP8qc9BI7eq+8gPgr1w0Nm170Mt8a9VkPdnbj1umpUsngK4tYzry97y 9tsQw3tm99q0IW2gxJj8tq6vYl1v1d2b5hUBUi5qXFDdU2Bz1BgNoUssrLHqsOF83B4j cN6wI0enkX3LLa6E1gxBGBxqCrY5LMUu8JEfDeovDSb9nVFBm+RIWEvSBecfxcYLalZh i7AQ== 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=s7WXx62+MOhDXb1ufkVJvDp7uBsxYjZ3FFYINM8gOSw=; b=h1jEbQfT1boaEJZlqsG+4y84R0t/Lk9FFtkQ6fULmcc6q5BGaZxeqL08Mjzw9RNm6L gPZDw91flDw8SyqGUKqq45BY0yjbDJk1VVANVvv0sWpGz5TFabYX0oNmVDWO8EHXRFOr F+sITBfBGOBhWtvXlEFABgoHFAwwh+SiPzzXraDt9qYsuqYnNU6lYbTz19DR/1lh7JJa Da7mXUV3O3H/4jzXl/nFqup3ZF1P4ZwhYuahFRzhWsZe0WkdzZbkIIdhRsJeHTP2F64y uyS7oPyQ/ElaTvOWz9ViSVMYI9GKFMRKNp3mLhKzu648/iPbvZYaPZex68TvUhe5XwFW ZCTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=O+gNpg1j; 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 d16-20020a056a00245000b0051840478994si29742876pfj.375.2022.06.07.23.01.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 23:01:12 -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=O+gNpg1j; 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 1DEC9136C2F; Tue, 7 Jun 2022 22:25:59 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1444162AbiFHBHU (ORCPT + 99 others); Tue, 7 Jun 2022 21:07:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383452AbiFGWa6 (ORCPT ); Tue, 7 Jun 2022 18:30:58 -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 A83DA275599; Tue, 7 Jun 2022 12:23:59 -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 189A160B89; Tue, 7 Jun 2022 19:23:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 241D7C385A2; Tue, 7 Jun 2022 19:23:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629838; bh=e5c3CxGrpbc0Jirl6dkEelSrmn2mfAXYagN8IL4SVRg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O+gNpg1jbThA3toFtdPFCSqFr7B7qOMjJSF+YPKr72zVxx7OTcQHraBA95qUB7Jd4 eyQ/osmLU+iyayajwA0wsaElYblHF7vAJw+TJFX9Tq2mHwBMDWCtzSc2F7YT13KXy4 MLPeH60iLDLkr+DHMItYheNQmKnpCpFHNBdmlnrY= 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.18 834/879] xtensa/simdisk: fix proc_read_simdisk() Date: Tue, 7 Jun 2022 19:05:52 +0200 Message-Id: <20220607165027.064347224@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@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 @@ -211,12 +211,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); }