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=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no 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 4985CC433EF for ; Tue, 21 Sep 2021 15:44:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D6A4E60F56 for ; Tue, 21 Sep 2021 15:44:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D6A4E60F56 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 6C827940011; Tue, 21 Sep 2021 11:44:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6770A940007; Tue, 21 Sep 2021 11:44:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 56655940011; Tue, 21 Sep 2021 11:44:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0005.hostedemail.com [216.40.44.5]) by kanga.kvack.org (Postfix) with ESMTP id 47B73940007 for ; Tue, 21 Sep 2021 11:44:43 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id F340E82499A8 for ; Tue, 21 Sep 2021 15:44:42 +0000 (UTC) X-FDA: 78612003246.09.AAF230E Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf26.hostedemail.com (Postfix) with ESMTP id 9927A20019C8 for ; Tue, 21 Sep 2021 15:44:42 +0000 (UTC) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 68D4D20165; Tue, 21 Sep 2021 15:44:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1632239081; 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=nWfIiRk8SwvJHkqqWpNtD+lexrjS+OYHtMwGR8knjjw=; b=DUz7+j2qlyD7dfx4dJY69O9WrXBoB0KARXL6nfiFfLqC27G4lhBbOg2iFFJ1/Q0LKQRPLO T6swjazRz8feOf8EiWCl+Ct6oBLdnCDrwQtQ6pATyfCo+kS6paAp7pSTAhBVOnkERHQ0r4 3imdo1LZdgG1FO15ijNt4AbUrtkbyCk= Received: from suse.cz (unknown [10.100.201.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 31F16A3B88; Tue, 21 Sep 2021 15:44:40 +0000 (UTC) Date: Tue, 21 Sep 2021 17:44:38 +0200 From: Michal Hocko To: Chen Jun Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, feng.tang@intel.com, rui.xiang@huawei.com Subject: Re: [PATCH] mm: Fix the uninitialized use in overcommit_policy_handler Message-ID: References: <20210921140301.9058-1-chenjun102@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210921140301.9058-1-chenjun102@huawei.com> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 9927A20019C8 X-Stat-Signature: xbow4ryf3uoqga49iepthapfw95cne6n Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=DUz7+j2q; spf=pass (imf26.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.29 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com X-HE-Tag: 1632239082-188755 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue 21-09-21 14:03:01, Chen Jun wrote: > An unexpected value of /proc/sys/vm/panic_on_oom we will get, > after running the following program > > int main() > { > int fd = open("/proc/sys/vm/panic_on_oom", O_RDWR) > write(fd, "1", 1); > write(fd, "2", 1); > close(fd); > } > > write(fd, "2", 1) will pass *ppos = 1 to proc_dointvec_minmax. > proc_dointvec_minmax will return 0 without setting new_policy. > > t.data = &new_policy; > ret = proc_dointvec_minmax(&t, write, buffer, lenp, ppos) > -->do_proc_dointvec > -->__do_proc_dointvec > if (write) { > if (proc_first_pos_non_zero_ignore(ppos, table)) > goto out; > > sysctl_overcommit_memory = new_policy; > > so sysctl_overcommit_memory will be set to an uninitialized value. The overcommit_policy_handler (ab)use of proc_dointvec_minmax is really an odd one. It is not really great that proc_dointvec_minmax cannot really tell whether the value has been changed but likely nobody really needed that so far. I strongly suspect the intention was to do all the follow up handling before making the new mode visible to others. Maybe this can be changed so that the handler doesn't really need to do any hops. Your fix is an easier part I would just initialize the to -1 so that we can tell nothing has been done the handler can bail out without any follow up work. -- Michal Hocko SUSE Labs