History

Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6

Pull crypto fix from Herbert Xu: "This fixes a bug in the RSA self-test that may cause crashes on some architectures such as SPARC" * 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: crypto: testmgr - Use kmalloc memory for RSA input

Linus Torvalds committed 10 years ago

Commit dc0f2f82 parents a2ccb68 df27b261 file · +22 −5Browse files

Unified · Split

crypto/testmgr.c+22−5
@@ -1776,6 +1776,7 @@ static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver, · 1775 unmodified lines
17761776 static int do_test_rsa(struct crypto_akcipher *tfm,
17771777 struct akcipher_testvec *vecs)
17781778 {
1779+ char *xbuf[XBUFSIZE];
17791780 struct akcipher_request *req;
17801781 void *outbuf_enc = NULL;
17811782 void *outbuf_dec = NULL;
@@ -1784,9 +1785,12 @@ static int do_test_rsa(struct crypto_akcipher *tfm, · 2 unmodified lines
17841785 int err = -ENOMEM;
17851786 struct scatterlist src, dst, src_tab[2];
17861787
1788+ if (testmgr_alloc_buf(xbuf))
1789+ return err;
1790+
17871791 req = akcipher_request_alloc(tfm, GFP_KERNEL);
17881792 if (!req)
1789− return err;
1793+ goto free_xbuf;
17901794
17911795 init_completion(&result.completion);
17921796
@@ -1804,9 +1808,14 @@ static int do_test_rsa(struct crypto_akcipher *tfm, · 11 unmodified lines
18041808 if (!outbuf_enc)
18051809 goto free_req;
18061810
1811+ if (WARN_ON(vecs->m_size > PAGE_SIZE))
1812+ goto free_all;
1813+
1814+ memcpy(xbuf[0], vecs->m, vecs->m_size);
1815+
18071816 sg_init_table(src_tab, 2);
1808− sg_set_buf(&src_tab[0], vecs->m, 8);
1809− sg_set_buf(&src_tab[1], vecs->m + 8, vecs->m_size - 8);
1817+ sg_set_buf(&src_tab[0], xbuf[0], 8);
1818+ sg_set_buf(&src_tab[1], xbuf[0] + 8, vecs->m_size - 8);
18101819 sg_init_one(&dst, outbuf_enc, out_len_max);
18111820 akcipher_request_set_crypt(req, src_tab, &dst, vecs->m_size,
18121821 out_len_max);
@@ -1825,7 +1834,7 @@ static int do_test_rsa(struct crypto_akcipher *tfm, · 12 unmodified lines
18251834 goto free_all;
18261835 }
18271836 /* verify that encrypted message is equal to expected */
1828− if (memcmp(vecs->c, sg_virt(req->dst), vecs->c_size)) {
1837+ if (memcmp(vecs->c, outbuf_enc, vecs->c_size)) {
18291838 pr_err("alg: rsa: encrypt test failed. Invalid output\n");
18301839 err = -EINVAL;
18311840 goto free_all;
@@ -1840,7 +1849,13 @@ static int do_test_rsa(struct crypto_akcipher *tfm, · 8 unmodified lines
18401849 err = -ENOMEM;
18411850 goto free_all;
18421851 }
1843− sg_init_one(&src, vecs->c, vecs->c_size);
1852+
1853+ if (WARN_ON(vecs->c_size > PAGE_SIZE))
1854+ goto free_all;
1855+
1856+ memcpy(xbuf[0], vecs->c, vecs->c_size);
1857+
1858+ sg_init_one(&src, xbuf[0], vecs->c_size);
18441859 sg_init_one(&dst, outbuf_dec, out_len_max);
18451860 init_completion(&result.completion);
18461861 akcipher_request_set_crypt(req, &src, &dst, vecs->c_size, out_len_max);
@@ -1867,6 +1882,8 @@ free_all: · 20 unmodified lines
18671882 kfree(outbuf_enc);
18681883 free_req:
18691884 akcipher_request_free(req);
1885+free_xbuf:
1886+ testmgr_free_buf(xbuf);
18701887 return err;
18711888 }
18721889

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t