[linux-pam] Check for return value of pam_get_item() in pam_echo module.
by Tomáš Mráz
commit 3475dbeb44238b5b8910cea4abfde106c6e90618
Author: Tomas Mraz <tmraz(a)fedoraproject.org>
Date: Thu Jun 2 21:57:31 2011 +0200
Check for return value of pam_get_item() in pam_echo module.
ChangeLog | 3 +++
modules/pam_echo/pam_echo.c | 5 ++++-
2 files changed, 7 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 90bb7c0..a7c485c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -16,6 +16,9 @@
* modules/pam_filter/pam_filter.c (process_args): Guard for error return
from pam_get_user().
+ * modules/pam_echo/pam_echo.c (replace_and_print): Guard for error return
+ from pam_get_item().
+
2011-05-30 Thorsten Kukuk <kukuk(a)thkukuk.de>
* modules/pam_timestamp/pam_timestamp.c (main): Remove unsused
diff --git a/modules/pam_echo/pam_echo.c b/modules/pam_echo/pam_echo.c
index 31ebca2..043ff70 100644
--- a/modules/pam_echo/pam_echo.c
+++ b/modules/pam_echo/pam_echo.c
@@ -119,7 +119,10 @@ replace_and_print (pam_handle_t *pamh, const char *mesg)
str = &myhostname;
}
else
- pam_get_item (pamh, item, &str);
+ {
+ if (pam_get_item (pamh, item, &str) != PAM_SUCCESS)
+ str = NULL;
+ }
if (str == NULL)
str = "(null)";
for (q = str; *q != '\0' && len < length - 1; ++q)
13 years
[linux-pam] Guard for pam_get_user() error in pam_filter module.
by Tomáš Mráz
commit 26747b9b490d190dd20543ea9cbde082ae667402
Author: Tomas Mraz <tmraz(a)fedoraproject.org>
Date: Thu Jun 2 21:55:41 2011 +0200
Guard for pam_get_user() error in pam_filter module.
ChangeLog | 3 +++
modules/pam_filter/pam_filter.c | 4 ++--
2 files changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 7af2a86..90bb7c0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -13,6 +13,9 @@
on NULL strings.
(password_check): Guard for NULLs returned from memory allocation.
+ * modules/pam_filter/pam_filter.c (process_args): Guard for error return
+ from pam_get_user().
+
2011-05-30 Thorsten Kukuk <kukuk(a)thkukuk.de>
* modules/pam_timestamp/pam_timestamp.c (main): Remove unsused
diff --git a/modules/pam_filter/pam_filter.c b/modules/pam_filter/pam_filter.c
index 2f290fd..da98148 100644
--- a/modules/pam_filter/pam_filter.c
+++ b/modules/pam_filter/pam_filter.c
@@ -177,8 +177,8 @@ static int process_args(pam_handle_t *pamh
#define USER_OFFSET 5 /* strlen('USER='); */
#define USER_NAME "USER="
- pam_get_user(pamh, &user, NULL);
- if (user == NULL) {
+ if (pam_get_user(pamh, &user, NULL) != PAM_SUCCESS ||
+ user == NULL) {
user = "<unknown>";
}
size = USER_OFFSET+strlen(user);
13 years
[linux-pam] Guards for memory allocation errors in pam_cracklib module.
by Tomáš Mráz
commit 48590abce86b34e55c84f71424449f16d285eaf2
Author: Tomas Mraz <tmraz(a)fedoraproject.org>
Date: Thu Jun 2 21:53:55 2011 +0200
Guards for memory allocation errors in pam_cracklib module.
ChangeLog | 4 +++
modules/pam_cracklib/pam_cracklib.c | 38 +++++++++++++++++++++++++---------
2 files changed, 32 insertions(+), 10 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e91af88..7af2a86 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,10 @@
* modules/pam_namespace/pam_namespace.8.xml: Document the mount_private
option.
+ * modules/pam_cracklib/pam_cracklib.c (str_lower): Make it no-op
+ on NULL strings.
+ (password_check): Guard for NULLs returned from memory allocation.
+
2011-05-30 Thorsten Kukuk <kukuk(a)thkukuk.de>
* modules/pam_timestamp/pam_timestamp.c (main): Remove unsused
diff --git a/modules/pam_cracklib/pam_cracklib.c b/modules/pam_cracklib/pam_cracklib.c
index 2e91126..1955b83 100644
--- a/modules/pam_cracklib/pam_cracklib.c
+++ b/modules/pam_cracklib/pam_cracklib.c
@@ -473,6 +473,9 @@ static char * str_lower(char *string)
{
char *cp;
+ if (!string)
+ return NULL;
+
for (cp = string; *cp; cp++)
*cp = tolower(*cp);
return string;
@@ -492,15 +495,26 @@ static const char *password_check(struct cracklib_options *opt,
}
newmono = str_lower(x_strdup(new));
+ if (!newmono)
+ msg = _("memory allocation error");
+
usermono = str_lower(x_strdup(user));
- if (old) {
- oldmono = str_lower(x_strdup(old));
- wrapped = malloc(strlen(oldmono) * 2 + 1);
- strcpy (wrapped, oldmono);
- strcat (wrapped, oldmono);
+ if (!usermono)
+ msg = _("memory allocation error");
+
+ if (!msg && old) {
+ oldmono = str_lower(x_strdup(old));
+ if (oldmono)
+ wrapped = malloc(strlen(oldmono) * 2 + 1);
+ if (wrapped) {
+ strcpy (wrapped, oldmono);
+ strcat (wrapped, oldmono);
+ } else {
+ msg = _("memory allocation error");
+ }
}
- if (palindrome(newmono))
+ if (!msg && palindrome(newmono))
msg = _("is a palindrome");
if (!msg && oldmono && strcmp(oldmono, newmono) == 0)
@@ -524,13 +538,17 @@ static const char *password_check(struct cracklib_options *opt,
if (!msg && usercheck(opt, newmono, usermono))
msg = _("contains the user name in some form");
- memset(newmono, 0, strlen(newmono));
- free(newmono);
free(usermono);
- if (old) {
+ if (newmono) {
+ memset(newmono, 0, strlen(newmono));
+ free(newmono);
+ }
+ if (oldmono) {
memset(oldmono, 0, strlen(oldmono));
- memset(wrapped, 0, strlen(wrapped));
free(oldmono);
+ }
+ if (wrapped) {
+ memset(wrapped, 0, strlen(wrapped));
free(wrapped);
}
13 years
[linux-pam] Add support for the mount_private option to pam_namespace.
by Tomáš Mráz
commit be52e613145564d55becf220111c0c81038eb7f6
Author: Tomas Mraz <tmraz(a)fedoraproject.org>
Date: Thu Jun 2 21:50:11 2011 +0200
Add support for the mount_private option to pam_namespace.
ChangeLog | 11 +++++++++++
modules/pam_namespace/pam_namespace.8.xml | 18 ++++++++++++++++++
modules/pam_namespace/pam_namespace.c | 29 ++++++++++++++++++++++++-----
modules/pam_namespace/pam_namespace.h | 1 +
4 files changed, 54 insertions(+), 5 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index c60a143..e91af88 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2011-06-02 Tomas Mraz <tm(a)t8m.info>
+
+ * modules/pam_namespace/pam_namespace.c (protect_dir): Add parameter
+ to always do protect mount the last directory in the path.
+ (check_inst_parent, create_polydir): Update the protect_dir() call.
+ (ns_setup): Likewise and add the MS_PRIVATE mount() call.
+ (pam_sm_open_session): Check the mount_private option.
+ * modules/pam_namespace/pam_namespace.h: Add the PAMNS_MOUNT_PRIVATE.
+ * modules/pam_namespace/pam_namespace.8.xml: Document the mount_private
+ option.
+
2011-05-30 Thorsten Kukuk <kukuk(a)thkukuk.de>
* modules/pam_timestamp/pam_timestamp.c (main): Remove unsused
diff --git a/modules/pam_namespace/pam_namespace.8.xml b/modules/pam_namespace/pam_namespace.8.xml
index 0433f0f..f0ebe2c 100644
--- a/modules/pam_namespace/pam_namespace.8.xml
+++ b/modules/pam_namespace/pam_namespace.8.xml
@@ -52,6 +52,9 @@
<arg choice="opt">
use_default_context
</arg>
+ <arg choice="opt">
+ mount_private
+ </arg>
</cmdsynopsis>
</refsynopsisdiv>
@@ -234,6 +237,21 @@
</listitem>
</varlistentry>
+ <varlistentry>
+ <term>
+ <option>mount_private</option>
+ </term>
+ <listitem>
+ <para>
+ This option should be used on systems where the / mount point and
+ its submounts are made shared (for example with a
+ <command>mount --make-rshared /</command> command).
+ The module will make the polyinstantiated directory mount points
+ private.
+ </para>
+ </listitem>
+ </varlistentry>
+
</variablelist>
</refsect1>
diff --git a/modules/pam_namespace/pam_namespace.c b/modules/pam_namespace/pam_namespace.c
index c47599e..d5a2d78 100644
--- a/modules/pam_namespace/pam_namespace.c
+++ b/modules/pam_namespace/pam_namespace.c
@@ -1003,7 +1003,7 @@ static int protect_mount(int dfd, const char *path, struct instance_data *idata)
return 0;
}
-static int protect_dir(const char *path, mode_t mode, int do_mkdir,
+static int protect_dir(const char *path, mode_t mode, int do_mkdir, int always,
struct instance_data *idata)
{
char *p = strdup(path);
@@ -1082,7 +1082,7 @@ static int protect_dir(const char *path, mode_t mode, int do_mkdir,
}
}
- if (flags & O_NOFOLLOW) {
+ if ((flags & O_NOFOLLOW) || always) {
/* we are inside user-owned dir - protect */
if (protect_mount(rv, p, idata) == -1) {
save_errno = errno;
@@ -1124,7 +1124,7 @@ static int check_inst_parent(char *ipath, struct instance_data *idata)
if (trailing_slash)
*trailing_slash = '\0';
- dfd = protect_dir(inst_parent, 0, 1, idata);
+ dfd = protect_dir(inst_parent, 0, 1, 0, idata);
if (dfd == -1 || fstat(dfd, &instpbuf) < 0) {
pam_syslog(idata->pamh, LOG_ERR,
@@ -1259,7 +1259,7 @@ static int create_polydir(struct polydir_s *polyptr,
}
#endif
- rc = protect_dir(dir, mode, 1, idata);
+ rc = protect_dir(dir, mode, 1, idata->flags & PAMNS_MOUNT_PRIVATE, idata);
if (rc == -1) {
pam_syslog(idata->pamh, LOG_ERR,
"Error creating directory %s: %m", dir);
@@ -1447,7 +1447,7 @@ static int ns_setup(struct polydir_s *polyptr,
pam_syslog(idata->pamh, LOG_DEBUG,
"Set namespace for directory %s", polyptr->dir);
- retval = protect_dir(polyptr->dir, 0, 0, idata);
+ retval = protect_dir(polyptr->dir, 0, 0, idata->flags & PAMNS_MOUNT_PRIVATE, idata);
if (retval < 0 && errno != ENOENT) {
pam_syslog(idata->pamh, LOG_ERR, "Polydir %s access error: %m",
@@ -1534,6 +1534,22 @@ static int ns_setup(struct polydir_s *polyptr,
goto error_out;
}
+ if (idata->flags & PAMNS_MOUNT_PRIVATE) {
+ /*
+ * Make the polyinstantiated dir private mount. This depends
+ * on making the dir a mount point in the protect_dir call.
+ */
+ if (mount(polyptr->dir, polyptr->dir, NULL, MS_PRIVATE|MS_REC, NULL) < 0) {
+ pam_syslog(idata->pamh, LOG_ERR, "Error making %s a private mount, %m",
+ polyptr->dir);
+ goto error_out;
+ }
+ if (idata->flags & PAMNS_DEBUG)
+ pam_syslog(idata->pamh, LOG_DEBUG,
+ "Polyinstantiated directory %s made as private mount", polyptr->dir);
+
+ }
+
/*
* Bind mount instance directory on top of the polyinstantiated
* directory to provide an instance of polyinstantiated directory
@@ -1964,6 +1980,9 @@ PAM_EXTERN int pam_sm_open_session(pam_handle_t *pamh, int flags UNUSED,
idata.flags |= PAMNS_USE_DEFAULT_CONTEXT;
idata.flags |= PAMNS_CTXT_BASED_INST;
}
+ if (strcmp(argv[i], "mount_private") == 0) {
+ idata.flags |= PAMNS_MOUNT_PRIVATE;
+ }
if (strcmp(argv[i], "unmnt_remnt") == 0)
unmnt = UNMNT_REMNT;
if (strcmp(argv[i], "unmnt_only") == 0)
diff --git a/modules/pam_namespace/pam_namespace.h b/modules/pam_namespace/pam_namespace.h
index da21bd7..7b39068 100644
--- a/modules/pam_namespace/pam_namespace.h
+++ b/modules/pam_namespace/pam_namespace.h
@@ -96,6 +96,7 @@
#define PAMNS_NO_UNMOUNT_ON_CLOSE 0x00010000 /* no unmount at session close */
#define PAMNS_USE_CURRENT_CONTEXT 0x00020000 /* use getcon instead of getexeccon */
#define PAMNS_USE_DEFAULT_CONTEXT 0x00040000 /* use get_default_context instead of getexeccon */
+#define PAMNS_MOUNT_PRIVATE 0x00080000 /* Make the polydir mounts private */
/* polydir flags */
#define POLYDIR_EXCLUSIVE 0x00000001 /* polyinstatiate exclusively for override uids */
13 years