From patchwork Mon Dec 16 17:47:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 181772 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp4654819ile; Mon, 16 Dec 2019 10:08:22 -0800 (PST) X-Google-Smtp-Source: APXvYqzOntadEqnRqD7vdFiR4xUmLghlvojFdP6FG1RLom4E5igp0FboQKN2oT+6mB8Du5LJaqK5 X-Received: by 2002:a9d:6f07:: with SMTP id n7mr32157071otq.112.1576519702697; Mon, 16 Dec 2019 10:08:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576519702; cv=none; d=google.com; s=arc-20160816; b=QxW4/1HBELOweXabXqzVrWXz6o5OYPd9rw5aZX4AMYAY3lGMo7VHeqg1CvOOd3Asfb /wgCR8u2SQznb9l/9MNgek30MRACVzcGgWB57MDocN1w1t3aoyvTVxX7Bn8FyJwttJay Z5KcFHYDBaKwqIzX1xlGPOok2oKzp9Egg2EH4twOvtlIoL8a3qurPmg0dJoMsKQCa14c Zx7gA+y5nOa/SVU/TAa209pZcUoTyetcL7qsRN6fHpkJU85bQU6E/ZZfy2Oar86SOvbj 1eCXuJq2N2cOOeLvYuaYkzgC8xx3Y1Ut8leMQruptBuf7692nEdDSNqcOuskiMaNTM5U YoEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Idg9Phb4YIVJ17OXVOXxqIZETdQI4sZ+3EZOriDW71Y=; b=ceoV05HMZ9MYLcolTIWL2IMnTjDPi5a+M5p56n1pA4IQSI8bp99yV0tSFqJyzADcZY 6p22D2DO6xKlaZ6DOEZNwSJek8/gnKb8nhA5E/H+mV0f/RYno3U3Wx44bFj8EDJGsxCm uCXHCJJGpdj+OJYNRQ3GNDuF9XOXCAlisOjfOvghmuGUHeK2qULDtBOqM8VaDoNPxxRY m/bTFkan30XldkU52JycjURwd6hF1exGl7dno2/0XXrB+m5G/lrUqD3pKSCFzRLmewzn 0IVS6b2eQGewmFQcNMAoXLnAPflEJkvmlnqxziAkpxprfEaCsQIdCdiT9HwCWTUWFmM2 nxdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Rwj56Ahj; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3si10724619oir.132.2019.12.16.10.08.22; Mon, 16 Dec 2019 10:08:22 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Rwj56Ahj; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730252AbfLPSIV (ORCPT + 14 others); Mon, 16 Dec 2019 13:08:21 -0500 Received: from mail.kernel.org ([198.145.29.99]:49778 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730124AbfLPSIT (ORCPT ); Mon, 16 Dec 2019 13:08:19 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 50DF22072B; Mon, 16 Dec 2019 18:08:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576519698; bh=WSQUyA0Xex8fQZML6qSyOtUq3dH3w80jNaQVKkPJlGY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rwj56AhjRoAm82EyChkHZybxpWeVqYs4X7hevkhvaTBoRWKx50sLfpURYRBWrvVAO VHU2cPyjdNQgoH7f0BbOIamZmNSBB1FaRWX59ant++oFWvw2bmUkHd4JViMr8STnxz ytrcjuKv2tuX7JeAb1asdSyAn1n/vsSY4CYktsPU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arnd Bergmann , Stanimir Varbanov , Hans Verkuil , Mauro Carvalho Chehab Subject: [PATCH 5.3 007/180] media: venus: remove invalid compat_ioctl32 handler Date: Mon, 16 Dec 2019 18:47:27 +0100 Message-Id: <20191216174807.376288047@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191216174806.018988360@linuxfoundation.org> References: <20191216174806.018988360@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Arnd Bergmann commit 4adc0423de92cf850d1ef5c0e7cb28fd7a38219e upstream. v4l2_compat_ioctl32() is the function that calls into v4l2_file_operations->compat_ioctl32(), so setting that back to the same function leads to a trivial endless loop, followed by a kernel stack overrun. Remove the incorrect assignment. Cc: stable@vger.kernel.org Fixes: 7472c1c69138 ("[media] media: venus: vdec: add video decoder files") Fixes: aaaa93eda64b ("[media] media: venus: venc: add video encoder files") Signed-off-by: Arnd Bergmann Acked-by: Stanimir Varbanov Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Greg Kroah-Hartman --- drivers/media/platform/qcom/venus/vdec.c | 3 --- drivers/media/platform/qcom/venus/venc.c | 3 --- 2 files changed, 6 deletions(-) --- a/drivers/media/platform/qcom/venus/vdec.c +++ b/drivers/media/platform/qcom/venus/vdec.c @@ -1104,9 +1104,6 @@ static const struct v4l2_file_operations .unlocked_ioctl = video_ioctl2, .poll = v4l2_m2m_fop_poll, .mmap = v4l2_m2m_fop_mmap, -#ifdef CONFIG_COMPAT - .compat_ioctl32 = v4l2_compat_ioctl32, -#endif }; static int vdec_probe(struct platform_device *pdev) --- a/drivers/media/platform/qcom/venus/venc.c +++ b/drivers/media/platform/qcom/venus/venc.c @@ -1230,9 +1230,6 @@ static const struct v4l2_file_operations .unlocked_ioctl = video_ioctl2, .poll = v4l2_m2m_fop_poll, .mmap = v4l2_m2m_fop_mmap, -#ifdef CONFIG_COMPAT - .compat_ioctl32 = v4l2_compat_ioctl32, -#endif }; static int venc_probe(struct platform_device *pdev) From patchwork Mon Dec 16 17:50:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 181776 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp4662003ile; Mon, 16 Dec 2019 10:13:56 -0800 (PST) X-Google-Smtp-Source: APXvYqwgtic0DnmdiVIHhpx3EJGbhDpfB6wId4jIEooli4uX57srqJ39+imcaV1Vjwke9k+R39p9 X-Received: by 2002:a9d:5552:: with SMTP id h18mr32039569oti.122.1576520036239; Mon, 16 Dec 2019 10:13:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576520036; cv=none; d=google.com; s=arc-20160816; b=BA80PlVDQmxbGSP5Fs0nn2inwnostRz/u7I7f1CdkeqGjVoC8FSpDBnqI2MxNQLmj6 k4ntPX4YWLYt7bkDj9/zygvKFdShY5O+jBwNUxTNXLlDT126vs1BOj+kTlqhfvLh3rel AVTidyyxeivPSZKu7zGgnf7+e+L4xHctK6gQhmbcHKGQc2TgYAB4nlQD7zZ033ZX8g5i qlbAPZiiplRYXaKcojU61OzDGNydqTG7kY2j822THf6P+FwuMnqxOvcFq0WOqNE1LfUS qhRq/aQOOdNf7OTGtsZ0UTGidDQXq2H4je26kNmWvWyJ/gMpcoJhEF8VFKDfVomR4TyO mIFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2jyEYB8s84HH6vs8mDUPTOTX58CuqhGIhUjP0+Hg5W4=; b=Tf2sK68BrzVxTUOMUZKJJuyBTJkITudlMsyu+SPEJtj0yF0zXp9IWnAt80YBz4Rrsx a8gdz7rlUCqeAcmrzpmfAkXHkob6r/VH5oQQz1tIqduQ0ni8yHBE0lIJ5sdjchiIJ8DO +vkx4/EtCvftsoh3/R7UEAUJi1gzqenU3My8zy+wS65/56/fvMobsBlXdCvvNNB/zSs4 JUx6tRm0TdlaW4cKDTL6OykV0YEVqOvdiGml9oh3pwYNSvPhNMn7XqCf8Gmn0Ad0ER/J bh9os/VuFYA74QpvnoBdSl3lufKwliYq5P5wufC3NLAjyljDQTPMJOnfSe9phvGVAbDN CRqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QyFdjh+l; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f60si11380774otf.119.2019.12.16.10.13.56; Mon, 16 Dec 2019 10:13:56 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QyFdjh+l; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731155AbfLPSNy (ORCPT + 14 others); Mon, 16 Dec 2019 13:13:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:60644 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730830AbfLPSNx (ORCPT ); Mon, 16 Dec 2019 13:13:53 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 53CAC207FF; Mon, 16 Dec 2019 18:13:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576520032; bh=xIAUMyEs4IxOo03+cfmn9uPZNxEon7WbX0KauaAyN3Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QyFdjh+ldUz+Q1BjNf5+CMjhhxKrB6+X4Si3iUgplfDCera+5ISqC6UgN99xYkLie q55yZpEtqn8bLn0CYO7lDQVgQ6Hwsq18KIh0i4DCJNrmsSAdZ72cihGW9sQCiL/ij2 WhB2GV5EfpwuU3SkbMrDLnMC1JL5tfjDP3Eb721c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nicolas Geoffray , "Joel Fernandes (Google)" , Hugh Dickins , Shuah Khan , Andrew Morton , Linus Torvalds Subject: [PATCH 5.3 170/180] mm, memfd: fix COW issue on MAP_PRIVATE and F_SEAL_FUTURE_WRITE mappings Date: Mon, 16 Dec 2019 18:50:10 +0100 Message-Id: <20191216174847.528262321@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191216174806.018988360@linuxfoundation.org> References: <20191216174806.018988360@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Nicolas Geoffray commit 05d351102dbe4e103d6bdac18b1122cd3cd04925 upstream. F_SEAL_FUTURE_WRITE has unexpected behavior when used with MAP_PRIVATE: A private mapping created after the memfd file that gets sealed with F_SEAL_FUTURE_WRITE loses the copy-on-write at fork behavior, meaning children and parent share the same memory, even though the mapping is private. The reason for this is due to the code below: static int shmem_mmap(struct file *file, struct vm_area_struct *vma) { struct shmem_inode_info *info = SHMEM_I(file_inode(file)); if (info->seals & F_SEAL_FUTURE_WRITE) { /* * New PROT_WRITE and MAP_SHARED mmaps are not allowed when * "future write" seal active. */ if ((vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_WRITE)) return -EPERM; /* * Since the F_SEAL_FUTURE_WRITE seals allow for a MAP_SHARED * read-only mapping, take care to not allow mprotect to revert * protections. */ vma->vm_flags &= ~(VM_MAYWRITE); } ... } And for the mm to know if a mapping is copy-on-write: static inline bool is_cow_mapping(vm_flags_t flags) { return (flags & (VM_SHARED | VM_MAYWRITE)) == VM_MAYWRITE; } The patch fixes the issue by making the mprotect revert protection happen only for shared mappings. For private mappings, using mprotect will have no effect on the seal behavior. The F_SEAL_FUTURE_WRITE feature was introduced in v5.1 so v5.3.x stable kernels would need a backport. [akpm@linux-foundation.org: reflow comment, per Christoph] Link: http://lkml.kernel.org/r/20191107195355.80608-1-joel@joelfernandes.org Fixes: ab3948f58ff84 ("mm/memfd: add an F_SEAL_FUTURE_WRITE seal to memfd") Signed-off-by: Nicolas Geoffray Signed-off-by: Joel Fernandes (Google) Cc: Hugh Dickins Cc: Shuah Khan Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/shmem.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2198,11 +2198,14 @@ static int shmem_mmap(struct file *file, return -EPERM; /* - * Since the F_SEAL_FUTURE_WRITE seals allow for a MAP_SHARED - * read-only mapping, take care to not allow mprotect to revert - * protections. + * Since an F_SEAL_FUTURE_WRITE sealed memfd can be mapped as + * MAP_SHARED and read-only, take care to not allow mprotect to + * revert protections on such mappings. Do this only for shared + * mappings. For private mappings, don't need to mask + * VM_MAYWRITE as we still want them to be COW-writable. */ - vma->vm_flags &= ~(VM_MAYWRITE); + if (vma->vm_flags & VM_SHARED) + vma->vm_flags &= ~(VM_MAYWRITE); } file_accessed(file);