Skip to content

Commit

Permalink
crypto: user - ensure user supplied strings are nul-terminated
Browse files Browse the repository at this point in the history
To avoid misuse, ensure cru_name and cru_driver_name are always
nul-terminated strings.

Signed-off-by: Mathias Krause <minipli@googlemail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
  • Loading branch information
minipli authored and herbertx committed Feb 19, 2013
1 parent e336ed9 commit 8fd61d3
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crypto/crypto_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

#include "internal.h"

#define null_terminated(x) (strnlen(x, sizeof(x)) < sizeof(x))

static DEFINE_MUTEX(crypto_cfg_mutex);

/* The crypto netlink socket */
Expand Down Expand Up @@ -196,6 +198,9 @@ static int crypto_report(struct sk_buff *in_skb, struct nlmsghdr *in_nlh,
struct crypto_dump_info info;
int err;

if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
return -EINVAL;

if (!p->cru_driver_name[0])
return -EINVAL;

Expand Down Expand Up @@ -260,6 +265,9 @@ static int crypto_update_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
LIST_HEAD(list);

if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
return -EINVAL;

if (priority && !strlen(p->cru_driver_name))
return -EINVAL;

Expand Down Expand Up @@ -287,6 +295,9 @@ static int crypto_del_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
struct crypto_alg *alg;
struct crypto_user_alg *p = nlmsg_data(nlh);

if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
return -EINVAL;

alg = crypto_alg_match(p, 1);
if (!alg)
return -ENOENT;
Expand Down Expand Up @@ -368,6 +379,9 @@ static int crypto_add_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
struct crypto_user_alg *p = nlmsg_data(nlh);
struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];

if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
return -EINVAL;

if (strlen(p->cru_driver_name))
exact = 1;

Expand Down

0 comments on commit 8fd61d3

Please sign in to comment.