From patchwork Tue Jan 19 20:02:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 366809 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_RED 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 49A43C433E6 for ; Tue, 19 Jan 2021 20:03:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0AD862310C for ; Tue, 19 Jan 2021 20:03:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729263AbhASUCu (ORCPT ); Tue, 19 Jan 2021 15:02:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:52998 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727673AbhASUCp (ORCPT ); Tue, 19 Jan 2021 15:02:45 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 87D702310B; Tue, 19 Jan 2021 20:02:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1611086523; bh=K4y4wPQqp3TLEyf/F1oiLqy12C+hPVp+IhKBkIAF5N4=; h=Date:From:To:Subject:From; b=cCOoXaurC4sT5ZSaQW6aBbTsZyBqjWSC1SRknCRsl2N7k/X8C8F3LIxoLy2YgBpru Owh7I5dF+CxVD2/jk164DXnlmnuu53I+ulxEcqky9ZtYni8qPQdRapbnyhQIAFQiM/ zv8vVhgqLstR2cp82+t4KrYPUVDCbhORMLBtIdkk= Date: Tue, 19 Jan 2021 12:02:01 -0800 From: akpm@linux-foundation.org To: adobriyan@gmail.com, hkallweit1@gmail.com, keescook@chromium.org, mcgrof@kernel.org, mhiramat@kernel.org, mhocko@suse.com, mm-commits@vger.kernel.org, nixiaoming@huawei.com, rdunlap@infradead.org, stable@vger.kernel.org, vbabka@suse.cz, yzaikin@google.com Subject: + proc_sysctl-fix-oops-caused-by-incorrect-command-parameters.patch added to -mm tree Message-ID: <20210119200201.KWSj1XBo1%akpm@linux-foundation.org> User-Agent: s-nail v14.8.16 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org The patch titled Subject: proc_sysctl: fix oops caused by incorrect command parameters has been added to the -mm tree. Its filename is proc_sysctl-fix-oops-caused-by-incorrect-command-parameters.patch This patch should soon appear at https://ozlabs.org/~akpm/mmots/broken-out/proc_sysctl-fix-oops-caused-by-incorrect-command-parameters.patch and later at https://ozlabs.org/~akpm/mmotm/broken-out/proc_sysctl-fix-oops-caused-by-incorrect-command-parameters.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Xiaoming Ni Subject: proc_sysctl: fix oops caused by incorrect command parameters The process_sysctl_arg() does not check whether val is empty before invoking strlen(val). If the command line parameter () is incorrectly configured and val is empty, oops is triggered. For example: "hung_task_panic=1" is incorrectly written as "hung_task_panic", oops is triggered. The call stack is as follows: Kernel command line: .... hung_task_panic ...... Call trace: __pi_strlen+0x10/0x98 parse_args+0x278/0x344 do_sysctl_args+0x8c/0xfc kernel_init+0x5c/0xf4 ret_from_fork+0x10/0x30 To fix it, check whether "val" is empty when "phram" is a sysctl field. Error codes are returned in the failure branch, and error logs are generated by parse_args(). Link: https://lkml.kernel.org/r/20210118133029.28580-1-nixiaoming@huawei.com Fixes: 3db978d480e2843 ("kernel/sysctl: support setting sysctl parameters from kernel command line") Signed-off-by: Xiaoming Ni Acked-by: Vlastimil Babka Cc: Luis Chamberlain Cc: Kees Cook Cc: Iurii Zaikin Cc: Alexey Dobriyan Cc: Michal Hocko Cc: Masami Hiramatsu Cc: Heiner Kallweit Cc: Randy Dunlap Cc: [5.8+] Signed-off-by: Andrew Morton --- fs/proc/proc_sysctl.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/fs/proc/proc_sysctl.c~proc_sysctl-fix-oops-caused-by-incorrect-command-parameters +++ a/fs/proc/proc_sysctl.c @@ -1770,6 +1770,12 @@ static int process_sysctl_arg(char *para return 0; } + if (!val) + return -EINVAL; + len = strlen(val); + if (len == 0) + return -EINVAL; + /* * To set sysctl options, we use a temporary mount of proc, look up the * respective sys/ file and write to it. To avoid mounting it when no @@ -1811,7 +1817,6 @@ static int process_sysctl_arg(char *para file, param, val); goto out; } - len = strlen(val); wret = kernel_write(file, val, len, &pos); if (wret < 0) { err = wret;