Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp951640pxj; Fri, 4 Jun 2021 02:16:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxiFi1A7J/x8stMObY6IHQyWrdF8d0Pvfy2WJwq7SPn80q7gCPaD21+kjH1lC4rh2Wuqp3 X-Received: by 2002:a05:6402:3546:: with SMTP id f6mr3551794edd.191.1622798219188; Fri, 04 Jun 2021 02:16:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622798219; cv=none; d=google.com; s=arc-20160816; b=eJ9nvT//sKCusBtMITHwe+6bhEG5v19TcTBr9WqmjSJ9SttCHFfnTSmyfBXE4mGeEy +Za0WHKYI4Mk8YBz7jS64dor4X7KbjRRzENiVSwsaoy3/JhIEI3qo9iLWHV9j1RGawZs mY6i2tKs5TDnQLjmqPaRkaThdye0JcJfiQnI6UeDzP4w+0V42LeCIKYe1fH8uZirUmXL 96NsqWiE4Yfbe8178tQXdrol0LyRKmwESg+HQ6qxY6EwH4wvOuAvuAd/LkVFOK75PZvJ cAQJiHugfU7AvdQcQRL5MrFAdeT7TLFElblibkKdvMxKuMJn314ouxVafmQRAzsxUedX 5Sjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=YzOrkrkHZq0r60g/e950hTfN5Vx2FE30j84KKoiKa8s=; b=cvMKvBmX4pDBCBC+KtkVoQWv5fjeNOlOV4TgMjClLqi/EkMTMgJ+Y44VRPcAVKTxEX Q4RSA4mZQc9TFmWzKwMc8mJwcFssbl1FaN65i/SnNn5RF/GYrHFKPeziiN02074rGLeb HmuYzwnbBoDBntxCEUx4PtBEbznXOqJc2zGxvN7/NzebkCoirBfvuIbBy76HFbMMSvnF YwQ4ZUHY4XN1hCNlO5toJXBm+fOjFrFI+4S+KeKGM1UfbGpVi5gaz/oSHedAcA1rcXVq NL1Iv4ic8iWs//GE7B2y6mtcd2BpuIdJTsk2U4nlxleX+kLvea5vcc296OKzS+Gqppm6 Ek6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=iDxCxwmP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w13si4729320edx.449.2021.06.04.02.16.34; Fri, 04 Jun 2021 02:16:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=iDxCxwmP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230128AbhFDJQL (ORCPT + 99 others); Fri, 4 Jun 2021 05:16:11 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:57392 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229981AbhFDJQH (ORCPT ); Fri, 4 Jun 2021 05:16:07 -0400 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 15496lI2028502; Fri, 4 Jun 2021 11:14:19 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=selector1; bh=YzOrkrkHZq0r60g/e950hTfN5Vx2FE30j84KKoiKa8s=; b=iDxCxwmPHj4pe1jtp8nuWXAad7WC3SPcSo3FptZS6yD4N+qKTGRkxvQdm0J/iHzZk4pg Tv4v2vx6XBaC7imMqdQoUJYoxzg7UixstbifU56ULokajqbDCaPZoeqtR32qKrv9eM83 Ntz0XLDiCPuQ5EzBcoey904lFI1zYU/creVoHamtcC0cpigTn5A26UC8QKgpMKL3xRjk Ub+gkA4Ly6hS1y/S0l2CH8btWs5uAgQFG1E7WXu4gOsUDzKwveX1FSGBbpCXTGEgTP4S 8tfc2k6yutyaDJfRih3oLxZaEHPeQgCdjUtudP2MzJiG5uJWWdpJvAoJ5k84ZYaMS1Vz Pg== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 38yg960grh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 04 Jun 2021 11:14:19 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 3BC7310002A; Fri, 4 Jun 2021 11:14:19 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag2node3.st.com [10.75.127.6]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 2F8A4216EEF; Fri, 4 Jun 2021 11:14:19 +0200 (CEST) Received: from localhost (10.75.127.51) by SFHDAG2NODE3.st.com (10.75.127.6) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 4 Jun 2021 11:14:18 +0200 From: Arnaud Pouliquen To: Bjorn Andersson , Ohad Ben-Cohen , Mathieu Poirier CC: , , , Subject: [PATCH 3/4] rpmsg: ctrl: Add check on rpmsg device removability from user space Date: Fri, 4 Jun 2021 11:14:05 +0200 Message-ID: <20210604091406.15901-4-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210604091406.15901-1-arnaud.pouliquen@foss.st.com> References: <20210604091406.15901-1-arnaud.pouliquen@foss.st.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.75.127.51] X-ClientProxiedBy: SFHDAG3NODE2.st.com (10.75.127.8) To SFHDAG2NODE3.st.com (10.75.127.6) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-06-04_05:2021-06-04,2021-06-04 signatures=0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Using the RPMSG_RELEASE_DEV_IOCTL is possible to remove any rpmsg device (such as the rpmsg ns or the rpmsg ctrldev). Add a new field to store the removability of the device. By default the rpmsg device can not be removed by user space. It is set to 1 by the rpmsg ctrl on RPMSG_CREATE_DEV_IOCTL request, but could also be set by an rpmsg driver during probe. Signed-off-by: Arnaud Pouliquen --- drivers/rpmsg/rpmsg_ctrl.c | 17 ++++++++++++++++- include/linux/rpmsg.h | 2 ++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/rpmsg/rpmsg_ctrl.c b/drivers/rpmsg/rpmsg_ctrl.c index cb19e32d05e1..e93c6ec49038 100644 --- a/drivers/rpmsg/rpmsg_ctrl.c +++ b/drivers/rpmsg/rpmsg_ctrl.c @@ -74,6 +74,7 @@ static long rpmsg_ctrldev_ioctl(struct file *fp, unsigned int cmd, struct rpmsg_endpoint_info eptinfo; struct rpmsg_channel_info chinfo; struct rpmsg_device *rpdev; + struct device *dev; int ret = 0; if (copy_from_user(&eptinfo, argp, sizeof(eptinfo))) @@ -95,11 +96,25 @@ static long rpmsg_ctrldev_ioctl(struct file *fp, unsigned int cmd, if (!rpdev) { dev_err(&ctrldev->dev, "failed to create %s channel\n", chinfo.name); ret = -ENXIO; + } else { + /* Allow user space to release the device. */ + rpdev->us_removable = 1; } break; case RPMSG_RELEASE_DEV_IOCTL: - ret = rpmsg_release_channel(ctrldev->rpdev, &chinfo); + dev = rpmsg_find_device(ctrldev->rpdev->dev.parent, &chinfo); + if (!dev) + ret = -ENXIO; + + /* Verify that rpmsg device removal is allowed. */ + if (!ret) { + rpdev = to_rpmsg_device(dev); + if (!rpdev->us_removable) + ret = -EACCES; + } + if (!ret) + ret = rpmsg_release_channel(ctrldev->rpdev, &chinfo); if (ret) dev_err(&ctrldev->dev, "failed to release %s channel (%d)\n", chinfo.name, ret); diff --git a/include/linux/rpmsg.h b/include/linux/rpmsg.h index d97dcd049f18..3642aad1a789 100644 --- a/include/linux/rpmsg.h +++ b/include/linux/rpmsg.h @@ -47,6 +47,7 @@ struct rpmsg_channel_info { * @ept: the rpmsg endpoint of this channel * @announce: if set, rpmsg will announce the creation/removal of this channel * @little_endian: True if transport is using little endian byte representation + * @us_removable: True if userspace application has permission to remove the rpmsg device */ struct rpmsg_device { struct device dev; @@ -57,6 +58,7 @@ struct rpmsg_device { struct rpmsg_endpoint *ept; bool announce; bool little_endian; + bool us_removable; const struct rpmsg_device_ops *ops; }; -- 2.17.1