Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp829804rwb; Wed, 14 Dec 2022 03:25:41 -0800 (PST) X-Google-Smtp-Source: AA0mqf7NgKZERgCkN2C5u3cYPWS3TljuWxWFEnqm0juNot4Xsvlo1nIKkndmaMpByrQKrJ4xd7F6 X-Received: by 2002:a17:906:1c0c:b0:7c1:e7a:62e6 with SMTP id k12-20020a1709061c0c00b007c10e7a62e6mr20067875ejg.71.1671017140763; Wed, 14 Dec 2022 03:25:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671017140; cv=none; d=google.com; s=arc-20160816; b=Vs5ESjtTvVJWW1bGYHbVHSmuwnVNFFqUkcy4LMen+bXYh6Rs3g6GIiTAJzgpH7BJ1f fLexnyOutRS5BOFNdOOq/rXWQ5gz+1eU4amMJRzvCXnqdrd6Iv5sHBi8jGCCffNP/zSI 4aOqg/p3BGzNL6tEFqgsTIWub3a1N+IREwiE3hOdk4E3+333/YZFaxJYAdicZ8/FJ/rK HM0xMBlKgJ4DisoUfqjwF4JI2/FAP08eaEqpc2sBQbltIsDbBBZXLrA+tDRDDbBXFwto 44NWSjrApcc4CTvEpXKGfpT7nOxo8WpKNvXMybu6I57tDBMQURKOFKCzSTtNkyU3rw54 nFbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=2NMzT5WxxanwVRj3ltZhzzgNHC+/kTxBdOPUCNNU8Ak=; b=nbCJYn3sfof4QggaIX5qEDv4PC3pHQYLcfcSAruM7jt0PxYtkRdiBu2FSjVPk+8tLb whguZ/bXyv1ACF2zpyBQB1U3rbUaltNZHbtNIshiO6a+MnkVBMCyJyA11tqGRjftXEtQ 1zhUbHFFeYfsrkihKMswMNKn0sHaWU3iefvzn9P9HD6NmfKoeb5hvjB7iFw43u5oxd7L JI8tu4K6LnqofFa+YnXH2qnp0UXNL/jpDW6+BLO/ZpTLcU5a6LCFIJyFRad7RN81X36i /fjYGvcrJbjr4O9VN2fHQsWaT0f2GCujESZswq2A+TX4ey8ADTqOtWHMdF46N/7lZePZ UMOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TwKaFh7R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ss2-20020a170907c00200b007c0a6ffebbdsi9179882ejc.722.2022.12.14.03.25.23; Wed, 14 Dec 2022 03:25:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TwKaFh7R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237788AbiLNLIZ (ORCPT + 69 others); Wed, 14 Dec 2022 06:08:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238194AbiLNLIX (ORCPT ); Wed, 14 Dec 2022 06:08:23 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBC94B75 for ; Wed, 14 Dec 2022 03:07:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671016058; 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=2NMzT5WxxanwVRj3ltZhzzgNHC+/kTxBdOPUCNNU8Ak=; b=TwKaFh7RCX8AcHA9aFQ8uk6/2ZQfOMJGUMbIIsVscOdCs1jV66mR7XHLSFgRzq4TXVcY3N WM9jtk99FyF5xk/2A9ixHX8nSfo62vyot8fg24AGaYJcl7+GN/oEjgpsWPTkoYHiMZRXGv Yng4B8DEkZvjU1i9sSOU1RfMa1sjCPk= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-592-XOLkrDBBM8-OvpkBgf87LA-1; Wed, 14 Dec 2022 06:07:37 -0500 X-MC-Unique: XOLkrDBBM8-OvpkBgf87LA-1 Received: by mail-ed1-f71.google.com with SMTP id w15-20020a05640234cf00b0046d32d7b153so9167177edc.0 for ; Wed, 14 Dec 2022 03:07:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2NMzT5WxxanwVRj3ltZhzzgNHC+/kTxBdOPUCNNU8Ak=; b=iy+wSSwQRrplejhb/H3nOgKuYbmZrNIdkoslhildF5cyIOpcE3RWSQ8GieOEOtBTUG KDzA6ZtVp6jQohMgSN68Nxo1DA1E4Quu9czzbKBvFw8oQSeyDA8hUqi6gClCsJBgXHUj BzvXB7KeXQEJd1gHAgeIQWh/Gztf4rdyiIREyfiqfmbXBFpwBDLYDx9Tca6fhJJF94Nr Tv9e6BTMhz7dIhSp9gBL4yfs/eIqBzh/Lpie4sb+P+E6eX3iXLKa8/qqzV343qe6Tptu uZYe5/+PN5tpMueK8AY2aXPBSCkJbAAdo+eP+SGG0vtH04gAmMyBdLIibGxfeQ6yXbS/ afrA== X-Gm-Message-State: ANoB5plCqYc3LIPRHZVf07wyhuCqxG1wHiohBF4m4OJp4zEuMkUp0kcB bI7Gseq8SKueUyzEpQ8WQm+7n3HoWZvZwrohlJqsegfOYsAw+wqJJJdhlcDXxRO3C4OAQL/SADj 8YcbL78h7IMzsIp7ALQKvcJp5 X-Received: by 2002:a05:6402:2408:b0:461:f0a7:156 with SMTP id t8-20020a056402240800b00461f0a70156mr21772629eda.36.1671016055975; Wed, 14 Dec 2022 03:07:35 -0800 (PST) X-Received: by 2002:a05:6402:2408:b0:461:f0a7:156 with SMTP id t8-20020a056402240800b00461f0a70156mr21772623eda.36.1671016055802; Wed, 14 Dec 2022 03:07:35 -0800 (PST) Received: from ?IPV6:2001:1c00:c1e:bf00:d69d:5353:dba5:ee81? (2001-1c00-0c1e-bf00-d69d-5353-dba5-ee81.cable.dynamic.v6.ziggo.nl. [2001:1c00:c1e:bf00:d69d:5353:dba5:ee81]) by smtp.gmail.com with ESMTPSA id w14-20020a056402070e00b00463a83ce063sm5991090edx.96.2022.12.14.03.07.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 14 Dec 2022 03:07:35 -0800 (PST) Message-ID: Date: Wed, 14 Dec 2022 12:07:34 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: Dubious usage of VM_SHARED in atomisp_fops.c Content-Language: en-US, nl To: David Hildenbrand Cc: "linux-mm@kvack.org" , Mauro Carvalho Chehab , "linux-media@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Sakari Ailus , Andy Shevchenko References: From: Hans de Goede In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham 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 Hi David, On 12/14/22 11:22, David Hildenbrand wrote: > Hi, > > going over all VM_SHARED and VM_MAYSHARE user in the kernel, I stumbled over the following dubious code in drivers/staging/media/atomisp/pci/atomisp_fops.c: > > > if (!(vma->vm_flags & (VM_WRITE | VM_READ))) >     return -EACCES; > > ... > > if (!(vma->vm_flags & VM_SHARED)) { >     /* Map private buffer. >      * Set VM_SHARED to the flags since we need >      * to map the buffer page by page. >      * Without VM_SHARED, remap_pfn_range() treats >      * this kind of mapping as invalid. >      */ >     vma->vm_flags |= VM_SHARED; >     ret = hmm_mmap(vma, vma->vm_pgoff << PAGE_SHIFT); >     ... > } > > > We're converting a writable MAP_PRIVATE mapping ("COW mapping") into a writable MAP_SHARED mapping, to hack around the is_cow_mapping() check in remap_pfn_range_notrack(). > > We're not even setting VM_MAYSHARE and turn the mapping silently into something with completely different semantics. > > > That code has to go. > > > One approach would be to reject such mappings (no idea if user space relies on private mappings), the other one would be to remove this driver. Judging that the driver already was marked broken in 2020 (ad85094b293e ("Revert "media: staging: atomisp: Remove driver"")), maybe it's time for the driver to go. There is still quite a lot of hw out there (and being used with Linux) which has camera sensors connected to the atomisp2. Recently a community member finally managed to actually make the driver work and I have been working on cleaning it up since. For 6.2 I set of patches converting the driver to the videobuf2 framework will land and as part of that all the problematic code you point to above has been removed. If you grep for VM_SHARED under drivers/staging/media/atomisp in linux-next you will find no hits :) Regards, Hans