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=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 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 ECB4FC433EF for ; Wed, 22 Sep 2021 15:30:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6F77261168 for ; Wed, 22 Sep 2021 15:30:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6F77261168 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id DE7E1940007; Wed, 22 Sep 2021 11:30:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D98156B0075; Wed, 22 Sep 2021 11:30:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C8564940007; Wed, 22 Sep 2021 11:30:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0065.hostedemail.com [216.40.44.65]) by kanga.kvack.org (Postfix) with ESMTP id BAC896B0074 for ; Wed, 22 Sep 2021 11:30:51 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 5AC671808F54E for ; Wed, 22 Sep 2021 15:30:51 +0000 (UTC) X-FDA: 78615597102.12.4C94D9C Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by imf21.hostedemail.com (Postfix) with ESMTP id 4F7ECD02F2D2 for ; Wed, 22 Sep 2021 15:30:50 +0000 (UTC) X-IronPort-AV: E=McAfee;i="6200,9189,10115"; a="221734148" X-IronPort-AV: E=Sophos;i="5.85,314,1624345200"; d="scan'208";a="221734148" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2021 08:30:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,314,1624345200"; d="scan'208";a="474728205" Received: from shbuild999.sh.intel.com (HELO localhost) ([10.239.146.151]) by fmsmga007.fm.intel.com with ESMTP; 22 Sep 2021 08:30:45 -0700 Date: Wed, 22 Sep 2021 23:30:45 +0800 From: Feng Tang To: Michal Hocko Cc: Chen Jun , linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, rui.xiang@huawei.com Subject: Re: [PATCH] mm: Fix the uninitialized use in overcommit_policy_handler Message-ID: <20210922153045.GA68763@shbuild999.sh.intel.com> References: <20210921140301.9058-1-chenjun102@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Stat-Signature: gx4qgebzjznnzw1nwn63bdxp1xffo4dg Authentication-Results: imf21.hostedemail.com; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=intel.com (policy=none); spf=none (imf21.hostedemail.com: domain of feng.tang@intel.com has no SPF policy when checking 192.55.52.120) smtp.mailfrom=feng.tang@intel.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 4F7ECD02F2D2 X-HE-Tag: 1632324650-145989 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, Sep 21, 2021 at 05:44:38PM +0200, Michal Hocko wrote: > 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. IIRC, You are right, there was some error caught by ltp tool, that when the overcommit policy get frequently changed while there is stress memory test, so if the policy is changed to OVERCOMMIT_NEVER, it must happen after the batch number is changed. Thanks, Feng > 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