keyctl.c (4a38e122e2cc6294779021ff4ccc784a3997059e) keyctl.c (70a5bb72b55e82fbfbf1e22cae6975fac58a1e2d)
1/* keyctl.c: userspace keyctl operations
2 *
3 * Copyright (C) 2004-5 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version

--- 6 unchanged lines hidden (view full) ---

15#include <linux/slab.h>
16#include <linux/syscalls.h>
17#include <linux/keyctl.h>
18#include <linux/fs.h>
19#include <linux/capability.h>
20#include <linux/string.h>
21#include <linux/err.h>
22#include <linux/vmalloc.h>
1/* keyctl.c: userspace keyctl operations
2 *
3 * Copyright (C) 2004-5 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version

--- 6 unchanged lines hidden (view full) ---

15#include <linux/slab.h>
16#include <linux/syscalls.h>
17#include <linux/keyctl.h>
18#include <linux/fs.h>
19#include <linux/capability.h>
20#include <linux/string.h>
21#include <linux/err.h>
22#include <linux/vmalloc.h>
23#include <linux/security.h>
23#include <asm/uaccess.h>
24#include "internal.h"
25
26static int key_get_type_from_user(char *type,
27 const char __user *_type,
28 unsigned len)
29{
30 int ret;

--- 1044 unchanged lines hidden (view full) ---

1075 current->request_key_auth = authkey;
1076 ret = authkey->serial;
1077
1078error:
1079 return ret;
1080
1081} /* end keyctl_assume_authority() */
1082
24#include <asm/uaccess.h>
25#include "internal.h"
26
27static int key_get_type_from_user(char *type,
28 const char __user *_type,
29 unsigned len)
30{
31 int ret;

--- 1044 unchanged lines hidden (view full) ---

1076 current->request_key_auth = authkey;
1077 ret = authkey->serial;
1078
1079error:
1080 return ret;
1081
1082} /* end keyctl_assume_authority() */
1083
1084/*
1085 * get the security label of a key
1086 * - the key must grant us view permission
1087 * - if there's a buffer, we place up to buflen bytes of data into it
1088 * - unless there's an error, we return the amount of information available,
1089 * irrespective of how much we may have copied (including the terminal NUL)
1090 * - implements keyctl(KEYCTL_GET_SECURITY)
1091 */
1092long keyctl_get_security(key_serial_t keyid,
1093 char __user *buffer,
1094 size_t buflen)
1095{
1096 struct key *key, *instkey;
1097 key_ref_t key_ref;
1098 char *context;
1099 long ret;
1100
1101 key_ref = lookup_user_key(NULL, keyid, 0, 1, KEY_VIEW);
1102 if (IS_ERR(key_ref)) {
1103 if (PTR_ERR(key_ref) != -EACCES)
1104 return PTR_ERR(key_ref);
1105
1106 /* viewing a key under construction is also permitted if we
1107 * have the authorisation token handy */
1108 instkey = key_get_instantiation_authkey(keyid);
1109 if (IS_ERR(instkey))
1110 return PTR_ERR(key_ref);
1111 key_put(instkey);
1112
1113 key_ref = lookup_user_key(NULL, keyid, 0, 1, 0);
1114 if (IS_ERR(key_ref))
1115 return PTR_ERR(key_ref);
1116 }
1117
1118 key = key_ref_to_ptr(key_ref);
1119 ret = security_key_getsecurity(key, &context);
1120 if (ret == 0) {
1121 /* if no information was returned, give userspace an empty
1122 * string */
1123 ret = 1;
1124 if (buffer && buflen > 0 &&
1125 copy_to_user(buffer, "", 1) != 0)
1126 ret = -EFAULT;
1127 } else if (ret > 0) {
1128 /* return as much data as there's room for */
1129 if (buffer && buflen > 0) {
1130 if (buflen > ret)
1131 buflen = ret;
1132
1133 if (copy_to_user(buffer, context, buflen) != 0)
1134 ret = -EFAULT;
1135 }
1136
1137 kfree(context);
1138 }
1139
1140 key_ref_put(key_ref);
1141 return ret;
1142}
1143
1083/*****************************************************************************/
1084/*
1085 * the key control system call
1086 */
1087asmlinkage long sys_keyctl(int option, unsigned long arg2, unsigned long arg3,
1088 unsigned long arg4, unsigned long arg5)
1089{
1090 switch (option) {

--- 64 unchanged lines hidden (view full) ---

1155
1156 case KEYCTL_SET_TIMEOUT:
1157 return keyctl_set_timeout((key_serial_t) arg2,
1158 (unsigned) arg3);
1159
1160 case KEYCTL_ASSUME_AUTHORITY:
1161 return keyctl_assume_authority((key_serial_t) arg2);
1162
1144/*****************************************************************************/
1145/*
1146 * the key control system call
1147 */
1148asmlinkage long sys_keyctl(int option, unsigned long arg2, unsigned long arg3,
1149 unsigned long arg4, unsigned long arg5)
1150{
1151 switch (option) {

--- 64 unchanged lines hidden (view full) ---

1216
1217 case KEYCTL_SET_TIMEOUT:
1218 return keyctl_set_timeout((key_serial_t) arg2,
1219 (unsigned) arg3);
1220
1221 case KEYCTL_ASSUME_AUTHORITY:
1222 return keyctl_assume_authority((key_serial_t) arg2);
1223
1224 case KEYCTL_GET_SECURITY:
1225 return keyctl_get_security((key_serial_t) arg2,
1226 (char *) arg3,
1227 (size_t) arg4);
1228
1163 default:
1164 return -EOPNOTSUPP;
1165 }
1166
1167} /* end sys_keyctl() */
1229 default:
1230 return -EOPNOTSUPP;
1231 }
1232
1233} /* end sys_keyctl() */