mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: Michal Ludvig <mludvig@suse.cz>
Cc: CryptoAPI List <cryptoapi@lists.logix.cz>,
	linux-kernel@vger.kernel.org, James Morris <jmorris@redhat.com>
Subject: Re: [PATCH] /dev/crypto for Linux
Date: Wed, 25 Aug 2004 15:26:51 +0100	[thread overview]
Message-ID: <20040825152651.A8381@infradead.org> (raw)
In-Reply-To: <412BB517.4040204@suse.cz>; from mludvig@suse.cz on Tue, Aug 24, 2004 at 11:37:27PM +0200

> +static int verbosity = 0;

no need to initialize to 0

> +module_param(verbosity, int, 0644);
> +MODULE_PARM_DESC(verbosity, "0: normal, 1: verbose, 2: debug");
> +
> +#ifdef CRYPTODEV_STATS

whi is this not a config option?

> +static int enable_stats = 0;

as above

> +	copy_from_user(alg_name, sop->alg_name, sop->alg_namelen);

this needs error checking.

> +	keyp = kmalloc(sop->keylen, GFP_KERNEL);

retval checking

> +	copy_from_user(keyp, sop->key, sop->keylen);

error checking

> +	if(down_trylock(&ses_ptr->sem)) {
> +		dprintk(2, KERN_DEBUG, "Waiting for semaphore of sid=0x%08X\n",
> +			ses_ptr->sid);
> +		down(&ses_ptr->sem);
> +	}

just use down please

> +static int
> +clonefd(struct file *filp)
> +{
> +	struct files_struct * files = current->files;
> +	int fd;
> +
> +	fd = get_unused_fd();
> +	if (fd >= 0) {
> +		get_file(filp);
> +		FD_SET(fd, files->open_fds);
> +		fd_install(fd, filp);
> +	}
> +
> +	return fd;
> +}

Yikes.

> +static int
> +cryptodev_ioctl(struct inode *inode, struct file *filp,
> +		unsigned int cmd, unsigned long arg)
> +{
> +	struct session_op sop;
> +	struct crypt_op cop;
> +	struct fcrypt *fcr = filp->private_data;
> +	uint32_t ses;
> +	int ret, fd;
> +
> +	if (!fcr)
> +		BUG();
> +
> +	switch (cmd) {
> +		case CRIOGET:
> +			fd = clonefd(filp);
> +			put_user(fd, (int*)arg);
> +			return 0;

Extremly bad API.  Just allow opening the device multiple times,
and get a new context each time (can be stored in file->private_data

> +		case CIOCGSESSION:
> +			copy_from_user(&sop, (void*)arg, sizeof(sop));
> +			ret = crypto_create_session(fcr, &sop);
> +			if (ret)
> +				return ret;
> +			copy_to_user((void*)arg, &sop, sizeof(sop));

missing error check.

> +			return 0;
> +
> +		case CIOCFSESSION:
> +			get_user(ses, (uint32_t*)arg);

dito

> +			ret = crypto_finish_session(fcr, ses);
> +			return ret;
> +
> +		case CIOCCRYPT:
> +			copy_from_user(&cop, (void*)arg, sizeof(cop));
> +			ret = crypto_run(fcr, &cop);
> +			copy_to_user((void*)arg, &cop, sizeof(cop));

dito


besides the rather crappy implementation I'm not sure a crypto device
makes any sense until we have hardware accelerators, and for these this
is most likely not he right API

  parent reply	other threads:[~2004-08-25 14:27 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-24 21:37 Michal Ludvig
     [not found] ` <20040824215351.GA9272@halcrow.us>
2004-08-25  7:37   ` Michal Ludvig
2004-08-25 14:17     ` Jeff Garzik
2004-08-25 14:41       ` Michal Ludvig
2004-08-25 14:26 ` Christoph Hellwig [this message]
2004-08-25 15:44   ` Michal Ludvig
2004-08-25 14:42 ` Christoph Hellwig
2004-08-25 14:44 ` James Morris
2004-08-25 21:28   ` Bill Davidsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040825152651.A8381@infradead.org \
    --to=hch@infradead.org \
    --cc=cryptoapi@lists.logix.cz \
    --cc=jmorris@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mludvig@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome