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=-15.1 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 7BA34C4727F for ; Wed, 30 Sep 2020 23:22:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3F9782076A for ; Wed, 30 Sep 2020 23:22:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="o6wFEBgI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732203AbgI3XWV (ORCPT ); Wed, 30 Sep 2020 19:22:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731321AbgI3XWP (ORCPT ); Wed, 30 Sep 2020 19:22:15 -0400 Received: from mail-yb1-xb42.google.com (mail-yb1-xb42.google.com [IPv6:2607:f8b0:4864:20::b42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06C65C061755 for ; Wed, 30 Sep 2020 16:22:14 -0700 (PDT) Received: by mail-yb1-xb42.google.com with SMTP id v60so2564309ybi.10 for ; Wed, 30 Sep 2020 16:22:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=PGlnswLCEbO8zj3EJbctth4RiRNCq3y8UGSmi1Mw83E=; b=o6wFEBgIzTm9Qy5lEIMUS/k8X2PABBVt1TCORpbI/sROaLzcsJIjQraiWU9XcnujRF 4EqBI/4aPa/ucrjdz0MSrCEVlut+eqiudSD5l8CaT+MmrMctt0aK+iO8fX52uI6VogGP vVd8d5P04W2IllMoLxdJpu3I4i4p3UD8uGUoATr51xPDShI0sM1ctjqsJsJWQUUdNUr6 fgjee1q2DQYiNxzaEwnEG+JzDY8joxBgMNyTAp7w7uvMpoAZImKfwkID0abaMoow8aG5 03hxtsXXDXkLKYEToY+C8ZAshPt/pC2XGh/AivywvzI5x7m8C5L5Xn+JBuFmSGjxsh7T VArg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=PGlnswLCEbO8zj3EJbctth4RiRNCq3y8UGSmi1Mw83E=; b=gWwUZ9+MDfobsMHK01GjWme5sVPmJLdaVTN7lI+L8C1fnoMGnfhT/0rB2yrE4EOI7o xhbWKNeFUlmpFsSfqGegwkrhR7kKJVEh1pe6MsuTS3mjW8qrfxiFhz+SbdWFsImSJcXI S+/QpMu6+aJAZjZVSVz0yHwR5F5ca8QVQtMZrF0O/Qj+/poPWzkh/FmFRT7yh3CnUSGw xbKStelU6jk99YhGb1L7meYBifTHbA1qRXWBy4wt+e78UukMrPMTDjNuVXnXmQ/9pVNO 2wdvKqSHmwX7zvntKUawWfj5VIMGN045U/0Py129ZjAYXOjVipWPSEXQnVZ3zONwKW18 I3LQ== X-Gm-Message-State: AOAM5320Wdm/UbysnYNts77lcGxS3qTBUi5zACUNlYoD+Rb+qRk0Zfoa 3oMqG3BMsk1qBOozq5VR3k70Mj27OzsROhB3xbkkxg== X-Google-Smtp-Source: ABdhPJx0nCwi62CTHcPTZSjFp3h6IxK3xoGUNxz4YS/KvWpXzEDzAx8kw3NKuYQBZBxL81jZXILzT/zQEcR9j/CcM70= X-Received: by 2002:a25:c549:: with SMTP id v70mr6871788ybe.516.1601508133034; Wed, 30 Sep 2020 16:22:13 -0700 (PDT) MIME-Version: 1.0 References: <20200930011944.19869-1-jannh@google.com> In-Reply-To: From: Michel Lespinasse Date: Wed, 30 Sep 2020 16:22:00 -0700 Message-ID: Subject: Re: [PATCH 2/4] binfmt_elf: Take the mmap lock around find_extend_vma() To: Jann Horn Cc: Andrew Morton , linux-mm , LKML , "Eric W . Biederman" , Mauro Carvalho Chehab , Sakari Ailus Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 29, 2020 at 6:20 PM Jann Horn wrote: > create_elf_tables() runs after setup_new_exec(), so other tasks can > already access our new mm and do things like process_madvise() on it. > (At the time I'm writing this commit, process_madvise() is not in mainline > yet, but has been in akpm's tree for some time.) > > While I believe that there are currently no APIs that would actually allow > another process to mess up our VMA tree (process_madvise() is limited to > MADV_COLD and MADV_PAGEOUT, and uring and userfaultfd cannot reach an mm > under which no syscalls have been executed yet), this seems like an > accident waiting to happen. > > Let's make sure that we always take the mmap lock around GUP paths as long > as another process might be able to see the mm. > > (Yes, this diff looks suspicious because we drop the lock before doing > anything with `vma`, but that's because we actually don't do anything with > it apart from the NULL check.) > > Signed-off-by: Jann Horn Thanks for these cleanups :) Acked-by: Michel Lespinasse 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=-15.1 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 15785C4363D for ; Wed, 30 Sep 2020 23:22:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 69FDD20848 for ; Wed, 30 Sep 2020 23:22:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="o6wFEBgI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 69FDD20848 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CE51C6B0062; Wed, 30 Sep 2020 19:22:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C962B6B0068; Wed, 30 Sep 2020 19:22:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BABD66B006C; Wed, 30 Sep 2020 19:22:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0046.hostedemail.com [216.40.44.46]) by kanga.kvack.org (Postfix) with ESMTP id A5B606B0062 for ; Wed, 30 Sep 2020 19:22:14 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 64D413659 for ; Wed, 30 Sep 2020 23:22:14 +0000 (UTC) X-FDA: 77321303388.17.beds91_4f093f727196 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id 42C0C18150C22 for ; Wed, 30 Sep 2020 23:22:14 +0000 (UTC) X-HE-Tag: beds91_4f093f727196 X-Filterd-Recvd-Size: 3976 Received: from mail-yb1-f194.google.com (mail-yb1-f194.google.com [209.85.219.194]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Wed, 30 Sep 2020 23:22:13 +0000 (UTC) Received: by mail-yb1-f194.google.com with SMTP id b142so2570606ybg.9 for ; Wed, 30 Sep 2020 16:22:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=PGlnswLCEbO8zj3EJbctth4RiRNCq3y8UGSmi1Mw83E=; b=o6wFEBgIzTm9Qy5lEIMUS/k8X2PABBVt1TCORpbI/sROaLzcsJIjQraiWU9XcnujRF 4EqBI/4aPa/ucrjdz0MSrCEVlut+eqiudSD5l8CaT+MmrMctt0aK+iO8fX52uI6VogGP vVd8d5P04W2IllMoLxdJpu3I4i4p3UD8uGUoATr51xPDShI0sM1ctjqsJsJWQUUdNUr6 fgjee1q2DQYiNxzaEwnEG+JzDY8joxBgMNyTAp7w7uvMpoAZImKfwkID0abaMoow8aG5 03hxtsXXDXkLKYEToY+C8ZAshPt/pC2XGh/AivywvzI5x7m8C5L5Xn+JBuFmSGjxsh7T VArg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=PGlnswLCEbO8zj3EJbctth4RiRNCq3y8UGSmi1Mw83E=; b=IcubQc52g8NaILavwb/fZkx8DIEvqmnpdhaBQnUD67w3FwvB7MIYh6cty4HKaQ/5Aw B5Zgx4asxkqSBCFdajki5uPk3lwdDLza0lTZheYPR2JLLp0KnqXE5nwJ5GcHIPakMvhB O4o6hVDsWsWt/WdflCSZxOVMB/ofQ0WH61ivB9TutkN7z7NI71zxxH5F94EDeC92omuk Wgcr4LroUugFKlx2lyZdylIyDOjfL3G6HWFEwtoGnpEUrI2m+6kyo1ULHTITRnKhZzLY N2cyQzF5SbJ2bflg0dwoDnTjMOBVwm8GN2M8WrAEOdZJm0YSVMaE9IfWdhGaPoyaCf3F E0ig== X-Gm-Message-State: AOAM5312W0a+Yp8ULPFhi7Z9agtBXsDO6awlVUQNNtKNRyMGf6l1IwSF a5YSti4Z3hwEwuRRwGrgZHXehC6Vylg8V7LTJJan+g== X-Google-Smtp-Source: ABdhPJx0nCwi62CTHcPTZSjFp3h6IxK3xoGUNxz4YS/KvWpXzEDzAx8kw3NKuYQBZBxL81jZXILzT/zQEcR9j/CcM70= X-Received: by 2002:a25:c549:: with SMTP id v70mr6871788ybe.516.1601508133034; Wed, 30 Sep 2020 16:22:13 -0700 (PDT) MIME-Version: 1.0 References: <20200930011944.19869-1-jannh@google.com> In-Reply-To: From: Michel Lespinasse Date: Wed, 30 Sep 2020 16:22:00 -0700 Message-ID: Subject: Re: [PATCH 2/4] binfmt_elf: Take the mmap lock around find_extend_vma() To: Jann Horn Cc: Andrew Morton , linux-mm , LKML , "Eric W . Biederman" , Mauro Carvalho Chehab , Sakari Ailus Content-Type: text/plain; charset="UTF-8" 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 Tue, Sep 29, 2020 at 6:20 PM Jann Horn wrote: > create_elf_tables() runs after setup_new_exec(), so other tasks can > already access our new mm and do things like process_madvise() on it. > (At the time I'm writing this commit, process_madvise() is not in mainline > yet, but has been in akpm's tree for some time.) > > While I believe that there are currently no APIs that would actually allow > another process to mess up our VMA tree (process_madvise() is limited to > MADV_COLD and MADV_PAGEOUT, and uring and userfaultfd cannot reach an mm > under which no syscalls have been executed yet), this seems like an > accident waiting to happen. > > Let's make sure that we always take the mmap lock around GUP paths as long > as another process might be able to see the mm. > > (Yes, this diff looks suspicious because we drop the lock before doing > anything with `vma`, but that's because we actually don't do anything with > it apart from the NULL check.) > > Signed-off-by: Jann Horn Thanks for these cleanups :) Acked-by: Michel Lespinasse