mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christophe Saout <christophe@saout.de>
To: Andrew Morton <akpm@osdl.org>
Cc: James Morris <jmorris@redhat.com>,
	jlcooke@certainkey.com, linux-kernel@vger.kernel.org,
	adam@yggdrasil.com
Subject: [PATCH 2/2] fix in-place de/encryption bug with highmem
Date: Wed, 25 Feb 2004 23:55:53 +0100	[thread overview]
Message-ID: <20040225225552.GB6536@leto.cs.pocnet.net> (raw)
In-Reply-To: <20040225115027.580cc2ed.akpm@osdl.org>

This patch fixes the bug where in-place encryption was not detected
when the same highmem pages is mapped twice to different virtual
addresses.

This adds a parameter to xxx_process to indicate whether this is an
in-place encryption and moves the responsability to the caller using
a helper function scatterwalk.h.

diff -Nur linux.orig/crypto/cipher.c linux/crypto/cipher.c
--- linux.orig/crypto/cipher.c	2004-02-25 23:43:39.125619688 +0100
+++ linux/crypto/cipher.c	2004-02-25 23:44:51.335642096 +0100
@@ -22,7 +22,7 @@
 
 typedef void (cryptfn_t)(void *, u8 *, const u8 *);
 typedef void (procfn_t)(struct crypto_tfm *, u8 *,
-                        u8*, cryptfn_t, int enc, void *);
+                        u8*, cryptfn_t, int enc, void *, int);
 
 static inline void xor_64(u8 *a, const u8 *b)
 {
@@ -78,7 +78,9 @@
 
 		scatterwalk_copychunks(src_p, &walk_in, bsize, 0);
 
-		prfn(tfm, dst_p, src_p, crfn, enc, info);
+		prfn(tfm, dst_p, src_p, crfn, enc, info,
+		     scatterwalk_samebuf(&walk_in, &walk_out,
+					 src_p, dst_p));
 
 		scatterwalk_done(&walk_in, 0, nbytes);
 
@@ -92,8 +94,8 @@
 	}
 }
 
-static void cbc_process(struct crypto_tfm *tfm,
-                        u8 *dst, u8 *src, cryptfn_t fn, int enc, void *info)
+static void cbc_process(struct crypto_tfm *tfm, u8 *dst, u8 *src,
+			cryptfn_t fn, int enc, void *info, int in_place)
 {
 	u8 *iv = info;
 	
@@ -106,9 +108,8 @@
 		fn(crypto_tfm_ctx(tfm), dst, iv);
 		memcpy(iv, dst, crypto_tfm_alg_blocksize(tfm));
 	} else {
-		const int need_stack = (src == dst);
-		u8 stack[need_stack ? crypto_tfm_alg_blocksize(tfm) : 0];
-		u8 *buf = need_stack ? stack : dst;
+		u8 stack[in_place ? crypto_tfm_alg_blocksize(tfm) : 0];
+		u8 *buf = in_place ? stack : dst;
 
 		fn(crypto_tfm_ctx(tfm), buf, src);
 		tfm->crt_u.cipher.cit_xor_block(buf, iv);
@@ -119,7 +120,7 @@
 }
 
 static void ecb_process(struct crypto_tfm *tfm, u8 *dst, u8 *src,
-                        cryptfn_t fn, int enc, void *info)
+			cryptfn_t fn, int enc, void *info, int in_place)
 {
 	fn(crypto_tfm_ctx(tfm), dst, src);
 }
diff -Nur linux.orig/crypto/scatterwalk.h linux/crypto/scatterwalk.h
--- linux.orig/crypto/scatterwalk.h	2004-02-25 23:43:39.133618472 +0100
+++ linux/crypto/scatterwalk.h	2004-02-25 23:44:51.342641032 +0100
@@ -33,6 +33,14 @@
 	return sg + 1;
 }
 
+static inline int scatterwalk_samebuf(struct scatter_walk *walk_in,
+				      struct scatter_walk *walk_out,
+				      void *src_p, void *dst_p)
+{
+	return walk_in->page == walk_out->page &&
+	       walk_in->data == src_p && walk_out->data == dst_p;
+}
+
 void *scatterwalk_whichbuf(struct scatter_walk *walk, unsigned int nbytes, void *scratch);
 void scatterwalk_start(struct scatter_walk *walk, struct scatterlist *sg);
 int scatterwalk_copychunks(void *buf, struct scatter_walk *walk, size_t nbytes, int out);


  parent reply	other threads:[~2004-02-25 23:02 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-24 20:49 cryptoapi highmem bug Christophe Saout
2004-02-24 22:34 ` Jean-Luc Cooke
2004-02-24 23:01   ` Christophe Saout
2004-02-25  4:32     ` Jean-Luc Cooke
2004-02-25  6:00       ` Andrew Morton
2004-02-25 13:27         ` James Morris
2004-02-25 15:17           ` Jean-Luc Cooke
2004-02-25 19:50           ` Andrew Morton
2004-02-25 21:27             ` Christophe Saout
2004-02-25 21:41               ` Jean-Luc Cooke
2004-02-25 22:55             ` [PATCH 1/2] move scatterwalk functions to own file Christophe Saout
2004-02-25 22:55             ` Christophe Saout [this message]
2004-02-26  4:13               ` [PATCH 2/2] fix in-place de/encryption bug with highmem James Morris
2004-02-26 11:03                 ` Christophe Saout
2004-02-25 15:31         ` cryptoapi highmem bug Christophe Saout
2004-02-25 15:51           ` Christophe Saout
2004-02-25 15:44             ` Jean-Luc Cooke
2004-02-25 16:13               ` Christophe Saout
2004-02-25 16:09                 ` Jean-Luc Cooke
2004-02-25 18:11                   ` cryptoapi OMAC (was: cryptoapi highmem bug) Christophe Saout
2004-02-25 20:59                     ` Jean-Luc Cooke
2004-02-25 21:44                       ` Christophe Saout
2004-02-25 18:15               ` cryptoapi highmem bug Christophe Saout
2004-02-25 20:12                 ` Jean-Luc Cooke
2004-02-25 20:39                   ` Christophe Saout
2004-02-25 20:46                     ` Jean-Luc Cooke
2004-02-25 21:36                       ` Christophe Saout
2004-02-25 21:52                         ` Jean-Luc Cooke

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=20040225225552.GB6536@leto.cs.pocnet.net \
    --to=christophe@saout.de \
    --cc=adam@yggdrasil.com \
    --cc=akpm@osdl.org \
    --cc=jlcooke@certainkey.com \
    --cc=jmorris@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®