From nobody Mon Apr 13 06:39:20 2026 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 D88E1C6FD1F for ; Wed, 22 Mar 2023 14:12:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231262AbjCVOMF (ORCPT ); Wed, 22 Mar 2023 10:12:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231299AbjCVOL5 (ORCPT ); Wed, 22 Mar 2023 10:11:57 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE4B062329; Wed, 22 Mar 2023 07:11:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679494316; x=1711030316; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7YSrH58f/8PCUQYRKrz3TF1JgsLkqas7q/pNYTkDdYg=; b=WheSQgqFqkhGk6imopb2h1P4H1rqvyS8a99bKra+DmoCEf7E2mz4Aq5R 6VWwqvJJVj169H4a59yd13JK6r71cWrj/JTyqH73KTbyBTQTBJBQj7kY/ wUei93bxePoW+m+5P2EA5gMbqXvio5cdwmm2CV3Z+SkoycnOaTQjF9Tf3 3e/Vt5SGhHAGJHLvhSb3r2763llOh+Ctz5KZYT5CJzJacfiTS4mdWqUCo Edyda6w8X4JtZ+IXVVE7w1nkfJycvD4VEnBtyLuAUmHXymY/dL+BvI2jb wjBjz96+TKuY4bV0bhWmA7HJmFyuK6Q1OamcAY9GnHm+avHnoLuQUFYSX A==; X-IronPort-AV: E=McAfee;i="6600,9927,10657"; a="318865981" X-IronPort-AV: E=Sophos;i="5.98,282,1673942400"; d="scan'208";a="318865981" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Mar 2023 07:11:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10657"; a="1011377031" X-IronPort-AV: E=Sophos;i="5.98,282,1673942400"; d="scan'208";a="1011377031" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga005.fm.intel.com with ESMTP; 22 Mar 2023 07:11:34 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 5AC3C3DD; Wed, 22 Mar 2023 16:12:20 +0200 (EET) From: Andy Shevchenko To: Kees Cook , Greg Kroah-Hartman , Andy Shevchenko , Cezary Rojewski , linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Theodore Ts'o" , Jan Kara , Andy Shevchenko , "Rafael J. Wysocki" Subject: [PATCH v1 1/3] jbd2: Avoid printing out the boundary Date: Wed, 22 Mar 2023 16:12:04 +0200 Message-Id: <20230322141206.56347-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230322141206.56347-1-andriy.shevchenko@linux.intel.com> References: <20230322141206.56347-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Theoretically possible that "%pg" will take all room for the j_devname and hence the "-%lu" will go out the boundary due to unconditional sprintf() in use. To make this code more robust, replace two sequential s*printf():s by a single call and then replace forbidden character. It's possible to do this way, because '/' won't ever be in the result of "-%lu". Signed-off-by: Andy Shevchenko Reviewed-by: Jan Kara --- fs/jbd2/journal.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index 8ae419152ff6..00c0aa4a3a91 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -1515,9 +1515,8 @@ journal_t *jbd2_journal_init_inode(struct inode *inod= e) =20 journal->j_inode =3D inode; snprintf(journal->j_devname, sizeof(journal->j_devname), - "%pg", journal->j_dev); - p =3D strreplace(journal->j_devname, '/', '!'); - sprintf(p, "-%lu", journal->j_inode->i_ino); + "%pg-%lu", journal->j_dev, journal->j_inode->i_ino); + strreplace(journal->j_devname, '/', '!'); jbd2_stats_proc_init(journal); =20 return journal; --=20 2.40.0.1.gaa8946217a0b From nobody Mon Apr 13 06:39:20 2026 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 9778CC6FD1C for ; Wed, 22 Mar 2023 14:12:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229970AbjCVOL6 (ORCPT ); Wed, 22 Mar 2023 10:11:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231334AbjCVOLw (ORCPT ); Wed, 22 Mar 2023 10:11:52 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 664E061538; Wed, 22 Mar 2023 07:11:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679494310; x=1711030310; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NtifLXAlEOC7145wqW0H2RVF/LMJYofx4l0+YchUjsw=; b=ZDQGjBZdmgowWchuIny2nhWLOqMzfjcShR2zPaQIagn3RBo3E5BoGnGP BN51OFTYZoDlUI9FEisRQtYCe/xWOVk156zpWE+4GHcjl+ANf2kjonBo4 cMI1OrPoDICdBuy/7sPBYM7I+qcgwuEA75OXcpxpMqI/LNqlPajutWkNj XI6F4F81LyyHyqr6PJXBPg09axxp1zBS9VYo2jr2v2/xjgUhJM2rMYCDJ pUyjI6RkFldACgNPeuO8xjy4qU/X6XJ+Ag++HZ9LbbW9XC6R/kj03lQC9 aOyifkHLd+6Qi8d8ayQUhKwVbVQRx3NxRX9qZch2rue8LhjCxRFbragP6 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10657"; a="319613517" X-IronPort-AV: E=Sophos;i="5.98,282,1673942400"; d="scan'208";a="319613517" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Mar 2023 07:11:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10657"; a="805829250" X-IronPort-AV: E=Sophos;i="5.98,282,1673942400"; d="scan'208";a="805829250" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga004.jf.intel.com with ESMTP; 22 Mar 2023 07:11:46 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 236531CC; Wed, 22 Mar 2023 16:12:33 +0200 (EET) From: Andy Shevchenko To: Kees Cook , Greg Kroah-Hartman , Andy Shevchenko , Cezary Rojewski , linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Theodore Ts'o" , Jan Kara , Andy Shevchenko , "Rafael J. Wysocki" Subject: [PATCH v1 2/3] lib/string_helpers: Change returned value of the strreplace() Date: Wed, 22 Mar 2023 16:12:05 +0200 Message-Id: <20230322141206.56347-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230322141206.56347-1-andriy.shevchenko@linux.intel.com> References: <20230322141206.56347-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" It's more useful to return the original string with strreplace(), so it may be used like attr->name =3D strreplace(name, '/', '_'); While at it, amend the kernel documentation. Signed-off-by: Andy Shevchenko --- include/linux/string.h | 2 +- lib/string_helpers.c | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/linux/string.h b/include/linux/string.h index a7bff7ed3cb0..cb0c24ce0826 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -169,7 +169,7 @@ static inline void memcpy_flushcache(void *dst, const v= oid *src, size_t cnt) #endif =20 void *memchr_inv(const void *s, int c, size_t n); -char *strreplace(char *s, char old, char new); +char *strreplace(char *str, char old, char new); =20 extern void kfree_const(const void *x); =20 diff --git a/lib/string_helpers.c b/lib/string_helpers.c index 230020a2e076..ab7b1577cbcf 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c @@ -979,14 +979,18 @@ EXPORT_SYMBOL(__sysfs_match_string); =20 /** * strreplace - Replace all occurrences of character in string. - * @s: The string to operate on. + * @str: The string to operate on. * @old: The character being replaced. * @new: The character @old is replaced with. * - * Returns pointer to the nul byte at the end of @s. + * Replaces the each @old character with a @new one in the given string @s= tr. + * + * Return: pointer to the original string @str. */ -char *strreplace(char *s, char old, char new) +char *strreplace(char *str, char old, char new) { + char *s =3D str; + for (; *s; ++s) if (*s =3D=3D old) *s =3D new; --=20 2.40.0.1.gaa8946217a0b From nobody Mon Apr 13 06:39:20 2026 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 32363C6FD1C for ; Wed, 22 Mar 2023 14:12:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230001AbjCVOMg (ORCPT ); Wed, 22 Mar 2023 10:12:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229521AbjCVOMc (ORCPT ); Wed, 22 Mar 2023 10:12:32 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24AA66484B; Wed, 22 Mar 2023 07:12:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679494339; x=1711030339; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=skh8+hJ3oe4RQZywlVKVS1TXtOKwAEOQhUA8WWOtK0g=; b=MXMWHxqPi4sBbyGZrjhnK7OYVgF7SZo/pdmBi5iIflo/a5rijL7cAZt7 q9JmqVVE1q4/QMwKHJAx+f8zJMw0brf/hCJgXX1TmIp5qb8KIHflwgoPp RNvOtD7G/gs8mAb9YoJEBveBbZxVVVHJYaJcOoynrk66oaX78ROUjwyzq JiYOtz8CWQJ5uqrA6dFZ+/y891viSDS3x4/o+8wW8LGQ8ddBWBp7QxiDd K2+Vl6Q4F6QduhcSBo4Cv+MkqFqtjZXecKeHj9CmQjZx759bJQmlKhxuR VxtpAJpi5/e3nXoUuPu9Yq4OZtGohuQaNMXeSKFNzmWxZGKi8FYsOlpYi g==; X-IronPort-AV: E=McAfee;i="6600,9927,10657"; a="319613611" X-IronPort-AV: E=Sophos;i="5.98,282,1673942400"; d="scan'208";a="319613611" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Mar 2023 07:12:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10657"; a="805829396" X-IronPort-AV: E=Sophos;i="5.98,282,1673942400"; d="scan'208";a="805829396" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga004.jf.intel.com with ESMTP; 22 Mar 2023 07:11:59 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 150091CC; Wed, 22 Mar 2023 16:12:46 +0200 (EET) From: Andy Shevchenko To: Kees Cook , Greg Kroah-Hartman , Andy Shevchenko , Cezary Rojewski , linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Theodore Ts'o" , Jan Kara , Andy Shevchenko , "Rafael J. Wysocki" Subject: [PATCH v1 3/3] kobject: Use return value of strreplace() Date: Wed, 22 Mar 2023 16:12:06 +0200 Message-Id: <20230322141206.56347-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230322141206.56347-1-andriy.shevchenko@linux.intel.com> References: <20230322141206.56347-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Since strreplace() returns the pointer to the original string, we may use it directly in the code. Signed-off-by: Andy Shevchenko --- lib/kobject.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/kobject.c b/lib/kobject.c index f79a434e1231..16d530f9c174 100644 --- a/lib/kobject.c +++ b/lib/kobject.c @@ -281,8 +281,7 @@ int kobject_set_name_vargs(struct kobject *kobj, const = char *fmt, kfree_const(s); if (!t) return -ENOMEM; - strreplace(t, '/', '!'); - s =3D t; + s =3D strreplace(t, '/', '!'); } kfree_const(kobj->name); kobj->name =3D s; --=20 2.40.0.1.gaa8946217a0b