Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4455183pxb; Mon, 21 Feb 2022 22:08:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJzozedj3tB9y9ZvCocMBPX2F4ZSkMm5jDMR2ABxRQWpoMNg3Y6rDPHOqwOKY95zK3j9v4vx X-Received: by 2002:a17:903:1d0:b0:14d:a620:5828 with SMTP id e16-20020a17090301d000b0014da6205828mr21191107plh.64.1645510133836; Mon, 21 Feb 2022 22:08:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645510133; cv=none; d=google.com; s=arc-20160816; b=oqZb9n6amLu1DoHoYJ3/XAAZ5o8r3hoyHz1HH1pR1JnFR8esr82yjAPNgO2B65wUSv O6h6v6BFFeZ34kjgUmfvLpGam9d1ztISjKGFQpZm21/5SyajPtUb3Z/DgVz+2jNZJFUD h4fTSPWz05oPrKlyDk6tVwHsZrT3uoSQWzadg4HVWx0D0Z8U3gH/L4PiKFOsI8AoMPI/ jNQmVYGz+yt97yTqRX5OSGdJB20b/+xj019N1BAj4FkaJoMSXKoVT3sP6EYjxnw7UBm2 tH2mGLei2JuKPUe7qLAFnE2Dgh0Zxt5j46+udXQohNyppnnLnjUTbwevf1Lc+poEx39r k3eg== 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=hw6aQJa1MO9WdpxwzimvLityGgLsFlQla0AXaHMQmt0=; b=Q9OTdpALOi7uPpe5pF95bQ7q1RfoNnZDYoWo0sYSgDLYARyO2ld64eLkchoKndvw6C WkOGZu5vSuEfMco9VyEs1Rrm+h/yKnZicl6R0cFdSWVYOiDC98i1o55iN2WnG1LoU7Sp f1H8i7A1chf5j4joGCmXRxqa5adMqMGUJ5He8Dgx6+cO3S7qd8xqAbrqi+0nIxwuKV3v o1eNW7f0dq9E5l5EwZwMnX3H7mZvAVJs27L4/jTyhBaf9taqh63PIfcReoBSWUTfMYRG TaZv8M/yxcpmcb1nDXhLuphW6Nur/2f9xoT03eevkuJydrt4SG4oQMW2luy/ugRcpFyv zS/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="q//0ngBw"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m5si9072287pll.374.2022.02.21.22.08.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 22:08:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="q//0ngBw"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 92B11986EF; Mon, 21 Feb 2022 21:48:18 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229923AbiBVFsi (ORCPT + 99 others); Tue, 22 Feb 2022 00:48:38 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:59844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229912AbiBVFsh (ORCPT ); Tue, 22 Feb 2022 00:48:37 -0500 Received: from mail-yw1-x112a.google.com (mail-yw1-x112a.google.com [IPv6:2607:f8b0:4864:20::112a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 693C813F77 for ; Mon, 21 Feb 2022 21:48:12 -0800 (PST) Received: by mail-yw1-x112a.google.com with SMTP id 00721157ae682-2d625082ae2so161421827b3.1 for ; Mon, 21 Feb 2022 21:48:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=hw6aQJa1MO9WdpxwzimvLityGgLsFlQla0AXaHMQmt0=; b=q//0ngBw/9CR5mrn8X0xPqPq9wEjbNjeSbSLQaR1T9XnxZ6n6eOU/zM9nTaILAgbDj AbZb2CzrN8VVOPIZg8lcIqeo1AyHKbg9rHy33/6sqG+f6Jxs5gpFmcChMOkJzsrY3xgw YcBPrAMipOn34XET6lfU5xmem/NSO6dn5bfVUzx3vXqrcq5J26cdP9DraWBw9kth9RM4 ZEoIhB30eylsyqC+bBwoned+sm1fvSG980njnWDcZO+XUhtDNalHnyPWclNCojmomU9r pkQZkjfsXAbLe78VXjdYJzkjvpfaFQh7ffzpHoqI7ZmyMpfEntiQF9WrMYaJxrBknlJQ w13w== 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=hw6aQJa1MO9WdpxwzimvLityGgLsFlQla0AXaHMQmt0=; b=AKGH9rIZXWWpM+ITXjw/F8S8OdjvHl5cqQqq3B/8Yp0SYg9M5bZ4tk1xCms9xTGJKS ZtDx/Y8DJDK1lXotMwqZMGgIchFoZfGgzhoGjos+Lef7zdjj5pG2diK6UUMMxevYXcJm gQG4ihtzbYVtq7PRQg8jSdzt+SlUpUN1kOFLMRY4OuV2Qr8AaXb0+yQOrTbgzYiUzCJ1 4ezmpvOy6Kd00aCvWafelSIiDqvDhkbJMYEYhV5SU9SC5FQ0yYPqgD5kFwk5+PStwq5+ 4enlFw64FPNv8J+sUxrO4nE2CTCyxkZZ2V04RqF1uid2eGpPIReg1GgUi79Hd6wPgw0z LHXg== X-Gm-Message-State: AOAM5336Ps6NuoeF8odHhN53CG2WogTvnrQwOzFjacOjfJIGE7venY8H D6A/G7Dlwd0wzWSH6bQ6L4yAchu2cMIiRj4mTruTUg== X-Received: by 2002:a81:1748:0:b0:2d6:41ae:1384 with SMTP id 69-20020a811748000000b002d641ae1384mr22200124ywx.293.1645508891454; Mon, 21 Feb 2022 21:48:11 -0800 (PST) MIME-Version: 1.0 References: <20220211013032.623763-1-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Mon, 21 Feb 2022 21:48:00 -0800 Message-ID: Subject: Re: [PATCH v3 1/1] mm: fix use-after-free when anon vma name is used after vma is freed To: Michal Hocko Cc: Andrew Morton , Colin Cross , Sumit Semwal , Dave Hansen , Kees Cook , Matthew Wilcox , "Kirill A . Shutemov" , Vlastimil Babka , Johannes Weiner , "Eric W. Biederman" , Christian Brauner , legion@kernel.org, ran.xiaokai@zte.com.cn, sashal@kernel.org, Chris Hyser , Davidlohr Bueso , Peter Collingbourne , caoxiaofeng@yulong.com, David Hildenbrand , Cyrill Gorcunov , linux-mm , LKML , kernel-team , syzbot+aa7b3d4b35f9dc46a366@syzkaller.appspotmail.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 17, 2022 at 11:54 AM Suren Baghdasaryan wrote: > > On Wed, Feb 16, 2022 at 12:06 AM Michal Hocko wrote: > > > > On Tue 15-02-22 15:02:54, Suren Baghdasaryan wrote: > > > On Tue, Feb 15, 2022 at 12:05 PM Michal Hocko wrote: > > > > > > > > One thing I was considering is to check agains ref counte overflo (a > > > > deep process chain with many vmas could grow really high. ref_count > > > > interface doesn't provide any easy way to check for overflows as far as > > > > I could see from a quick glance so I gave up there but the logic would > > > > be really straightforward. We just create a new anon_vma_name with the same > > > > content and use it when duplicating if the usage grow really > > > > (arbitrarily) high. > > > > > > I went over proposed changes. I see a couple small required fixes > > > (resetting the name to NULL seems to be missing and I think > > > dup_vma_anon_name needs some tweaking) but overall quite > > > straight-forward. > > > > OK, great that this makes sense to you. As I've said I didn't really go > > into details, not even dared to boot that to test. So it will very > > likely need some more work but I do not expect this to grow much. > > > > > I'll post a separate patch to do this refactoring. > > > The original patch is fixing the UAF issue, so I don't want to mix it > > > with refactoring. Please let me know if you see an issue with > > > separating it that way. > > > > Well, I am not sure TBH. Look at diffstats. Your fix > > 2 files changed, 63 insertions(+), 17 deletions(-) > > the refactoring which should fix this and potentially others that might > > be still lurking there (because mixing shared pointers and their internal > > objects just begs for problems) is > > 7 files changed, 63 insertions(+), 86 deletions(-) > > > > more files touched for sure but the net result is much more clear and a > > much more code removed. > > The overflow logic would make it bigger but I guess the existing scheme > > needs it as well. > > Ok, I'll see how to slice it after it's complete and tested. > Thanks for the input! I posted the new patchset that includes: 1. refactoring of the code suggested by Michal: https://lore.kernel.org/all/20220222054025.3412898-1-surenb@google.com 2. refcount overflow protection suggested by Michal: https://lore.kernel.org/all/20220222054025.3412898-2-surenb@google.com 3. UAF fix (originally implemented by this patch) reimplemented after the first two changes: https://lore.kernel.org/all/20220222054025.3412898-3-surenb@google.com Hopefully this sequence makes sense. Thanks, Suren. > > > > > I would also claim that both approaches are really painful to review > > because the existing model spreads into several areas and it is not > > really clear you caught them all just by staring into the diff so both > > will be rather painful to backport to older kernels. Fortunately this > > would be only 5.17. > > -- > > Michal Hocko > > SUSE Labs