original development tree for Linux kernel GTP module; now long in mainline.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

180 lines
4.8 KiB

include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h percpu.h is included by sched.h and module.h and thus ends up being included when building most .c files. percpu.h includes slab.h which in turn includes gfp.h making everything defined by the two files universally available and complicating inclusion dependencies. percpu.h -> slab.h dependency is about to be removed. Prepare for this change by updating users of gfp and slab facilities include those headers directly instead of assuming availability. As this conversion needs to touch large number of source files, the following script is used as the basis of conversion. http://userweb.kernel.org/~tj/misc/slabh-sweep.py The script does the followings. * Scan files for gfp and slab usages and update includes such that only the necessary includes are there. ie. if only gfp is used, gfp.h, if slab is used, slab.h. * When the script inserts a new include, it looks at the include blocks and try to put the new include such that its order conforms to its surrounding. It's put in the include block which contains core kernel includes, in the same order that the rest are ordered - alphabetical, Christmas tree, rev-Xmas-tree or at the end if there doesn't seem to be any matching order. * If the script can't find a place to put a new include (mostly because the file doesn't have fitting include block), it prints out an error message indicating which .h file needs to be added to the file. The conversion was done in the following steps. 1. The initial automatic conversion of all .c files updated slightly over 4000 files, deleting around 700 includes and adding ~480 gfp.h and ~3000 slab.h inclusions. The script emitted errors for ~400 files. 2. Each error was manually checked. Some didn't need the inclusion, some needed manual addition while adding it to implementation .h or embedding .c file was more appropriate for others. This step added inclusions to around 150 files. 3. The script was run again and the output was compared to the edits from #2 to make sure no file was left behind. 4. Several build tests were done and a couple of problems were fixed. e.g. lib/decompress_*.c used malloc/free() wrappers around slab APIs requiring slab.h to be added manually. 5. The script was run on all .h files but without automatically editing them as sprinkling gfp.h and slab.h inclusions around .h files could easily lead to inclusion dependency hell. Most gfp.h inclusion directives were ignored as stuff from gfp.h was usually wildly available and often used in preprocessor macros. Each slab.h inclusion directive was examined and added manually as necessary. 6. percpu.h was updated not to include slab.h. 7. Build test were done on the following configurations and failures were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my distributed build env didn't work with gcov compiles) and a few more options had to be turned off depending on archs to make things build (like ipr on powerpc/64 which failed due to missing writeq). * x86 and x86_64 UP and SMP allmodconfig and a custom test config. * powerpc and powerpc64 SMP allmodconfig * sparc and sparc64 SMP allmodconfig * ia64 SMP allmodconfig * s390 SMP allmodconfig * alpha SMP allmodconfig * um on x86_64 SMP allmodconfig 8. percpu.h modifications were reverted so that it could be applied as a separate patch and serve as bisection point. Given the fact that I had only a couple of failures from tests on step 6, I'm fairly confident about the coverage of this conversion patch. If there is a breakage, it's likely to be something in one of the arch headers which should be easily discoverable easily on most builds of the specific arch. Signed-off-by: Tejun Heo <tj@kernel.org> Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
12 years ago
KEYS: Add payload preparsing opportunity prior to key instantiate or update Give the key type the opportunity to preparse the payload prior to the instantiation and update routines being called. This is done with the provision of two new key type operations: int (*preparse)(struct key_preparsed_payload *prep); void (*free_preparse)(struct key_preparsed_payload *prep); If the first operation is present, then it is called before key creation (in the add/update case) or before the key semaphore is taken (in the update and instantiate cases). The second operation is called to clean up if the first was called. preparse() is given the opportunity to fill in the following structure: struct key_preparsed_payload { char *description; void *type_data[2]; void *payload; const void *data; size_t datalen; size_t quotalen; }; Before the preparser is called, the first three fields will have been cleared, the payload pointer and size will be stored in data and datalen and the default quota size from the key_type struct will be stored into quotalen. The preparser may parse the payload in any way it likes and may store data in the type_data[] and payload fields for use by the instantiate() and update() ops. The preparser may also propose a description for the key by attaching it as a string to the description field. This can be used by passing a NULL or "" description to the add_key() system call or the key_create_or_update() function. This cannot work with request_key() as that required the description to tell the upcall about the key to be created. This, for example permits keys that store PGP public keys to generate their own name from the user ID and public key fingerprint in the key. The instantiate() and update() operations are then modified to look like this: int (*instantiate)(struct key *key, struct key_preparsed_payload *prep); int (*update)(struct key *key, struct key_preparsed_payload *prep); and the new payload data is passed in *prep, whether or not it was preparsed. Signed-off-by: David Howells <dhowells@redhat.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
9 years ago
  1. /*
  2. * fs/cifs/cifs_spnego.c -- SPNEGO upcall management for CIFS
  3. *
  4. * Copyright (c) 2007 Red Hat, Inc.
  5. * Author(s): Jeff Layton (jlayton@redhat.com)
  6. *
  7. * This library is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published
  9. * by the Free Software Foundation; either version 2.1 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * the GNU Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License
  18. * along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #include <linux/list.h>
  22. #include <linux/slab.h>
  23. #include <linux/string.h>
  24. #include <keys/user-type.h>
  25. #include <linux/key-type.h>
  26. #include <linux/inet.h>
  27. #include "cifsglob.h"
  28. #include "cifs_spnego.h"
  29. #include "cifs_debug.h"
  30. /* create a new cifs key */
  31. static int
  32. cifs_spnego_key_instantiate(struct key *key, struct key_preparsed_payload *prep)
  33. {
  34. char *payload;
  35. int ret;
  36. ret = -ENOMEM;
  37. payload = kmemdup(prep->data, prep->datalen, GFP_KERNEL);
  38. if (!payload)
  39. goto error;
  40. /* attach the data */
  41. key->payload.data = payload;
  42. ret = 0;
  43. error:
  44. return ret;
  45. }
  46. static void
  47. cifs_spnego_key_destroy(struct key *key)
  48. {
  49. kfree(key->payload.data);
  50. }
  51. /*
  52. * keytype for CIFS spnego keys
  53. */
  54. struct key_type cifs_spnego_key_type = {
  55. .name = "cifs.spnego",
  56. .instantiate = cifs_spnego_key_instantiate,
  57. .match = user_match,
  58. .destroy = cifs_spnego_key_destroy,
  59. .describe = user_describe,
  60. };
  61. /* length of longest version string e.g. strlen("ver=0xFF") */
  62. #define MAX_VER_STR_LEN 8
  63. /* length of longest security mechanism name, eg in future could have
  64. * strlen(";sec=ntlmsspi") */
  65. #define MAX_MECH_STR_LEN 13
  66. /* strlen of "host=" */
  67. #define HOST_KEY_LEN 5
  68. /* strlen of ";ip4=" or ";ip6=" */
  69. #define IP_KEY_LEN 5
  70. /* strlen of ";uid=0x" */
  71. #define UID_KEY_LEN 7
  72. /* strlen of ";creduid=0x" */
  73. #define CREDUID_KEY_LEN 11
  74. /* strlen of ";user=" */
  75. #define USER_KEY_LEN 6
  76. /* strlen of ";pid=0x" */
  77. #define PID_KEY_LEN 7
  78. /* get a key struct with a SPNEGO security blob, suitable for session setup */
  79. struct key *
  80. cifs_get_spnego_key(struct cifs_ses *sesInfo)
  81. {
  82. struct TCP_Server_Info *server = sesInfo->server;
  83. struct sockaddr_in *sa = (struct sockaddr_in *) &server->dstaddr;
  84. struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *) &server->dstaddr;
  85. char *description, *dp;
  86. size_t desc_len;
  87. struct key *spnego_key;
  88. const char *hostname = server->hostname;
  89. /* length of fields (with semicolons): ver=0xyz ip4=ipaddress
  90. host=hostname sec=mechanism uid=0xFF user=username */
  91. desc_len = MAX_VER_STR_LEN +
  92. HOST_KEY_LEN + strlen(hostname) +
  95. UID_KEY_LEN + (sizeof(uid_t) * 2) +
  96. CREDUID_KEY_LEN + (sizeof(uid_t) * 2) +
  97. PID_KEY_LEN + (sizeof(pid_t) * 2) + 1;
  98. if (sesInfo->user_name)
  99. desc_len += USER_KEY_LEN + strlen(sesInfo->user_name);
  100. spnego_key = ERR_PTR(-ENOMEM);
  101. description = kzalloc(desc_len, GFP_KERNEL);
  102. if (description == NULL)
  103. goto out;
  104. dp = description;
  105. /* start with version and hostname portion of UNC string */
  106. spnego_key = ERR_PTR(-EINVAL);
  107. sprintf(dp, "ver=0x%x;host=%s;", CIFS_SPNEGO_UPCALL_VERSION,
  108. hostname);
  109. dp = description + strlen(description);
  110. /* add the server address */
  111. if (server->dstaddr.ss_family == AF_INET)
  112. sprintf(dp, "ip4=%pI4", &sa->sin_addr);
  113. else if (server->dstaddr.ss_family == AF_INET6)
  114. sprintf(dp, "ip6=%pI6", &sa6->sin6_addr);
  115. else
  116. goto out;
  117. dp = description + strlen(description);
  118. /* for now, only sec=krb5 and sec=mskrb5 are valid */
  119. if (server->sec_kerberos)
  120. sprintf(dp, ";sec=krb5");
  121. else if (server->sec_mskerberos)
  122. sprintf(dp, ";sec=mskrb5");
  123. else
  124. goto out;
  125. dp = description + strlen(description);
  126. sprintf(dp, ";uid=0x%x",
  127. from_kuid_munged(&init_user_ns, sesInfo->linux_uid));
  128. dp = description + strlen(description);
  129. sprintf(dp, ";creduid=0x%x",
  130. from_kuid_munged(&init_user_ns, sesInfo->cred_uid));
  131. if (sesInfo->user_name) {
  132. dp = description + strlen(description);
  133. sprintf(dp, ";user=%s", sesInfo->user_name);
  134. }
  135. dp = description + strlen(description);
  136. sprintf(dp, ";pid=0x%x", current->pid);
  137. cifs_dbg(FYI, "key description = %s\n", description);
  138. spnego_key = request_key(&cifs_spnego_key_type, description, "");
  139. #ifdef CONFIG_CIFS_DEBUG2
  140. if (cifsFYI && !IS_ERR(spnego_key)) {
  141. struct cifs_spnego_msg *msg = spnego_key->payload.data;
  142. cifs_dump_mem("SPNEGO reply blob:", msg->data, min(1024U,
  143. msg->secblob_len + msg->sesskey_len));
  144. }
  145. #endif /* CONFIG_CIFS_DEBUG2 */
  146. out:
  147. kfree(description);
  148. return spnego_key;
  149. }