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 B4055C19F2D for ; Tue, 9 Aug 2022 20:42:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2C0838E0002; Tue, 9 Aug 2022 16:42:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 26FB38E0001; Tue, 9 Aug 2022 16:42:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 111DD8E0002; Tue, 9 Aug 2022 16:42:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id F30558E0001 for ; Tue, 9 Aug 2022 16:42:11 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C002E1604DF for ; Tue, 9 Aug 2022 20:42:11 +0000 (UTC) X-FDA: 79781226462.05.0FFE849 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 5642D40024 for ; Tue, 9 Aug 2022 20:42:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660077730; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ft7/3/k2/7AI7wRPnrTn6/PiafTIMMMl8iv+c+g4UYE=; b=gAIeBLHopoPAWsO/TMPH7rNNJTXLoFoBmA2eqwTR5uz3HN/KkmkK2gMnYJsvU90Zw+U2LD Qb0WaVcMDtUde6Zr5V6YJw6LikuuObKS2ujdSyRqk/BlfTvXUI/PqS+WuUwn8RUyg8AKGi vKk3EyLEgyXkaHYYQkynMaIsw0I9nzc= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-533-pHvipWTRN4qJcHzuThCgaA-1; Tue, 09 Aug 2022 16:42:09 -0400 X-MC-Unique: pHvipWTRN4qJcHzuThCgaA-1 Received: by mail-wr1-f72.google.com with SMTP id k21-20020adfb355000000b0022079dc2559so2011034wrd.4 for ; Tue, 09 Aug 2022 13:42:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc; bh=Ft7/3/k2/7AI7wRPnrTn6/PiafTIMMMl8iv+c+g4UYE=; b=2205W+RUcbOBw9Erz5JoIT02KN7WFHyYsM6E0XUdQfkZOqwfQhgY7qvqsjfATvJcW2 zukoqc32AbOSQiixgsmdn51YCoXii93PuBoW/wS7L1///e+J2QlgZvhnGjRgKdlIgXh+ x/tHAIULuFoFGA29B437WouIaNReVRbjgo6piF0ADCFIA4Lys1gUtqcyYMwFYUSEy6BF 9oBcWTsEjmHHqYv+EOqT/nv8GCjtxV6ii8/BxVd5pumyeAdlA8ai5UA1BQnfbi6SeE0z 3DrSsBOx8E+svMZwu8h5huNXMeFzI/i1797rz8DaTzrOA2tVEsAnptS92mHvHwVJNQsD ZzVw== X-Gm-Message-State: ACgBeo1EZXPX9j4gmVmO/h9DErrRejxVdqm0PX96ubvPuIGyGqQI8El6 KayQV41qcis++tp6vG19KFqMMBAoEsIKmilXFALccKMcyZ4FkWLbnajCEyKDJTN4clxrUcDNSMZ noIIApIJootk= X-Received: by 2002:a05:6000:1f0e:b0:221:6d6f:5c7e with SMTP id bv14-20020a0560001f0e00b002216d6f5c7emr13477454wrb.256.1660077727991; Tue, 09 Aug 2022 13:42:07 -0700 (PDT) X-Google-Smtp-Source: AA6agR4iIiC6hStqy3Z4Hjcgi0BBwQ7RRcz3zdqmXKR+jrTcF24Ep9h2BTpKi9m93Ywx/SPxAehwzQ== X-Received: by 2002:a05:6000:1f0e:b0:221:6d6f:5c7e with SMTP id bv14-20020a0560001f0e00b002216d6f5c7emr13477446wrb.256.1660077727693; Tue, 09 Aug 2022 13:42:07 -0700 (PDT) Received: from ?IPV6:2003:cb:c705:3700:aed2:a0f8:c270:7f30? (p200300cbc7053700aed2a0f8c2707f30.dip0.t-ipconnect.de. [2003:cb:c705:3700:aed2:a0f8:c270:7f30]) by smtp.gmail.com with ESMTPSA id r27-20020adfa15b000000b0021d70a871cbsm14650710wrr.32.2022.08.09.13.42.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 09 Aug 2022 13:42:07 -0700 (PDT) Message-ID: <13f149cc-6535-8b50-04de-70437a679826@redhat.com> Date: Tue, 9 Aug 2022 22:42:06 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v1] mm/gup: fix FOLL_FORCE COW security issue and remove FOLL_COW To: Linus Torvalds Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, stable@vger.kernel.org, Andrew Morton , Greg Kroah-Hartman , Axel Rasmussen , Peter Xu , Hugh Dickins , Andrea Arcangeli , Matthew Wilcox , Vlastimil Babka , John Hubbard , Jason Gunthorpe References: <20220808073232.8808-1-david@redhat.com> <91e18a2f-c93d-00b8-7c1b-6d8493c3b2d5@redhat.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660077731; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Ft7/3/k2/7AI7wRPnrTn6/PiafTIMMMl8iv+c+g4UYE=; b=WPk2h35MG3bxWI5DdTgzD4JTcKhZjeT77yBWppYQF07QcNpu/DGFFrzxar5GnDuj7uJtsO kduqkyMXRXOK4TPOXrxGehXM82HgkfVLv1VYrbEhkGQKhrO0gCNEZJGFZu77TxYaKJPJM1 7gkk0PxaDzy9Wf2x5/OpxnwtyR6hZOE= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gAIeBLHo; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660077731; a=rsa-sha256; cv=none; b=pBV4Qdm6XcFNRCAS2Pkt0UxlVuX3qoEVadLKAw3po7TKsC88EDXlkWc4SuQ1rBShBvFlcf eazCEuqGZ1awymqrf1LIZKmFz4suT+kkNeeMoWJkEBojIC+bt4UQtOzOJjpoXDvbqdu2Mu KgNir7CmMWkSTpS4Q/kRpr5SgSQpRUQ= X-Rspamd-Queue-Id: 5642D40024 X-Rspamd-Server: rspam03 X-Rspam-User: Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gAIeBLHo; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com X-Stat-Signature: aphee1nqtiyrgt5j5z1ji4n4rx88rs9q X-HE-Tag: 1660077731-885791 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 09.08.22 22:30, Linus Torvalds wrote: > On Tue, Aug 9, 2022 at 1:20 PM David Hildenbrand wrote: >> >> IIUC VM_MAYSHARE is always set in a MAP_SHARED mapping, but for file >> mappings we only set VM_SHARED if the file allows for writes > > Heh. > > This is a horrific hack, and probably should go away. > > Yeah, we have that > > if (!(file->f_mode & FMODE_WRITE)) > vm_flags &= ~(VM_MAYWRITE | VM_SHARED); > > > but I think that's _entirely_ historical. > > Long long ago, in a galaxy far away, we didn't handle shared mmap() > very well. In fact, we used to not handle it at all. > > But nntpd would use write() to update the spool file, adn them read it > through a shared mmap. > > And since our mmap() *was* coherent with people doing write() system > calls, but didn't handle actual dirty shared mmap, what Linux used to > do was to just say "Oh, you want a read-only shared file mmap? I can > do that - I'll just downgrade it to a read-only _private_ mapping, and > it actually ends up with the same semantics". > > And here we are, 30 years later, and it still does that, but it leaves > the VM_MAYSHARE flag so that /proc//maps can show that it's a > shared mapping. I was suspecting that this code is full of legacy :) What would make sense to me is to just have VM_SHARED and make it correspond to MAP_SHARED, that would at least confuse me less. Once I have some spare cycles I'll see how easy that might be to achieve. -- Thanks, David / dhildenb