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=-6.5 required=3.0 tests=BAYES_00,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 22596C4338F for ; Fri, 20 Aug 2021 07:34:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A06DD60200 for ; Fri, 20 Aug 2021 07:34:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A06DD60200 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 2FDC76B0071; Fri, 20 Aug 2021 03:34:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2ADF26B0072; Fri, 20 Aug 2021 03:34:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 19CF68D0001; Fri, 20 Aug 2021 03:34:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0137.hostedemail.com [216.40.44.137]) by kanga.kvack.org (Postfix) with ESMTP id F2DE06B0071 for ; Fri, 20 Aug 2021 03:34:02 -0400 (EDT) Received: from smtpin40.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 9CD5027761 for ; Fri, 20 Aug 2021 07:34:02 +0000 (UTC) X-FDA: 78494645124.40.6C1C7BA Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by imf02.hostedemail.com (Postfix) with ESMTP id 413167001A05 for ; Fri, 20 Aug 2021 07:34:02 +0000 (UTC) Received: by mail-pf1-f182.google.com with SMTP id t42so5296542pfg.12 for ; Fri, 20 Aug 2021 00:34:02 -0700 (PDT) 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=OdZwHSPvBf7v8TQzJgGvLUz2M9eAxdHhfezfY1ArgPY=; b=EmvoMyKhPrYNoLdElwrJbx+ch2kLlhtAaBuHABjBtXG7s3LErAyDyTpRW0WKYwDYu7 lnBgLN0SGA67qYrSd9mlyGLzp9/QllciG0rtYIy2koKjYw51O7wnBAscI2X6IjExvOV8 ucWJBay9ZSVGQ3xNPVqOwJb0tucMYAZlIdKTg= 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=OdZwHSPvBf7v8TQzJgGvLUz2M9eAxdHhfezfY1ArgPY=; b=l/qDqhojSkjisQwN88zibCJZkHqQ2CZ0CvtYz16H6hGBGSGRMtCzTgeGc180TwCgE3 Us1wCMHhxhuP9VqOjaPI6YbJyear67P5jxMCm9puzUHf2bBv2DeG0HmAvfnY1gEwBzNP 8296nJxt7u2cpFnALxaP6dQF25b41icWZx7fw4XYAciGMjENv2/ea2Zg4qJ5x4C1H9+y +vT913uhEdxmkZmrhqJ5r5yGq+RR8XYQUpYPkVRE510Rnt2Nz4WVZf0yQIjLvfcALh6V nCDP9A0b7i+KgVfpmCKZU5mmv1xk0uIFLkH6yinuuBrltbYu0defC6lkRiHZIIUhB5Gl tDIA== X-Gm-Message-State: AOAM531Cu4IuYnFT0Fyr37lcDMR7QrrhAyDo/LTEvEL3VBa5OZmugZDb 5YCnxoLnX0VvlCi16ucn8QImuQ== X-Google-Smtp-Source: ABdhPJyl8Pz1tgvSdMmTUn1bWAcfV38nnU6/ESt68A28mRcBFWuomuJUbGtSteVQqR4uvUtUHcHy9A== X-Received: by 2002:a63:1b45:: with SMTP id b5mr17581761pgm.302.1629444841222; Fri, 20 Aug 2021 00:34:01 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id 22sm6656587pgn.88.2021.08.20.00.34.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Aug 2021 00:34:00 -0700 (PDT) Date: Fri, 20 Aug 2021 00:33:59 -0700 From: Kees Cook To: Peter Zijlstra Cc: Linus Torvalds , Will Deacon , Andrew Morton , Borislav Petkov , Xiyu Yang , Alistair Popple , Yang Shi , Shakeel Butt , Hugh Dickins , Miaohe Lin , Linux Kernel Mailing List , Linux-MM , yuanxzhang@fudan.edu.cn, Xin Tan , Will Deacon , David Howells Subject: Re: [PATCH] mm/rmap: Convert from atomic_t to refcount_t on anon_vma->refcount Message-ID: <202108200017.9F1744F76@keescook> References: <1626665029-49104-1-git-send-email-xiyuyang19@fudan.edu.cn> <20210720160127.ac5e76d1e03a374b46f25077@linux-foundation.org> <20210819132131.GA15779@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=EmvoMyKh; spf=pass (imf02.hostedemail.com: domain of keescook@chromium.org designates 209.85.210.182 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 413167001A05 X-Stat-Signature: ns9kg7n1mhix6ck3uxdrpw3uetawhmzc X-HE-Tag: 1629444842-954961 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 Fri, Aug 20, 2021 at 08:43:40AM +0200, Peter Zijlstra wrote: > On Thu, Aug 19, 2021 at 12:09:37PM -0700, Linus Torvalds wrote: > > On Thu, Aug 19, 2021 at 8:21 AM Peter Zijlstra wrote: > > > > > > If we can skip the OF... we can do something like this: > > > > Honestly, I think a lot of the refcount code is questionable. It was > > absolutely written with no care for performance AT ALL. > > That's a bit unfair I feel. Will's last rewrite of the stuff was > specifically to address performance issues. Well, to address performance issues with the "full" version. The default x86-specific code was already as fast as atomic_t. Will got it to nearly match while making it catch all conditions, not just the exploitable ones. (i.e. it didn't bother trying to catch underflow; there's no way to mitigate it). Will's version gave us three properties: correctness (it catches all the pathological conditions), speed (it was very nearly the same speed as regular atomic_t), and arch-agnosticism, which expanded this protection to things beyond just x86 and arm64. > > But see above: maybe just make this a separate "careful atomic_t", > > with the option to panic-on-overflow. So then we could get rid of > > refcount_warn_saturate() enmtirely above, and instead just have a > > (compile-time option) BUG() case, with the non-careful version just > > being our existing atomic_dec_and_test. This is nearly what we had before. But refcount_t should always saturate on overflow -- that's specifically the mitigation needed to defang the traditional atomic_t overflow exploits (of which we had several a year before refcount_t and now we've seen zero since). > We used to have that option; the argument was made that everybody cares > about security and as long as this doesn't show up on benchmarks we > good. > > Also, I don't think most people want the overflow to go BUG, WARN is > mostly the right thing and only the super paranoid use panic-on-warn or > something. Saturating on overflow stops exploitability. WARNing is informational. BUG kills the system for no good reason: the saturation is the defense against attack, and the WARN is the "oh, I found a bug" details needed to fix it. I prefer the arch-agnostic, fully checked, very fast version of this (i.e. what we have right now). :P I appreciate it's larger, but in my opinion size isn't as important as correctness and speed. If it's just as fast as a small version but has greater coverage, that seems worth the size. -- Kees Cook