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,SPF_HELO_NONE,SPF_PASS 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 4E06CC433E0 for ; Tue, 12 Jan 2021 07:25:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 02EAE22B30 for ; Tue, 12 Jan 2021 07:25:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391894AbhALHYy (ORCPT ); Tue, 12 Jan 2021 02:24:54 -0500 Received: from mx2.suse.de ([195.135.220.15]:59390 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726949AbhALHYy (ORCPT ); Tue, 12 Jan 2021 02:24:54 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1610436247; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=JCay/17P6BAKq/OecOsxZY1Dicmtnhe0h47GlK1ceGU=; b=dZ3m2B+BCvAmVPLSXGmvJpL4Dj2aeBDJMF0E+6DzJnX+hzoR76hGKTc3cHt5yLAL1v1l3o MlLSlo0hQCa2lpEHiIR6kgXdoq8RGRkEQFa4T4K16ivw2g3jrKttrfajpRXc0AtLfMtydD LxjKZymaXUO3h2lC9XlHHsY+ejsZOUU= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 015B3AC95; Tue, 12 Jan 2021 07:24:07 +0000 (UTC) Date: Tue, 12 Jan 2021 08:24:06 +0100 From: Michal Hocko To: Andrew Morton Cc: Xiaoming Ni , linux-kernel@vger.kernel.org, mcgrof@kernel.org, keescook@chromium.org, yzaikin@google.com, adobriyan@gmail.com, linux-fsdevel@vger.kernel.org, vbabka@suse.cz, andy.shevchenko@gmail.com, wangle6@huawei.com Subject: Re: [PATCH v3] proc_sysctl: fix oops caused by incorrect command parameters. Message-ID: <20210112072406.GF22493@dhcp22.suse.cz> References: <20210112033155.91502-1-nixiaoming@huawei.com> <20210111203340.98dd3c8fa675b709bcf6d49e@linux-foundation.org> <89d1369e-f0a8-66f2-c0ea-3aac3a55e2c1@huawei.com> <20210111222845.67ceb4e3c7f64f267756e4e8@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210111222845.67ceb4e3c7f64f267756e4e8@linux-foundation.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 11-01-21 22:28:45, Andrew Morton wrote: > 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. Yes, other sysfs specific error messages are likely useful. I just fail to see why a missing value should be handled here when there is an existing handling in the caller. Not sure whether a complete shadow reporting in process_sysctl_arg is a deliberate decision or not. Vlastimil? Anyway one way or the other, all I care about is to have a reporting in place because this shouldn't be a silent failure. -- Michal Hocko SUSE Labs