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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92AD8C2BA4C for ; Wed, 26 Jan 2022 19:23:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ED4556B007B; Wed, 26 Jan 2022 14:23:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E5C4C6B0080; Wed, 26 Jan 2022 14:23:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CFD826B0082; Wed, 26 Jan 2022 14:23:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0053.hostedemail.com [216.40.44.53]) by kanga.kvack.org (Postfix) with ESMTP id BC7446B007B for ; Wed, 26 Jan 2022 14:23:06 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 7658382FDA for ; Wed, 26 Jan 2022 19:23:06 +0000 (UTC) X-FDA: 79073411172.26.C8EB1B1 Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) by imf10.hostedemail.com (Postfix) with ESMTP id 10A89C0002 for ; Wed, 26 Jan 2022 19:23:04 +0000 (UTC) Received: by mail-ed1-f52.google.com with SMTP id b13so664261edn.0 for ; Wed, 26 Jan 2022 11:23:04 -0800 (PST) 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=OR88/sfRY5SMmc2c9xo/1F4PCsLLeRL/qMHWSYMFz3I=; b=EYKETIbY/P3WkYufym3oL6Eqta+w/21YPUVijxyAM9rrurbda5tFdxg/eHVy6dTxTm zilVzZg1MJd/4lNhyhG8cXT+Tf7cXcquWRxZoFFXwc1qTl32xSNqPq0eaFApM9YZ2yl8 6S64485VemOg4pRzgADUQWMu/4IouFdPFeDQt4lF1fivP9H2kyUxWnCBhTFzsFDNwVxr nuZsGrV/NPl00sZOw2xXPWSLhGQG6AqtHaPzZDlmkEb3e5Fw01Db04ghZpTTSt7uFNCA oA6+gypt3mOLvw92drow2IJlgnrQ8YyzRKTz6PKkZkhfGjTBMCOrVltJ9vPihjUXX4Ou cefQ== 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=OR88/sfRY5SMmc2c9xo/1F4PCsLLeRL/qMHWSYMFz3I=; b=vNBvCDkyyVVDsBUWgZ9tk/xzcy+xM1t5huxPt5XbFfNJf8CwHpk1sdzcIoYP7de+DW Y2z1ZbrlceJkIO2ggmfjzkOvFeGKtF5N8YFnK3olqHjh1LO5C4+Td51aUK5/4d8ThB8p Qk/430xzFv9Ob4Jh53XjKlyvjDsPvCpvg+WV27i/oSDN5C+4pTnQT29Z18/AtBtVZm0M cVKTsnJ+NpNgsdwI8/eqlTQwemSVq9PjTHunba1147THAhDPVXhzSP0Bf+TiD7I/NPzp jpzfmh6o5NmuEhlNdWqZMinrwf8apYlGx8CgOLPunjhwaM2VLkjKusjo6EVxh9FBJR86 7qqw== X-Gm-Message-State: AOAM531y5KCnLIk4S5EV+Bz2AFB6WmTMMeYi4MjAPKUwjEwsLDU15hhW DzlEW/F2RpHbE3fO4S/TL2LpJGoDDfVdOfJfY2lraw== X-Google-Smtp-Source: ABdhPJwHpdzySdqPiWFjt2cOrzaJ9iFbSVQyBQjRBWw+Sc1wrVLOI+Keh8xzsaUAdgYN+E5YBWV1U0UT+F+wDWhLd+c= X-Received: by 2002:a05:6402:3c3:: with SMTP id t3mr482443edw.336.1643224983732; Wed, 26 Jan 2022 11:23:03 -0800 (PST) MIME-Version: 1.0 References: <20220126183429.1840447-1-pasha.tatashin@soleen.com> <20220126183429.1840447-2-pasha.tatashin@soleen.com> In-Reply-To: From: Pasha Tatashin Date: Wed, 26 Jan 2022 14:22:26 -0500 Message-ID: Subject: Re: [PATCH v3 1/9] mm: add overflow and underflow checks for 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 , Muchun Song , Wei Xu , Greg Thelen , David Rientjes , Paul Turner , Hugh Dickins Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 10A89C0002 X-Stat-Signature: wrujkqi86ids3g4grjjzen1zjm78zi8s Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=EYKETIbY; dmarc=none; spf=pass (imf10.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.208.52 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com X-Rspam-User: nil X-HE-Tag: 1643224984-899335 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 Wed, Jan 26, 2022 at 1:59 PM Matthew Wilcox wrote: > > On Wed, Jan 26, 2022 at 06:34:21PM +0000, Pasha Tatashin wrote: > > The problems with page->_refcount are hard to debug, because usually > > when they are detected, the damage has occurred a long time ago. Yet, > > the problems with invalid page refcount may be catastrophic and lead to > > memory corruptions. > > > > Reduce the scope of when the _refcount problems manifest themselves by > > adding checks for underflows and overflows into functions that modify > > _refcount. > > If you're chasing a bug like this, presumably you turn on page > tracepoints. So could we reduce the cost of this by putting the > VM_BUG_ON_PAGE parts into __page_ref_mod() et al? Yes, we'd need to > change the arguments to those functions to pass in old & new, but that > should be a cheap change compared to embedding the VM_BUG_ON_PAGE. This is not only about chasing a bug. This also about preventing memory corruption and information leaking that are caused by ref_count bugs from happening. Several months ago a memory corruption bug was discovered by accident: an engineer was studying a process core from a production system and noticed that some memory does not look like it belongs to the original process. We tried to manually reproduce that bug but failed. However, later analysis by our team, explained that the problem occured due to ref_count bug in Linux, and the bug itself was root caused and fixed (mentioned in the cover letter). This work would have prevented similar ref_count bugs from yielding to the memory corruption situation. Pasha