[linux-cifs-client] [PATCH 1/5] [CIFS] implement SPNEGO in
userspace via keyctl API
Jeff Layton
jlayton at redhat.com
Thu Oct 25 17:43:32 GMT 2007
Add routines to handle upcalls to userspace via keyctl. The intent is
to offload all of SPNEGO negotiation to userspace. Clean up the
Makefile a bit and set it up to only compile cifs_spnego if
CONFIG_CIFS_UPCALL is set. Also change CONFIG_CIFS_UPCALL to depend
on CONFIG_KEYS rather than CONFIG_CONNECTOR.
cifs_spnego.h defines the communications between kernel and userspace
and is intended to be shared with userspace programs.
Signed-off-by: Jeff Layton <jlayton at redhat.com>
---
fs/Kconfig | 2 +-
fs/cifs/Makefile | 7 +++-
fs/cifs/cifs_spnego.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++
fs/cifs/cifs_spnego.h | 44 +++++++++++++++++++
fs/cifs/cifsproto.h | 3 +
5 files changed, 169 insertions(+), 2 deletions(-)
create mode 100644 fs/cifs/cifs_spnego.c
create mode 100644 fs/cifs/cifs_spnego.h
diff --git a/fs/Kconfig b/fs/Kconfig
index cc28a69..e431c38 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -2007,7 +2007,7 @@ config CIFS_EXPERIMENTAL
config CIFS_UPCALL
bool "Kerberos/SPNEGO advanced session setup (EXPERIMENTAL)"
depends on CIFS_EXPERIMENTAL
- depends on CONNECTOR
+ depends on KEYS
help
Enables an upcall mechanism for CIFS which will be used to contact
userspace helper utilities to provide SPNEGO packaged Kerberos
diff --git a/fs/cifs/Makefile b/fs/cifs/Makefile
index ff6ba8d..45e42fb 100644
--- a/fs/cifs/Makefile
+++ b/fs/cifs/Makefile
@@ -3,4 +3,9 @@
#
obj-$(CONFIG_CIFS) += cifs.o
-cifs-objs := cifsfs.o cifssmb.o cifs_debug.o connect.o dir.o file.o inode.o link.o misc.o netmisc.o smbdes.o smbencrypt.o transport.o asn1.o md4.o md5.o cifs_unicode.o nterr.o xattr.o cifsencrypt.o fcntl.o readdir.o ioctl.o sess.o export.o cifsacl.o
+cifs-y := cifsfs.o cifssmb.o cifs_debug.o connect.o dir.o file.o inode.o \
+ link.o misc.o netmisc.o smbdes.o smbencrypt.o transport.o asn1.o \
+ md4.o md5.o cifs_unicode.o nterr.o xattr.o cifsencrypt.o fcntl.o \
+ readdir.o ioctl.o sess.o export.o cifsacl.o
+
+cifs-$(CONFIG_CIFS_UPCALL) += cifs_spnego.o
diff --git a/fs/cifs/cifs_spnego.c b/fs/cifs/cifs_spnego.c
new file mode 100644
index 0000000..7cb3b45
--- /dev/null
+++ b/fs/cifs/cifs_spnego.c
@@ -0,0 +1,115 @@
+/*
+ * fs/cifs/cifs_spnego.c -- SPNEGO upcall management for CIFS
+ *
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Author(s): Jeff Layton (jlayton at redhat.com)
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <linux/list.h>
+#include <linux/string.h>
+#include <keys/user-type.h>
+#include <linux/key-type.h>
+#include "cifsglob.h"
+#include "cifs_spnego.h"
+#include "cifs_debug.h"
+
+/* create a new cifs key */
+static int
+cifs_spnego_key_instantiate(struct key *key, const void *data, size_t datalen)
+{
+ char *payload;
+ int ret;
+
+ ret = -ENOMEM;
+ payload = kmalloc(datalen, GFP_KERNEL);
+ if (!payload)
+ goto error;
+
+ /* attach the data */
+ memcpy(payload, data, datalen);
+ rcu_assign_pointer(key->payload.data, payload);
+ ret = 0;
+
+error:
+ return ret;
+}
+
+static void
+cifs_spnego_key_destroy(struct key *key)
+{
+ kfree(key->payload.data);
+}
+
+
+/*
+ * keytype for CIFS spnego keys
+ */
+struct key_type cifs_spnego_key_type = {
+ .name = "cifs.spnego",
+ .instantiate = cifs_spnego_key_instantiate,
+ .match = user_match,
+ .destroy = cifs_spnego_key_destroy,
+ .describe = user_describe,
+};
+
+/* get a key struct with a SPNEGO security blob, suitable for session setup */
+struct key *
+cifs_get_spnego_key(struct cifsSesInfo *sesInfo, const unsigned char *secblob,
+ size_t seclen, const char *hostname)
+{
+ struct TCP_Server_Info *server = sesInfo->server;
+ char *description = NULL;
+ struct key *spnego_key;
+
+ spnego_key = ERR_PTR(-ENOMEM);
+ /* version + ;ip{4|6}= + address + ; + host=hostname + NULL */
+ description = kzalloc((2 + 5 + 32 + 1 + 5 + strlen(hostname) + 1),
+ GFP_KERNEL);
+ if (description == NULL)
+ goto out;
+
+ spnego_key = ERR_PTR(-EINVAL);
+ if (server->addr.sockAddr.sin_family == AF_INET)
+ sprintf(description, "%2.2x;ip4=" NIPQUAD_FMT ";host=%s",
+ CIFS_SPNEGO_UPCALL_VERSION,
+ NIPQUAD(server->addr.sockAddr.sin_addr),
+ hostname);
+ else if (server->addr.sockAddr.sin_family == AF_INET6)
+ sprintf(description, "%2.2x;ip6=" NIP6_SEQFMT ";host=%s",
+ CIFS_SPNEGO_UPCALL_VERSION,
+ NIP6(server->addr.sockAddr6.sin6_addr),
+ hostname);
+ /* BB: anything special for SCTP? */
+ else
+ goto out;
+
+ cFYI(1,("key description = %s", description));
+ spnego_key = request_key_with_auxdata(&cifs_spnego_key_type,
+ description, secblob,
+ seclen, NULL);
+
+ if (cifsFYI && !IS_ERR(spnego_key)) {
+ struct cifs_spnego_msg *msg = spnego_key->payload.data;
+ cifs_dump_mem("SPNEGO reply blob:", msg->data,
+ msg->secblob_len + msg->sesskey_len);
+ }
+
+out:
+ if (description)
+ kfree(description);
+ return spnego_key;
+}
diff --git a/fs/cifs/cifs_spnego.h b/fs/cifs/cifs_spnego.h
new file mode 100644
index 0000000..73f17e9
--- /dev/null
+++ b/fs/cifs/cifs_spnego.h
@@ -0,0 +1,44 @@
+/*
+ * fs/cifs/cifs_spnego.h -- SPNEGO upcall management for CIFS
+ *
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Author(s): Jeff Layton (jlayton at redhat.com)
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef _CIFS_SPNEGO_H
+#define _CIFS_SPNEGO_H
+
+#define CIFS_SPNEGO_UPCALL_VERSION 1
+
+#define CIFS_SPNEGO_KRB5 0x00000001
+#define CIFS_SPNEGO_NTLMSSP 0x00000002
+
+/*
+ * The flags field should have either CIFS_SPNEGO_KRB5 or CIFS_SPNEGO_NTLMSSP
+ * set. The data field consists of SessionKey + SecurityBlob
+ *
+ * BB: should this be ((packed)) ?
+ */
+struct cifs_spnego_msg {
+ uint32_t version;
+ uint32_t flags;
+ uint32_t sesskey_len;
+ uint32_t secblob_len;
+ uint8_t data[1];
+};
+
+#endif /* _CIFS_SPNEGO_H */
diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h
index 7c445f8..4bbddf4 100644
--- a/fs/cifs/cifsproto.h
+++ b/fs/cifs/cifsproto.h
@@ -73,6 +73,9 @@ extern void header_assemble(struct smb_hdr *, char /* command */ ,
extern int small_smb_init_no_tc(const int smb_cmd, const int wct,
struct cifsSesInfo *ses,
void **request_buf);
+extern struct key *cifs_get_spnego_key(struct cifsSesInfo *sesInfo,
+ const unsigned char *secblob,
+ size_t seclen, const char *hostname);
extern int CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses,
const int stage,
const struct nls_table *nls_cp);
--
1.5.2.1
More information about the linux-cifs-client
mailing list