samba-CVE-2011-0719.patch 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. From 724e44eed299c618066dec411530aa9f156119ec Mon Sep 17 00:00:00 2001
  2. From: Karolin Seeger <kseeger@samba.org>
  3. Date: Sun, 27 Feb 2011 18:28:29 +0100
  4. Subject: [PATCH] Fix denial of service - memory corruption.
  5. CVE-2011-0719
  6. Fix bug #7949 (DoS in Winbind and smbd with many file descriptors open).
  7. All current released versions of Samba are vulnerable to
  8. a denial of service caused by memory corruption. Range
  9. checks on file descriptors being used in the FD_SET macro
  10. were not present allowing stack corruption. This can cause
  11. the Samba code to crash or to loop attempting to select
  12. on a bad file descriptor set.
  13. A connection to a file share, or a local account is needed
  14. to exploit this problem, either authenticated or unauthenticated
  15. (guest connection).
  16. Currently we do not believe this flaw is exploitable
  17. beyond a crash or causing the code to loop, but on the
  18. advice of our security reviewers we are releasing fixes
  19. in case an exploit is discovered at a later date.
  20. ---
  21. source/client/client.c | 4 +++-
  22. source/client/dnsbrowse.c | 12 ++++++++++++
  23. source/lib/events.c | 13 +++++++++++++
  24. source/lib/packet.c | 5 +++++
  25. source/lib/readline.c | 5 +++++
  26. source/lib/select.c | 6 ++++++
  27. source/lib/util_sock.c | 11 +++++++++--
  28. source/libaddns/dnssock.c | 6 +++++-
  29. source/libsmb/nmblib.c | 5 +++++
  30. source/nmbd/nmbd_packets.c | 24 ++++++++++++++++++++++--
  31. source/nsswitch/wb_common.c | 22 ++++++++++++++++++++--
  32. source/printing/printing.c | 5 +++++
  33. source/smbd/dnsregister.c | 6 ++++++
  34. source/smbd/oplock.c | 5 ++++-
  35. source/smbd/oplock_irix.c | 5 +++++
  36. source/smbd/process.c | 2 +-
  37. source/smbd/server.c | 29 +++++++++++++++++++++--------
  38. source/utils/smbfilter.c | 8 ++++++--
  39. source/winbindd/winbindd.c | 12 +++++++++++-
  40. source/winbindd/winbindd_dual.c | 7 +++++++
  41. 20 files changed, 171 insertions(+), 21 deletions(-)
  42. diff --git a/source/client/client.c b/source/client/client.c
  43. index 53bd9e6..a989441 100644
  44. --- a/source/client/client.c
  45. +++ b/source/client/client.c
  46. @@ -4379,8 +4379,10 @@ static void readline_callback(void)
  47. again:
  48. - if (cli->fd == -1)
  49. + if (cli->fd < 0 || cli->fd >= FD_SETSIZE) {
  50. + errno = EBADF;
  51. return;
  52. + }
  53. FD_ZERO(&fds);
  54. FD_SET(cli->fd,&fds);
  55. diff --git a/source/client/dnsbrowse.c b/source/client/dnsbrowse.c
  56. index 5e3a4de..aa2fb22 100644
  57. --- a/source/client/dnsbrowse.c
  58. +++ b/source/client/dnsbrowse.c
  59. @@ -81,6 +81,11 @@ static void do_smb_resolve(struct mdns_smbsrv_result *browsesrv)
  60. TALLOC_FREE(fdset);
  61. }
  62. + if (mdnsfd < 0 || mdnsfd >= FD_SETSIZE) {
  63. + errno = EBADF;
  64. + break;
  65. + }
  66. +
  67. fdsetsz = howmany(mdnsfd + 1, NFDBITS) * sizeof(fd_mask);
  68. fdset = TALLOC_ZERO(ctx, fdsetsz);
  69. FD_SET(mdnsfd, fdset);
  70. @@ -183,6 +188,13 @@ int do_smb_browse(void)
  71. fdsetsz = howmany(mdnsfd + 1, NFDBITS) * sizeof(fd_mask);
  72. fdset = TALLOC_ZERO(ctx, fdsetsz);
  73. +
  74. + if (mdnsfd < 0 || mdnsfd >= FD_SETSIZE) {
  75. + errno = EBADF;
  76. + TALLOC_FREE(ctx);
  77. + return 1;
  78. + }
  79. +
  80. FD_SET(mdnsfd, fdset);
  81. tv.tv_sec = 1;
  82. diff --git a/source/lib/events.c b/source/lib/events.c
  83. index cd20ceb..2ddbab7 100644
  84. --- a/source/lib/events.c
  85. +++ b/source/lib/events.c
  86. @@ -140,6 +140,11 @@ struct fd_event *event_add_fd(struct event_context *event_ctx,
  87. {
  88. struct fd_event *fde;
  89. + if (fd < 0 || fd >= FD_SETSIZE) {
  90. + errno = EBADF;
  91. + return NULL;
  92. + }
  93. +
  94. if (!(fde = TALLOC_P(mem_ctx, struct fd_event))) {
  95. return NULL;
  96. }
  97. @@ -190,6 +195,14 @@ bool event_add_to_select_args(struct event_context *event_ctx,
  98. bool ret = False;
  99. for (fde = event_ctx->fd_events; fde; fde = fde->next) {
  100. + if (fde->fd < 0 || fde->fd >= FD_SETSIZE) {
  101. + /* We ignore here, as it shouldn't be
  102. + possible to add an invalid fde->fd
  103. + but we don't want FD_SET to see an
  104. + invalid fd. */
  105. + continue;
  106. + }
  107. +
  108. if (fde->flags & EVENT_FD_READ) {
  109. FD_SET(fde->fd, read_fds);
  110. ret = True;
  111. diff --git a/source/lib/packet.c b/source/lib/packet.c
  112. index e048616..512c7f2 100644
  113. --- a/source/lib/packet.c
  114. +++ b/source/lib/packet.c
  115. @@ -106,6 +106,11 @@ NTSTATUS packet_fd_read_sync(struct packet_context *ctx)
  116. int res;
  117. fd_set r_fds;
  118. + if (ctx->fd < 0 || ctx->fd >= FD_SETSIZE) {
  119. + errno = EBADF;
  120. + return map_nt_error_from_unix(errno);
  121. + }
  122. +
  123. FD_ZERO(&r_fds);
  124. FD_SET(ctx->fd, &r_fds);
  125. diff --git a/source/lib/readline.c b/source/lib/readline.c
  126. index 34867aa..70a82f2 100644
  127. --- a/source/lib/readline.c
  128. +++ b/source/lib/readline.c
  129. @@ -91,6 +91,11 @@ static char *smb_readline_replacement(const char *prompt, void (*callback)(void)
  130. timeout.tv_sec = 5;
  131. timeout.tv_usec = 0;
  132. + if (fd < 0 || fd >= FD_SETSIZE) {
  133. + errno = EBADF;
  134. + break;
  135. + }
  136. +
  137. FD_ZERO(&fds);
  138. FD_SET(fd,&fds);
  139. diff --git a/source/lib/select.c b/source/lib/select.c
  140. index c3da6a9..2d5f02c 100644
  141. --- a/source/lib/select.c
  142. +++ b/source/lib/select.c
  143. @@ -61,6 +61,11 @@ int sys_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, s
  144. if (pipe(select_pipe) == -1)
  145. smb_panic("Could not create select pipe");
  146. + if (select_pipe[0] < 0 || select_pipe[0] >= FD_SETSIZE) {
  147. + errno = EBADF;
  148. + return -1;
  149. + }
  150. +
  151. /*
  152. * These next two lines seem to fix a bug with the Linux
  153. * 2.0.x kernel (and probably other UNIXes as well) where
  154. @@ -87,6 +92,7 @@ int sys_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, s
  155. readfds2 = &readfds_buf;
  156. FD_ZERO(readfds2);
  157. }
  158. +
  159. FD_SET(select_pipe[0], readfds2);
  160. errno = 0;
  161. diff --git a/source/lib/util_sock.c b/source/lib/util_sock.c
  162. index 650bd13..8aa2c97 100644
  163. --- a/source/lib/util_sock.c
  164. +++ b/source/lib/util_sock.c
  165. @@ -960,6 +960,11 @@ NTSTATUS read_socket_with_timeout(int fd, char *buf,
  166. timeout.tv_usec = (long)(1000 * (time_out % 1000));
  167. for (nread=0; nread < mincnt; ) {
  168. + if (fd < 0 || fd >= FD_SETSIZE) {
  169. + errno = EBADF;
  170. + return map_nt_error_from_unix(EBADF);
  171. + }
  172. +
  173. FD_ZERO(&fds);
  174. FD_SET(fd,&fds);
  175. @@ -1492,7 +1497,7 @@ bool open_any_socket_out(struct sockaddr_storage *addrs, int num_addrs,
  176. for (i=0; i<num_addrs; i++) {
  177. sockets[i] = socket(addrs[i].ss_family, SOCK_STREAM, 0);
  178. - if (sockets[i] < 0)
  179. + if (sockets[i] < 0 || sockets[i] >= FD_SETSIZE)
  180. goto done;
  181. set_blocking(sockets[i], false);
  182. }
  183. @@ -1541,8 +1546,10 @@ bool open_any_socket_out(struct sockaddr_storage *addrs, int num_addrs,
  184. FD_ZERO(&r_fds);
  185. for (i=0; i<num_addrs; i++) {
  186. - if (sockets[i] == -1)
  187. + if (sockets[i] < 0 || sockets[i] >= FD_SETSIZE) {
  188. + /* This cannot happen - ignore if so. */
  189. continue;
  190. + }
  191. FD_SET(sockets[i], &wr_fds);
  192. FD_SET(sockets[i], &r_fds);
  193. if (sockets[i]>maxfd)
  194. diff --git a/source/libaddns/dnssock.c b/source/libaddns/dnssock.c
  195. index 7c8bd41..f427bd5 100644
  196. --- a/source/libaddns/dnssock.c
  197. +++ b/source/libaddns/dnssock.c
  198. @@ -218,7 +218,11 @@ static DNS_ERROR read_all(int fd, uint8 *data, size_t len)
  199. while (total < len) {
  200. ssize_t ret;
  201. int fd_ready;
  202. -
  203. +
  204. + if (fd < 0 || fd >= FD_SETSIZE) {
  205. + return ERROR_DNS_SOCKET_ERROR;
  206. + }
  207. +
  208. FD_ZERO( &rfds );
  209. FD_SET( fd, &rfds );
  210. diff --git a/source/libsmb/nmblib.c b/source/libsmb/nmblib.c
  211. index bfe5e7b..768e54d 100644
  212. --- a/source/libsmb/nmblib.c
  213. +++ b/source/libsmb/nmblib.c
  214. @@ -1097,6 +1097,11 @@ struct packet_struct *receive_packet(int fd,enum packet_type type,int t)
  215. struct timeval timeout;
  216. int ret;
  217. + if (fd < 0 || fd >= FD_SETSIZE) {
  218. + errno = EBADF;
  219. + return NULL;
  220. + }
  221. +
  222. FD_ZERO(&fds);
  223. FD_SET(fd,&fds);
  224. timeout.tv_sec = t/1000;
  225. diff --git a/source/nmbd/nmbd_packets.c b/source/nmbd/nmbd_packets.c
  226. index 4b97819..03e5362 100644
  227. --- a/source/nmbd/nmbd_packets.c
  228. +++ b/source/nmbd/nmbd_packets.c
  229. @@ -1683,7 +1683,7 @@ static bool create_listen_fdset(fd_set **ppset, int **psock_array, int *listen_n
  230. for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
  231. count++;
  232. - if((count*2) + 2 > FD_SETSIZE) {
  233. + if((count*2) + 2 >= FD_SETSIZE) {
  234. DEBUG(0,("create_listen_fdset: Too many file descriptors needed (%d). We can \
  235. only use %d.\n", (count*2) + 2, FD_SETSIZE));
  236. SAFE_FREE(pset);
  237. @@ -1699,24 +1699,44 @@ only use %d.\n", (count*2) + 2, FD_SETSIZE));
  238. FD_ZERO(pset);
  239. /* Add in the broadcast socket on 137. */
  240. + if (ClientNMB < 0 || ClientNMB >= FD_SETSIZE) {
  241. + errno = EBADF;
  242. + SAFE_FREE(pset);
  243. + return True;
  244. + }
  245. +
  246. FD_SET(ClientNMB,pset);
  247. sock_array[num++] = ClientNMB;
  248. *maxfd = MAX( *maxfd, ClientNMB);
  249. /* Add in the 137 sockets on all the interfaces. */
  250. for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
  251. + if (subrec->nmb_sock < 0 || subrec->nmb_sock >= FD_SETSIZE) {
  252. + /* We have to ignore sockets outside FD_SETSIZE. */
  253. + continue;
  254. + }
  255. FD_SET(subrec->nmb_sock,pset);
  256. sock_array[num++] = subrec->nmb_sock;
  257. *maxfd = MAX( *maxfd, subrec->nmb_sock);
  258. }
  259. /* Add in the broadcast socket on 138. */
  260. + if (ClientDGRAM < 0 || ClientDGRAM >= FD_SETSIZE) {
  261. + errno = EBADF;
  262. + SAFE_FREE(pset);
  263. + return True;
  264. + }
  265. +
  266. FD_SET(ClientDGRAM,pset);
  267. sock_array[num++] = ClientDGRAM;
  268. *maxfd = MAX( *maxfd, ClientDGRAM);
  269. /* Add in the 138 sockets on all the interfaces. */
  270. for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
  271. + if (subrec->dgram_sock < 0 || subrec->dgram_sock >= FD_SETSIZE) {
  272. + /* We have to ignore sockets outside FD_SETSIZE. */
  273. + continue;
  274. + }
  275. FD_SET(subrec->dgram_sock,pset);
  276. sock_array[num++] = subrec->dgram_sock;
  277. *maxfd = MAX( *maxfd, subrec->dgram_sock);
  278. @@ -1767,7 +1787,7 @@ bool listen_for_packets(bool run_election)
  279. #ifndef SYNC_DNS
  280. dns_fd = asyncdns_fd();
  281. - if (dns_fd != -1) {
  282. + if (dns_fd >= 0 && dns_fd < FD_SETSIZE) {
  283. FD_SET(dns_fd, &r_fds);
  284. maxfd = MAX( maxfd, dns_fd);
  285. }
  286. diff --git a/source/nsswitch/wb_common.c b/source/nsswitch/wb_common.c
  287. index a164621..4f76bd0 100644
  288. --- a/source/nsswitch/wb_common.c
  289. +++ b/source/nsswitch/wb_common.c
  290. @@ -240,6 +240,12 @@ static int winbind_named_pipe_sock(const char *dir)
  291. switch (errno) {
  292. case EINPROGRESS:
  293. +
  294. + if (fd < 0 || fd >= FD_SETSIZE) {
  295. + errno = EBADF;
  296. + goto error_out;
  297. + }
  298. +
  299. FD_ZERO(&w_fds);
  300. FD_SET(fd, &w_fds);
  301. tv.tv_sec = CONNECT_TIMEOUT - wait_time;
  302. @@ -383,7 +389,13 @@ int winbind_write_sock(void *buffer, int count, int recursing, int need_priv)
  303. while(nwritten < count) {
  304. struct timeval tv;
  305. fd_set r_fds;
  306. -
  307. +
  308. + if (winbindd_fd < 0 || winbindd_fd >= FD_SETSIZE) {
  309. + errno = EBADF;
  310. + winbind_close_sock();
  311. + return -1;
  312. + }
  313. +
  314. /* Catch pipe close on other end by checking if a read()
  315. call would not block by calling select(). */
  316. @@ -443,7 +455,13 @@ int winbind_read_sock(void *buffer, int count)
  317. while(nread < count) {
  318. struct timeval tv;
  319. fd_set r_fds;
  320. -
  321. +
  322. + if (winbindd_fd < 0 || winbindd_fd >= FD_SETSIZE) {
  323. + errno = EBADF;
  324. + winbind_close_sock();
  325. + return -1;
  326. + }
  327. +
  328. /* Catch pipe close on other end by checking if a read()
  329. call would not block by calling select(). */
  330. diff --git a/source/printing/printing.c b/source/printing/printing.c
  331. index a9272eb..c3b8c61 100644
  332. --- a/source/printing/printing.c
  333. +++ b/source/printing/printing.c
  334. @@ -1407,6 +1407,11 @@ void start_background_queue(void)
  335. exit(1);
  336. }
  337. + if (pause_pipe[1] < 0 || pause_pipe[1] >= FD_SETSIZE) {
  338. + DEBUG(5,("start_background_queue: pipe fd out of range.\n"));
  339. + exit(1);
  340. + }
  341. +
  342. background_lpq_updater_pid = sys_fork();
  343. if (background_lpq_updater_pid == -1) {
  344. diff --git a/source/smbd/dnsregister.c b/source/smbd/dnsregister.c
  345. index f02739e..3c689b9 100644
  346. --- a/source/smbd/dnsregister.c
  347. +++ b/source/smbd/dnsregister.c
  348. @@ -125,6 +125,9 @@ void dns_register_smbd(struct dns_reg_state ** dns_state_ptr,
  349. */
  350. if (dns_state->srv_ref != NULL) {
  351. mdnsd_conn_fd = DNSServiceRefSockFD(dns_state->srv_ref);
  352. + if (mdnsd_conn_fd < 0 || mdnsd_conn_fd >= FD_SETSIZE) {
  353. + return;
  354. + }
  355. FD_SET(mdnsd_conn_fd, listen_set);
  356. return;
  357. }
  358. @@ -156,6 +159,9 @@ void dns_register_smbd(struct dns_reg_state ** dns_state_ptr,
  359. }
  360. mdnsd_conn_fd = DNSServiceRefSockFD(dns_state->srv_ref);
  361. + if (mdnsd_conn_fd < 0 || mdnsd_conn_fd >= FD_SETSIZE) {
  362. + return;
  363. + }
  364. FD_SET(mdnsd_conn_fd, listen_set);
  365. *maxfd = MAX(*maxfd, mdnsd_conn_fd);
  366. *timeout = timeval_zero();
  367. diff --git a/source/smbd/oplock.c b/source/smbd/oplock.c
  368. index a07d05d..5ae3fdf 100644
  369. --- a/source/smbd/oplock.c
  370. +++ b/source/smbd/oplock.c
  371. @@ -241,7 +241,10 @@ bool downgrade_oplock(files_struct *fsp)
  372. int oplock_notify_fd(void)
  373. {
  374. if (koplocks) {
  375. - return koplocks->notification_fd;
  376. + int fd = koplocks->notification_fd;
  377. + if (fd < 0 || fd >= FD_SETSIZE) {
  378. + return -1;
  379. + }
  380. }
  381. return -1;
  382. diff --git a/source/smbd/oplock_irix.c b/source/smbd/oplock_irix.c
  383. index 8c287c9..6e86fac 100644
  384. --- a/source/smbd/oplock_irix.c
  385. +++ b/source/smbd/oplock_irix.c
  386. @@ -284,6 +284,11 @@ struct kernel_oplocks *irix_init_kernel_oplocks(void)
  387. return False;
  388. }
  389. + if (pfd[0] < 0 || pfd[0] >= FD_SETSIZE) {
  390. + DEBUG(0,("setup_kernel_oplock_pipe: fd out of range.\n"));
  391. + return False;
  392. + }
  393. +
  394. oplock_pipe_read = pfd[0];
  395. oplock_pipe_write = pfd[1];
  396. diff --git a/source/smbd/process.c b/source/smbd/process.c
  397. index 403c7c6..9b8f29b 100644
  398. --- a/source/smbd/process.c
  399. +++ b/source/smbd/process.c
  400. @@ -698,7 +698,7 @@ static void async_processing(fd_set *pfds)
  401. static int select_on_fd(int fd, int maxfd, fd_set *fds)
  402. {
  403. - if (fd != -1) {
  404. + if (fd != -1 && fd < FD_SETSIZE) {
  405. FD_SET(fd, fds);
  406. maxfd = MAX(maxfd, fd);
  407. }
  408. diff --git a/source/smbd/server.c b/source/smbd/server.c
  409. index 5129484..a670334 100644
  410. --- a/source/smbd/server.c
  411. +++ b/source/smbd/server.c
  412. @@ -209,7 +209,13 @@ static bool open_sockets_inetd(void)
  413. /* Started from inetd. fd 0 is the socket. */
  414. /* We will abort gracefully when the client or remote system
  415. goes away */
  416. - smbd_set_server_fd(dup(0));
  417. + int fd = dup(0);
  418. +
  419. + if (fd < 0 || fd >= FD_SETSIZE) {
  420. + return false;
  421. + }
  422. +
  423. + smbd_set_server_fd(fd);
  424. /* close our standard file descriptors */
  425. close_low_fds(False); /* Don't close stderr */
  426. @@ -436,7 +442,8 @@ static bool open_sockets_smbd(bool is_daemon, bool interactive, const char *smb_
  427. num_sockets == 0 ? 0 : 2,
  428. ifss,
  429. true);
  430. - if(s == -1) {
  431. + if(s < 0 || s >= FD_SETSIZE) {
  432. + close(s);
  433. continue;
  434. }
  435. @@ -516,7 +523,7 @@ static bool open_sockets_smbd(bool is_daemon, bool interactive, const char *smb_
  436. num_sockets == 0 ? 0 : 2,
  437. &ss,
  438. true);
  439. - if (s == -1) {
  440. + if (s < 0 || s >= FD_SETSIZE) {
  441. continue;
  442. }
  443. @@ -709,6 +716,7 @@ static bool open_sockets_smbd(bool is_daemon, bool interactive, const char *smb_
  444. struct sockaddr addr;
  445. socklen_t in_addrlen = sizeof(addr);
  446. pid_t child = 0;
  447. + int fd;
  448. s = -1;
  449. for(i = 0; i < num_sockets; i++) {
  450. @@ -721,16 +729,21 @@ static bool open_sockets_smbd(bool is_daemon, bool interactive, const char *smb_
  451. }
  452. }
  453. - smbd_set_server_fd(accept(s,&addr,&in_addrlen));
  454. -
  455. - if (smbd_server_fd() == -1 && errno == EINTR)
  456. + fd = accept(s,&addr,&in_addrlen);
  457. + if (fd == -1 && errno == EINTR)
  458. continue;
  459. -
  460. - if (smbd_server_fd() == -1) {
  461. + if (fd == -1) {
  462. DEBUG(2,("open_sockets_smbd: accept: %s\n",
  463. strerror(errno)));
  464. continue;
  465. }
  466. + if (fd < 0 || fd >= FD_SETSIZE) {
  467. + DEBUG(2,("open_sockets_smbd: bad fd %d\n",
  468. + fd ));
  469. + continue;
  470. + }
  471. +
  472. + smbd_set_server_fd(fd);
  473. /* Ensure child is set to blocking mode */
  474. set_blocking(smbd_server_fd(),True);
  475. diff --git a/source/utils/smbfilter.c b/source/utils/smbfilter.c
  476. index 1e22a40..45f9207 100644
  477. --- a/source/utils/smbfilter.c
  478. +++ b/source/utils/smbfilter.c
  479. @@ -162,8 +162,8 @@ static void filter_child(int c, struct sockaddr_storage *dest_ss)
  480. int num;
  481. FD_ZERO(&fds);
  482. - if (s != -1) FD_SET(s, &fds);
  483. - if (c != -1) FD_SET(c, &fds);
  484. + if (s >= 0 && s < FD_SETSIZE) FD_SET(s, &fds);
  485. + if (c >= 0 && c < FD_SETSIZE) FD_SET(c, &fds);
  486. num = sys_select_intr(MAX(s+1, c+1),&fds,NULL,NULL,NULL);
  487. if (num <= 0) continue;
  488. @@ -235,6 +235,10 @@ static void start_filter(char *desthost)
  489. struct sockaddr_storage ss;
  490. socklen_t in_addrlen = sizeof(ss);
  491. + if (s < 0 || s >= FD_SETSIZE) {
  492. + break;
  493. + }
  494. +
  495. FD_ZERO(&fds);
  496. FD_SET(s, &fds);
  497. diff --git a/source/winbindd/winbindd.c b/source/winbindd/winbindd.c
  498. index 1d618e2..6b5c251 100644
  499. --- a/source/winbindd/winbindd.c
  500. +++ b/source/winbindd/winbindd.c
  501. @@ -836,7 +836,8 @@ static void process_loop(void)
  502. listen_sock = open_winbindd_socket();
  503. listen_priv_sock = open_winbindd_priv_socket();
  504. - if (listen_sock == -1 || listen_priv_sock == -1) {
  505. + if (listen_sock < 0 || listen_sock >= FD_SETSIZE ||
  506. + listen_priv_sock < 0 || listen_priv_sock >= FD_SETSIZE) {
  507. perror("open_winbind_socket");
  508. exit(1);
  509. }
  510. @@ -861,6 +862,9 @@ static void process_loop(void)
  511. FD_ZERO(&r_fds);
  512. FD_ZERO(&w_fds);
  513. +
  514. + /* We check the range for listen_sock and
  515. + listen_priv_sock above. */
  516. FD_SET(listen_sock, &r_fds);
  517. FD_SET(listen_priv_sock, &r_fds);
  518. @@ -890,6 +894,12 @@ static void process_loop(void)
  519. }
  520. for (ev = fd_events; ev; ev = ev->next) {
  521. + if (ev->fd < 0 || ev->fd >= FD_SETSIZE) {
  522. + /* Ignore here - event_add_to_select_args
  523. + should make this impossible. */
  524. + continue;
  525. + }
  526. +
  527. if (ev->flags & EVENT_FD_READ) {
  528. FD_SET(ev->fd, &r_fds);
  529. maxfd = MAX(ev->fd, maxfd);
  530. diff --git a/source/winbindd/winbindd_dual.c b/source/winbindd/winbindd_dual.c
  531. index ff004f2..b30ec20 100644
  532. --- a/source/winbindd/winbindd_dual.c
  533. +++ b/source/winbindd/winbindd_dual.c
  534. @@ -1250,6 +1250,12 @@ static bool fork_domain_child(struct winbindd_child *child)
  535. return False;
  536. }
  537. + if (fdpair[0] < 0 || fdpair[0] >= FD_SETSIZE) {
  538. + DEBUG(0, ("fork_domain_child: bad fd range (%d)\n", fdpair[0]));
  539. + errno = EBADF;
  540. + return False;
  541. + }
  542. +
  543. ZERO_STRUCT(state);
  544. state.pid = sys_getpid();
  545. @@ -1405,6 +1411,7 @@ static bool fork_domain_child(struct winbindd_child *child)
  546. message_dispatch(winbind_messaging_context());
  547. FD_ZERO(&read_fds);
  548. + /* We check state.sock against FD_SETSIZE above. */
  549. FD_SET(state.sock, &read_fds);
  550. ret = sys_select(state.sock + 1, &read_fds, NULL, NULL, tp);
  551. --
  552. 1.6.4.2