From patchwork Wed Sep 4 09:14:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hongbo Li X-Patchwork-Id: 13790179 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF94B19E978 for ; Wed, 4 Sep 2024 09:06:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725440797; cv=none; b=jRTVZW+07uaGlzQe3ffD0n4QpEEnP2xgBukHiYH0rxMiipnFUv240T/lQ6IgYPoiqXZ2tQZnvzRJHmqojE7ED+HcrMtmEdgAO5mfh+hYxkx5Y6DEL/ljWnb14EzyZI5Yfv411UHJnR9RdA4M7xolRBqDoGpQa1yBY7af4CcF8ZA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725440797; c=relaxed/simple; bh=2E1mpyUBjQ3uIGIXWboa+zbLWW2ynCUtsxDkG2lJnAE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nSvulhIx8EpvoJ67Ay2mJJl6JQfca4ECVg6PvvNVFf9YmYOfpwc4/DmKUcJ/VNHq/FP4A1ZzEprbR+nGIz5F6U7KgkzgYFyRxgb/LEthVVM3WWA8eiK9+9Z+Jf8MVh02MsC1yBGtxxY9lx4OzSu6IlHtMOzPaQpJs1O5r0ZaIA4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4WzGlQ651zzpVDr; Wed, 4 Sep 2024 17:04:34 +0800 (CST) Received: from dggpeml500022.china.huawei.com (unknown [7.185.36.66]) by mail.maildlp.com (Postfix) with ESMTPS id 63F0C1800B8; Wed, 4 Sep 2024 17:06:27 +0800 (CST) Received: from huawei.com (10.90.53.73) by dggpeml500022.china.huawei.com (7.185.36.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Wed, 4 Sep 2024 17:06:27 +0800 From: Hongbo Li To: , , , CC: , , Subject: [PATCH -next v2 1/9] coccinelle: Add rules to find str_true_false() replacements Date: Wed, 4 Sep 2024 17:14:43 +0800 Message-ID: <20240904091451.3328272-2-lihongbo22@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240904091451.3328272-1-lihongbo22@huawei.com> References: <20240904091451.3328272-1-lihongbo22@huawei.com> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml500022.china.huawei.com (7.185.36.66) After str_true_false() has been introduced in the tree, we can add rules for finding places where str_true_false() can be used. A simple test can find over 10 locations. Signed-off-by: Hongbo Li --- scripts/coccinelle/api/string_choices.cocci | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scripts/coccinelle/api/string_choices.cocci b/scripts/coccinelle/api/string_choices.cocci index 5e729f187f22..50329c4c8acd 100644 --- a/scripts/coccinelle/api/string_choices.cocci +++ b/scripts/coccinelle/api/string_choices.cocci @@ -85,3 +85,26 @@ e << str_down_up_r.E; @@ coccilib.report.print_report(p[0], "opportunity for str_down_up(%s)" % e) + +@str_true_false depends on patch@ +expression E; +@@ +( +- ((E) ? "true" : "false") ++ str_true_false(E) +) + +@str_true_false_r depends on !patch exists@ +expression E; +position P; +@@ +( +* ((E@P) ? "true" : "false") +) + +@script:python depends on report@ +p << str_true_false_r.P; +e << str_true_false_r.E; +@@ + +coccilib.report.print_report(p[0], "opportunity for str_true_false(%s)" % e) From patchwork Wed Sep 4 09:14:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hongbo Li X-Patchwork-Id: 13790178 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9868719D09A for ; Wed, 4 Sep 2024 09:06:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725440793; cv=none; b=pNBIfsASZBD4jFl9N81H+JfGMf2c6TYOKRRS9jNPqLKE7LwtSY7+Z4n2+7ORFY35/aVVZKz6uFYY3oedvNvuFcygSn8j4vBuKHWih8+jMHenQowidpIcZ0lYgP50MhqkVHujScml6xXPu9ju5P3YQHYT2+WfxbZmuzPvp0BL1bk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725440793; c=relaxed/simple; bh=3QqrD3rq+BwzYNVSJKe9mxLSM7CER/nh7p5DfOAoCgU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OLHuAxtYsveYvJ77teijYZ08fS19ELwizojl4vG+d1UaC9UqP4TDN2eglIqe75wnhU8Zrmc9WoMHsrKDYiaFOjniMlL7OoDhO3zDL2EMUp2SzcT79NvGXdG4oftscR8LiT3uoeTb4GkdwWNVBj+yRbKFqjkb/9NBKxzkh3683u8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4WzGnC22wPz2DbfW; Wed, 4 Sep 2024 17:06:07 +0800 (CST) Received: from dggpeml500022.china.huawei.com (unknown [7.185.36.66]) by mail.maildlp.com (Postfix) with ESMTPS id 877021402CC; Wed, 4 Sep 2024 17:06:27 +0800 (CST) Received: from huawei.com (10.90.53.73) by dggpeml500022.china.huawei.com (7.185.36.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Wed, 4 Sep 2024 17:06:27 +0800 From: Hongbo Li To: , , , CC: , , Subject: [PATCH -next v2 2/9] coccinelle: Add rules to find str_false_true() replacements Date: Wed, 4 Sep 2024 17:14:44 +0800 Message-ID: <20240904091451.3328272-3-lihongbo22@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240904091451.3328272-1-lihongbo22@huawei.com> References: <20240904091451.3328272-1-lihongbo22@huawei.com> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml500022.china.huawei.com (7.185.36.66) As done with str_true_false(), add checks for str_false_true() opportunities. A simple test can find over 9 cases currently exist in the tree. Signed-off-by: Hongbo Li --- scripts/coccinelle/api/string_choices.cocci | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scripts/coccinelle/api/string_choices.cocci b/scripts/coccinelle/api/string_choices.cocci index 50329c4c8acd..a1141bd29b3c 100644 --- a/scripts/coccinelle/api/string_choices.cocci +++ b/scripts/coccinelle/api/string_choices.cocci @@ -108,3 +108,26 @@ e << str_true_false_r.E; @@ coccilib.report.print_report(p[0], "opportunity for str_true_false(%s)" % e) + +@str_false_true depends on patch@ +expression E; +@@ +( +- ((E) ? "false" : "true") ++ str_false_true(E) +) + +@str_false_true_r depends on !patch exists@ +expression E; +position P; +@@ +( +* ((E@P) ? "false" : "true") +) + +@script:python depends on report@ +p << str_false_true_r.P; +e << str_false_true_r.E; +@@ + +coccilib.report.print_report(p[0], "opportunity for str_false_true(%s)" % e) From patchwork Wed Sep 4 09:14:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hongbo Li X-Patchwork-Id: 13790183 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C6B719D09A for ; Wed, 4 Sep 2024 09:06:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725440798; cv=none; b=s6GRjlvTOQIjE6j7z0NEGWEFTIolUjCphmEMX4dAq5DHH5zDYcl5bMBUZqQT8edkqQ8oMEctQRygo2tajbRmLFEqj2buG5vQ89FWxksyND3QaYjxgs16FwtvGMJHHt9bQM3IKjLZa1a+tXNrvCOykZTo2a2WbGZ2pupCwjTjMCs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725440798; c=relaxed/simple; bh=gfUNmLspY9syJXQ6mKQ6GhmGRc6uN93t2aDLD9fu7Nk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=M+20Zf4k/ogfs3aQSujapCUwGYx+pK/j6bNVE51wOdKNBLtgGWQLNGkdl4BQf3yh/6htoisaD5c7NncqrPTF8ZztyNk7/YpbY0BKcrII0GVm9K24ONr3BcB1eSFMGw0PPE8GFcq/RS1bLzu3PBG+MlCbwiWxDotQGj4zwcSosl8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4WzGlR11RyzpVDw; Wed, 4 Sep 2024 17:04:35 +0800 (CST) Received: from dggpeml500022.china.huawei.com (unknown [7.185.36.66]) by mail.maildlp.com (Postfix) with ESMTPS id AF1061800B8; Wed, 4 Sep 2024 17:06:27 +0800 (CST) Received: from huawei.com (10.90.53.73) by dggpeml500022.china.huawei.com (7.185.36.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Wed, 4 Sep 2024 17:06:27 +0800 From: Hongbo Li To: , , , CC: , , Subject: [PATCH -next v2 3/9] coccinelle: Add rules to find str_hi{gh}_lo{w}() replacements Date: Wed, 4 Sep 2024 17:14:45 +0800 Message-ID: <20240904091451.3328272-4-lihongbo22@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240904091451.3328272-1-lihongbo22@huawei.com> References: <20240904091451.3328272-1-lihongbo22@huawei.com> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml500022.china.huawei.com (7.185.36.66) As other rules done, we add rules for str_hi{gh}_lo{w}() to check the relative opportunities. Signed-off-by: Hongbo Li --- scripts/coccinelle/api/string_choices.cocci | 46 +++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/scripts/coccinelle/api/string_choices.cocci b/scripts/coccinelle/api/string_choices.cocci index a1141bd29b3c..67818cd6ee09 100644 --- a/scripts/coccinelle/api/string_choices.cocci +++ b/scripts/coccinelle/api/string_choices.cocci @@ -131,3 +131,49 @@ e << str_false_true_r.E; @@ coccilib.report.print_report(p[0], "opportunity for str_false_true(%s)" % e) + +@str_hi_lo depends on patch@ +expression E; +@@ +( +- ((E) ? "hi" : "lo") ++ str_hi_lo(E) +) + +@str_hi_lo_r depends on !patch exists@ +expression E; +position P; +@@ +( +* ((E@P) ? "hi" : "lo") +) + +@script:python depends on report@ +p << str_hi_lo_r.P; +e << str_hi_lo_r.E; +@@ + +coccilib.report.print_report(p[0], "opportunity for str_hi_lo(%s)" % e) + +@str_high_low depends on patch@ +expression E; +@@ +( +- ((E) ? "high" : "low") ++ str_high_low(E) +) + +@str_high_low_r depends on !patch exists@ +expression E; +position P; +@@ +( +* ((E@P) ? "high" : "low") +) + +@script:python depends on report@ +p << str_high_low_r.P; +e << str_high_low_r.E; +@@ + +coccilib.report.print_report(p[0], "opportunity for str_high_low(%s)" % e) From patchwork Wed Sep 4 09:14:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hongbo Li X-Patchwork-Id: 13790175 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07947198E7F for ; Wed, 4 Sep 2024 09:06:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725440791; cv=none; b=DAcS1EHNSajd4cm6gAWPj60DL3nfXzYnnIiyEC68rxs5iXE+ouIVduStc7k5vPu5uCKGimjuH8CHUoJz/jxc0rLPi4clXi/VekJy5v7fXGQ2Hf0iwhQB6UFNvvSyHlkz5x4BFpRzptNvOfSMxIXbm18XQ1jXS1F4Lkgqbu9c9wY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725440791; c=relaxed/simple; bh=Q1rHAD2z4v1f75mfg2BtbNE9kcDKvP3+crmva8tW2Z4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UzfbpCszzPMMzZ+hPiL3ytMx4sahwPj49vZibL8M++mvdugHw0uKngsl+96lxWUn1GXp7JVC/IjSRwIx6zelQBkw+bnpjTj7QB64Kn1znCrpao7Fk8/hwtzia1IQhAG8yoIq46EYrgZzeqZY9kWfTLDAUx7ms4aw7pmHYe7ugsk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4WzGjc3Bsqz1HJ8Y; Wed, 4 Sep 2024 17:03:00 +0800 (CST) Received: from dggpeml500022.china.huawei.com (unknown [7.185.36.66]) by mail.maildlp.com (Postfix) with ESMTPS id D49061A0188; Wed, 4 Sep 2024 17:06:27 +0800 (CST) Received: from huawei.com (10.90.53.73) by dggpeml500022.china.huawei.com (7.185.36.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Wed, 4 Sep 2024 17:06:27 +0800 From: Hongbo Li To: , , , CC: , , Subject: [PATCH -next v2 4/9] coccinelle: Add rules to find str_lo{w}_hi{gh}() replacements Date: Wed, 4 Sep 2024 17:14:46 +0800 Message-ID: <20240904091451.3328272-5-lihongbo22@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240904091451.3328272-1-lihongbo22@huawei.com> References: <20240904091451.3328272-1-lihongbo22@huawei.com> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml500022.china.huawei.com (7.185.36.66) As other rules done, we add rules for str_lo{w}_hi{gh}() to check the relative opportunities. Signed-off-by: Hongbo Li --- scripts/coccinelle/api/string_choices.cocci | 46 +++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/scripts/coccinelle/api/string_choices.cocci b/scripts/coccinelle/api/string_choices.cocci index 67818cd6ee09..53fd34a0fcb4 100644 --- a/scripts/coccinelle/api/string_choices.cocci +++ b/scripts/coccinelle/api/string_choices.cocci @@ -177,3 +177,49 @@ e << str_high_low_r.E; @@ coccilib.report.print_report(p[0], "opportunity for str_high_low(%s)" % e) + +@str_lo_hi depends on patch@ +expression E; +@@ +( +- ((E) ? "lo" : "hi") ++ str_lo_hi(E) +) + +@str_lo_hi_r depends on !patch exists@ +expression E; +position P; +@@ +( +* ((E@P) ? "lo" : "hi") +) + +@script:python depends on report@ +p << str_lo_hi_r.P; +e << str_lo_hi_r.E; +@@ + +coccilib.report.print_report(p[0], "opportunity for str_lo_hi(%s)" % e) + +@str_low_high depends on patch@ +expression E; +@@ +( +- ((E) ? "low" : "high") ++ str_low_high(E) +) + +@str_low_high_r depends on !patch exists@ +expression E; +position P; +@@ +( +* ((E@P) ? "low" : "high") +) + +@script:python depends on report@ +p << str_low_high_r.P; +e << str_low_high_r.E; +@@ + +coccilib.report.print_report(p[0], "opportunity for str_low_high(%s)" % e) From patchwork Wed Sep 4 09:14:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hongbo Li X-Patchwork-Id: 13790177 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45F67195FEA for ; Wed, 4 Sep 2024 09:06:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725440792; cv=none; b=b+BkY659yo0Am62F+v63VE+a3jnNMofbvKA2pYyY1km3TKuGIJ7PdEF/3E9MqzA5yJirSFFO/OTQxfAa4xaBFn8/swR3iPJ4UdnbILjPWtJoEMUQaI1Eb3uyAgctOc216wIuThM23YiNXXsmncOkXCJGSM5lFnRB5KKvpoqr2K0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725440792; c=relaxed/simple; bh=c0joXO4IQSsJhvGCrRBcVVfUJzc464YTU9KipWZOQBc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dtCRLfT+5BJ//USHdixwnBFkloMi3ArxsApn3s1cL5UT+P8wMTJ29slgVCaNbFdBAy6VY3v9kQKEAmBkiOfyK/Jx9dDosrEDptQex7y9O6HFJLx/6Y0qrwlwAj4jXF3VfJeM44bZwHcCA3zQVDgCGx4bok2bbR3QceT5Z1wRXtQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4WzGnC6g1Rz1j6km; Wed, 4 Sep 2024 17:06:07 +0800 (CST) Received: from dggpeml500022.china.huawei.com (unknown [7.185.36.66]) by mail.maildlp.com (Postfix) with ESMTPS id 053A314011D; Wed, 4 Sep 2024 17:06:28 +0800 (CST) Received: from huawei.com (10.90.53.73) by dggpeml500022.china.huawei.com (7.185.36.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Wed, 4 Sep 2024 17:06:27 +0800 From: Hongbo Li To: , , , CC: , , Subject: [PATCH -next v2 5/9] coccinelle: Add rules to find str_enable{d}_disable{d}() replacements Date: Wed, 4 Sep 2024 17:14:47 +0800 Message-ID: <20240904091451.3328272-6-lihongbo22@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240904091451.3328272-1-lihongbo22@huawei.com> References: <20240904091451.3328272-1-lihongbo22@huawei.com> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml500022.china.huawei.com (7.185.36.66) As other rules done, we add rules for str_enable{d}_ disable{d}() to check the relative opportunities. Signed-off-by: Hongbo Li --- scripts/coccinelle/api/string_choices.cocci | 46 +++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/scripts/coccinelle/api/string_choices.cocci b/scripts/coccinelle/api/string_choices.cocci index 53fd34a0fcb4..7400eafdf040 100644 --- a/scripts/coccinelle/api/string_choices.cocci +++ b/scripts/coccinelle/api/string_choices.cocci @@ -223,3 +223,49 @@ e << str_low_high_r.E; @@ coccilib.report.print_report(p[0], "opportunity for str_low_high(%s)" % e) + +@str_enable_disable depends on patch@ +expression E; +@@ +( +- ((E) ? "enable" : "disable") ++ str_enable_disable(E) +) + +@str_enable_disable_r depends on !patch exists@ +expression E; +position P; +@@ +( +* ((E@P) ? "enable" : "disable") +) + +@script:python depends on report@ +p << str_enable_disable_r.P; +e << str_enable_disable_r.E; +@@ + +coccilib.report.print_report(p[0], "opportunity for str_enable_disable(%s)" % e) + +@str_enabled_disabled depends on patch@ +expression E; +@@ +( +- ((E) ? "enabled" : "disabled") ++ str_enabled_disabled(E) +) + +@str_enabled_disabled_r depends on !patch exists@ +expression E; +position P; +@@ +( +* ((E@P) ? "enabled" : "disabled") +) + +@script:python depends on report@ +p << str_enabled_disabled_r.P; +e << str_enabled_disabled_r.E; +@@ + +coccilib.report.print_report(p[0], "opportunity for str_enabled_disabled(%s)" % e) From patchwork Wed Sep 4 09:14:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hongbo Li X-Patchwork-Id: 13790176 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66E9319AD56 for ; Wed, 4 Sep 2024 09:06:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725440792; cv=none; b=UY+YIzQzAa0xsp3Hka7pOf43biS0Orq4h2082BDBkoW/ilrmRXnJxpysr5fA0OCPFhcqaiGF7VLbsx5OofYahv6SNOXAEh9LTKAygh/8URtdlm2uadU3MObMYmuL10T4Vy4idxUtlL0z+T1dNanDKEi19dl68GoTHuHJ3JJNq9U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725440792; c=relaxed/simple; bh=fVA4X7cFT3m7GzoI5QwZDoNZJpB3g0fRWQ39lp8KD8Y=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=d1ltqh1ZpbQYKFIoZpa5RPQjhsKEPVNlM5VH5mY+CvbuX9T2C/HoTnwfSweUhf8stgmJYFiZ6gSN34hXkFDes2CUi4kwzEduWXxXRTrIxidN6862QkGz48TcI/zRAGCPfufmiVcVLSCYTBjWshWaJokN5n11UG1u7TMNWsmVwng= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4WzGgv11j6z20nMt; Wed, 4 Sep 2024 17:01:31 +0800 (CST) Received: from dggpeml500022.china.huawei.com (unknown [7.185.36.66]) by mail.maildlp.com (Postfix) with ESMTPS id 2733F1402CC; Wed, 4 Sep 2024 17:06:28 +0800 (CST) Received: from huawei.com (10.90.53.73) by dggpeml500022.china.huawei.com (7.185.36.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Wed, 4 Sep 2024 17:06:27 +0800 From: Hongbo Li To: , , , CC: , , Subject: [PATCH -next v2 6/9] coccinelle: Add rules to find str_read_write() replacements Date: Wed, 4 Sep 2024 17:14:48 +0800 Message-ID: <20240904091451.3328272-7-lihongbo22@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240904091451.3328272-1-lihongbo22@huawei.com> References: <20240904091451.3328272-1-lihongbo22@huawei.com> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml500022.china.huawei.com (7.185.36.66) As other rules done, we add rules for str_read_write() to check the relative opportunities. Signed-off-by: Hongbo Li --- scripts/coccinelle/api/string_choices.cocci | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scripts/coccinelle/api/string_choices.cocci b/scripts/coccinelle/api/string_choices.cocci index 7400eafdf040..f9ee0352cc3b 100644 --- a/scripts/coccinelle/api/string_choices.cocci +++ b/scripts/coccinelle/api/string_choices.cocci @@ -269,3 +269,26 @@ e << str_enabled_disabled_r.E; @@ coccilib.report.print_report(p[0], "opportunity for str_enabled_disabled(%s)" % e) + +@str_read_write depends on patch@ +expression E; +@@ +( +- ((E) ? "read" : "write") ++ str_read_write(E) +) + +@str_read_write_r depends on !patch exists@ +expression E; +position P; +@@ +( +* ((E@P) ? "read" : "write") +) + +@script:python depends on report@ +p << str_read_write_r.P; +e << str_read_write_r.E; +@@ + +coccilib.report.print_report(p[0], "opportunity for str_read_write(%s)" % e) From patchwork Wed Sep 4 09:14:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hongbo Li X-Patchwork-Id: 13790180 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C70C1AAE33 for ; Wed, 4 Sep 2024 09:06:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725440797; cv=none; b=GEfpeQjBkAzhwJnHvxpamTco/zB8VYu3+LlDEf+8jCxA0QWR33NzxTRbfz9Xnu++2WcKunx1LjvQyXEVhe2KHH57ozpZNdEqYN8HGwrjI2JOXbkQq2J0Zx/RrFBfSY3FWL6cSs+zddFJajJ3cqEsM+vRTsnf3ydo243N2cVwra4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725440797; c=relaxed/simple; bh=uexWtHFG931q4BLZbSK12Y9wi05Rqz6P+BoAE1n63p8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=olbHgV3QKPL4p3O+Y3DMO/ItNh1ytyOVDk7GemzFgJFiK5jf9rZBQol/qJGVR5/lrK11d24jZCyN3PLVZLNx84VHmDKAEpfSmNjImZR5OIpdM+okmcws+pFLWFZvAUaBw1FN4jglff1BCByKcMI/Ion3jys00paCUbb4aypDj2I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4WzGl90k2ZzgYw8; Wed, 4 Sep 2024 17:04:21 +0800 (CST) Received: from dggpeml500022.china.huawei.com (unknown [7.185.36.66]) by mail.maildlp.com (Postfix) with ESMTPS id 4DD16180105; Wed, 4 Sep 2024 17:06:28 +0800 (CST) Received: from huawei.com (10.90.53.73) by dggpeml500022.china.huawei.com (7.185.36.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Wed, 4 Sep 2024 17:06:28 +0800 From: Hongbo Li To: , , , CC: , , Subject: [PATCH -next v2 7/9] coccinelle: Add rules to find str_write_read() replacements Date: Wed, 4 Sep 2024 17:14:49 +0800 Message-ID: <20240904091451.3328272-8-lihongbo22@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240904091451.3328272-1-lihongbo22@huawei.com> References: <20240904091451.3328272-1-lihongbo22@huawei.com> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml500022.china.huawei.com (7.185.36.66) As other rules done, we add rules for str_write_read() to check the relative opportunities. Signed-off-by: Hongbo Li --- scripts/coccinelle/api/string_choices.cocci | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scripts/coccinelle/api/string_choices.cocci b/scripts/coccinelle/api/string_choices.cocci index f9ee0352cc3b..3ef7309164f4 100644 --- a/scripts/coccinelle/api/string_choices.cocci +++ b/scripts/coccinelle/api/string_choices.cocci @@ -292,3 +292,26 @@ e << str_read_write_r.E; @@ coccilib.report.print_report(p[0], "opportunity for str_read_write(%s)" % e) + +@str_write_read depends on patch@ +expression E; +@@ +( +- ((E) ? "write" : "read") ++ str_write_read(E) +) + +@str_write_read_r depends on !patch exists@ +expression E; +position P; +@@ +( +* ((E@P) ? "write" : "read") +) + +@script:python depends on report@ +p << str_write_read_r.P; +e << str_write_read_r.E; +@@ + +coccilib.report.print_report(p[0], "opportunity for str_write_read(%s)" % e) From patchwork Wed Sep 4 09:14:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hongbo Li X-Patchwork-Id: 13790181 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF99A1A727F for ; Wed, 4 Sep 2024 09:06:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725440797; cv=none; b=kFXbxbinTCze101VjHcKMg8MdkFmraecN2rcx/aQd8KaEG+O34NVIAGcnAaDLZ/eeKkhpqVquMT6RKTBh+egYy26EKX4SJab4sXriVSBd9TaFMWRGUYh5sJHXB3gLmFM4IqEj4ZtOMBYvSvOmdP8SrYtyqm1SNtyze5aEg4QlCA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725440797; c=relaxed/simple; bh=jc/6avPNtWWIdeO5+r/j5FjmPpxKjBbm497J2ACaN/M=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MZE+4qqP4nPdeSgStK4YcZEbMYfhbW2wuD42oDkgmcey1jkU4AM5FND9cDFd80tgjcsqEYAc/pXVLoB3RDeZ1LLLT1IVXE1LlSUy3RmY9UjoXrFDxA59WJuRJxjnHrSow9Ovz89MKV+mVqiD3qAOeEGyu2KarjO+XuHOynWwVKg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4WzGlR6Sz2zpVFH; Wed, 4 Sep 2024 17:04:35 +0800 (CST) Received: from dggpeml500022.china.huawei.com (unknown [7.185.36.66]) by mail.maildlp.com (Postfix) with ESMTPS id 72785140137; Wed, 4 Sep 2024 17:06:28 +0800 (CST) Received: from huawei.com (10.90.53.73) by dggpeml500022.china.huawei.com (7.185.36.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Wed, 4 Sep 2024 17:06:28 +0800 From: Hongbo Li To: , , , CC: , , Subject: [PATCH -next v2 8/9] coccinelle: Add rules to find str_on_off() replacements Date: Wed, 4 Sep 2024 17:14:50 +0800 Message-ID: <20240904091451.3328272-9-lihongbo22@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240904091451.3328272-1-lihongbo22@huawei.com> References: <20240904091451.3328272-1-lihongbo22@huawei.com> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml500022.china.huawei.com (7.185.36.66) As other rules done, we add rules for str_on_off() to check the relative opportunities. Signed-off-by: Hongbo Li --- scripts/coccinelle/api/string_choices.cocci | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scripts/coccinelle/api/string_choices.cocci b/scripts/coccinelle/api/string_choices.cocci index 3ef7309164f4..bb09076e5f58 100644 --- a/scripts/coccinelle/api/string_choices.cocci +++ b/scripts/coccinelle/api/string_choices.cocci @@ -315,3 +315,26 @@ e << str_write_read_r.E; @@ coccilib.report.print_report(p[0], "opportunity for str_write_read(%s)" % e) + +@str_on_off depends on patch@ +expression E; +@@ +( +- ((E) ? "on" : "off") ++ str_on_off(E) +) + +@str_on_off_r depends on !patch exists@ +expression E; +position P; +@@ +( +* ((E@P) ? "on" : "off") +) + +@script:python depends on report@ +p << str_on_off_r.P; +e << str_on_off_r.E; +@@ + +coccilib.report.print_report(p[0], "opportunity for str_on_off(%s)" % e) From patchwork Wed Sep 4 09:14:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hongbo Li X-Patchwork-Id: 13790182 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73FA11A3032 for ; Wed, 4 Sep 2024 09:06:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725440797; cv=none; b=kG129WmV/aHeylvOF0Hc1dmw04Z6Gef44P+s2KDFbyS00Rqau9KBN0x8yCoxP6wM9WFR8k+1rEQTfWNCRhpOlE2mxRSPd9eETgq8Z7Jr+A/ZwoYELnYst1k5xaE2VM6r4nNBMIc9fGb+1weqRd/PEth+Ge3zyCgVOh7o4Yyec0g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725440797; c=relaxed/simple; bh=NRwT4tirGvmE3tun4fOBCMFt/WcV9MjiIVpMXNRpIvE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=U31zGWUdxqJl8fQaPi3Kofwy6NtwJrXCdeurjejzjfR4xPYX9cE91pREnfthFUXOVVoz0DkIYnP2krbnTz+/0R0JCE8ovMuyog96rD0XUQdNR37+n2io8YEVb74p0eWenINGRxq98/9e3+U2QqGzYfGHqCE0MQ7OPpX+mmfefRs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4WzGl930jkzgYwH; Wed, 4 Sep 2024 17:04:21 +0800 (CST) Received: from dggpeml500022.china.huawei.com (unknown [7.185.36.66]) by mail.maildlp.com (Postfix) with ESMTPS id 9C267180105; Wed, 4 Sep 2024 17:06:28 +0800 (CST) Received: from huawei.com (10.90.53.73) by dggpeml500022.china.huawei.com (7.185.36.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Wed, 4 Sep 2024 17:06:28 +0800 From: Hongbo Li To: , , , CC: , , Subject: [PATCH -next v2 9/9] coccinelle: Add rules to find str_yes_no() replacements Date: Wed, 4 Sep 2024 17:14:51 +0800 Message-ID: <20240904091451.3328272-10-lihongbo22@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240904091451.3328272-1-lihongbo22@huawei.com> References: <20240904091451.3328272-1-lihongbo22@huawei.com> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml500022.china.huawei.com (7.185.36.66) As other rules done, we add rules for str_yes_no() to check the relative opportunities. Signed-off-by: Hongbo Li --- scripts/coccinelle/api/string_choices.cocci | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scripts/coccinelle/api/string_choices.cocci b/scripts/coccinelle/api/string_choices.cocci index bb09076e5f58..7b00d0450b17 100644 --- a/scripts/coccinelle/api/string_choices.cocci +++ b/scripts/coccinelle/api/string_choices.cocci @@ -338,3 +338,26 @@ e << str_on_off_r.E; @@ coccilib.report.print_report(p[0], "opportunity for str_on_off(%s)" % e) + +@str_yes_no depends on patch@ +expression E; +@@ +( +- ((E) ? "yes" : "no") ++ str_yes_no(E) +) + +@str_yes_no_r depends on !patch exists@ +expression E; +position P; +@@ +( +* ((E@P) ? "yes" : "no") +) + +@script:python depends on report@ +p << str_yes_no_r.P; +e << str_yes_no_r.E; +@@ + +coccilib.report.print_report(p[0], "opportunity for str_yes_no(%s)" % e)