af_alg.c (bf3c0e5e7102f5787d693379d9d384b813fe890b) | af_alg.c (77ebdabe8de7c02f43c6de3357f79ff96f9f0579) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * af_alg: User-space algorithm interface 4 * 5 * This file provides the user-space API for algorithms. 6 * 7 * Copyright (c) 2010 Herbert Xu <herbert@gondor.apana.org.au> 8 */ 9 10#include <linux/atomic.h> 11#include <crypto/if_alg.h> 12#include <linux/crypto.h> 13#include <linux/init.h> 14#include <linux/kernel.h> 15#include <linux/list.h> 16#include <linux/module.h> 17#include <linux/net.h> 18#include <linux/rwsem.h> | 1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * af_alg: User-space algorithm interface 4 * 5 * This file provides the user-space API for algorithms. 6 * 7 * Copyright (c) 2010 Herbert Xu <herbert@gondor.apana.org.au> 8 */ 9 10#include <linux/atomic.h> 11#include <crypto/if_alg.h> 12#include <linux/crypto.h> 13#include <linux/init.h> 14#include <linux/kernel.h> 15#include <linux/list.h> 16#include <linux/module.h> 17#include <linux/net.h> 18#include <linux/rwsem.h> |
19#include <linux/sched.h> | |
20#include <linux/sched/signal.h> 21#include <linux/security.h> 22 23struct alg_type_list { 24 const struct af_alg_type *type; 25 struct list_head list; 26}; 27 --- 221 unchanged lines hidden (view full) --- 249 err = alg_setkey(sk, optval, optlen); 250 break; 251 case ALG_SET_AEAD_AUTHSIZE: 252 if (sock->state == SS_CONNECTED) 253 goto unlock; 254 if (!type->setauthsize) 255 goto unlock; 256 err = type->setauthsize(ask->private, optlen); | 19#include <linux/sched/signal.h> 20#include <linux/security.h> 21 22struct alg_type_list { 23 const struct af_alg_type *type; 24 struct list_head list; 25}; 26 --- 221 unchanged lines hidden (view full) --- 248 err = alg_setkey(sk, optval, optlen); 249 break; 250 case ALG_SET_AEAD_AUTHSIZE: 251 if (sock->state == SS_CONNECTED) 252 goto unlock; 253 if (!type->setauthsize) 254 goto unlock; 255 err = type->setauthsize(ask->private, optlen); |
256 break; 257 case ALG_SET_DRBG_ENTROPY: 258 if (sock->state == SS_CONNECTED) 259 goto unlock; 260 if (!type->setentropy) 261 goto unlock; 262 263 err = type->setentropy(ask->private, optval, optlen); |
|
257 } 258 259unlock: 260 release_sock(sk); 261 262 return err; 263} 264 --- 16 unchanged lines hidden (view full) --- 281 err = -ENOMEM; 282 if (!sk2) 283 goto unlock; 284 285 sock_init_data(newsock, sk2); 286 security_sock_graft(sk2, newsock); 287 security_sk_clone(sk, sk2); 288 | 264 } 265 266unlock: 267 release_sock(sk); 268 269 return err; 270} 271 --- 16 unchanged lines hidden (view full) --- 288 err = -ENOMEM; 289 if (!sk2) 290 goto unlock; 291 292 sock_init_data(newsock, sk2); 293 security_sock_graft(sk2, newsock); 294 security_sk_clone(sk, sk2); 295 |
296 /* 297 * newsock->ops assigned here to allow type->accept call to override 298 * them when required. 299 */ 300 newsock->ops = type->ops; |
|
289 err = type->accept(ask->private, sk2); 290 291 nokey = err == -ENOKEY; 292 if (nokey && type->accept_nokey) 293 err = type->accept_nokey(ask->private, sk2); 294 295 if (err) 296 goto unlock; 297 298 if (atomic_inc_return_relaxed(&ask->refcnt) == 1) 299 sock_hold(sk); 300 if (nokey) { 301 atomic_inc(&ask->nokey_refcnt); 302 atomic_set(&alg_sk(sk2)->nokey_refcnt, 1); 303 } 304 alg_sk(sk2)->parent = sk; 305 alg_sk(sk2)->type = type; 306 | 301 err = type->accept(ask->private, sk2); 302 303 nokey = err == -ENOKEY; 304 if (nokey && type->accept_nokey) 305 err = type->accept_nokey(ask->private, sk2); 306 307 if (err) 308 goto unlock; 309 310 if (atomic_inc_return_relaxed(&ask->refcnt) == 1) 311 sock_hold(sk); 312 if (nokey) { 313 atomic_inc(&ask->nokey_refcnt); 314 atomic_set(&alg_sk(sk2)->nokey_refcnt, 1); 315 } 316 alg_sk(sk2)->parent = sk; 317 alg_sk(sk2)->type = type; 318 |
307 newsock->ops = type->ops; | |
308 newsock->state = SS_CONNECTED; 309 310 if (nokey) 311 newsock->ops = type->ops_nokey; 312 313 err = 0; 314 315unlock: --- 525 unchanged lines hidden (view full) --- 841 return -EINVAL; 842 } 843 844 if (con.iv && con.iv->ivlen != ivsize) 845 return -EINVAL; 846 } 847 848 lock_sock(sk); | 319 newsock->state = SS_CONNECTED; 320 321 if (nokey) 322 newsock->ops = type->ops_nokey; 323 324 err = 0; 325 326unlock: --- 525 unchanged lines hidden (view full) --- 852 return -EINVAL; 853 } 854 855 if (con.iv && con.iv->ivlen != ivsize) 856 return -EINVAL; 857 } 858 859 lock_sock(sk); |
849 if (ctx->init && !ctx->more) { 850 if (ctx->used) { 851 err = -EINVAL; 852 goto unlock; 853 } 854 855 pr_info_once( 856 "%s sent an empty control message without MSG_MORE.\n", 857 current->comm); | 860 if (ctx->init && (init || !ctx->more)) { 861 err = -EINVAL; 862 goto unlock; |
858 } 859 ctx->init = true; 860 861 if (init) { 862 ctx->enc = enc; 863 if (con.iv) 864 memcpy(ctx->iv, con.iv->iv, ivsize); 865 --- 337 unchanged lines hidden --- | 863 } 864 ctx->init = true; 865 866 if (init) { 867 ctx->enc = enc; 868 if (con.iv) 869 memcpy(ctx->iv, con.iv->iv, ivsize); 870 --- 337 unchanged lines hidden --- |