From nobody Wed Dec 17 19:18:23 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2290BC2FC02 for ; Wed, 16 Aug 2023 23:49:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347233AbjHPXsg (ORCPT ); Wed, 16 Aug 2023 19:48:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347254AbjHPXsL (ORCPT ); Wed, 16 Aug 2023 19:48:11 -0400 Received: from mx0a-0064b401.pphosted.com (mx0a-0064b401.pphosted.com [205.220.166.238]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05F92272B for ; Wed, 16 Aug 2023 16:48:09 -0700 (PDT) Received: from pps.filterd (m0250810.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37GNfhfJ023635; Wed, 16 Aug 2023 16:47:48 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriver.com; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding:content-type; s=PPS06212021; bh=WVU2u zKddnXlCad+ANAGfo3SuoARuRz7UHij1ZIKRUM=; b=pvzn10MqvW87VWv1UyoIR 4G99mGvVbqQ1fH7cy63RzF3R5SjTGpqZyrnDANWrpYDRfScKYiWetIC6Zl407HiG 74F69+iHKoBrgwFS8IToosZKnU1xj758ynHXZyUE3g0qb2ZVZsyGP6ux07QcdGP5 Ps3XBcjN2pEJ6iSxNLKoSZjz5fWy4i07IEEQ4s4xxaAKAO/cQBUZk4v7fg6MQMeW pin7CQGfd65gRPORHZu6n/75e8yIALUdD34I+I+JTuHWPCN9KuLte+4KlntFa1Fz Gp3JkENGuxyaGZlj0UHQ89BzTSsgj+9KJHeW3OR+8CVgvNMSU6QlaVAFR55ULjHT g== Received: from ala-exchng02.corp.ad.wrs.com (ala-exchng02.wrs.com [147.11.82.254]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 3se5byc9yr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 16 Aug 2023 16:47:48 -0700 (PDT) Received: from ala-exchng01.corp.ad.wrs.com (147.11.82.252) by ALA-EXCHNG02.corp.ad.wrs.com (147.11.82.254) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 16 Aug 2023 16:47:46 -0700 Received: from pek-lpd-ccm5.wrs.com (147.11.136.210) by ala-exchng01.corp.ad.wrs.com (147.11.82.252) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Wed, 16 Aug 2023 16:47:45 -0700 From: Yun Zhou To: , , , CC: Subject: [PATCH] printk: fix the check on modifying printk_devkmsg Date: Thu, 17 Aug 2023 07:47:45 +0800 Message-ID: <20230816234745.2856989-1-yun.zhou@windriver.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: S1zsWk9kFgbPTxjuIUphhA9z9JVyB0M6 X-Proofpoint-ORIG-GUID: S1zsWk9kFgbPTxjuIUphhA9z9JVyB0M6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-16_21,2023-08-15_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 malwarescore=0 clxscore=1011 priorityscore=1501 mlxlogscore=789 lowpriorityscore=0 adultscore=0 mlxscore=0 spamscore=0 impostorscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2306200000 definitions=main-2308160211 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When we use 'echo' to write a string to printk_devkmsg, it writes '\0' at the end. It means lenp is larger then the length of string 1. However, sometimes we write data with string length by other way, e.g write(fd, string, strlen(string)); In this case, the writing will fail. Comparing err with string length is able to handle all scenarios. Signed-off-by: Yun Zhou Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 357a4d18f6387..992872f7b7747 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -229,7 +229,7 @@ int devkmsg_sysctl_set_loglvl(struct ctl_table *table, = int write, * Do not accept an unknown string OR a known string with * trailing crap... */ - if (err < 0 || (err + 1 !=3D *lenp)) { + if (err !=3D strlen(devkmsg_log_str)) { =20 /* ... and restore old setting. */ devkmsg_log =3D old; --=20 2.27.0