Bug 544 - sshd w/privsep fails on Linux 2.0, mm_receive_fd: expected type 1 got 1074276337
Summary: sshd w/privsep fails on Linux 2.0, mm_receive_fd: expected type 1 got 1074276337
Status: CLOSED FIXED
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: sshd (show other bugs)
Version: -current
Hardware: ix86 Linux
: P2 normal
Assignee: OpenSSH Bugzilla mailing list
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2003-04-19 16:26 AEST by Darren Tucker
Modified: 2004-04-14 12:24 AEST (History)
0 users

See Also:


Attachments
fdpasstest.c: test for descriptor-passing bug on Linux 2.0 (1.11 KB, text/plain)
2003-04-19 16:33 AEST, Darren Tucker
no flags Details
Define BROKEN_CMSG_TYPE for Linux 2.0 kernels (1.87 KB, patch)
2003-04-20 22:34 AEST, Darren Tucker
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Darren Tucker 2003-04-19 16:26:10 AEST
I'm attempting to reproduce some of the reported bugs on early Linuxes and I've 
found the following problem with privsep enabled (Debian slink, kernel 2.0.38, 
libc6 2.0.7).  It seems to be related to file descriptor passing.

$ ./sshd -ddd -p 2022
[snip]
debug3: mm_answer_pty entering
debug1: session_new: init
debug1: session_new: session 0
debug3: mm_pty_allocate: waiting for MONITOR_ANS_PTY
debug3: mm_request_receive_expect entering: type 26
debug3: mm_request_receive entering
debug3: mm_request_send entering: type 26
mm_receive_fd: expected type 1 got 1074276337

It seems to be a bug in 2.0 kernels, cmsg_level and cmsg_type returned by 
recvmsg() make no sense.  I built a test program (which I will attach) from code 
from monitor_fdpass.c.

After the fd pass, a 2.0.38 kernel gives:
(gdb) print *cmsg
$1 = {cmsg_len = 16, cmsg_level = 134514016, cmsg_type = -1073742828,   
__cmsg_data = 0xbffffc08 "\005"}

A 2.4.18 kernel gives:
(gdb) print *cmsg
$1 = {cmsg_len = 16, cmsg_level = 1, cmsg_type = 1, __cmsg_data = 0xbffff5fc 
"\a"}

If you comment out the "if (cmsg->cmsg_type != SCM_RIGHTS)" test in 
mm_receive_fd(), privsep seems to work OK on 2.0 kernels.

I will reduce the test program to an autoconf test, add "#ifndef 
BROKEN_CMSG_TYPE" and attach the resulting patch.
Comment 1 Darren Tucker 2003-04-19 16:33:33 AEST
Created attachment 271 [details]
fdpasstest.c: test for descriptor-passing bug on Linux 2.0

Quick hacked-together test for fd passing bug.
Comment 2 Darren Tucker 2003-04-20 22:34:13 AEST
Created attachment 272 [details]
Define BROKEN_CMSG_TYPE for Linux 2.0 kernels

I couldn't get the test case to work with compiler optimization on (ie the
default CFLAGS).  Not sure why.

Gave up and added a test for Linux 2.0 in configure.ac.
Comment 3 Darren Tucker 2003-05-02 20:52:46 AEST
Fix applied.
Comment 4 Damien Miller 2004-04-14 12:24:19 AEST
Mass change of RESOLVED bugs to CLOSED