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.

Dependency Surface

Detected Declarations

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

Implementation Notes