Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp162700pxb; Wed, 27 Oct 2021 00:07:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxavuEWRuzc/3/1kFA85rU9dgEjIUPftD9IytAasIJVqW1jw5n0jpm/ehKSFEBi2nvJQMvk X-Received: by 2002:aa7:cd88:: with SMTP id x8mr41552500edv.203.1635318450004; Wed, 27 Oct 2021 00:07:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635318449; cv=none; d=google.com; s=arc-20160816; b=sWIQwYYqtc3k61bMdbO2MB58T24Pg7XRID4V4DKou1pmNR/Gi5mP9D3Og3fkNNAXkh ucTZyjCCvZC+cx0Gt709VK7lf3hSeM7RNXn11VcSMX6lb+8jYogWrBB0ypvzh8dC6rx0 GclW3SW/SBqWxwizovoY+ADyDMq6YEgTecZjfv1EEhgMnhieS4Yr8GPzhV+PegfVhGQq t2WNquO+fiFV6jf4JMlIYlSNFG38pdGWdgqLZO03fJqS1elEKMh7pzoJwpjvLIPGsz5d 5qZ32YalZdzzqgFp/2VY6uxtyHTQ+bij5tT+IP417qWvnc7z+HeWUg4er9+ibX3v7ZUE POGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=OXguLh0WNHEKlfFuQvMTGTJ+7qrh6TUIs5KKrA5WmaA=; b=QLuNQiVlNheoAhWFr4i6kJ6rcPmb2DIsu003LKOYjnpqlzfaoksrHFoCKG+NjAFi0R lFlKfu2sOgUyyDBrKqZwWevpJtz7BBLmqkuIy53W6UKKf4tcuExh9hUaGTCx1aiVmkto YiSDl4neHBmOYANNATpTo1+Dup6fL+JuqpAyHAPBTerpP4Xsw7MR5Sz9K2c97nVNBfdE 9ksoho+49iT6dgx6L1tC4Ek5UNWlW5NL+IXtVupelUZv+lp2nlQLMZIbiW3WsGHmiIku 1dt4dvrN8SpXfgZhaUnwV1fOXKhmOA0O6oMh4iDfxPQCpjHAYnVpjT2kgoH1PnU5IKpP XKTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b=WoIY+3Xd; 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 dp9si561069ejc.639.2021.10.27.00.07.05; Wed, 27 Oct 2021 00:07:29 -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=@soleen.com header.s=google header.b=WoIY+3Xd; 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 S238297AbhJZSd2 (ORCPT + 99 others); Tue, 26 Oct 2021 14:33:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236131AbhJZSd2 (ORCPT ); Tue, 26 Oct 2021 14:33:28 -0400 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA810C061767 for ; Tue, 26 Oct 2021 11:31:03 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id e2so310827ljg.13 for ; Tue, 26 Oct 2021 11:31:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=OXguLh0WNHEKlfFuQvMTGTJ+7qrh6TUIs5KKrA5WmaA=; b=WoIY+3XdSLW9YQe7GBf/6F1NA6RHYjzIp8j60phOurkXAHlRC8TPVC0LXcErTJfae0 NRbIOwv1z+NqQFeyKR8Nk7pF/rFqREGBipIUkO10+CJ+6xScbZ1KpkrW+cM8Zhz3Wrfu hpEoiclGT0yC4qAQrH2iTxrhuwIYk4UpPNbmnolvw4YEXdH5rZJpTkynDvIxx9YWpwN8 nXRlBhH/6qQ/8sOfIIfbBSxylC81esVi3rtpGs0/cNdYHbPJ8DDe1jt6fzycHSZhU/ou LxnNyZGXctoRenoSIL+9HxmXDUhOs1zA+56xSstmnqRJ6RPoLvlGTeEcWpZB3M+3tBbI Ffzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=OXguLh0WNHEKlfFuQvMTGTJ+7qrh6TUIs5KKrA5WmaA=; b=c4qJ9zO8H0nKWMRLuwvavC77vV/TGF1x1PqbrlPF1d1mOwcENPzwuXpbi+eqqnq6i+ mT7f1c67QVym76o6qlPHCOMkQZN2RLZ5yCKp3hPgTIdK29+XaG8VY5sx1sWb47MnXKOF 1FADcrcpEAme3mXXG8C/3pCwMsI/GtLRsLUslUE8hxwCpmC5qbIjuJAKFdjWamngC7B4 1bhLEBFucOvyGix0WW7j1scsMmOIFjAc58+9HQ5cCx1RlvzpJBtJhVpGDkJZCiBhuVUC apk0KSVoRJbJKt4aOnhzjUsqeDwdq9tVKaobVQAqHT5dmWxY/vH4JuddAfkfekZZx3Ju 3vTQ== X-Gm-Message-State: AOAM532FYyMTbr3ZCuB+tpSMt2kGgdboUIyLGgWr10ac/6/GdVhRWTBa dZQktIVHYmmAZMUJsPA/pVHJVdQKnfsLldfcfbAR1w== X-Received: by 2002:a2e:9b0e:: with SMTP id u14mr27526325lji.247.1635273062045; Tue, 26 Oct 2021 11:31:02 -0700 (PDT) MIME-Version: 1.0 References: <20211026173822.502506-1-pasha.tatashin@soleen.com> In-Reply-To: From: Pasha Tatashin Date: Tue, 26 Oct 2021 14:30:25 -0400 Message-ID: Subject: Re: [RFC 0/8] Hardening page _refcount To: Matthew Wilcox Cc: LKML , linux-mm , linux-m68k@lists.linux-m68k.org, Anshuman Khandual , Andrew Morton , william.kucharski@oracle.com, Mike Kravetz , Vlastimil Babka , Geert Uytterhoeven , schmitzmic@gmail.com, Steven Rostedt , Ingo Molnar , Johannes Weiner , Roman Gushchin , songmuchun@bytedance.com, weixugc@google.com, Greg Thelen Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 26, 2021 at 2:24 PM Matthew Wilcox wrote: > > 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. We can't because set_page_count(v) is used for 1. changing _refcount form a current value to unconstrained v 2. initialize _refcount from undefined state to v. In this work we forbid the first case, and reduce the second case to initialize only to 1. Pasha