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=-11.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 B9098C433DF for ; Tue, 18 Aug 2020 08:31:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6EEFE2067C for ; Tue, 18 Aug 2020 08:31:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Wv+1pa2A" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6EEFE2067C 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 D3ACA6B0006; Tue, 18 Aug 2020 04:31:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CF3866B0007; Tue, 18 Aug 2020 04:31:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD9956B0008; Tue, 18 Aug 2020 04:31:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0178.hostedemail.com [216.40.44.178]) by kanga.kvack.org (Postfix) with ESMTP id A62306B0006 for ; Tue, 18 Aug 2020 04:31:49 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 5FC45180AD838 for ; Tue, 18 Aug 2020 08:31:49 +0000 (UTC) X-FDA: 77163021138.05.fear85_46057dd2701d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin05.hostedemail.com (Postfix) with ESMTP id 31BAA180137D1 for ; Tue, 18 Aug 2020 08:31:49 +0000 (UTC) X-HE-Tag: fear85_46057dd2701d X-Filterd-Recvd-Size: 5194 Received: from mail-lf1-f65.google.com (mail-lf1-f65.google.com [209.85.167.65]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Tue, 18 Aug 2020 08:31:48 +0000 (UTC) Received: by mail-lf1-f65.google.com with SMTP id c15so9791270lfi.3 for ; Tue, 18 Aug 2020 01:31:48 -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=Q8GP7eS1LzqVo1eId0/J96ZQfgvz1Pc6gH5ak12QY8s=; b=Wv+1pa2AmKmIwoKJdEL2ArgVsY1NxHFTuMHeNtykD6cHJqyOs6Ldd9+CJCFjNiNw1n d//IcpMHQNlTzB1i8GiRa4VxLjdUliW2WYb/GTUaK1vaDU8mAYXpoo2Jc46qsC3kP5Wm 0pn0jblTpfNawL8JTIl/OAsSIKZMS4Sd0olHFj2Qds9nFW/nRCvT6D0zZUS+m7KgqxpJ O7MvpSd5P3cLMl/q2NEF24plBojGwsdc7mNKcUet6FFV5RSF4oPL4Ina3hGzvu2YYh7C TJKOo4Orwsi4xp3qCJiXrJvCnVL2jVGuBxHVWeLy2/eYHcNpXYbAf5wrxAilDZcXCJVk kfFA== 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=Q8GP7eS1LzqVo1eId0/J96ZQfgvz1Pc6gH5ak12QY8s=; b=XKlb9RUVpS6zrz9RCg9kEVQNgEYwi1PZuKRg+DJuYhV918eGcqGYzjnYrAIGrWwPTh qqGY7z1Q/e5AIpSRieXwGUZjfWaQ6m0sUONfM+HYzQ1zffPYUOEq9u6LAACrYvrPy3Sn sINNBIDfBfe19tqdQzDvmM9YEI/uascj1xMORYoVJ7DaqA+HdkFc46qp8tcIPtgQ6M9Z 72UbXJifv0bjvKaeWhkwjyoiA0W6HzHSbTIfDoVapeFJKIziSPF45dDW6Y4EuwHIz/on ApgoTtG27CTTN6bshIBdPF4/HtLol9rMVG8NC6yXp3+ceSkvRcnywQRw+tk4Q/zP25wE dbjQ== X-Gm-Message-State: AOAM5322JjODAdUvYcYMeib06DnHlXA3POWL55NfpIqNm4ckxVSRBd6D YdPylp3zE35ZC2RBVeKGvsMRjZ6wJKfr0Ohe8QCZxQ== X-Google-Smtp-Source: ABdhPJwOK2qkpFlid8UNu4o909xNlNZeU/CcgMi47GISHCDqEJo0W4B9K2Dvq8R5VeBxjw2o4Ig7Cozq0ziLwGTgteY= X-Received: by 2002:a19:4844:: with SMTP id v65mr9475947lfa.184.1597739506937; Tue, 18 Aug 2020 01:31:46 -0700 (PDT) MIME-Version: 1.0 References: <20200818061239.29091-1-jannh@google.com> <20200818061239.29091-5-jannh@google.com> In-Reply-To: From: Jann Horn Date: Tue, 18 Aug 2020 10:31:20 +0200 Message-ID: Subject: Re: [PATCH v3 4/5] binfmt_elf, binfmt_elf_fdpic: Use a VMA list snapshot To: Linus Torvalds Cc: Andrew Morton , Christoph Hellwig , Linux Kernel Mailing List , Linux-MM , linux-fsdevel , Alexander Viro , "Eric W . Biederman" , Oleg Nesterov Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 31BAA180137D1 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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, Aug 18, 2020 at 10:18 AM Linus Torvalds wrote: > On Mon, Aug 17, 2020 at 11:13 PM Jann Horn wrote: > > > > /* > > * If this looks like the beginning of a DSO or executable mapping, > > + * we'll check for an ELF header. If we find one, we'll dump the first > > + * page to aid in determining what was mapped here. > > + * However, we shouldn't sleep on userspace reads while holding the > > + * mmap_lock, so we just return a placeholder for now that will be fixed > > + * up later in vma_dump_size_fixup(). > > I still don't like this. > > And I still don't think it's necessary. > > The whole - and only - point of "check if it's an ELF header" is that > we don't want to dump data that could just be found by looking at the > original binary. > > But by the time we get to this point, we already know that > > (a) it's a private mapping with file backing, and it's the first page > of the file > > (b) it has never been written to and it's mapped for reading > > and the choice at this point is "don't dump at all", or "dump just the > first page". > > And honestly, that whole "check if it has the ELF header" signature > was always just a heuristic. Nothing should depend on it anyway. > > We already skip dumping file data under a lot of other circumstances > (and perhaps equally importantly, we already decided to dump it all > under other circumstances). > > I think this DUMP_SIZE_MAYBE_ELFHDR_PLACEHOLDER hackery is worse than > just changing the heuristic. > > So instead, just say "ok, if the file was executable, let's dump the > first page". > > The test might be as simple as jjust checking > > if (file_inode(vma->vm_file)->i_mode & 0111) > > and you'd be done. That's likely a _better_ heuristic than the "let's > go look at the random first word in memory". > > Your patches look otherwise fine, but I really really despise that > DUMP_SIZE_MAYBE_ELFHDR_PLACEHOLDER, and I don't think it's even > necessary. Yeah, good point, it's a pretty ugly hack. I'll make a new version along the lines of what you suggested.