License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2010-02-03 08:07:07 +08:00
|
|
|
|
2010-04-07 06:14:15 +08:00
|
|
|
#include <linux/ceph/ceph_debug.h>
|
2010-02-03 08:07:07 +08:00
|
|
|
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/scatterlist.h>
|
2017-01-16 21:35:17 +08:00
|
|
|
#include <linux/sched.h>
|
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>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2016-01-24 21:18:40 +08:00
|
|
|
#include <crypto/aes.h>
|
|
|
|
#include <crypto/skcipher.h>
|
2011-03-29 05:59:38 +08:00
|
|
|
#include <linux/key-type.h>
|
2017-02-03 03:43:54 +08:00
|
|
|
#include <linux/sched/mm.h>
|
2010-02-03 08:07:07 +08:00
|
|
|
|
2011-03-29 05:59:38 +08:00
|
|
|
#include <keys/ceph-type.h>
|
2014-07-19 01:56:35 +08:00
|
|
|
#include <keys/user-type.h>
|
2010-04-07 06:14:15 +08:00
|
|
|
#include <linux/ceph/decode.h>
|
2010-02-03 08:07:07 +08:00
|
|
|
#include "crypto.h"
|
|
|
|
|
2016-12-02 23:35:08 +08:00
|
|
|
/*
|
|
|
|
* Set ->key and ->tfm. The rest of the key should be filled in before
|
|
|
|
* this function is called.
|
|
|
|
*/
|
|
|
|
static int set_secret(struct ceph_crypto_key *key, void *buf)
|
|
|
|
{
|
|
|
|
unsigned int noio_flag;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
key->key = NULL;
|
|
|
|
key->tfm = NULL;
|
|
|
|
|
|
|
|
switch (key->type) {
|
|
|
|
case CEPH_CRYPTO_NONE:
|
|
|
|
return 0; /* nothing to do */
|
|
|
|
case CEPH_CRYPTO_AES:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -ENOTSUPP;
|
|
|
|
}
|
|
|
|
|
2017-11-07 13:57:26 +08:00
|
|
|
if (!key->len)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2016-12-02 23:35:08 +08:00
|
|
|
key->key = kmemdup(buf, key->len, GFP_NOIO);
|
|
|
|
if (!key->key) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2018-09-19 10:10:45 +08:00
|
|
|
/* crypto_alloc_sync_skcipher() allocates with GFP_KERNEL */
|
2016-12-02 23:35:08 +08:00
|
|
|
noio_flag = memalloc_noio_save();
|
2018-09-19 10:10:45 +08:00
|
|
|
key->tfm = crypto_alloc_sync_skcipher("cbc(aes)", 0, 0);
|
2016-12-02 23:35:08 +08:00
|
|
|
memalloc_noio_restore(noio_flag);
|
|
|
|
if (IS_ERR(key->tfm)) {
|
|
|
|
ret = PTR_ERR(key->tfm);
|
|
|
|
key->tfm = NULL;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2018-09-19 10:10:45 +08:00
|
|
|
ret = crypto_sync_skcipher_setkey(key->tfm, key->key, key->len);
|
2016-12-02 23:35:08 +08:00
|
|
|
if (ret)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
ceph_crypto_key_destroy(key);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-26 07:32:57 +08:00
|
|
|
int ceph_crypto_key_clone(struct ceph_crypto_key *dst,
|
|
|
|
const struct ceph_crypto_key *src)
|
|
|
|
{
|
|
|
|
memcpy(dst, src, sizeof(struct ceph_crypto_key));
|
2016-12-02 23:35:08 +08:00
|
|
|
return set_secret(dst, src->key);
|
2011-03-26 07:32:57 +08:00
|
|
|
}
|
|
|
|
|
2010-02-03 08:07:07 +08:00
|
|
|
int ceph_crypto_key_encode(struct ceph_crypto_key *key, void **p, void *end)
|
|
|
|
{
|
|
|
|
if (*p + sizeof(u16) + sizeof(key->created) +
|
|
|
|
sizeof(u16) + key->len > end)
|
|
|
|
return -ERANGE;
|
|
|
|
ceph_encode_16(p, key->type);
|
|
|
|
ceph_encode_copy(p, &key->created, sizeof(key->created));
|
|
|
|
ceph_encode_16(p, key->len);
|
|
|
|
ceph_encode_copy(p, key->key, key->len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ceph_crypto_key_decode(struct ceph_crypto_key *key, void **p, void *end)
|
|
|
|
{
|
2016-12-02 23:35:08 +08:00
|
|
|
int ret;
|
|
|
|
|
2010-02-03 08:07:07 +08:00
|
|
|
ceph_decode_need(p, end, 2*sizeof(u16) + sizeof(key->created), bad);
|
|
|
|
key->type = ceph_decode_16(p);
|
|
|
|
ceph_decode_copy(p, &key->created, sizeof(key->created));
|
|
|
|
key->len = ceph_decode_16(p);
|
|
|
|
ceph_decode_need(p, end, key->len, bad);
|
2016-12-02 23:35:08 +08:00
|
|
|
ret = set_secret(key, *p);
|
|
|
|
*p += key->len;
|
|
|
|
return ret;
|
2010-02-03 08:07:07 +08:00
|
|
|
|
|
|
|
bad:
|
|
|
|
dout("failed to decode crypto key\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ceph_crypto_key_unarmor(struct ceph_crypto_key *key, const char *inkey)
|
|
|
|
{
|
|
|
|
int inlen = strlen(inkey);
|
|
|
|
int blen = inlen * 3 / 4;
|
|
|
|
void *buf, *p;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
dout("crypto_key_unarmor %s\n", inkey);
|
|
|
|
buf = kmalloc(blen, GFP_NOFS);
|
|
|
|
if (!buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
blen = ceph_unarmor(buf, inkey, inkey+inlen);
|
|
|
|
if (blen < 0) {
|
|
|
|
kfree(buf);
|
|
|
|
return blen;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = buf;
|
|
|
|
ret = ceph_crypto_key_decode(key, &p, p + blen);
|
|
|
|
kfree(buf);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
dout("crypto_key_unarmor key %p type %d len %d\n", key,
|
|
|
|
key->type, key->len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-12-02 23:35:08 +08:00
|
|
|
void ceph_crypto_key_destroy(struct ceph_crypto_key *key)
|
|
|
|
{
|
|
|
|
if (key) {
|
|
|
|
kfree(key->key);
|
|
|
|
key->key = NULL;
|
2019-07-24 17:43:06 +08:00
|
|
|
if (key->tfm) {
|
|
|
|
crypto_free_sync_skcipher(key->tfm);
|
|
|
|
key->tfm = NULL;
|
|
|
|
}
|
2016-12-02 23:35:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-03 06:48:23 +08:00
|
|
|
static const u8 *aes_iv = (u8 *)CEPH_AES_IV;
|
2010-02-03 08:07:07 +08:00
|
|
|
|
2014-10-23 04:25:22 +08:00
|
|
|
/*
|
|
|
|
* Should be used for buffers allocated with ceph_kvmalloc().
|
|
|
|
* Currently these are encrypt out-buffer (ceph_buffer) and decrypt
|
|
|
|
* in-buffer (msg front).
|
|
|
|
*
|
|
|
|
* Dispose of @sgt with teardown_sgtable().
|
|
|
|
*
|
|
|
|
* @prealloc_sg is to avoid memory allocation inside sg_alloc_table()
|
|
|
|
* in cases where a single sg is sufficient. No attempt to reduce the
|
|
|
|
* number of sgs by squeezing physically contiguous pages together is
|
|
|
|
* made though, for simplicity.
|
|
|
|
*/
|
|
|
|
static int setup_sgtable(struct sg_table *sgt, struct scatterlist *prealloc_sg,
|
|
|
|
const void *buf, unsigned int buf_len)
|
|
|
|
{
|
|
|
|
struct scatterlist *sg;
|
|
|
|
const bool is_vmalloc = is_vmalloc_addr(buf);
|
|
|
|
unsigned int off = offset_in_page(buf);
|
|
|
|
unsigned int chunk_cnt = 1;
|
|
|
|
unsigned int chunk_len = PAGE_ALIGN(off + buf_len);
|
|
|
|
int i;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (buf_len == 0) {
|
|
|
|
memset(sgt, 0, sizeof(*sgt));
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_vmalloc) {
|
|
|
|
chunk_cnt = chunk_len >> PAGE_SHIFT;
|
|
|
|
chunk_len = PAGE_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chunk_cnt > 1) {
|
|
|
|
ret = sg_alloc_table(sgt, chunk_cnt, GFP_NOFS);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
} else {
|
|
|
|
WARN_ON(chunk_cnt != 1);
|
|
|
|
sg_init_table(prealloc_sg, 1);
|
|
|
|
sgt->sgl = prealloc_sg;
|
|
|
|
sgt->nents = sgt->orig_nents = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for_each_sg(sgt->sgl, sg, sgt->orig_nents, i) {
|
|
|
|
struct page *page;
|
|
|
|
unsigned int len = min(chunk_len - off, buf_len);
|
|
|
|
|
|
|
|
if (is_vmalloc)
|
|
|
|
page = vmalloc_to_page(buf);
|
|
|
|
else
|
|
|
|
page = virt_to_page(buf);
|
|
|
|
|
|
|
|
sg_set_page(sg, page, len, off);
|
|
|
|
|
|
|
|
off = 0;
|
|
|
|
buf += len;
|
|
|
|
buf_len -= len;
|
|
|
|
}
|
|
|
|
WARN_ON(buf_len != 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void teardown_sgtable(struct sg_table *sgt)
|
|
|
|
{
|
|
|
|
if (sgt->orig_nents > 1)
|
|
|
|
sg_free_table(sgt);
|
|
|
|
}
|
|
|
|
|
2016-12-02 23:35:07 +08:00
|
|
|
static int ceph_aes_crypt(const struct ceph_crypto_key *key, bool encrypt,
|
|
|
|
void *buf, int buf_len, int in_len, int *pout_len)
|
|
|
|
{
|
2018-09-19 10:10:45 +08:00
|
|
|
SYNC_SKCIPHER_REQUEST_ON_STACK(req, key->tfm);
|
2016-12-02 23:35:07 +08:00
|
|
|
struct sg_table sgt;
|
|
|
|
struct scatterlist prealloc_sg;
|
2017-01-17 02:16:46 +08:00
|
|
|
char iv[AES_BLOCK_SIZE] __aligned(8);
|
2016-12-02 23:35:07 +08:00
|
|
|
int pad_byte = AES_BLOCK_SIZE - (in_len & (AES_BLOCK_SIZE - 1));
|
|
|
|
int crypt_len = encrypt ? in_len + pad_byte : in_len;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
WARN_ON(crypt_len > buf_len);
|
|
|
|
if (encrypt)
|
|
|
|
memset(buf + in_len, pad_byte, pad_byte);
|
|
|
|
ret = setup_sgtable(&sgt, &prealloc_sg, buf, crypt_len);
|
|
|
|
if (ret)
|
2016-12-02 23:35:08 +08:00
|
|
|
return ret;
|
2016-12-02 23:35:07 +08:00
|
|
|
|
|
|
|
memcpy(iv, aes_iv, AES_BLOCK_SIZE);
|
2018-09-19 10:10:45 +08:00
|
|
|
skcipher_request_set_sync_tfm(req, key->tfm);
|
2016-12-02 23:35:07 +08:00
|
|
|
skcipher_request_set_callback(req, 0, NULL, NULL);
|
|
|
|
skcipher_request_set_crypt(req, sgt.sgl, sgt.sgl, crypt_len, iv);
|
|
|
|
|
|
|
|
/*
|
|
|
|
print_hex_dump(KERN_ERR, "key: ", DUMP_PREFIX_NONE, 16, 1,
|
|
|
|
key->key, key->len, 1);
|
|
|
|
print_hex_dump(KERN_ERR, " in: ", DUMP_PREFIX_NONE, 16, 1,
|
|
|
|
buf, crypt_len, 1);
|
|
|
|
*/
|
|
|
|
if (encrypt)
|
|
|
|
ret = crypto_skcipher_encrypt(req);
|
|
|
|
else
|
|
|
|
ret = crypto_skcipher_decrypt(req);
|
|
|
|
skcipher_request_zero(req);
|
|
|
|
if (ret) {
|
|
|
|
pr_err("%s %scrypt failed: %d\n", __func__,
|
|
|
|
encrypt ? "en" : "de", ret);
|
|
|
|
goto out_sgt;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
print_hex_dump(KERN_ERR, "out: ", DUMP_PREFIX_NONE, 16, 1,
|
|
|
|
buf, crypt_len, 1);
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (encrypt) {
|
|
|
|
*pout_len = crypt_len;
|
|
|
|
} else {
|
|
|
|
pad_byte = *(char *)(buf + in_len - 1);
|
|
|
|
if (pad_byte > 0 && pad_byte <= AES_BLOCK_SIZE &&
|
|
|
|
in_len >= pad_byte) {
|
|
|
|
*pout_len = in_len - pad_byte;
|
|
|
|
} else {
|
|
|
|
pr_err("%s got bad padding %d on in_len %d\n",
|
|
|
|
__func__, pad_byte, in_len);
|
|
|
|
ret = -EPERM;
|
|
|
|
goto out_sgt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out_sgt:
|
|
|
|
teardown_sgtable(&sgt);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ceph_crypt(const struct ceph_crypto_key *key, bool encrypt,
|
|
|
|
void *buf, int buf_len, int in_len, int *pout_len)
|
|
|
|
{
|
|
|
|
switch (key->type) {
|
|
|
|
case CEPH_CRYPTO_NONE:
|
|
|
|
*pout_len = in_len;
|
|
|
|
return 0;
|
|
|
|
case CEPH_CRYPTO_AES:
|
|
|
|
return ceph_aes_crypt(key, encrypt, buf, buf_len, in_len,
|
|
|
|
pout_len);
|
|
|
|
default:
|
|
|
|
return -ENOTSUPP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-19 01:56:35 +08:00
|
|
|
static int ceph_key_preparse(struct key_preparsed_payload *prep)
|
2011-03-29 05:59:38 +08:00
|
|
|
{
|
|
|
|
struct ceph_crypto_key *ckey;
|
2012-09-13 20:06:29 +08:00
|
|
|
size_t datalen = prep->datalen;
|
2011-03-29 05:59:38 +08:00
|
|
|
int ret;
|
|
|
|
void *p;
|
|
|
|
|
|
|
|
ret = -EINVAL;
|
2012-09-13 20:06:29 +08:00
|
|
|
if (datalen <= 0 || datalen > 32767 || !prep->data)
|
2011-03-29 05:59:38 +08:00
|
|
|
goto err;
|
|
|
|
|
|
|
|
ret = -ENOMEM;
|
|
|
|
ckey = kmalloc(sizeof(*ckey), GFP_KERNEL);
|
|
|
|
if (!ckey)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
/* TODO ceph_crypto_key_decode should really take const input */
|
2012-09-13 20:06:29 +08:00
|
|
|
p = (void *)prep->data;
|
|
|
|
ret = ceph_crypto_key_decode(ckey, &p, (char*)prep->data+datalen);
|
2011-03-29 05:59:38 +08:00
|
|
|
if (ret < 0)
|
|
|
|
goto err_ckey;
|
|
|
|
|
2015-10-21 21:04:48 +08:00
|
|
|
prep->payload.data[0] = ckey;
|
2014-07-19 01:56:35 +08:00
|
|
|
prep->quotalen = datalen;
|
2011-03-29 05:59:38 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_ckey:
|
|
|
|
kfree(ckey);
|
|
|
|
err:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-07-19 01:56:35 +08:00
|
|
|
static void ceph_key_free_preparse(struct key_preparsed_payload *prep)
|
|
|
|
{
|
2015-10-21 21:04:48 +08:00
|
|
|
struct ceph_crypto_key *ckey = prep->payload.data[0];
|
2014-07-19 01:56:35 +08:00
|
|
|
ceph_crypto_key_destroy(ckey);
|
|
|
|
kfree(ckey);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ceph_key_destroy(struct key *key)
|
|
|
|
{
|
2015-10-21 21:04:48 +08:00
|
|
|
struct ceph_crypto_key *ckey = key->payload.data[0];
|
2011-03-29 05:59:38 +08:00
|
|
|
|
|
|
|
ceph_crypto_key_destroy(ckey);
|
2012-08-03 00:12:59 +08:00
|
|
|
kfree(ckey);
|
2011-03-29 05:59:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct key_type key_type_ceph = {
|
|
|
|
.name = "ceph",
|
2014-07-19 01:56:35 +08:00
|
|
|
.preparse = ceph_key_preparse,
|
|
|
|
.free_preparse = ceph_key_free_preparse,
|
|
|
|
.instantiate = generic_key_instantiate,
|
2011-03-29 05:59:38 +08:00
|
|
|
.destroy = ceph_key_destroy,
|
|
|
|
};
|
|
|
|
|
2018-03-10 20:32:05 +08:00
|
|
|
int __init ceph_crypto_init(void)
|
|
|
|
{
|
2011-03-29 05:59:38 +08:00
|
|
|
return register_key_type(&key_type_ceph);
|
|
|
|
}
|
|
|
|
|
2018-03-10 20:32:05 +08:00
|
|
|
void ceph_crypto_shutdown(void)
|
|
|
|
{
|
2011-03-29 05:59:38 +08:00
|
|
|
unregister_key_type(&key_type_ceph);
|
|
|
|
}
|