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=-0.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 BA7E3C43331 for ; Tue, 12 Nov 2019 21:04:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 893FB20659 for ; Tue, 12 Nov 2019 21:04:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="BO/KRDnt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726906AbfKLVEG (ORCPT ); Tue, 12 Nov 2019 16:04:06 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:43520 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726376AbfKLVEG (ORCPT ); Tue, 12 Nov 2019 16:04:06 -0500 Received: by mail-pg1-f194.google.com with SMTP id l24so12639532pgh.10 for ; Tue, 12 Nov 2019 13:04:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=MOlDpdH/Pg9WevSDU8icH81SRQw0v3HMIviMNaByetc=; b=BO/KRDntxicD6HYAqt9wCy3jOUjRGsHxhxlqSAbqvleHC2k2Z5+hMj6EwHVenDjhE5 mHDhGXgblHgd0siA5XA3ihuhTHJFCAZc4JEWOEnZB1Hm/t2CFpCfgapmpckCm089wZ0j d4Rj0+uqhAZxINts6LuG9rPj+xATmQ7kzfAPU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=MOlDpdH/Pg9WevSDU8icH81SRQw0v3HMIviMNaByetc=; b=T1ZToqQtf/DJPsJv4PP+wSJ8XD0orKwS+Tz2DWfay6UH9bRuNkUoJX39qQZbTEJxU8 VtGR7gKIbx2A2K2oQF/pZSFh/NPzi3ojbiqOL9xAQn32VV/ysJrR5nrKTU8NJ9aidAIS rUpRBIim+hnb9XGoP/ZWoJOVGcKGYc3nzMul4hlLMeUW7Gw+nbegczBuiVLq0BFfKpIk tXO+dMSX5VyWLVYmDgv6ox76HNyklhKMY/mffGf3oLBqNr+xHgRWYsYgwSyyaa0vBPW0 vm9LI+vIx49q9KrFXcpRgbAOO79HgruTtZeumxrGTqmOYlCIfVEDMTEkKRWexfDBLUEa 9VeA== X-Gm-Message-State: APjAAAWcYm7WNPDbU09OEg9auj7D6yobVhaAn5E9db7NvqDjJFRu9z/5 kwRf3+ExxsdQ5bVKmQHP351b7S/Wzhk= X-Google-Smtp-Source: APXvYqwA84Bvn54cRclHfOZqz37ZUCIbsHdfpkNwpkkU86Jt5kVLRc1BJr3jokb8RIORk8Le9wSwlw== X-Received: by 2002:a63:5c4a:: with SMTP id n10mr38532982pgm.120.1573592645334; Tue, 12 Nov 2019 13:04:05 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id e8sm20292961pga.17.2019.11.12.13.04.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2019 13:04:04 -0800 (PST) Date: Tue, 12 Nov 2019 13:04:03 -0800 From: Kees Cook To: Johannes Weiner Cc: Stephen Rothwell , Andrew Morton , "Gustavo A. R. Silva" , linux-next@vger.kernel.org Subject: Re: Coverity: shrink_node_memcgs(): Null pointer dereferences Message-ID: <201911121301.885CE00@keescook> References: <201911111735.8DBFBDF0@keescook> <20191112152123.GB168812@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191112152123.GB168812@cmpxchg.org> Sender: linux-next-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-next@vger.kernel.org On Tue, Nov 12, 2019 at 10:21:23AM -0500, Johannes Weiner wrote: > On Mon, Nov 11, 2019 at 05:35:37PM -0800, coverity-bot wrote: > > Hello! > > > > This is an experimental automated report about issues detected by Coverity > > from a scan of next-20191108 as part of the linux-next weekly scan project: > > https://scan.coverity.com/projects/linux-next-weekly-scan > > > > You're getting this email because you were associated with the identified > > lines of code (noted below) that were touched by recent commits: > > > > c34aa3085f94 ("mm-vmscan-split-shrink_node-into-node-part-and-memcgs-part-fix") > > > > Coverity reported the following: > > > > *** CID 1487844: Null pointer dereferences (NULL_RETURNS) > > /mm/vmscan.c: 2695 in shrink_node_memcgs() > > 2689 memcg = mem_cgroup_iter(target_memcg, NULL, NULL); > > 2690 do { > > 2691 struct lruvec *lruvec = mem_cgroup_lruvec(memcg, pgdat); > > 2692 unsigned long reclaimed; > > 2693 unsigned long scanned; > > 2694 > > vvv CID 1487844: Null pointer dereferences (NULL_RETURNS) > > vvv Dereferencing a pointer that might be "NULL" "memcg" when calling "mem_cgroup_protected". > > 2695 switch (mem_cgroup_protected(target_memcg, memcg)) { > > This appears to be a false alarm. Okay, thanks! > All the "culprit" patch did was rename the local variable > "target_memcg". > > And while it's correct that memcg can be NULL (befor and after this > patch), it's the case only when mem_cgroup_disabled(), and > mem_cgroup_protected() checks for this case. Right, that's certainly the design. I wonder if in the interests of defensively asserting requirements, it would be worth adding something like this to mem_cgroup_protected(): if (WARN_ON_ONCE(!memcg)) return MEMCG_PROT_NONE; ? -- Kees Cook