Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B0BA7E for ; Tue, 1 Nov 2022 11:29:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F888C433C1; Tue, 1 Nov 2022 11:29:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667302184; bh=6sP9h93YrpIv5TXNZMZ5AKmCbkXIrVhlzCLnufAOI8g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KzhNimWpqOzplMB57v1195F6FrlwL2TxO+ntTg0KSi0VMhikFHDgYNQL5Uyodjy6z VkbHcbP/CKRNFzrZ45r74LQhy2Le2Dg2tLe1nK8qMfl3VVmIQ+SZSPFHly3Plx3hZv f8r9ffLZIZvPe1sFWPKTyx4wbgc2E/UGLJLXULXpVU7M4rhBnCMEKQ/BT4Q8SmyMS0 sHRSzeBhc35zMAW8Kf/sLZfqjCVSQH2SceqPcZosRLNb468VXweNiI8NnEQVtNjTfl 2thNfpaGSVOwLQ9AV9aTIWZ5z7ejH5D+7nscExq5ZA9DuoPhX7fUQiXtS8NytSQt7r 5MZIBaij7TdDA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Hans de Goede , Andy Shevchenko , Mauro Carvalho Chehab , Sasha Levin , gregkh@linuxfoundation.org, andriy.shevchenko@linux.intel.com, kitakar@gmail.com, linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH AUTOSEL 5.15 11/19] media: atomisp: Ensure that USERPTR pointers are page aligned Date: Tue, 1 Nov 2022 07:29:11 -0400 Message-Id: <20221101112919.799868-11-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221101112919.799868-1-sashal@kernel.org> References: <20221101112919.799868-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-staging@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Hans de Goede [ Upstream commit 6e6c4ae0f0ba295dbf6cbd48d93bec169d6ce431 ] The atomisp code needs USERPTR pointers to be page aligned, otherwise bad things (scribbling over other parts of the process' RAM) happen. Add a check to ensure this and exit VIDIOC_QBUF calls with unaligned pointers with -EINVAL. Reviewed-by: Andy Shevchenko Signed-off-by: Hans de Goede Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/staging/media/atomisp/pci/atomisp_ioctl.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c index b7dda4b96d49..b98074418718 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c +++ b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c @@ -1291,6 +1291,12 @@ static int atomisp_qbuf(struct file *file, void *fh, struct v4l2_buffer *buf) * address and reprograme out page table properly */ if (buf->memory == V4L2_MEMORY_USERPTR) { + if (offset_in_page(buf->m.userptr)) { + dev_err(isp->dev, "Error userptr is not page aligned.\n"); + ret = -EINVAL; + goto error; + } + vb = pipe->capq.bufs[buf->index]; vm_mem = vb->priv; if (!vm_mem) { -- 2.35.1