Thanks to visit codestin.com
Credit goes to github.com

Skip to content

mlock returns EINVAL #136

@chrisridd

Description

@chrisridd

On Solaris, the process calling mlock needs the "proc_lock_memory" privilege in RBAC.

Even with that privilege, mlock on Solaris fails if the address passed is not a multiple of the page size. (i.e. it must be the start of a page.) errno is set to EINVAL in this case. This causes test 2 in s2n_ecc_test to fail.

This restriction is part of the POSIX standard that you are compiling against (_POSIX_C_SOURCE=200112L) so it looks to me like your use of mlock() is not correct. Does it make sense to make the use of mlock configurable, or should you be using posix_memalign() instead of realloc()? Something like the following allows a significant number of tests to pass:

diff --git a/utils/s2n_mem.c b/utils/s2n_mem.c
index 7591274..9a4ce1d 100644
--- a/utils/s2n_mem.c
+++ b/utils/s2n_mem.c
@@ -38,7 +38,8 @@ int s2n_realloc(struct s2n_blob *b, uint32_t size)
         return 0;
     }

-    uint8_t *data = realloc(b->data, size);
+    void *data = NULL;
+    GUARD(posix_memalign(&data, 4096, size));
     if (data == NULL) {
         S2N_ERROR(S2N_ERR_REALLOC);
     }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions