From patchwork Thu Aug 6 07:29:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frederic Chen X-Patchwork-Id: 11703217 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 0123C138C for ; Thu, 6 Aug 2020 12:21:28 +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 DF673204FD for ; Thu, 6 Aug 2020 12:21:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="H6ijHPN0"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="ldAGfpV+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DF673204FD 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=SQlfezD/PnH4l1krLQaJn2MCAy0psgmp6Hi4uwmH4c4=; b=H6ijHPN0fe+odVpttY4AKQPNJ1 yUIUK+3y9/YQzg4aGjC+dyO7pNE/aj/r9zds0x4H41xZc5mv5Cshcp55oWPHUo1WVs7/lRr59F6yr qTONnasOguZoh7WlZbXlkfrYknTjKmeKN9+zqiTPQzKUBkUk9nsl5d0A6D3236IX5Lypx05/s9tvN ypk5BhLLfSvo9nVsg2iPQzxxzmuNFuac7a8oakpYC2rnOd+j3IyQ7F8QD4FVU3YcbNmzDy52W8pFI k1t6llk8HEn+XrwUUR4gaP8fGdpkYcBcE1D/mbV1D1uCWy+oo7Vt4tOXNCV9OBT0h5teYafDrdeYF UTxceySQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1k3aMh-0002Or-Q9; Thu, 06 Aug 2020 07:31:03 +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 1k3aMf-0002Nt-7j; Thu, 06 Aug 2020 07:31:02 +0000 X-UUID: f0bc0435eeef4ead976e92bf2f99eeaa-20200805 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=HPY1Y8WchrDTl7dW9nXX5eI/MbrnUntKhJLM+zFG4Ko=; b=ldAGfpV+ws5Wa7QwAJzZLrDKqDaDR8ozIdBSqykIHKFRRFEkFQi6wM+qWHOelZOB01TJjvtwZjrKyu/m11hOotpa9O3BJYKz33Z4UbsKuynxpieDN9ZSDDMb+G8WhFqLQDE0opBURo472+NRY0zrXnTsoiZWy+MpraCiVFVpc24=; X-UUID: f0bc0435eeef4ead976e92bf2f99eeaa-20200805 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 138367907; Wed, 05 Aug 2020 23:30:58 -0800 Received: from MTKMBS02N1.mediatek.inc (172.21.101.77) by MTKMBS62N2.mediatek.inc (172.29.193.42) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 6 Aug 2020 00:30:06 -0700 Received: from mtkcas08.mediatek.inc (172.21.101.126) by mtkmbs02n1.mediatek.inc (172.21.101.77) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 6 Aug 2020 15:29:59 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas08.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 6 Aug 2020 15:29:59 +0800 From: To: , , , , Subject: [PATCH 0/1] media: change media_device_request_alloc to match media_ioctl_info Date: Thu, 6 Aug 2020 15:29:51 +0800 Message-ID: <20200806072952.11709-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_033101_422588_59F79D8A X-CRM114-Status: GOOD ( 10.59 ) 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 *** BLURB HERE *** 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. Frederic Chen (1): media: mc-device.c: change media_device_request_alloc to match media_ioctl_info drivers/media/mc/mc-device.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)