--- trousers-0.3.11.2/src/tspi/tsp_policy.c.orig +++ trousers-0.3.11.2/src/tspi/tsp_policy.c @@ -86,15 +86,13 @@ int pin_mem(void *addr, size_t len) { - /* only root can lock pages into RAM */ - if (getuid() != (uid_t)0) { - LogWarn("Not pinning secrets in memory due to insufficient perms."); - return 0; - } - len += (uintptr_t)addr & PGOFFSET; addr = (void *)((uintptr_t)addr & PGMASK); if (mlock(addr, len) == -1) { + if (errno == EPERM) { + LogWarn("Not pinning secrets in memory due to insufficient perms."); + return 0; + } LogError("mlock: %s", strerror(errno)); return 1; } @@ -105,14 +103,12 @@ int unpin_mem(void *addr, size_t len) { - /* only root can lock pages into RAM */ - if (getuid() != (uid_t)0) { - return 0; - } - len += (uintptr_t)addr & PGOFFSET; addr = (void *)((uintptr_t)addr & PGMASK); if (munlock(addr, len) == -1) { + if (errno == EPERM) { + return 0; + } LogError("mlock: %s", strerror(errno)); return 1; }