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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 73D7BC433E6 for ; Tue, 12 Jan 2021 06:29:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2B54D22CB2 for ; Tue, 12 Jan 2021 06:29:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733137AbhALG32 (ORCPT ); Tue, 12 Jan 2021 01:29:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:52646 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733070AbhALG31 (ORCPT ); Tue, 12 Jan 2021 01:29:27 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 54790229CA; Tue, 12 Jan 2021 06:28:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1610432926; bh=66Qx1gj4EzTEeVhhLDcGKAc/ygvdzEvNrer5sghrXJ4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=WFj9SeW+PsLybv3ux9riWrJaLAdMXDXKXz7KO+2WGT560uhpeR/6TKnzEuChPHvLc iT6R7pT6h6duplxwdDpwAo0C3uDu9tzJU3HGG0pcHydpL9QMzv9qVv1S6J2HjTUDmr JJMBPFJeJUT078kuTfy6+m+HsDPGx2Jdon+YmDkE= Date: Mon, 11 Jan 2021 22:28:45 -0800 From: Andrew Morton To: Xiaoming Ni Cc: , , , , , , , , , Subject: Re: [PATCH v3] proc_sysctl: fix oops caused by incorrect command parameters. Message-Id: <20210111222845.67ceb4e3c7f64f267756e4e8@linux-foundation.org> In-Reply-To: <89d1369e-f0a8-66f2-c0ea-3aac3a55e2c1@huawei.com> References: <20210112033155.91502-1-nixiaoming@huawei.com> <20210111203340.98dd3c8fa675b709bcf6d49e@linux-foundation.org> <89d1369e-f0a8-66f2-c0ea-3aac3a55e2c1@huawei.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 12 Jan 2021 14:24:05 +0800 Xiaoming Ni wrote: > 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? yes, but as a separate patch. The bugfix comes first. > > > > 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? I think the individual logs are very useful and should be retained.