Bug 1960 - Running sshd in wrong SELinux context causes segmentation fault when a user logs in
Summary: Running sshd in wrong SELinux context causes segmentation fault when a user l...
Status: CLOSED FIXED
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: sshd (show other bugs)
Version: 5.8p1
Hardware: amd64 Linux
: P2 minor
Assignee: Assigned to nobody
URL:
Keywords:
Depends on:
Blocks: V_6_0
  Show dependency treegraph
 
Reported: 2011-12-14 07:53 AEDT by Sven Vermeulen
Modified: 2023-01-13 13:37 AEDT (History)
1 user (show)

See Also:


Attachments
Suggested one-line patch to fix this issue (389 bytes, patch)
2011-12-14 07:53 AEDT, Sven Vermeulen
no flags Details | Diff
selinux-getctxbyname-null.diff (963 bytes, patch)
2012-02-24 11:32 AEDT, Damien Miller
dtucker: ok+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sven Vermeulen 2011-12-14 07:53:56 AEDT
Created attachment 2119 [details]
Suggested one-line patch to fix this issue

On a SELinux-enabled Linux system (but running in permissive mode), if the SSH daemon runs in the wrong context (for instance kernel_t) a logon of a user through SSH causes the session to terminate abruptly due to a segmentation fault. 

This is caused by not initializing the local variable "sc" in the openbsd-compat/port-linux.c::ssh_selinux_getctxbyname() function. The call to get_default_context() will result in the return code -1, but "sc" is left untouched (and thus not a valid security_context_t instance). Later in the function, "sc" is returned to the calling function (which is ssh_selinux_setup_exec_context) which tries to free the context through freecon(user_ctx).

This can be fixed by initializing sc to NULL to begin with (see line 59):

 55 /* Return the default security context for the given username */
 56 static security_context_t
 57 ssh_selinux_getctxbyname(char *pwname)
 58 {
 59         security_context_t sc = NULL;
 60         char *sename = NULL, *lvl = NULL;
 61         int r;

Because it is initialized to NULL, it will remain NULL if the context of SSH is wrong, in which case there will be no attempt to freecon() it in ssh_selinux_setup_exec_context. If the context is correct, "sc" will be updated to point to a proper security_context_t instance.
Comment 1 Damien Miller 2012-02-24 11:32:25 AEDT
Created attachment 2134 [details]
selinux-getctxbyname-null.diff

set sc=NULL on failues too
Comment 2 Damien Miller 2012-03-09 10:25:44 AEDT
Patch applied - will be in the openssh-6.0 release due very soon.

Thanks!
Comment 3 Damien Miller 2015-08-11 23:04:22 AEST
Set all RESOLVED bugs to CLOSED with release of OpenSSH 7.1