Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp2255408rwi; Tue, 1 Nov 2022 05:49:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5RQrN0VijEdaMMLjnnPDzcIb9nFeWhwkYzR5jDs1z2JFGDvukF3DXldNO7RWziHAmWPACp X-Received: by 2002:a17:90b:1c0c:b0:213:1455:131f with SMTP id oc12-20020a17090b1c0c00b002131455131fmr37310431pjb.129.1667306984173; Tue, 01 Nov 2022 05:49:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667306984; cv=none; d=google.com; s=arc-20160816; b=PXU7iNUQSitErGhUYxdkeGGMYo29ZJHyr6R/ML/jmcHiuli3fNaHkpRNaQgQm/K5t2 +u3t2r8Drg8bGgR4OWqDamcIuRPCrA2BpBpwTlZYpqSVorQWfgeWg+TTg8PJkKzJ6VFF utuBgnH4y0ycQl08piaLWKTX7SgQtGUO0flLkpiRMeW6Dup/fhCHAi5U5PiDKYBuNHIM jGmQ8kemzjxRjvbajm3dy5RMYRKbGfGBJFFcERmUM4N5BzrXdSkKJaRmoUkPuCiIg4qj T5fOprCQgLvlV7Fpf8lSv+p4B9VFpXcpOyaNr6EhsdaO10xK3MDBHtYyGaAMUsD1Xpdv 3k2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wuL/USq1iqxQs63ezJr0cDZSdxmwsiL3mhteEbXUgrc=; b=vd8clN+T7RYDJMA6hmNzSvScuHNNgUxHm+jq+E87kW0WlCF+VHyJp0RpK3DzvzYpgQ +RAFmXMVyymTdoQBIeJRbNvCQA1ZaMZhe1iPmLPDfqEx9sV7VNfJwsu/mUiOnW6LBEgG ZmoS075u8iAasDarBE1xJewIypQuoOravPD4tP0oj3YOrvtqKY/rDs+rgQsQzcymk0NO emnlsAyhuakC5GcLfsIIevb6+la88q9AuQJodxyUyJPlz8a9+7mH5PABwXrn0tvFRr5k mpqet5udC/bq8u8eVgAoQIVELg5MHR1+jqT7ORqECW9T5FuQ5E4rhTaSYx3uHviuRRqT XT4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lg2A7cxO; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m3-20020a654c83000000b0045c5a275046si13141236pgt.481.2022.11.01.05.49.30; Tue, 01 Nov 2022 05:49:44 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b=lg2A7cxO; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230383AbiKAL3W (ORCPT + 97 others); Tue, 1 Nov 2022 07:29:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230306AbiKAL2P (ORCPT ); Tue, 1 Nov 2022 07:28:15 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9412519C05; Tue, 1 Nov 2022 04:28:07 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E1085615D4; Tue, 1 Nov 2022 11:28:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43B0CC433C1; Tue, 1 Nov 2022 11:28:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667302086; bh=sFbRVrvnTUcWjQrPQOYG51/HG21tYtpyY/ElwlplYz0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lg2A7cxO4IwfOq/k7vfm38c9EDcoSFJ1pugxFEth/XlaSQFjLIaxoDXyUtpP+rB/L WFUAjzdJpQb5X8yleRF6hWUooYeVj8VFeW5Y94MsRrKWQTk186xWq9zcvaPYylxaYb 7RMbeWqJgV1d83AILkmd1/fTHPPHnPxGatsGPrmWOmFVxS6MoMbuUeaXN53l1J2SV/ uBya6Qyi+wUFxxoAKS26h2T46YOdrWjhuafMTYEElsGfkZzaJQPCKTkc23lwtH6aXq 2jjF5DuKWGGRB+3RNkFRlhaZhhbklQab1qvDf5xd8Kop6ZBMFkoqQe9txsFmggAmOi eMHcjdeZIe6Ww== 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 6.0 17/34] media: atomisp: Ensure that USERPTR pointers are page aligned Date: Tue, 1 Nov 2022 07:27:09 -0400 Message-Id: <20221101112726.799368-17-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221101112726.799368-1-sashal@kernel.org> References: <20221101112726.799368-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 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 459645c2e2a7..4de01aa28fe5 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c +++ b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c @@ -1338,6 +1338,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