mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-11-28 03:42:04 +01:00
Major update for unix_cmsg from Andrey Simonenko.
Quoting the submitter: - Added tests for SCM_BINTIME, LOCAL_PEERCRED, cmsghdr.cmsg_len - Code that checks correctness of groups was corrected (getgroups(2) change) - unix_cmsg.c was completely redesigned and simplified - Use less timeout value in unix_cmsg.c for faster work - Added support for not sending data in a message, not sending data and data array associated with a cmsghdr structure in a message - Existent tests were improved - unix_cmsg.t was redesigned and simplified Correctness of unix_cmsg verified on 7.1-STABLE, 9.1-STABLE and 10-CURRENT. PR: bin/131567 Submitted by: Andrey Simonenko <simon@comsys.ntu-kpi.kiev.ua> MFC after: 2 weeks
This commit is contained in:
parent
ff20578569
commit
b57181586c
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=246670
@ -1,127 +1,160 @@
|
||||
$FreeBSD$
|
||||
|
||||
About unix_cmsg
|
||||
================
|
||||
===============
|
||||
|
||||
This program is a collection of regression tests for ancillary (control)
|
||||
data for PF_LOCAL sockets (local domain or Unix domain sockets). There
|
||||
are tests for stream and datagram sockets.
|
||||
This program is a collection of regression tests for ancillary data
|
||||
(control information) for PF_LOCAL sockets (local domain or Unix domain
|
||||
sockets). There are tests for stream and datagram sockets.
|
||||
|
||||
Usually each test does following steps: create Server, fork Client,
|
||||
Client sends something to Server, Server verifies if everything
|
||||
is correct in received message. Sometimes Client sends several
|
||||
messages to Server.
|
||||
Usually each test does following steps: creates Server, forks Client,
|
||||
Client sends something to Server, Server verifies whether everything is
|
||||
correct in received message(s).
|
||||
|
||||
It is better to change the owner of unix_cmsg to some safe user
|
||||
(eg. nobody:nogroup) and set SUID and SGID bits, else some tests
|
||||
can give correct results for wrong implementation.
|
||||
(eg. nobody:nogroup) and set SUID and SGID bits, else some tests that
|
||||
check credentials can give correct results for wrong implementation.
|
||||
|
||||
It is better to run this program by a user that belongs to more
|
||||
than 16 groups.
|
||||
|
||||
Available options
|
||||
=================
|
||||
|
||||
-d Output debugging information, values of different fields of
|
||||
received messages, etc. Will produce many lines of information.
|
||||
usage: unix_cmsg [-dh] [-n num] [-s size] [-t type] [-z value] [testno]
|
||||
|
||||
-h Output help message and exit.
|
||||
Options are:
|
||||
-d Output debugging information
|
||||
-h Output the help message and exit
|
||||
-n num Number of messages to send
|
||||
-s size Specify size of data for IPC
|
||||
-t type Specify socket type (stream, dgram) for tests
|
||||
-z value Do not send data in a message (bit 0x1), do not send
|
||||
data array associated with a cmsghdr structure (bit 0x2)
|
||||
testno Run one test by its number (require the -t option)
|
||||
|
||||
-t <socktype>
|
||||
Run tests only for the given socket type: "stream" or "dgram".
|
||||
With this option it is possible to run only particular test,
|
||||
not all of them.
|
||||
Description
|
||||
===========
|
||||
|
||||
-z Do not send real control data if possible. Struct cmsghdr{}
|
||||
should be followed by real control data. It is not clear if
|
||||
a sender should give control data in all cases (this is not
|
||||
documented and an arbitrary application can choose anything).
|
||||
If Client sends something to Server, then it sends 5 messages by default.
|
||||
Number of messages can be changed in the -n command line option. Number
|
||||
of messages will be given as N in the following descriptions.
|
||||
|
||||
At least for PF_LOCAL sockets' control messages with types
|
||||
SCM_CREDS and SCM_TIMESTAMP the kernel does not need any
|
||||
control data. This option allow to not send real control data
|
||||
for SCM_CREDS and SCM_TIMESTAMP control messages.
|
||||
If Client sends something to Server, then it sends some data (few bytes)
|
||||
in each message by default. The size of this data can be changed by the -s
|
||||
command line option. The "-s 0" command line option means, that Client will
|
||||
send zero bytes represented by { NULL, 0 } value of struct iovec{}, referenced
|
||||
by the msg_iov field from struct msghdr{}. The "-z 1" or "-z 3" command line
|
||||
option means, that Client will send zero bytes represented by the NULL value
|
||||
in the msg_iov field from struct msghdr{}.
|
||||
|
||||
Description of tests
|
||||
====================
|
||||
If Client sends some ancillary data object, then this ancillary data object
|
||||
always has associated data array by default. The "-z 2" or "-z 3" option
|
||||
means, that Client will not send associated data array if possible.
|
||||
|
||||
For SOCK_STREAM sockets:
|
||||
-----------------------
|
||||
|
||||
1: Sending, receiving cmsgcred
|
||||
|
||||
Client connects to Server and sends two messages with data and
|
||||
control message with SCM_CREDS type to Server. Server should
|
||||
receive two messages, in both messages there should be data and
|
||||
control message with SCM_CREDS type followed by struct cmsgcred{}
|
||||
and this structure should contain correct information.
|
||||
Client connects to Server and sends N messages with SCM_CREDS ancillary
|
||||
data object. Server should receive N messages, each message should
|
||||
have SCM_CREDS ancillary data object followed by struct cmsgcred{}.
|
||||
|
||||
2: Receiving sockcred (listening socket has LOCAL_CREDS)
|
||||
2: Receiving sockcred (listening socket)
|
||||
|
||||
Server creates listen socket and set socket option LOCAL_CREDS
|
||||
for it. Client connects to Server and sends two messages with data
|
||||
to Server. Server should receive two messages, in first message
|
||||
there should be data and control message with SCM_CREDS type followed
|
||||
by struct sockcred{} and this structure should contain correct
|
||||
information, in second message there should be data and no control
|
||||
message.
|
||||
Server creates a listening stream socket and sets the LOCAL_CREDS
|
||||
socket option for it. Client connects to Server two times, each time
|
||||
it sends N messages. Server accepts two connections and receives N
|
||||
messages from each connection. The first message from each connection
|
||||
should have SCM_CREDS ancillary data object followed by struct sockcred{},
|
||||
next messages from the same connection should not have ancillary data.
|
||||
|
||||
3: Receiving sockcred (accepted socket has LOCAL_CREDS)
|
||||
3: Receiving sockcred (accepted socket)
|
||||
|
||||
Client connects to Server and sends two messages with data. Server
|
||||
accepts connection and set socket option LOCAL_CREDS for just accepted
|
||||
socket (here synchronization is used, to allow Client to see just set
|
||||
flag on Server's socket before sending messages to Server). Server
|
||||
should receive two messages, in first message there should be data and
|
||||
control message with SOCK_CRED type followed by struct sockcred{} and
|
||||
this structure should contain correct information, in second message
|
||||
there should be data and no control message.
|
||||
Client connects to Server. Server accepts connection and sets the
|
||||
LOCAL_CREDS socket option for just accepted socket. Client sends N
|
||||
messages to Server. Server should receive N messages, the first
|
||||
message should have SCM_CREDS ancillary data object followed by
|
||||
struct sockcred{}, next messages should not have ancillary data.
|
||||
|
||||
4: Sending cmsgcred, receiving sockcred
|
||||
|
||||
Server creates listen socket and set socket option LOCAL_CREDS
|
||||
for it. Client connects to Server and sends one message with data
|
||||
and control message with SCM_CREDS type to Server. Server should
|
||||
receive one message with data and control message with SCM_CREDS type
|
||||
followed by struct sockcred{} and this structure should contain
|
||||
correct information.
|
||||
Server creates a listening stream socket and sets the LOCAL_CREDS
|
||||
socket option for it. Client connects to Server and sends N messages
|
||||
with SCM_CREDS ancillary data object. Server should receive N messages,
|
||||
the first message should have SCM_CREDS ancillary data object followed
|
||||
by struct sockcred{}, each of next messages should have SCM_CREDS
|
||||
ancillary data object followed by struct cmsgcred{}.
|
||||
|
||||
5: Sending, receiving timestamp
|
||||
5: Sending, receiving timeval
|
||||
|
||||
Client connects to Server and sends message with data and control
|
||||
message with SCM_TIMESTAMP type to Server. Server should receive
|
||||
message with data and control message with SCM_TIMESTAMP type
|
||||
followed by struct timeval{}.
|
||||
Client connects to Server and sends message with SCM_TIMESTAMP ancillary
|
||||
data object. Server should receive one message with SCM_TIMESTAMP
|
||||
ancillary data object followed by struct timeval{}.
|
||||
|
||||
6: Sending, receiving bintime
|
||||
|
||||
Client connects to Server and sends message with SCM_BINTIME ancillary
|
||||
data object. Server should receive one message with SCM_BINTIME
|
||||
ancillary data object followed by struct bintime{}.
|
||||
|
||||
7: Checking cmsghdr.cmsg_len
|
||||
|
||||
Client connects to Server and tries to send several messages with
|
||||
SCM_CREDS ancillary data object that has wrong cmsg_len field in its
|
||||
struct cmsghdr{}. All these attempts should fail, since cmsg_len
|
||||
in all requests is less than CMSG_LEN(0).
|
||||
|
||||
8: Check LOCAL_PEERCRED socket option
|
||||
|
||||
This test does not use ancillary data, but can be implemented here.
|
||||
Client connects to Server. Both Client and Server verify that
|
||||
credentials of the peer are correct using LOCAL_PEERCRED socket option.
|
||||
|
||||
For SOCK_DGRAM sockets:
|
||||
----------------------
|
||||
|
||||
1: Sending, receiving cmsgcred
|
||||
|
||||
Client sends to Server two messages with data and control message
|
||||
with SCM_CREDS type to Server. Server should receive two messages,
|
||||
in both messages there should be data and control message with
|
||||
SCM_CREDS type followed by struct cmsgcred{} and this structure
|
||||
should contain correct information.
|
||||
Client connects to Server and sends N messages with SCM_CREDS ancillary
|
||||
data object. Server should receive N messages, each message should
|
||||
have SCM_CREDS ancillary data object followed by struct cmsgcred{}.
|
||||
|
||||
2: Receiving sockcred
|
||||
|
||||
Server creates datagram socket and set socket option LOCAL_CREDS
|
||||
for it. Client sends two messages with data to Server. Server should
|
||||
receive two messages, in both messages there should be data and control
|
||||
message with SCM_CREDS type followed by struct sockcred{} and this
|
||||
structure should contain correct information.
|
||||
Server creates datagram socket and sets the LOCAL_CREDS socket option
|
||||
for it. Client sends N messages to Server. Server should receive N
|
||||
messages, each message should have SCM_CREDS ancillary data object
|
||||
followed by struct sockcred{}.
|
||||
|
||||
3: Sending cmsgcred, receiving sockcred
|
||||
|
||||
Server creates datagram socket and set socket option LOCAL_CREDS
|
||||
for it. Client sends one message with data and control message with
|
||||
SOCK_CREDS type to Server. Server should receive one message with
|
||||
data and control message with SCM_CREDS type followed by struct
|
||||
sockcred{} and this structure should contain correct information.
|
||||
|
||||
4: Sending, receiving timestamp
|
||||
Server creates datagram socket and sets the LOCAL_CREDS socket option
|
||||
for it. Client sends N messages with SCM_CREDS ancillary data object
|
||||
to Server. Server should receive N messages, the first message should
|
||||
have SCM_CREDS ancillary data object followed by struct sockcred{},
|
||||
each of next messages should have SCM_CREDS ancillary data object
|
||||
followed by struct cmsgcred{}.
|
||||
|
||||
Client sends message with data and control message with SCM_TIMESTAMP
|
||||
type to Server. Server should receive message with data and control
|
||||
message with SCM_TIMESTAMP type followed by struct timeval{}.
|
||||
4: Sending, receiving timeval
|
||||
|
||||
Client sends one message with SCM_TIMESTAMP ancillary data object
|
||||
to Server. Server should receive one message with SCM_TIMESTAMP
|
||||
ancillary data object followed by struct timeval{}.
|
||||
|
||||
5: Sending, receiving bintime
|
||||
|
||||
Client sends one message with SCM_BINTIME ancillary data object
|
||||
to Server. Server should receive one message with SCM_BINTIME
|
||||
ancillary data object followed by struct bintime{}.
|
||||
|
||||
6: Checking cmsghdr.cmsg_len
|
||||
|
||||
Client tries to send Server several messages with SCM_CREDS ancillary
|
||||
data object that has wrong cmsg_len field in its struct cmsghdr{}.
|
||||
All these attempts should fail, since cmsg_len in all requests is less
|
||||
than CMSG_LEN(0).
|
||||
|
||||
- Andrey Simonenko
|
||||
simon@comsys.ntu-kpi.kiev.ua
|
||||
andreysimonenko@users.sourceforge.net
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -11,47 +11,78 @@ n=0
|
||||
|
||||
run()
|
||||
{
|
||||
result=`${cmd} -t $2 $3 $4 2>&1`
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -n "ok $1"
|
||||
else
|
||||
echo -n "not ok $1"
|
||||
result=`${cmd} -t $2 $3 ${5%% *} 2>&1`
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -n "not "
|
||||
fi
|
||||
echo " -" $5
|
||||
echo "ok $1 - $4 ${5#* }"
|
||||
echo ${result} | grep -E "SERVER|CLIENT" | while read line; do
|
||||
echo "# ${line}"
|
||||
done
|
||||
}
|
||||
|
||||
echo "1..15"
|
||||
echo "1..47"
|
||||
|
||||
for desc in \
|
||||
"Sending, receiving cmsgcred" \
|
||||
"Receiving sockcred (listening socket has LOCAL_CREDS) # TODO" \
|
||||
"Receiving sockcred (accepted socket has LOCAL_CREDS) # TODO" \
|
||||
"Sending cmsgcred, receiving sockcred # TODO" \
|
||||
"Sending, receiving timestamp"
|
||||
for t1 in \
|
||||
"1 Sending, receiving cmsgcred" \
|
||||
"4 Sending cmsgcred, receiving sockcred" \
|
||||
"5 Sending, receiving timeval" \
|
||||
"6 Sending, receiving bintime" \
|
||||
"7 Check cmsghdr.cmsg_len"
|
||||
do
|
||||
n=`expr ${n} + 1`
|
||||
run ${n} stream "" ${n} "STREAM ${desc}"
|
||||
for t2 in \
|
||||
"0 " \
|
||||
"1 (no data)" \
|
||||
"2 (no array)" \
|
||||
"3 (no data, array)"
|
||||
do
|
||||
n=$((n + 1))
|
||||
run ${n} stream "-z ${t2%% *}" STREAM "${t1} ${t2#* }"
|
||||
done
|
||||
done
|
||||
|
||||
i=0
|
||||
for desc in \
|
||||
"Sending, receiving cmsgcred" \
|
||||
"Receiving sockcred # TODO" \
|
||||
"Sending cmsgcred, receiving sockcred # TODO" \
|
||||
"Sending, receiving timestamp"
|
||||
for t1 in \
|
||||
"2 Receiving sockcred (listening socket)" \
|
||||
"3 Receiving sockcred (accepted socket)"
|
||||
do
|
||||
i=`expr ${i} + 1`
|
||||
n=`expr ${n} + 1`
|
||||
run ${n} dgram "" ${i} "DGRAM ${desc}"
|
||||
for t2 in \
|
||||
"0 " \
|
||||
"1 (no data)"
|
||||
do
|
||||
n=$((n + 1))
|
||||
run ${n} stream "-z ${t2%% *}" STREAM "${t1} ${t2#* }"
|
||||
done
|
||||
done
|
||||
|
||||
run 10 stream -z 1 "STREAM Sending, receiving cmsgcred (no control data)"
|
||||
run 11 stream -z 4 "STREAM Sending cmsgcred, receiving sockcred (no control data) # TODO"
|
||||
run 12 stream -z 5 "STREAM Sending, receiving timestamp (no control data)"
|
||||
n=$((n + 1))
|
||||
run ${n} stream "-z 0" STREAM "8 Check LOCAL_PEERCRED socket option"
|
||||
|
||||
run 13 dgram -z 1 "DGRAM Sending, receiving cmsgcred (no control data)"
|
||||
run 14 dgram -z 3 "DGRAM Sending cmsgcred, receiving sockcred (no control data) # TODO"
|
||||
run 15 dgram -z 4 "DGRAM Sending, receiving timestamp (no control data)"
|
||||
for t1 in \
|
||||
"1 Sending, receiving cmsgcred" \
|
||||
"3 Sending cmsgcred, receiving sockcred" \
|
||||
"4 Sending, receiving timeval" \
|
||||
"5 Sending, receiving bintime" \
|
||||
"6 Check cmsghdr.cmsg_len"
|
||||
do
|
||||
for t2 in \
|
||||
"0 " \
|
||||
"1 (no data)" \
|
||||
"2 (no array)" \
|
||||
"3 (no data, array)"
|
||||
do
|
||||
n=$((n + 1))
|
||||
run ${n} dgram "-z ${t2%% *}" DGRAM "${t1} ${t2#* }"
|
||||
done
|
||||
done
|
||||
|
||||
for t1 in \
|
||||
"2 Receiving sockcred"
|
||||
do
|
||||
for t2 in \
|
||||
"0 " \
|
||||
"1 (no data)"
|
||||
do
|
||||
n=$((n + 1))
|
||||
run ${n} dgram "-z ${t2%% *}" DGRAM "${t1} ${t2#* }"
|
||||
done
|
||||
done
|
||||
|
Loading…
Reference in New Issue
Block a user