Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp159814pxb; Wed, 27 Oct 2021 00:03:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwv+rcl6/tuzlGATy2Ns2Qrwsxy09zoTnx3HwRNY6F9twlyl2wKoToVsbtkvs3kN10dA0zp X-Received: by 2002:a05:6402:34d5:: with SMTP id w21mr42243324edc.358.1635318201128; Wed, 27 Oct 2021 00:03:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635318201; cv=none; d=google.com; s=arc-20160816; b=ByQIP/a6KMd6jqwQF21JcFQIpUUS3kH3thQMvSXxDXSJsJ2f4ldzTaNuYhdn2G4a1L +bTMirbiRhTKvAt3z5UeH8qHHUX+6G/jMl9aZm0ZdYHsMoJOjyTnt8IUnoZefUk3DSzW dGxkJDgAkTKiTKVdMd6cQpnqPmvyHOmRxhaBY1m42h5qXsLxavnk8h6LknS/m/LJz85k EZxkMmHxHbOPARkFSMch8S1rSEylMP4QUcl2/17UUns6AgWJPGtfBh08am6tmgj5/Pks tPl6ztd4wDx0xYyXGigLfwe1N+BFNgJfP98w9BxGwWm1dLUQCFQXSc+RuGvSeDBjAacw Jtgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=SKVPRp8QWsSk8ZgHZrLxDGZRN/Q7dRClGxVumXlu1ZY=; b=rITXdXblG+2EJdpaTVqwuYCMmedAqSnG/X1wqzwJFEfjHxaRXusaO0DdpwxQaRQev4 aIBAE/DYdWQWNY9fhkRlGQNNPoHRv5sZZXHkgM6sr+/xQCiMzy1Kd1sTjmDWTuwQzoCt /wMxY5MEi637Mk+YuZ4HyRL+3PXB06hMPgEiraBhhIbX26Jrcfwpxg0C/UjQq2jXWiKv VOjcOxqJyWiIB/Zd0ZQAIFCrk0RA0GxVTVomPAd1iMG5LKNRKsz4Mo/N0s6BcmSnoG0p jIzEJMuiQv+RJZe4VJya6VTrvdM4cgS0ec63K7DHcm0n5k1Ltq8bkQsCz3n4G2Noz5bd x8kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Teyeqh7H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hg7si213207ejc.439.2021.10.27.00.02.53; Wed, 27 Oct 2021 00:03:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Teyeqh7H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236881AbhJZS1A (ORCPT + 99 others); Tue, 26 Oct 2021 14:27:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231297AbhJZS07 (ORCPT ); Tue, 26 Oct 2021 14:26:59 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5D97C061745; Tue, 26 Oct 2021 11:24:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=SKVPRp8QWsSk8ZgHZrLxDGZRN/Q7dRClGxVumXlu1ZY=; b=Teyeqh7Huw8bhKcMXPttBtp+gS 837G3HJeGdTiA3TWiiaF5haLIYRjemb4QNAnOiBIPNDPNT5vdroNeVd+fPTz4hLqKjl95jU6kEKB7 ul6MNswaA78pepRxTDWjuKNTvZzrheO0pIko4nPDsZf+s7MPQjmZO0ShuR5uapfV+GRO/2I7ZubdB PAIakkdwrraDDIveZyrpXtQF0M83ZrPeSeUsyBpSzM8qgcO6Js7UuodGGvmQ5XMeTHI6brXiuy8CR vAk0SPV5woUbBB9B3jD8PKy4MRNPgkxHwDj6Ieik55P5sKgh28LIo6VTmRFHqdpbaOos8XmjDYZ2X iLFOSolg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mfR6p-00H4T7-BN; Tue, 26 Oct 2021 18:23:54 +0000 Date: Tue, 26 Oct 2021 19:23:39 +0100 From: Matthew Wilcox To: Pasha Tatashin Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-m68k@lists.linux-m68k.org, anshuman.khandual@arm.com, akpm@linux-foundation.org, william.kucharski@oracle.com, mike.kravetz@oracle.com, vbabka@suse.cz, geert@linux-m68k.org, schmitzmic@gmail.com, rostedt@goodmis.org, mingo@redhat.com, hannes@cmpxchg.org, guro@fb.com, songmuchun@bytedance.com, weixugc@google.com, gthelen@google.com Subject: Re: [RFC 0/8] Hardening page _refcount Message-ID: References: <20211026173822.502506-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211026173822.502506-1-pasha.tatashin@soleen.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 26, 2021 at 05:38:14PM +0000, Pasha Tatashin wrote: > It is hard to root cause _refcount problems, because they usually > manifest after the damage has occurred. Yet, they can lead to > catastrophic failures such memory corruptions. > > Improve debugability by adding more checks that ensure that > page->_refcount never turns negative (i.e. double free does not > happen, or free after freeze etc). > > - Check for overflow and underflow right from the functions that > modify _refcount > - Remove set_page_count(), so we do not unconditionally overwrite > _refcount with an unrestrained value > - Trace return values in all functions that modify _refcount I think this is overkill. Won't we get exactly the same protection by simply testing that page->_refcount == 0 in set_page_count()? Anything which triggers that BUG_ON would already be buggy because it can race with speculative gets.