sandbox-solaris.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright (c) 2015 Joyent, Inc
  3. * Author: Alex Wilson <alex.wilson@joyent.com>
  4. *
  5. * Permission to use, copy, modify, and distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include "includes.h"
  18. #ifdef SANDBOX_SOLARIS
  19. #ifndef USE_SOLARIS_PRIVS
  20. # error "--with-solaris-privs must be used with the Solaris sandbox"
  21. #endif
  22. #include <sys/types.h>
  23. #include <errno.h>
  24. #include <stdarg.h>
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <unistd.h>
  29. #ifdef HAVE_PRIV_H
  30. # include <priv.h>
  31. #endif
  32. #include "log.h"
  33. #include "ssh-sandbox.h"
  34. #include "xmalloc.h"
  35. struct ssh_sandbox {
  36. priv_set_t *pset;
  37. };
  38. struct ssh_sandbox *
  39. ssh_sandbox_init(struct monitor *monitor)
  40. {
  41. struct ssh_sandbox *box = NULL;
  42. box = xcalloc(1, sizeof(*box));
  43. /* Start with "basic" and drop everything we don't need. */
  44. box->pset = solaris_basic_privset();
  45. if (box->pset == NULL) {
  46. free(box);
  47. return NULL;
  48. }
  49. /* Drop everything except the ability to use already-opened files */
  50. if (priv_delset(box->pset, PRIV_FILE_LINK_ANY) != 0 ||
  51. #ifdef PRIV_NET_ACCESS
  52. priv_delset(box->pset, PRIV_NET_ACCESS) != 0 ||
  53. #endif
  54. #ifdef PRIV_DAX_ACCESS
  55. priv_delset(box->pset, PRIV_DAX_ACCESS) != 0 ||
  56. #endif
  57. #ifdef PRIV_SYS_IB_INFO
  58. priv_delset(box->pset, PRIV_SYS_IB_INFO) != 0 ||
  59. #endif
  60. priv_delset(box->pset, PRIV_PROC_EXEC) != 0 ||
  61. priv_delset(box->pset, PRIV_PROC_FORK) != 0 ||
  62. priv_delset(box->pset, PRIV_PROC_INFO) != 0 ||
  63. priv_delset(box->pset, PRIV_PROC_SESSION) != 0) {
  64. free(box);
  65. return NULL;
  66. }
  67. /* These may not be available on older Solaris-es */
  68. # if defined(PRIV_FILE_READ) && defined(PRIV_FILE_WRITE)
  69. if (priv_delset(box->pset, PRIV_FILE_READ) != 0 ||
  70. priv_delset(box->pset, PRIV_FILE_WRITE) != 0) {
  71. free(box);
  72. return NULL;
  73. }
  74. # endif
  75. return box;
  76. }
  77. void
  78. ssh_sandbox_child(struct ssh_sandbox *box)
  79. {
  80. if (setppriv(PRIV_SET, PRIV_PERMITTED, box->pset) != 0 ||
  81. setppriv(PRIV_SET, PRIV_LIMIT, box->pset) != 0 ||
  82. setppriv(PRIV_SET, PRIV_INHERITABLE, box->pset) != 0)
  83. fatal("setppriv: %s", strerror(errno));
  84. }
  85. void
  86. ssh_sandbox_parent_finish(struct ssh_sandbox *box)
  87. {
  88. priv_freeset(box->pset);
  89. box->pset = NULL;
  90. free(box);
  91. }
  92. void
  93. ssh_sandbox_parent_preauth(struct ssh_sandbox *box, pid_t child_pid)
  94. {
  95. /* Nothing to do here */
  96. }
  97. #endif /* SANDBOX_SOLARIS */