lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230216114234.36343-2-andriy.shevchenko@linux.intel.com>
Date:   Thu, 16 Feb 2023 13:42:34 +0200
From:   Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To:     Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        Kees Cook <keescook@...omium.org>, linux-s390@...r.kernel.org,
        linux-kernel@...r.kernel.org, sparclinux@...r.kernel.org,
        netdev@...r.kernel.org
Cc:     Heiko Carstens <hca@...ux.ibm.com>,
        Vasily Gorbik <gor@...ux.ibm.com>,
        Alexander Gordeev <agordeev@...ux.ibm.com>,
        Christian Borntraeger <borntraeger@...ux.ibm.com>,
        Sven Schnelle <svens@...ux.ibm.com>,
        "David S. Miller" <davem@...emloft.net>,
        Thomas Gleixner <tglx@...utronix.de>,
        Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
        Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
        "H. Peter Anvin" <hpa@...or.com>,
        Andy Shevchenko <andy@...nel.org>,
        Eric Dumazet <edumazet@...gle.com>,
        Jakub Kicinski <kuba@...nel.org>,
        Paolo Abeni <pabeni@...hat.com>
Subject: [PATCH net-next v1 2/2] dns: use memscan() instead of open coded variant

memscan() is a standard API to provide an equivalent to

	memchr(foo, $CHAR, end - foo) ?: end

so use it.

Memory footprint (x86_64):

  Function                                     old     new   delta
  dns_resolver_preparse                       1429    1393     -36
  Total: Before=3229, After=3193, chg -1.11%

Signed-off-by: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
---
 net/dns_resolver/dns_key.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/net/dns_resolver/dns_key.c b/net/dns_resolver/dns_key.c
index 01e54b46ae0b..835be6e2dd83 100644
--- a/net/dns_resolver/dns_key.c
+++ b/net/dns_resolver/dns_key.c
@@ -134,8 +134,8 @@ dns_resolver_preparse(struct key_preparsed_payload *prep)
 
 	/* deal with any options embedded in the data */
 	end = data + datalen;
-	opt = memchr(data, '#', datalen);
-	if (!opt) {
+	opt = memscan(data, '#', datalen);
+	if (opt == end) {
 		/* no options: the entire data is the result */
 		kdebug("no options");
 		result_len = datalen;
@@ -150,7 +150,7 @@ dns_resolver_preparse(struct key_preparsed_payload *prep)
 			const char *eq;
 			char optval[128];
 
-			next_opt = memchr(opt, '#', end - opt) ?: end;
+			next_opt = memscan(opt, '#', end - opt);
 			opt_len = next_opt - opt;
 			if (opt_len <= 0 || opt_len > sizeof(optval)) {
 				pr_warn_ratelimited("Invalid option length (%d) for dns_resolver key\n",
@@ -158,16 +158,10 @@ dns_resolver_preparse(struct key_preparsed_payload *prep)
 				return -EINVAL;
 			}
 
-			eq = memchr(opt, '=', opt_len);
-			if (eq) {
-				opt_nlen = eq - opt;
-				eq++;
-				memcpy(optval, eq, next_opt - eq);
-				optval[next_opt - eq] = '\0';
-			} else {
-				opt_nlen = opt_len;
-				optval[0] = '\0';
-			}
+			eq = memscan(opt, '=', opt_len);
+			opt_nlen = eq - opt;
+			memcpy(optval, eq, next_opt - eq);
+			optval[next_opt - eq] = '\0';
 
 			kdebug("option '%*.*s' val '%s'",
 			       opt_nlen, opt_nlen, opt, optval);
-- 
2.39.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ