Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp882087rwb; Sat, 1 Oct 2022 10:12:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7c3prJUbburGBfr/UMuwyPid9sXacRV4I5srciuDlHz4otA3z1KaGRikIusgwUFG1OJG66 X-Received: by 2002:a17:902:7b8e:b0:178:b9c9:97a1 with SMTP id w14-20020a1709027b8e00b00178b9c997a1mr14757406pll.111.1664644344197; Sat, 01 Oct 2022 10:12:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664644344; cv=none; d=google.com; s=arc-20160816; b=RU5K4bNFKpcqEamyymwAGHbrTJsKshGmc0Jgym91Df6zc2OFj7+3rLRddbeJmcpy1W ghjGq0snKfsmo33JgRjH7wFF4Xm0+yxidDrR9SZhmZvE/qiulVLMvylTAO2CsJs3rBTS CMMHC/i/ye0APSwTR+fR74gLFoSRfa4gikgrBsMynBgbLK39HB/bl/AeSsR0CSZhii6J UlfUy2wZB1TsDtB4vxHtemRgg6ZFj1YBBiz+xW23A2tXLcF0UOALQ3JG2W2DAvjhmfAo 8k3duE0d0y40ZkbnVRkxoLXE7lC5QOVnUE8txT1NHFe9q2EM0ZlPMrijh0Xvt5BxJfmi eb8A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KyEHZH41+VDH9bxxt3p+dgtz1T9wbtc1HGrXs5RGSsY=; b=wVxUbl5FIDx8PzELnTutz306PoygS0TIvHDEbBY0xdKqizmTYfjfmUAhAy04pBdJrm 4fx/s6EozdFzxl0CCK782J+QJiTzYGRQjV6iVf9eyZsodSdJUxZp1WlIDAZk4B2k6Z3c e0nwXdLB/glDj4+AdrG4cCs4lTBz+YB41e03HU8tZ7kiRkuzq6Cw/JijImaWiCmEU6Up AqlnXc3zqkxVzZYP1iaWSdY8n6BN4LBBFqO+1bdfYtX7c6yXft3yAEXfkPi/9aHBrF0s z8rsIDZb2zC7dLhYZsIYW9GbGsjPAbXZqYCPD0nJysg22SWB9W8vBl2ihpMA/Fl3kzwL 3Usw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DoDARNqo; 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=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b7-20020a170902e94700b00176bfd3b6b9si6398162pll.416.2022.10.01.10.12.13; Sat, 01 Oct 2022 10:12:24 -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=@linaro.org header.s=google header.b=DoDARNqo; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229585AbiJARLN (ORCPT + 99 others); Sat, 1 Oct 2022 13:11:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229558AbiJARLI (ORCPT ); Sat, 1 Oct 2022 13:11:08 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 883B65A3E1 for ; Sat, 1 Oct 2022 10:11:06 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id k3-20020a05600c1c8300b003b4fa1a85f8so3704700wms.3 for ; Sat, 01 Oct 2022 10:11:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=KyEHZH41+VDH9bxxt3p+dgtz1T9wbtc1HGrXs5RGSsY=; b=DoDARNqoL7+Q63BrbqhTfjnWZYx3qIWl8quEhAIddkb33lWwgDOGMHzs83j78geKio hEJahX3TB2WJwUxSD5zjFc3JmSRKhKb3v0j29HDahGu6HEreLmWvg53+X4uElH0AvU3f Q8wIOMB9XTGyeB8kZ6zfvpgNsXZnfl8yFfglHExHttiduFxgf68vZAJzhbgrjG6r/+D8 PNsTUc09JCPJTMahqYyzShcWYOpyo+2QLDGg2TMuIzcMuIXHcB0x05h/4X/7IfjE7dTn MsbgDe1TR79H+/MZ21Qs1SJqomC5RfwaiS3j+wjinPqUYOCiUZ6UThWIRMol2bAZROcn dMZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=KyEHZH41+VDH9bxxt3p+dgtz1T9wbtc1HGrXs5RGSsY=; b=GK3pChs0K5pIP0cvoV+W4BsfVaedkO7eYYemW6lL2VKHflqvfRxU2tnjc49sgKBnB2 hpt0F8PSvv/GmhMoxp4CkpnSCKKve/933HvwA7H7nhef9gtHQxjLJHmAbo+D5rBSwOsy fNqIEoUjZpX3Jm8XSR4afQn2VbQXG6IYuJaTjyTNalRBpnFkpApH04hqEz9T0eTWpKSW XJHh1c+CrIH+0b5bBnUBkRZuT+Fe/ii67naGQZFBNE/sTC7m4o7Ct9WYJ2tuhkb9odey 9NtVebMKmF3dK/mXjrAfTkVaV8Fw295phz/Av/8KWEyMS9uHbd3igO7YZ/oaPDdkOHtS +Cmg== X-Gm-Message-State: ACrzQf1lInXlDLPcILp3WCEvXf4BCmRzRfhxk+cWq56bMAfyy1liqmLw 3MY41R8xJc6lVMn0Qss3t9SxzQ== X-Received: by 2002:a05:600c:3511:b0:3b4:bb85:f1e3 with SMTP id h17-20020a05600c351100b003b4bb85f1e3mr2254005wmq.0.1664644264502; Sat, 01 Oct 2022 10:11:04 -0700 (PDT) Received: from radium.lan ([88.160.162.107]) by smtp.gmail.com with ESMTPSA id h40-20020a05600c49a800b003b49ab8ff53sm5817641wmp.8.2022.10.01.10.11.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Oct 2022 10:11:04 -0700 (PDT) From: Fabien Parent To: ilia.lin@kernel.org, agross@kernel.org, bjorn.andersson@linaro.org, rafael@kernel.org, viresh.kumar@linaro.org Cc: linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Fabien Parent Subject: [PATCH 3/3] cpufreq: qcom: fix writes in read-only memory region Date: Sat, 1 Oct 2022 19:10:27 +0200 Message-Id: <20221001171027.2101923-3-fabien.parent@linaro.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221001171027.2101923-1-fabien.parent@linaro.org> References: <20221001171027.2101923-1-fabien.parent@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS 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 This commit fixes a kernel oops because of a write in some read-only memory: [ 9.068287] Unable to handle kernel write to read-only memory at virtual address ffff800009240ad8 ..snip.. [ 9.138790] Internal error: Oops: 9600004f [#1] PREEMPT SMP ..snip.. [ 9.269161] Call trace: [ 9.276271] __memcpy+0x5c/0x230 [ 9.278531] snprintf+0x58/0x80 [ 9.282002] qcom_cpufreq_msm8939_name_version+0xb4/0x190 [ 9.284869] qcom_cpufreq_probe+0xc8/0x39c ..snip.. The following line defines a pointer that point to a char buffer stored in read-only memory: char *pvs_name = PVS_NAME; This pointer is meant to hold a template "speedXX-pvsXX-vXX" where the XX values get overridden by the qcom_cpufreq_krait_name_version function. Since the template is actually stored in read-only memory, when the function executes the following call we get an oops: snprintf(*pvs_name, sizeof(PVS_NAME), "speed%d-pvs%d-v%d", speed, pvs, pvs_ver); To fix this issue, we instead store the template name onto the stack by using the following syntax: char pvs_name_buffer[] = PVS_NAME; Because the `pvs_name` needs to be able to be assigned to NULL, the template buffer is stored in the pvs_name_template and not under the pvs_name variable. Signed-off-by: Fabien Parent --- drivers/cpufreq/qcom-cpufreq-nvmem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/cpufreq/qcom-cpufreq-nvmem.c b/drivers/cpufreq/qcom-cpufreq-nvmem.c index 64ce077a4848..3e097262f612 100644 --- a/drivers/cpufreq/qcom-cpufreq-nvmem.c +++ b/drivers/cpufreq/qcom-cpufreq-nvmem.c @@ -269,7 +269,8 @@ static int qcom_cpufreq_probe(struct platform_device *pdev) struct nvmem_cell *speedbin_nvmem; struct device_node *np; struct device *cpu_dev; - char *pvs_name = PVS_NAME_TEMPLATE; + char pvs_name_buffer[] = PVS_NAME_TEMPLATE; + char *pvs_name = pvs_name_buffer; unsigned cpu; const struct of_device_id *match; int ret; -- 2.37.2