From patchwork Wed Oct 21 09:22:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 7455271 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id AB0419F30B for ; Wed, 21 Oct 2015 09:23:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C0FC220830 for ; Wed, 21 Oct 2015 09:23:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CAB712082B for ; Wed, 21 Oct 2015 09:23:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932086AbbJUJWv (ORCPT ); Wed, 21 Oct 2015 05:22:51 -0400 Received: from mail-wi0-f179.google.com ([209.85.212.179]:36912 "EHLO mail-wi0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753863AbbJUJWn (ORCPT ); Wed, 21 Oct 2015 05:22:43 -0400 Received: by wicfv8 with SMTP id fv8so65495634wic.0 for ; Wed, 21 Oct 2015 02:22:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dIcup7/8cClkHBEjmkRQodyh340Y8sGKvcVbPqNi688=; b=OcjDpIpViHDcUFQvgOMBPQqVa+EriM7D3s9zUD2f/t0GH1qvbdtu8ycvct2VPnkRi+ EMRoIlsijQFyLvTrI2VMgeDM0DjXhfEyCDQPdSkVQUlE1kWuoQ2UrPn4GbfvK6oOlxL9 89UW8msBBQtd6WrP6MiDuBKLESMuL4jN1b7s/+CnpXP0FJKjth6pMpFSnHsflVU5KQYs wNuNlMJ3YOc7tB2XLygSdQd6YatNR+T4vK+vkKO6WKRVqtd77JXPvAr/7udRDoBRCgKp ciVurF5TjHQFeD1cpIhETc0a5iAdrHWfRy4aFIacJ1DGE/YBmf+kUR4lEc1Bn+dE9v6Z gnfA== X-Gm-Message-State: ALoCoQlgvsCbonPGZ5q7MG4KAKo4uFtSZCsHF7jA8F3DezrzgTWBgo93WDLkCCXR5ONn3ZHg2DZw X-Received: by 10.180.198.233 with SMTP id jf9mr27516651wic.66.1445419361433; Wed, 21 Oct 2015 02:22:41 -0700 (PDT) Received: from LMENX321.lme.st.com (LPuteaux-656-1-48-212.w82-127.abo.wanadoo.fr. [82.127.83.212]) by smtp.gmail.com with ESMTPSA id z4sm9119481wjz.29.2015.10.21.02.22.39 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Oct 2015 02:22:40 -0700 (PDT) From: Benjamin Gaignard To: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, daniel.vetter@ffwll.ch, robdclark@gmail.com, treding@nvidia.com, sumit.semwal@linaro.org, tom.cooksey@arm.com, daniel.stone@collabora.com, linux-security-module@vger.kernel.org, xiaoquan.li@vivantecorp.com, labbott@redhat.com Cc: tom.gall@linaro.org, linaro-mm-sig@lists.linaro.org, Benjamin Gaignard Subject: [PATCH v5 3/3] SMAF: add fake secure module Date: Wed, 21 Oct 2015 11:22:20 +0200 Message-Id: <1445419340-11471-4-git-send-email-benjamin.gaignard@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1445419340-11471-1-git-send-email-benjamin.gaignard@linaro.org> References: <1445419340-11471-1-git-send-email-benjamin.gaignard@linaro.org> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This module is allow testing secure calls of SMAF. Signed-off-by: Benjamin Gaignard --- drivers/smaf/Kconfig | 6 +++ drivers/smaf/Makefile | 1 + drivers/smaf/smaf-fakesecure.c | 92 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 drivers/smaf/smaf-fakesecure.c diff --git a/drivers/smaf/Kconfig b/drivers/smaf/Kconfig index 058ec4c..fd17005 100644 --- a/drivers/smaf/Kconfig +++ b/drivers/smaf/Kconfig @@ -9,3 +9,9 @@ config SMAF_CMA depends on SMAF && HAVE_DMA_ATTRS help Choose this option to enable CMA allocation within SMAF + +config SMAF_FAKE_SECURE + tristate "SMAF fake secure module" + depends on SMAF + help + Choose this option to enable fake secure module for test purpose diff --git a/drivers/smaf/Makefile b/drivers/smaf/Makefile index 05bab01..00d5cd4 100644 --- a/drivers/smaf/Makefile +++ b/drivers/smaf/Makefile @@ -1,2 +1,3 @@ obj-$(CONFIG_SMAF) += smaf-core.o obj-$(CONFIG_SMAF_CMA) += smaf-cma.o +obj-$(CONFIG_SMAF_FAKE_SECURE) += smaf-fakesecure.o diff --git a/drivers/smaf/smaf-fakesecure.c b/drivers/smaf/smaf-fakesecure.c new file mode 100644 index 0000000..75e12dd --- /dev/null +++ b/drivers/smaf/smaf-fakesecure.c @@ -0,0 +1,92 @@ +/* + * smaf-fakesecure.c + * + * Copyright (C) Linaro SA 2015 + * Author: Benjamin Gaignard for Linaro. + * License terms: GNU General Public License (GPL), version 2 + */ +#include +#include +#include + +#define MAGIC 0xDEADBEEF + +struct fake_private { + int magic; +}; + +static void *smaf_fakesecure_create(void) +{ + struct fake_private *priv; + + priv = kzalloc(sizeof(*priv), GFP_KERNEL); + priv->magic = MAGIC; + + return priv; +} + +static int smaf_fakesecure_destroy(void *ctx) +{ + struct fake_private *priv = (struct fake_private *)ctx; + + WARN_ON(!priv || (priv->magic != MAGIC)); + kfree(priv); + + return 0; +} + +static bool smaf_fakesecure_grant_access(void *ctx, + struct device *dev, + size_t addr, size_t size, + enum dma_data_direction direction) +{ + struct fake_private *priv = (struct fake_private *)ctx; + + WARN_ON(!priv || (priv->magic != MAGIC)); + + return priv->magic == MAGIC; +} + +static void smaf_fakesecure_revoke_access(void *ctx, + struct device *dev, + size_t addr, size_t size, + enum dma_data_direction direction) +{ + struct fake_private *priv = (struct fake_private *)ctx; + + WARN_ON(!priv || (priv->magic != MAGIC)); +} + +static bool smaf_fakesecure_allow_cpu_access(void *ctx, + enum dma_data_direction direction) +{ + struct fake_private *priv = (struct fake_private *)ctx; + + WARN_ON(!priv || (priv->magic != MAGIC)); + + return priv->magic == MAGIC; +} + +static struct smaf_secure fake = { + .create_ctx = smaf_fakesecure_create, + .destroy_ctx = smaf_fakesecure_destroy, + .grant_access = smaf_fakesecure_grant_access, + .revoke_access = smaf_fakesecure_revoke_access, + .allow_cpu_access = smaf_fakesecure_allow_cpu_access, +}; + +static int __init smaf_fakesecure_init(void) +{ + return smaf_register_secure(&fake); +} +module_init(smaf_fakesecure_init); + +static void __exit smaf_fakesecure_deinit(void) +{ + smaf_unregister_secure(&fake); +} +module_exit(smaf_fakesecure_deinit); + +MODULE_DESCRIPTION("SMAF fake secure module for test purpose"); +MODULE_LICENSE("GPL v2"); +MODULE_AUTHOR("Benjamin Gaignard ");