svn commit: samba r21505 - in branches: SAMBA_3_0/source/nsswitch
SAMBA_3_0_25/source/nsswitch
jerry at samba.org
jerry at samba.org
Thu Feb 22 17:21:28 GMT 2007
Author: jerry
Date: 2007-02-22 17:21:27 +0000 (Thu, 22 Feb 2007)
New Revision: 21505
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=21505
Log:
make sure mlock()'d memory is aligned on a page boundary
Modified:
branches/SAMBA_3_0/source/nsswitch/winbindd_cred_cache.c
branches/SAMBA_3_0/source/nsswitch/winbindd_nss.h
branches/SAMBA_3_0_25/source/nsswitch/winbindd_cred_cache.c
branches/SAMBA_3_0_25/source/nsswitch/winbindd_nss.h
Changeset:
Modified: branches/SAMBA_3_0/source/nsswitch/winbindd_cred_cache.c
===================================================================
--- branches/SAMBA_3_0/source/nsswitch/winbindd_cred_cache.c 2007-02-22 16:26:18 UTC (rev 21504)
+++ branches/SAMBA_3_0/source/nsswitch/winbindd_cred_cache.c 2007-02-22 17:21:27 UTC (rev 21505)
@@ -471,6 +471,8 @@
#if !defined(HAVE_MLOCK)
return NT_STATUS_OK;
#else
+ int psize = getpagesize();
+
/* new_entry->nt_hash is the base pointer for the block
of memory pointed into by new_entry->lm_hash and
new_entry->pass (if we're storing plaintext). */
@@ -480,17 +482,29 @@
memcredp->len += strlen(pass)+1;
}
- memcredp->nt_hash = (unsigned char *)TALLOC_ZERO(memcredp, memcredp->len);
- if (!memcredp->nt_hash) {
+ /* On non-linux platforms, mlock()'d memory must be aligned on
+ a page boundary so allocate a bit more so we can offset
+ enough */
+
+ memcredp->len += psize;
+
+ memcredp->buffer = (unsigned char*)TALLOC_ZERO(memcredp, memcredp->len);
+
+ if (!memcredp->buffer) {
return NT_STATUS_NO_MEMORY;
}
+
+ /* point the nt_hash at the page boundary in the buffer */
+
+ memcredp->nt_hash = memcredp->buffer +
+ (psize - ((uint32)memcredp->buffer % psize));
memcredp->lm_hash = memcredp->nt_hash + NT_HASH_LEN;
+
#ifdef DEBUG_PASSWORD
DEBUG(10,("mlocking memory: %p\n", memcredp->nt_hash));
#endif
-
- if ((mlock(memcredp->nt_hash, memcredp->len)) == -1) {
+ if ((mlock(memcredp->nt_hash, memcredp->len-psize)) == -1) {
DEBUG(0,("failed to mlock memory: %s (%d)\n",
strerror(errno), errno));
return map_nt_error_from_unix(errno);
@@ -522,13 +536,16 @@
#if !defined(HAVE_MUNLOCK)
return NT_STATUS_OK;
#else
- if (munlock(memcredp->nt_hash, memcredp->len) == -1) {
+ int psize = getpagesize();
+
+ if (munlock(memcredp->buffer, memcredp->len - psize) == -1) {
DEBUG(0,("failed to munlock memory: %s (%d)\n",
strerror(errno), errno));
return map_nt_error_from_unix(errno);
}
- memset(memcredp->nt_hash, '\0', memcredp->len);
- TALLOC_FREE(memcredp->nt_hash);
+ memset(memcredp->buffer, '\0', memcredp->len);
+ TALLOC_FREE(memcredp->buffer);
+ memcredp->nt_hash = NULL;
memcredp->lm_hash = NULL;
memcredp->pass = NULL;
memcredp->len = 0;
Modified: branches/SAMBA_3_0/source/nsswitch/winbindd_nss.h
===================================================================
--- branches/SAMBA_3_0/source/nsswitch/winbindd_nss.h 2007-02-22 16:26:18 UTC (rev 21504)
+++ branches/SAMBA_3_0/source/nsswitch/winbindd_nss.h 2007-02-22 17:21:27 UTC (rev 21505)
@@ -469,6 +469,8 @@
uid_t uid;
int ref_count;
size_t len;
+ unsigned char *buffer; /* buffer block containing the
+ following 3 */
unsigned char *nt_hash; /* Base pointer for the following 2 */
unsigned char *lm_hash;
char *pass;
Modified: branches/SAMBA_3_0_25/source/nsswitch/winbindd_cred_cache.c
===================================================================
--- branches/SAMBA_3_0_25/source/nsswitch/winbindd_cred_cache.c 2007-02-22 16:26:18 UTC (rev 21504)
+++ branches/SAMBA_3_0_25/source/nsswitch/winbindd_cred_cache.c 2007-02-22 17:21:27 UTC (rev 21505)
@@ -471,6 +471,8 @@
#if !defined(HAVE_MLOCK)
return NT_STATUS_OK;
#else
+ int psize = getpagesize();
+
/* new_entry->nt_hash is the base pointer for the block
of memory pointed into by new_entry->lm_hash and
new_entry->pass (if we're storing plaintext). */
@@ -480,17 +482,29 @@
memcredp->len += strlen(pass)+1;
}
- memcredp->nt_hash = (unsigned char *)TALLOC_ZERO(memcredp, memcredp->len);
- if (!memcredp->nt_hash) {
+ /* On non-linux platforms, mlock()'d memory must be aligned on
+ a page boundary so allocate a bit more so we can offset
+ enough */
+
+ memcredp->len += psize;
+
+ memcredp->buffer = (unsigned char*)TALLOC_ZERO(memcredp, memcredp->len);
+
+ if (!memcredp->buffer) {
return NT_STATUS_NO_MEMORY;
}
+
+ /* point the nt_hash at the page boundary in the buffer */
+
+ memcredp->nt_hash = memcredp->buffer +
+ (psize - ((uint32)memcredp->buffer % psize));
memcredp->lm_hash = memcredp->nt_hash + NT_HASH_LEN;
+
#ifdef DEBUG_PASSWORD
DEBUG(10,("mlocking memory: %p\n", memcredp->nt_hash));
#endif
-
- if ((mlock(memcredp->nt_hash, memcredp->len)) == -1) {
+ if ((mlock(memcredp->nt_hash, memcredp->len-psize)) == -1) {
DEBUG(0,("failed to mlock memory: %s (%d)\n",
strerror(errno), errno));
return map_nt_error_from_unix(errno);
@@ -522,13 +536,16 @@
#if !defined(HAVE_MUNLOCK)
return NT_STATUS_OK;
#else
- if (munlock(memcredp->nt_hash, memcredp->len) == -1) {
+ int psize = getpagesize();
+
+ if (munlock(memcredp->buffer, memcredp->len - psize) == -1) {
DEBUG(0,("failed to munlock memory: %s (%d)\n",
strerror(errno), errno));
return map_nt_error_from_unix(errno);
}
- memset(memcredp->nt_hash, '\0', memcredp->len);
- TALLOC_FREE(memcredp->nt_hash);
+ memset(memcredp->buffer, '\0', memcredp->len);
+ TALLOC_FREE(memcredp->buffer);
+ memcredp->nt_hash = NULL;
memcredp->lm_hash = NULL;
memcredp->pass = NULL;
memcredp->len = 0;
Modified: branches/SAMBA_3_0_25/source/nsswitch/winbindd_nss.h
===================================================================
--- branches/SAMBA_3_0_25/source/nsswitch/winbindd_nss.h 2007-02-22 16:26:18 UTC (rev 21504)
+++ branches/SAMBA_3_0_25/source/nsswitch/winbindd_nss.h 2007-02-22 17:21:27 UTC (rev 21505)
@@ -469,6 +469,8 @@
uid_t uid;
int ref_count;
size_t len;
+ unsigned char *buffer; /* buffer block containing the
+ following 3 */
unsigned char *nt_hash; /* Base pointer for the following 2 */
unsigned char *lm_hash;
char *pass;
More information about the samba-cvs
mailing list