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=-10.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 DA75CC433E0 for ; Tue, 12 Jan 2021 06:25:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8A1CD229CA for ; Tue, 12 Jan 2021 06:25:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732388AbhALGZA (ORCPT ); Tue, 12 Jan 2021 01:25:00 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:10710 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730742AbhALGY7 (ORCPT ); Tue, 12 Jan 2021 01:24:59 -0500 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4DFL9J4Jz5zl43b; Tue, 12 Jan 2021 14:23:00 +0800 (CST) Received: from [10.67.102.197] (10.67.102.197) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.498.0; Tue, 12 Jan 2021 14:24:10 +0800 Subject: Re: [PATCH v3] proc_sysctl: fix oops caused by incorrect command parameters. To: Andrew Morton CC: , , , , , , , , , References: <20210112033155.91502-1-nixiaoming@huawei.com> <20210111203340.98dd3c8fa675b709bcf6d49e@linux-foundation.org> From: Xiaoming Ni Message-ID: <89d1369e-f0a8-66f2-c0ea-3aac3a55e2c1@huawei.com> Date: Tue, 12 Jan 2021 14:24:05 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.0.1 MIME-Version: 1.0 In-Reply-To: <20210111203340.98dd3c8fa675b709bcf6d49e@linux-foundation.org> Content-Type: text/plain; charset="gbk"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.102.197] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/1/12 12:33, Andrew Morton wrote: > On Tue, 12 Jan 2021 11:31:55 +0800 Xiaoming Ni wrote: > >> 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. >> >> --- a/fs/proc/proc_sysctl.c >> +++ b/fs/proc/proc_sysctl.c >> @@ -1770,6 +1770,9 @@ static int process_sysctl_arg(char *param, char *val, >> return 0; >> } >> >> + if (!val) >> + return -EINVAL; >> + > > I think v2 (return 0) was preferable. Because all the other error-out > cases in process_sysctl_arg() also do a `return 0'. https://lore.kernel.org/lkml/bc098af4-c0cd-212e-d09d-46d617d0acab@huawei.com/ patch4: +++ b/fs/proc/proc_sysctl.c @@ -1757,6 +1757,9 @@ static int process_sysctl_arg(char *param, char *val, loff_t pos = 0; ssize_t wret; + if (!val) + return 0; + if (strncmp(param, "sysctl", sizeof("sysctl") - 1) == 0) { param += sizeof("sysctl") - 1; Is this the version you're talking about? > > If we're going to do a separate "patch: make process_sysctl_arg() > return an errno instead of 0" then fine, we can discuss that. But it's > conceptually a different work from fixing this situation. > . > However, are the logs generated by process_sysctl_arg() clearer and more accurate than parse_args()? Should the logs generated by process_sysctl_arg() be deleted? Thanks Xiaoming Ni