From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_2 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80097C83002 for ; Tue, 28 Apr 2020 02:54:19 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 417A9206D9 for ; Tue, 28 Apr 2020 02:54:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="JCOaCc6c" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 417A9206D9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=goodmis.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=MZvoskgDXhtPSOSD3ELfNmYhenoCotyaMyiQ6b/LEgo=; b=JCOaCc6cmWWcB4 D/m8wNpxXZF9zRtT8IvuUYQmhNjlbPAW4E2Gr8j5m3DS9mWQAR6kzFgallUh2kKGXvWKLHabz+Xsp nD/7frAlNmq3r7lpjpySxPhdN7HFNqz5KcxTpG7Yg9eWQrHyllUhjFqyg7nv3EJZMbpL0263d/+A4 TJs5cB+YYUEARC96ACbQ//wBmvy98ZImhFPAELd+9tzxHyUeWhR5kjvetAJfcikWvnkMyr/sw2Sxr AWDUCVYj6YnHSJz8JOFo7l8mQh17iDnM2sgkCIXVK5UQs17dLPVKzRMvUqlD/U/VEhg7LE0no/pgp CFepcB7730r8ag3qaaAA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jTGNy-0001r5-0X; Tue, 28 Apr 2020 02:54:14 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jTGNu-0001p4-5O for linux-arm-kernel@lists.infradead.org; Tue, 28 Apr 2020 02:54:11 +0000 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 66323206E2; Tue, 28 Apr 2020 02:54:08 +0000 (UTC) Date: Mon, 27 Apr 2020 22:54:06 -0400 From: Steven Rostedt To: Gavin Shan Subject: Re: [PATCH] arm64/mm: Reject invalid NUMA option Message-ID: <20200427225406.7cacc796@gandalf.local.home> In-Reply-To: References: <20200424045314.16017-1-gshan@redhat.com> <20200424101132.GC1167@C02TD0UTHF1T.local> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200427_195410_244749_8F89D5A6 X-CRM114-Status: GOOD ( 27.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , catalin.marinas@arm.com, linux-kernel@vger.kernel.org, shan.gavin@gmail.com, will@kernel.org, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, 28 Apr 2020 10:59:14 +1000 Gavin Shan wrote: > Hi Mark, > > On 4/24/20 8:11 PM, Mark Rutland wrote: > > [Adding Steve, who added str_has_prefix()] > > > > On Fri, Apr 24, 2020 at 02:53:14PM +1000, Gavin Shan wrote: > >> The NUMA option is parsed by str_has_prefix() and the invalid option > >> like "numa=o" can be regarded as "numa=off" wrongly. > > > > Are you certain that can pass? If that can happen, str_has_prefix() is > > misnamed and does not seem to do what its kerneldoc says it does, as > > "off" is not a prefix of "o". > > > > Yes, It's possible. str_has_prefix() depends on strncmp(). In this particular > case, it's equal to the snippet of code as below: strncmp() returns zero. > str_has_prefix() returns 3. Wait! strncmp("o", "off", 3) returns zero? That to me looks like a bug! This means str_has_prefix() is broken in other areas as well. > > int strncmp(const char *cs, const char *ct, size_t count) > { > unsigned char c1, c2; > > while (count) { > c1 = *cs++; > c2 = *ct++; > if (c1 != c2) > return c1 < c2 ? -1 : 1; > if (!c1) /* break after first character is compared */ Crap! That is totally wrong! /me goes to fix... -- Steve > break; > count--; > } > return 0; /* 0 returned */ > } > > static __always_inline size_t str_has_prefix(const char *str, const char *prefix) > { > size_t len = strlen("o"); > return strncmp("o", "off", 1) == 0 ? len : 0; > } > > >> This fixes the issue with sysfs_streq(), which have more sanity checks, > >> to avoid accepting the invalid options. > > > > That doesn't sound immediately right, since this is an early parameter, > > which has nothing to do with sysfs. Perhaps that's just a misleading > > name? > > > > sysfs_streq() was introduced to compare the parameters received from sysfs > entry, but I don't think it has to be necessarily tied with sysfs entry. > So the name is bit misleading. Alternatively, we also can fix it in another > way (as below) if we try to avoid using sysfs_streq(). > > diff --git a/arch/arm64/mm/numa.c b/arch/arm64/mm/numa.c > index 4decf1659700..b0c1ec78f50f 100644 > --- a/arch/arm64/mm/numa.c > +++ b/arch/arm64/mm/numa.c > @@ -29,9 +29,13 @@ static __init int numa_parse_early_param(char *opt) > { > if (!opt) > return -EINVAL; > - if (str_has_prefix(opt, "off")) > + > + if (strlen(opt) >= 3 && str_has_prefix(opt, "off")) > numa_off = true; > > > Thanks, > > Mark. > > > > Thanks, > Gavin > > >> Signed-off-by: Gavin Shan > >> --- > >> arch/arm64/mm/numa.c | 3 ++- > >> 1 file changed, 2 insertions(+), 1 deletion(-) > >> > >> diff --git a/arch/arm64/mm/numa.c b/arch/arm64/mm/numa.c > >> index 4decf1659700..bd458b28616a 100644 > >> --- a/arch/arm64/mm/numa.c > >> +++ b/arch/arm64/mm/numa.c > >> @@ -29,7 +29,8 @@ static __init int numa_parse_early_param(char *opt) > >> { > >> if (!opt) > >> return -EINVAL; > >> - if (str_has_prefix(opt, "off")) > >> + > >> + if (sysfs_streq(opt, "off")) > >> numa_off = true; > >> > >> return 0; > >> -- > >> 2.23.0 > >> > > > > _______________________________________________ > > linux-arm-kernel mailing list > > linux-arm-kernel@lists.infradead.org > > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel