From patchwork Mon Aug 7 06:23:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xuewen Yan X-Patchwork-Id: 131696 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp1268897vqr; Mon, 7 Aug 2023 00:00:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHsx3ZdEVRiIcMr7K7s5CKVp82eVbOYemai9etT0u4bx9kmb0tKfTK3/6ja+FNWNYW7K34m X-Received: by 2002:a17:903:2684:b0:1bc:4f77:e34b with SMTP id jf4-20020a170903268400b001bc4f77e34bmr6319528plb.9.1691391642158; Mon, 07 Aug 2023 00:00:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691391642; cv=none; d=google.com; s=arc-20160816; b=nI9DdN+PmkePfM+qqqza9ip8/xQkvyYxT0qiRROZXTkWNtXr7ZY5A2BW4M2g0oC+ok isDaxNLYW+uQYCMGCrD51DJlReJxA9CLEmT4mJvHUPyq1vihg8upw5kCgwiWYjCrAM8j y5JBG8BbOLoJ+8/Lhw/Wnh1tmCtPNrUPICHD4L4Z0nw/naJ8o1pHg8CQ8P22GxRTUFq/ wLVBq9qdGkQ2QP7g58OrsmBWTO6jI0goBilNk95WRBEZc5C6z47x6sIGtJx6J7GETQCm Jj5+rJq8+XRbUyG0wT9NSvGc1yo8jgpxLCP7pV6RnEM2eav9sn2vyGOdJMZ6CTOWA6iB DhZA== 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 :message-id:date:subject:cc:to:from; bh=WMEHymxDIyWPzfKuFH10Uy80ZbOk+pgPOyUMadZJ7Xs=; fh=iacxFwGZdXaDM8LUFlcBFwxnXW3OcJeoZ72n31Ijm+c=; b=dMEjTIcify9oz62hV4YL6DNEUU5+SCMWVbtuA8enupAOrTBnEqzTZLLp+7vosfNLC8 gREz8E6+eRZxyEm0IWKFGyS2CmJ4wGO1si7jN39Dy5AbxCtmR3qVvL1Mw+K2jWNNGqX9 YzN/nmHH1sWxsg2Vx/JhKxLU+5Vj10cqkvCKzgNbY12SnttmY1Mgmsxwffb5EGVV9GKS wjZ30xdh5NoESrRzBhtYz+TI5wqGOI31BDQkX+r+XxcraFH2jVuoMHW7qNn7blMib1gl k8x1niVvX3Vq8d1dDVFkE3Wl0YG4wt5o2kjGtiNKUUr7lzKSgq+IxVasSXOZ1Mc378ch 6KAQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n9-20020a170902d2c900b001b88ff529cfsi5439186plc.619.2023.08.07.00.00.28; Mon, 07 Aug 2023 00:00:42 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229728AbjHGGYp (ORCPT + 99 others); Mon, 7 Aug 2023 02:24:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229487AbjHGGYn (ORCPT ); Mon, 7 Aug 2023 02:24:43 -0400 Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE6CC10F9; Sun, 6 Aug 2023 23:24:41 -0700 (PDT) Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 3776O0je067960; Mon, 7 Aug 2023 14:24:00 +0800 (+08) (envelope-from Xuewen.Yan@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4RK5nq5kmwz2P65sW; Mon, 7 Aug 2023 14:22:07 +0800 (CST) Received: from BJ10918NBW01.spreadtrum.com (10.0.73.72) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Mon, 7 Aug 2023 14:23:57 +0800 From: Xuewen Yan To: , , CC: , , , Subject: [PATCH] PM: QOS: Always use "kstrtos32_from_user()" in cpu_latency_qos_write() Date: Mon, 7 Aug 2023 14:23:45 +0800 Message-ID: <20230807062345.490-1-xuewen.yan@unisoc.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.0.73.72] X-ClientProxiedBy: SHCAS01.spreadtrum.com (10.0.1.201) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 3776O0je067960 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773552682692003491 X-GMAIL-MSGID: 1773552682692003491 In cpu_latency_qos_write, there is a judgment on whether the count value is equal to sizeof(s32). This means that when user write 100~999, it would get error value because it would call the "copy_from_user()" instead of "kstrtos32". Just like: # echo 500 > /dev/cpu_dma_latency [T4893] write: qos value=170930229 [T4893] write: count value=4 [T4893] write: qos value=170930226 [T4893] write: count value=4 To prevent this happening, delete the "copy_from_user()" and always use "kstrtos32_from_user()". Signed-off-by: Xuewen Yan --- kernel/power/qos.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/kernel/power/qos.c b/kernel/power/qos.c index 782d3b41c1f3..21a2f873e921 100644 --- a/kernel/power/qos.c +++ b/kernel/power/qos.c @@ -379,17 +379,11 @@ static ssize_t cpu_latency_qos_write(struct file *filp, const char __user *buf, size_t count, loff_t *f_pos) { s32 value; + int ret; - if (count == sizeof(s32)) { - if (copy_from_user(&value, buf, sizeof(s32))) - return -EFAULT; - } else { - int ret; - - ret = kstrtos32_from_user(buf, count, 16, &value); - if (ret) - return ret; - } + ret = kstrtos32_from_user(buf, count, 16, &value); + if (ret) + return ret; cpu_latency_qos_update_request(filp->private_data, value);