security: tlk_driver: delete te_pin_user_pages() and its usage
Sharif Inamdar [Tue, 31 Dec 2013 11:40:30 +0000 (16:40 +0530)]
te_pin_user_pages() maps user pages, but the mapped pages never get used.

Bug 1430582

Change-Id: I2d815f1d970e491058cf89cc9fef0f78b8e9764c
Signed-off-by: Sharif Inamdar <isharif@nvidia.com>
Reviewed-on: http://git-master/r/351021
(cherry picked from commit 7ac517f2203a41ffa4f703d9b18c46a8558873e0)
Reviewed-on: http://git-master/r/351670
Reviewed-by: Varun Wadekar <vwadekar@nvidia.com>
Tested-by: Varun Wadekar <vwadekar@nvidia.com>

security/tlk_driver/ote_comms.c
security/tlk_driver/ote_protocol.h

index 3fb5e03..8cb11a2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013 NVIDIA Corporation. All rights reserved.
+ * Copyright (c) 2012-2014 NVIDIA Corporation. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -34,35 +34,7 @@ core_param(verbose_smc, verbose_smc, bool, 0644);
 
 #define SET_RESULT(req, r, ro) { req->result = r; req->result_origin = ro; }
 
-static int te_pin_user_pages(void *buffer, size_t size,
-               unsigned long *pages_ptr)
-{
-       int ret = 0;
-       unsigned int nr_pages;
-       struct page **pages = NULL;
-
-       nr_pages = (((unsigned int)buffer & (PAGE_SIZE - 1)) +
-                       (size + PAGE_SIZE - 1)) >> PAGE_SHIFT;
-
-       pages = kzalloc(nr_pages * sizeof(struct page *), GFP_KERNEL);
-       if (!pages)
-               return -ENOMEM;
-
-       down_read(&current->mm->mmap_sem);
-       ret = get_user_pages(current, current->mm, (unsigned long)buffer,
-                               nr_pages, WRITE, 0, pages, NULL);
-       if (ret < 0)
-               ret = get_user_pages(current, current->mm, (unsigned long)buffer,
-                               nr_pages, WRITE, 1/*force*/, pages, NULL);
-       up_read(&current->mm->mmap_sem);
-
-       *pages_ptr = (unsigned long) pages;
-
-       return ret;
-}
-
 static struct te_shmem_desc *te_add_shmem_desc(void *buffer, size_t size,
-               unsigned int nr_pages, struct page **pages,
                struct tlk_context *context)
 {
        struct te_shmem_desc *shmem_desc = NULL;
@@ -71,8 +43,6 @@ static struct te_shmem_desc *te_add_shmem_desc(void *buffer, size_t size,
                INIT_LIST_HEAD(&(shmem_desc->list));
                shmem_desc->buffer = buffer;
                shmem_desc->size = size;
-               shmem_desc->nr_pages = nr_pages;
-               shmem_desc->pages = pages;
                list_add_tail(&shmem_desc->list, &(context->shmem_alloc_list));
        }
 
@@ -87,16 +57,7 @@ static int te_pin_mem_buffers(void *buffer, size_t size,
        struct te_shmem_desc *shmem_desc = NULL;
        int ret = 0, nr_pages = 0;
 
-       nr_pages = te_pin_user_pages(buffer, size, &pages);
-       if (nr_pages <= 0) {
-               pr_err("%s: te_pin_user_pages Failed (%d)\n", __func__,
-                       nr_pages);
-               ret = OTE_ERROR_OUT_OF_MEMORY;
-               goto error;
-       }
-
-       shmem_desc = te_add_shmem_desc(buffer, size,
-                               nr_pages, (struct page **)pages, context);
+       shmem_desc = te_add_shmem_desc(buffer, size, context);
        if (!shmem_desc) {
                pr_err("%s: te_add_shmem_desc Failed\n", __func__);
                ret = OTE_ERROR_OUT_OF_MEMORY;
@@ -152,9 +113,6 @@ static void te_del_shmem_desc(void *buffer, struct tlk_context *context)
                &(context->shmem_alloc_list), list) {
                if (shmem_desc->buffer == buffer) {
                        list_del(&shmem_desc->list);
-                       for (i = 0; i < shmem_desc->nr_pages; i++)
-                               page_cache_release(shmem_desc->pages[i]);
-                       kfree(shmem_desc->pages);
                        kfree(shmem_desc);
                }
        }
index 7421451..cff135d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013 NVIDIA Corporation. All rights reserved.
+ * Copyright (c) 2012-2014 NVIDIA Corporation. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -112,8 +112,6 @@ struct te_shmem_desc {
        void *buffer;
        size_t size;
        unsigned int mem_type;
-       struct page **pages;
-       unsigned int nr_pages;
 };
 
 struct tlk_context {