Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3620698ybz; Mon, 27 Apr 2020 19:56:35 -0700 (PDT) X-Google-Smtp-Source: APiQypLDNJlChnXRMnW2wyE4huVCz1ZuNtSPTeCx7prXsTZ1ATaN5DvWZ6fil0TAYJEvyH5VRanL X-Received: by 2002:a50:e3cb:: with SMTP id c11mr21820660edm.105.1588042595170; Mon, 27 Apr 2020 19:56:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588042595; cv=none; d=google.com; s=arc-20160816; b=tiYE4hM9T5FOgWxnnwXE5RuK5qgIrrQ5p/gCIkJ1OpT9L2N4uB85ZXjraKWbDkcR9W jP7UYp8sV+V18cYiOPFImxDMXHmYikERT+8pYExz9+WNJ4YyxQ0JHfq/FkZZaIqNFy+3 ic1QeWxL5xxISa4vR1quyLa1ytMPnwbkaRgG1U/mF7F0TpyGSHsSPoby6he5ZW4DAqE0 4IrKb10lzAD/SanJORZrZGfJp/dZLVSmJ8Nr/XqjVzM7Z2LdAb1jqUDs0koKDlatBVVI xeHQSjv/PCOUUQWeeEGCbUs3CBVY+HUV2iLBQr0j3HCQcpDcCC0k5FZfnOO7nrw9Z7+n ky8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=k4ah+ibHQ7bpH3Og7w8OCgtmB5d82pSs76E15wfXQRU=; b=wVrJxY+yXyTYEuQd9h5Mg2i4UWUTaqVw8qQSm9sNn+3UGhD4nImvMqvd0m4+jP/Tzj QIgtBjLdD2JFImQaYON6K4gco8ugIG4h9aJg153uvI+p8wHB6xI2q/MAogCYViE03XQY c3bkuApTKUw5ZzIvDcp57DsA5O68a6aaeF++sPHpXNpiMqaI4fl5T3L7R14IlCNjRrgJ ONjVotblT8rKg5zZFkYZ5dSF75Sm+lSxDFmAC7Ah02NruUfn48+9Cyo5EDtlhaYXzVtO zmM1x6KQvAN/X3mSVX9Wf6urzgkPr8BC2PN9eMUHWfFZreq4PkHiPSEI3DW0HtDoffBr VOGA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t24si903056ejb.144.2020.04.27.19.56.11; Mon, 27 Apr 2020 19:56:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726360AbgD1CyK (ORCPT + 99 others); Mon, 27 Apr 2020 22:54:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:55436 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726284AbgD1CyK (ORCPT ); Mon, 27 Apr 2020 22:54:10 -0400 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 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 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 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 > >