From patchwork Thu Aug 6 15:58:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frederic Chen X-Patchwork-Id: 11703467 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CA97313B6 for ; Thu, 6 Aug 2020 15:59:02 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0FAAD22E01 for ; Thu, 6 Aug 2020 15:59:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="gjQyhyth"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="T6rsCij1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0FAAD22E01 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=mediatek.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=HGSySL9hxZOyrmWGN+TkfbutFZwWn20dC5dkILRL0TY=; b=gjQyhyth3Xj4/zHmOXoacdUxjv PbAJ4HGLMoSWXBrKvy+byqdtZo3O+xp6JKHPQIL69JGtVLtuW1g1/vgxmRW6AqIbQFGcDLGzzDRTj fyottcZceLDUitzkKi9LBMsR+Df8mYZALAn0ff0O9CM5bBTYYnjFdsHBMDMB8oOZNvTE+0Hvh60n3 26ZDFM5aQm+MFfDL+b8MmG7QQ4AWrc3SlBS1QhTYnEgNUd1Ncbqx3ITs88ntk4jIhkE4U0OmRopGL c/49yhclPxVp66pqpWdg5zGE/ndjZFtDounfOE2Eh2iAd9USJ+E3ccje1WUQYUXFYnVy8eZQ+77at zmnN7VZA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1k3iI0-0003ud-Us; Thu, 06 Aug 2020 15:58:44 +0000 Received: from mailgw02.mediatek.com ([216.200.240.185]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1k3iHx-0003u0-0c; Thu, 06 Aug 2020 15:58:42 +0000 X-UUID: d3289bf2109a404ea609ebdaed348894-20200806 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=OtJd/yRRZV8IvkNBbGFYLaPgoO8DWoAzhEC+fs64370=; b=T6rsCij1uCd9/OEjGIssBIhMIxwXMYtiMCMd0VsqyWPgrdzoU3Pe+aoAClLqm2LzQgHAgmKVANH3COsw6Bulk1eSLcjyZThm98tfPtbttAq7nDOcWwwijoU+Hdh3rvVLIgENNDwMoB92hgjk5VU5Z6+7QgCxoLcnJf1dJ166uvs=; X-UUID: d3289bf2109a404ea609ebdaed348894-20200806 Received: from mtkcas68.mediatek.inc [(172.29.94.19)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1389352060; Thu, 06 Aug 2020 07:58:33 -0800 Received: from mtkmbs05n1.mediatek.inc (172.21.101.15) by MTKMBS62N2.mediatek.inc (172.29.193.42) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 6 Aug 2020 08:58:29 -0700 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs05n1.mediatek.inc (172.21.101.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 6 Aug 2020 23:58:28 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 6 Aug 2020 23:58:29 +0800 From: To: , , , , Subject: [PATCH V2, 0/1] media: change media_device_request_alloc to match media_ioctl_info Date: Thu, 6 Aug 2020 23:58:21 +0800 Message-ID: <20200806155822.3772-1-frederic.chen@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200806_115841_187336_A1BEAD34 X-CRM114-Status: UNSURE ( 9.79 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.0 UNPARSEABLE_RELAY Informational: message has unparseable relay lines X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sean.Cheng@mediatek.com, srv_heupstream@mediatek.com, sj.huang@mediatek.com, yuzhao@chromium.org, linux-mediatek@lists.infradead.org, zwisler@chromium.org, christie.yu@mediatek.com, frederic.chen@mediatek.com, linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Hello, This patch is to modify media_device_request_alloc() so that it can pass CFI(Control Flow Integrity) check. I would like some review comments. media_device_request_alloc() is saved in fn of media_ioctl_info struct, which is defined as long (*fn)(struct media_device *dev, void *arg). The type of the second parameter of media_device_request_alloc() is int* now, but it is void* in fn of media_ioctl_info. We got some ABI violation here. Therefore, we would like to use void* instead of int* for the second parameter of media_device_request_alloc(). static long media_device_request_alloc(struct media_device *mdev, int *alloc_fd); struct media_ioctl_info { unsigned int cmd; unsigned short flags; long (*fn)(struct media_device *dev, void *arg); long (*arg_from_user)(void *karg, void __user *uarg, unsigned int cmd); long (*arg_to_user)(void __user *uarg, void *karg, unsigned int cmd); }; Here is an example. With Android’s CFI checking, we got the following error without this change. [ 23.502477] mtk-cam soc:camisp: sd:mtk-cam raw-0 pad:2 set format w/h/code 2328/1748/0x3007 [ 23.518690] Kernel panic - not syncing: CFI failure (target: media_device_request_alloc+0x0/0x4) [ 23.519804] CPU: 7 PID: 818 Comm: mtkv4l2_ut Tainted: G S O 5.4.39-g02c0a4858bed-dirty #45 [ 23.521553] Call trace: [ 23.521868] dump_backtrace.cfi_jt+0x0/0x4 [ 23.522389] dump_stack+0xb8/0x114 [ 23.522824] panic+0x170/0x3e0 [ 23.523215] __ubsan_handle_cfi_check_fail_abort+0x0/0x14 [ 23.523896] perf_proc_update_handler+0x0/0xcc [ 23.524460] __cfi_check+0x610cc/0x68ef0 [ 23.524959] media_device_ioctl+0x218/0x238 [ 23.525488] media_device_compat_ioctl+0x60/0x7c [ 23.526072] media_compat_ioctl+0x58/0x9c [ 23.526581] __arm64_compat_sys_ioctl+0x10c/0x434 [ 23.527176] el0_svc_common+0xb4/0x18c [ 23.527651] el0_svc_compat_handler+0x1c/0x28 [ 23.528202] el0_svc_compat+0x8/0x24 [ 23.528659] SMP: stopping secondary CPUs [ 23.529161] Kernel Offset: 0x24b8c00000 from 0xffffffc010000000 [ 23.529906] PHYS_OFFSET: 0xffffffdd00000000 [ 23.530434] CPU features: 0x00000006,2a80a238 [ 23.530983] Memory Limit: none PPL_LOG_STORE: check once, sig value 0x27, addr 0x116000. ================== Changes in v2 ================== We also removed the type cast in the MEDIA_IOC_ARG define . Frederic Chen (1): media: mc-device.c: change media_device_request_alloc to match media_ioctl_info drivers/media/mc/mc-device.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)