~ubuntu-branches/ubuntu/utopic/vsftpd/utopic-proposed

« back to all changes in this revision

Viewing changes to sysdeputil.c

  • Committer: Package Import Robot
  • Author(s): Daniel Llewellyn (Bang Communications)
  • Date: 2013-05-08 14:08:53 UTC
  • mfrom: (2.6.1 squeeze)
  • Revision ID: package-import@ubuntu.com-20130508140853-ahhuki963v9fuuns
Tags: 3.0.2-1ubuntu2
* debian/patches/13-disable-clone-newpid.patch
  - patch to remove CLONE_NEWPID syscall
    see: https://bugzilla.novell.com/show_bug.cgi?id=786024#c38
    Fixes LP: #1160372

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
  #define _LARGEFILE64_SOURCE 1
26
26
#endif
27
27
 
 
28
#ifdef __linux__
 
29
  #include <stdio.h>
 
30
  #include <sys/utsname.h>
 
31
#endif
 
32
 
28
33
/* For INT_MAX */
29
34
#include <limits.h>
30
35
 
64
69
#include <utmpx.h>
65
70
 
66
71
/* BEGIN config */
67
 
#if defined(__linux__)
 
72
#if defined(__linux__) && !defined(__s390__)
68
73
  #include <errno.h>
69
74
  #include <syscall.h>
70
75
  #define VSF_SYSDEP_HAVE_LINUX_CLONE
81
86
  #include <linux/unistd.h>
82
87
  #include <errno.h>
83
88
  #include <syscall.h>
 
89
  #if defined(__alpha__)
 
90
    #define __NR_getpid  __NR_getxpid
 
91
  #endif
84
92
#endif
85
93
 
86
94
#if defined(__linux__) && !defined(__ia64__) && !defined(__s390__)
322
330
                      const struct mystr* p_pass_str,
323
331
                      const struct mystr* p_remote_host)
324
332
{
325
 
  int retval;
 
333
  int retval = -1;
326
334
  pam_item_t item;
327
335
  const char* pam_user_name = 0;
328
336
  struct pam_conv the_conv =
335
343
    bug("vsf_sysdep_check_auth");
336
344
  }
337
345
  str_copy(&s_pword_str, p_pass_str);
338
 
  retval = pam_start(tunable_pam_service_name,
339
 
                     str_getbuf(p_user_str), &the_conv, &s_pamh);
 
346
  if (tunable_pam_service_name)
 
347
  {
 
348
    retval = pam_start(tunable_pam_service_name,
 
349
                       str_getbuf(p_user_str), &the_conv, &s_pamh);
 
350
  }
340
351
  if (retval != PAM_SUCCESS)
341
352
  {
342
353
    s_pamh = 0;
1259
1270
#endif
1260
1271
}
1261
1272
 
 
1273
#ifdef VSF_SYSDEP_HAVE_LINUX_CLONE
 
1274
/* On Linux versions <2.6.35, netns cleanup may be so slow that
 
1275
 * creating a netns per connection allows a remote denial-of-service.
 
1276
 * We therefore do not use CLONE_NEWNET on these versions.
 
1277
 */
 
1278
static int
 
1279
vsf_sysutil_netns_cleanup_is_fast(void)
 
1280
{
 
1281
#ifdef __linux__
 
1282
  struct utsname utsname;
 
1283
  int r1, r2, r3 = 0;
 
1284
  return (uname(&utsname) == 0 &&
 
1285
          sscanf(utsname.release, "%d.%d.%d", &r1, &r2, &r3) >= 2 &&
 
1286
          ((r1 << 16) | (r2 << 8) | r3) >= ((2 << 16) | (6 << 8) | 35));
 
1287
#else
 
1288
  /* Assume any other kernel that has the feature don't have this problem */
 
1289
  return 1;
 
1290
#endif
 
1291
}
 
1292
#endif
 
1293
 
1262
1294
int
1263
1295
vsf_sysutil_fork_isolate_all_failok()
1264
1296
{
1265
1297
#ifdef VSF_SYSDEP_HAVE_LINUX_CLONE
1266
 
  static int cloneflags_work = 1;
 
1298
  static int cloneflags_work = -1;
 
1299
  if (cloneflags_work < 0)
 
1300
  {
 
1301
    cloneflags_work = vsf_sysutil_netns_cleanup_is_fast();
 
1302
  }
1267
1303
  if (cloneflags_work)
1268
1304
  {
1269
1305
    int ret = syscall(__NR_clone,
1270
 
                      CLONE_NEWPID | CLONE_NEWIPC | CLONE_NEWNET | SIGCHLD,
 
1306
                      CLONE_NEWIPC | CLONE_NEWNET | SIGCHLD,
1271
1307
                      NULL);
1272
1308
    if (ret != -1 || (errno != EINVAL && errno != EPERM))
1273
1309
    {
1290
1326
  static int cloneflags_work = 1;
1291
1327
  if (cloneflags_work)
1292
1328
  {
1293
 
    int ret = syscall(__NR_clone, CLONE_NEWPID | CLONE_NEWIPC | SIGCHLD, NULL);
 
1329
    int ret = syscall(__NR_clone, CLONE_NEWIPC | SIGCHLD, NULL);
1294
1330
    if (ret != -1 || (errno != EINVAL && errno != EPERM))
1295
1331
    {
1296
1332
      if (ret == 0)
1309
1345
vsf_sysutil_fork_newnet()
1310
1346
{
1311
1347
#ifdef VSF_SYSDEP_HAVE_LINUX_CLONE
1312
 
  static int cloneflags_work = 1;
 
1348
  static int cloneflags_work = -1;
 
1349
  if (cloneflags_work < 0)
 
1350
  {
 
1351
    cloneflags_work = vsf_sysutil_netns_cleanup_is_fast();
 
1352
  }
1313
1353
  if (cloneflags_work)
1314
1354
  {
1315
1355
    int ret = syscall(__NR_clone, CLONE_NEWNET | SIGCHLD, NULL);