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=-16.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_IN_DEF_DKIM_WL autolearn=ham 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 EDF43C433E7 for ; Fri, 16 Oct 2020 21:35:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 76E8E21D40 for ; Fri, 16 Oct 2020 21:35:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="acrW9VgQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2411386AbgJPVfD (ORCPT ); Fri, 16 Oct 2020 17:35:03 -0400 Received: from linux.microsoft.com ([13.77.154.182]:56648 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2411382AbgJPVfC (ORCPT ); Fri, 16 Oct 2020 17:35:02 -0400 Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) by linux.microsoft.com (Postfix) with ESMTPSA id 4FBBA20BE4BC; Fri, 16 Oct 2020 14:35:02 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 4FBBA20BE4BC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1602884102; bh=PP8fzJsZM2/tnu0344Yrxpp1Zf5DPv6rUlSO+jHv0+I=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=acrW9VgQAg57vtOho6Eoy5fMGetptStkrZb+O1ZldshPDbydifndM2+5a1+rmiPUR nnAS2DwjGLjtwbL6URYfYwsXfBVjFWp9eS9k2kVzUxvVlOX0S2fVMbK8pUIUBUTd01 IvMnQLvzm5PtUj4EuxKWiQB7r4xyV0/ruAEfT4kU= Received: by mail-qk1-f175.google.com with SMTP id 140so3115934qko.2; Fri, 16 Oct 2020 14:35:02 -0700 (PDT) X-Gm-Message-State: AOAM5311xNuTXuEKTeuFInhngYgZ0Oa8bEdSynxwEt4ng3U1ESLGu//c T00jPDHk33o8R6BzLzbahD3KYh0SDejj0/CKDA0= X-Google-Smtp-Source: ABdhPJxQFqCgKm5rsFqzQtX6A7BOI5i02qVgsnqLoa7xal+AMdpRql8C839vr07TA/gQ9/xvE6hsP5llKMQM5AO8+AE= X-Received: by 2002:ae9:e108:: with SMTP id g8mr5887207qkm.220.1602884101304; Fri, 16 Oct 2020 14:35:01 -0700 (PDT) MIME-Version: 1.0 References: <20201016180907.171957-1-mcroce@linux.microsoft.com> <20201016180907.171957-3-mcroce@linux.microsoft.com> <202010161226.B136CDC8@keescook> In-Reply-To: <202010161226.B136CDC8@keescook> From: Matteo Croce Date: Fri, 16 Oct 2020 23:34:25 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 2/2] reboot: fix parsing of reboot cpu number To: Kees Cook , Petr Mladek Cc: linux-kernel@vger.kernel.org, Guenter Roeck , Arnd Bergmann , Mike Rapoport , Pavel Tatashin , Robin Holt , Fabian Frederick , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org On Fri, Oct 16, 2020 at 9:26 PM Kees Cook wrote: > > On Fri, Oct 16, 2020 at 08:09:07PM +0200, Matteo Croce wrote: > > From: Matteo Croce > > > > The kernel cmdline reboot= argument allows to specify the CPU used > > for rebooting, with the syntax `s####` among the other flags, e.g. > > > > reboot=soft,s4 > > reboot=warm,s31,force > > > > In the early days the parsing was done with simple_strtoul(), later > > deprecated in favor of the safer kstrtoint() which handles overflow. > > > > But kstrtoint() returns -EINVAL if there are non-digit characters > > in a string, so if this flag is not the last given, it's silently > > ignored as well as the subsequent ones. > > > > To fix it, revert the usage of simple_strtoul(), which is no longer > > deprecated, and restore the old behaviour. > > It is? Is there a reference, because this was never updated: > https://www.kernel.org/doc/html/latest/process/deprecated.html#simple-strtol-simple-strtoll-simple-strtoul-simple-strtoull > > -- > Kees Cook Seems so, Petr Mladek replied to the previous patch: > I suggest to go back to simple_strtoul(). It is not longer obsolete. > It still exists because it is needed for exactly this purpose, > see the comment in include/linux/kernel.h The comment says: /* * Use kstrto instead. * * NOTE: simple_strto does not check for the range overflow and, * depending on the input, may give interesting results. * * Use these functions if and only if you cannot use kstrto, because * the conversion ends on the first non-digit character, which may be far * beyond the supported range. It might be useful to parse the strings like * 10x50 or 12:21 without altering original string or temporary buffer in use. * Keep in mind above caveat. */ https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/kernel.h?h=v5.9#n452 Cheers, -- per aspera ad upstream