fs/smb/client/cifs_spnego.c
Source file repositories/reference/linux-study-clean/fs/smb/client/cifs_spnego.c
File Facts
- System
- Linux kernel
- Corpus path
fs/smb/client/cifs_spnego.c- Extension
.c- Size
- 6607 bytes
- Lines
- 253
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/list.hlinux/cred.hlinux/slab.hlinux/string.hkeys/user-type.hlinux/key-type.hlinux/keyctl.hlinux/inet.hcifsglob.hcifs_spnego.hcifs_debug.hcifsproto.h
Detected Declarations
function cifs_spnego_key_instantiatefunction cifs_spnego_key_destroyfunction cifs_spnego_key_vet_descriptionfunction cifs_get_spnego_keyfunction init_cifs_spnegofunction exit_cifs_spnego
Annotated Snippet
// SPDX-License-Identifier: LGPL-2.1
/*
* SPNEGO upcall management for CIFS
*
* Copyright (c) 2007 Red Hat, Inc.
* Author(s): Jeff Layton (jlayton@redhat.com)
*
*/
#include <linux/list.h>
#include <linux/cred.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <keys/user-type.h>
#include <linux/key-type.h>
#include <linux/keyctl.h>
#include <linux/inet.h>
#include "cifsglob.h"
#include "cifs_spnego.h"
#include "cifs_debug.h"
#include "cifsproto.h"
static const struct cred *spnego_cred;
/* create a new cifs key */
static int
cifs_spnego_key_instantiate(struct key *key, struct key_preparsed_payload *prep)
{
char *payload = kmemdup(prep->data, prep->datalen, GFP_KERNEL);
if (!payload)
return -ENOMEM;
/* attach the data */
key->payload.data[0] = payload;
return 0;
}
static void
cifs_spnego_key_destroy(struct key *key)
{
kfree(key->payload.data[0]);
}
static int
cifs_spnego_key_vet_description(const char *description)
{
/*
* cifs.spnego descriptions are authority-bearing inputs to cifs.upcall.
* They are only valid when produced by CIFS while using the private
* spnego_cred installed below. Do not let userspace create this type
* of key through request_key(2)/add_key(2), since the helper treats
* pid/uid/creduid/upcall_target as kernel-originating fields.
*/
if (current_cred() != spnego_cred)
return -EPERM;
return 0;
}
/*
* keytype for CIFS spnego keys
*/
struct key_type cifs_spnego_key_type = {
.name = "cifs.spnego",
.vet_description = cifs_spnego_key_vet_description,
.instantiate = cifs_spnego_key_instantiate,
.destroy = cifs_spnego_key_destroy,
.describe = user_describe,
};
/* length of longest version string e.g. strlen("ver=0xFF") */
#define MAX_VER_STR_LEN 8
/* length of longest security mechanism name, eg in future could have
* strlen(";sec=ntlmsspi") */
#define MAX_MECH_STR_LEN 13
/* strlen of ";host=" */
#define HOST_KEY_LEN 6
/* strlen of ";ip4=" or ";ip6=" */
#define IP_KEY_LEN 5
/* strlen of ";uid=0x" */
#define UID_KEY_LEN 7
/* strlen of ";creduid=0x" */
#define CREDUID_KEY_LEN 11
/* strlen of ";user=" */
#define USER_KEY_LEN 6
Annotation
- Immediate include surface: `linux/list.h`, `linux/cred.h`, `linux/slab.h`, `linux/string.h`, `keys/user-type.h`, `linux/key-type.h`, `linux/keyctl.h`, `linux/inet.h`.
- Detected declarations: `function cifs_spnego_key_instantiate`, `function cifs_spnego_key_destroy`, `function cifs_spnego_key_vet_description`, `function cifs_get_spnego_key`, `function init_cifs_spnego`, `function exit_cifs_spnego`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.