Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3535844ybz; Mon, 27 Apr 2020 18:01:28 -0700 (PDT) X-Google-Smtp-Source: APiQypKezYEkygFeWDqOmkPydiTu2Wvdlwy23Pe1v0A92FC7H8HuwoQ9W8gD5wpnLMnGiOWQOZK1 X-Received: by 2002:a17:906:edc2:: with SMTP id sb2mr20813053ejb.129.1588035688339; Mon, 27 Apr 2020 18:01:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588035688; cv=none; d=google.com; s=arc-20160816; b=ZKef8i3ptwHxYSl/74zD4W3Oi1c3s8V5ayAAd5+Jr9xji1tmNOVv2C+lV2xEJ7iJqB uVvQWXYfg/9im0OMflppP3XxtSumW4Ivzqd0AnIY4c84ttX7/XpwXmbeWNCTephL0+FH 411UWHyEybq49raxn+/umLJSBGd0uuDDsJzpOCvxVbmkpzw75VbhGZ94uL+nI2Z5fnRU Cg8R0DlxH7MJjavOu4/m6BwYn9n4JeTiPypKasgNJiRRoU5mc+bHZWziOUg81LFY3egL qM0E4E0MWAkgM/PqEeyblsLJQne0asz51L0oRDOWCdmGNz67Pbhmzrp6t21gP7FR0YKg j9Yw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:reply-to:dkim-signature; bh=eCXtDAIPXE5kafrfekAlH3tsNBYP9X2R1z9BOoq2aRk=; b=WiZeSU7SFaDpeNZAX54nqTughX3RzQG2yIEYSUt7QolpgjQOOOIwL8FcQqJmfgLvdN jC+QILEN7ujgxdUocm1kFxeD7NiPNxRs8kQXVLjowISk0uwMPgL0aEqUuORUJ/jsYwbJ ZipuYyAadNn6sm84YMUfZU9kwDqXb5RMHKbTV+TMGXUlYlK+yYyC5460abKHVLcOTWB6 r9ydz5pG74vehX0iKC9KN3LwlqXmjpogB8Bsx9SwlgWHWm3o0jlKpgQEB5rlVzNBG94c +FyfX0ybJtLVZYLDewKcQ5748Oou5giUTipC0+ja42MtkItrx/tEAWi0qRNlZCorjngz 5J0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YKt1hryq; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g16si643906edr.382.2020.04.27.18.01.04; Mon, 27 Apr 2020 18:01:28 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YKt1hryq; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726307AbgD1A73 (ORCPT + 99 others); Mon, 27 Apr 2020 20:59:29 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:51578 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726263AbgD1A73 (ORCPT ); Mon, 27 Apr 2020 20:59:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588035567; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eCXtDAIPXE5kafrfekAlH3tsNBYP9X2R1z9BOoq2aRk=; b=YKt1hryqKzUo05yylcpxXYsCc9Wahcu3yB2apuNgIGBO6XqwerZThLoUu9SebE6e1OHxUI gg9VyNAdt7LXUxSjDYqwyRP+Doe9XgsG1nzVb31tgSUzfTG+rEp1T3kKtI5Swg11khYtmh rm0M2AxyeGdtxh1lxt8sjjTtctHpxCU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-249-Z_pq3ejJNnaSiSk3m0hvjw-1; Mon, 27 Apr 2020 20:59:20 -0400 X-MC-Unique: Z_pq3ejJNnaSiSk3m0hvjw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4D786468; Tue, 28 Apr 2020 00:59:19 +0000 (UTC) Received: from localhost.localdomain (vpn2-54-127.bne.redhat.com [10.64.54.127]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C40F750C22; Tue, 28 Apr 2020 00:59:16 +0000 (UTC) Reply-To: Gavin Shan Subject: Re: [PATCH] arm64/mm: Reject invalid NUMA option To: Mark Rutland Cc: catalin.marinas@arm.com, linux-kernel@vger.kernel.org, Steven Rostedt , shan.gavin@gmail.com, will@kernel.org, linux-arm-kernel@lists.infradead.org References: <20200424045314.16017-1-gshan@redhat.com> <20200424101132.GC1167@C02TD0UTHF1T.local> From: Gavin Shan Message-ID: Date: Tue, 28 Apr 2020 10:59:14 +1000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.0 MIME-Version: 1.0 In-Reply-To: <20200424101132.GC1167@C02TD0UTHF1T.local> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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 */ 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 >