Skip to content

Commit 7532ca1

Browse files
committed
add access sanity check
1 parent 829a077 commit 7532ca1

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

samples/xskrestricted/xskrestricted.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ RunChild(
7777
XSK_RING TxRing;
7878
XSK_RING TxCompRing;
7979
UINT32 RingIndex;
80+
HANDLE CreatedXsk;
81+
HANDLE CreatedProgram;
82+
XDP_RULE Rule = {0};
8083

8184
//
8285
// Connect to the named pipe created by the parent to receive the
@@ -111,6 +114,26 @@ RunChild(
111114
"[Child] Running with duplicated handles: Socket=%p Program=%p IfIndex=%u",
112115
Socket, Program, Params.IfIndex);
113116

117+
//
118+
// For sanity, verify this restricted process can't create sockets or
119+
// programs.
120+
//
121+
122+
if (XskCreate(&CreatedXsk) != HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED)) {
123+
LOGERR("[Child] XskCreate was not denied access");
124+
return 1;
125+
}
126+
127+
Rule.Match = XDP_MATCH_ALL;
128+
Rule.Action = XDP_PROGRAM_ACTION_PASS;
129+
130+
if (XdpCreateProgram(
131+
Params.IfIndex, &XdpInspectRxL2, 0, XDP_CREATE_PROGRAM_FLAG_NONE, &Rule, 1,
132+
&CreatedProgram) != HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED)) {
133+
LOGERR("[Child] XdpCreateProgram was not denied access");
134+
return 1;
135+
}
136+
114137
//
115138
// Register our frame buffer with the AF_XDP socket. The parent created
116139
// and bound the socket, but UMEM registration, ring setup, and activation

0 commit comments

Comments
 (0)