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
1776static int do_test_rsa(struct crypto_akcipher *tfm,1776static int do_test_rsa(struct crypto_akcipher *tfm,
1777 struct akcipher_testvec *vecs)1777 struct akcipher_testvec *vecs)
1778{1778{
1779 char *xbuf[XBUFSIZE];
1779 struct akcipher_request *req;1780 struct akcipher_request *req;
1780 void *outbuf_enc = NULL;1781 void *outbuf_enc = NULL;
1781 void *outbuf_dec = NULL;1782 void *outbuf_dec = NULL;
@@ -1784,9 +1785,12 @@ static int do_test_rsa(struct crypto_akcipher *tfm, · 2 unmodified lines
1784 int err = -ENOMEM;1785 int err = -ENOMEM;
1785 struct scatterlist src, dst, src_tab[2];1786 struct scatterlist src, dst, src_tab[2];
1786 1787
1788 if (testmgr_alloc_buf(xbuf))
1789 return err;
1790
1787 req = akcipher_request_alloc(tfm, GFP_KERNEL);1791 req = akcipher_request_alloc(tfm, GFP_KERNEL);
1788 if (!req)1792 if (!req)
1789 return err;1793 goto free_xbuf;
1790 1794
1791 init_completion(&result.completion);1795 init_completion(&result.completion);
1792 1796
@@ -1804,9 +1808,14 @@ static int do_test_rsa(struct crypto_akcipher *tfm, · 11 unmodified lines
1804 if (!outbuf_enc)1808 if (!outbuf_enc)
1805 goto free_req;1809 goto free_req;
1806 1810
1811 if (WARN_ON(vecs->m_size > PAGE_SIZE))
1812 goto free_all;
1813
1814 memcpy(xbuf[0], vecs->m, vecs->m_size);
1815
1807 sg_init_table(src_tab, 2);1816 sg_init_table(src_tab, 2);
1808 sg_set_buf(&src_tab[0], vecs->m, 8);1817 sg_set_buf(&src_tab[0], xbuf[0], 8);
1809 sg_set_buf(&src_tab[1], vecs->m + 8, vecs->m_size - 8);1818 sg_set_buf(&src_tab[1], xbuf[0] + 8, vecs->m_size - 8);
1810 sg_init_one(&dst, outbuf_enc, out_len_max);1819 sg_init_one(&dst, outbuf_enc, out_len_max);
1811 akcipher_request_set_crypt(req, src_tab, &dst, vecs->m_size,1820 akcipher_request_set_crypt(req, src_tab, &dst, vecs->m_size,
1812 out_len_max);1821 out_len_max);
@@ -1825,7 +1834,7 @@ static int do_test_rsa(struct crypto_akcipher *tfm, · 12 unmodified lines
1825 goto free_all;1834 goto free_all;
1826 }1835 }
1827 /* verify that encrypted message is equal to expected */1836 /* 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)) {
1829 pr_err("alg: rsa: encrypt test failed. Invalid output\n");1838 pr_err("alg: rsa: encrypt test failed. Invalid output\n");
1830 err = -EINVAL;1839 err = -EINVAL;
1831 goto free_all;1840 goto free_all;
@@ -1840,7 +1849,13 @@ static int do_test_rsa(struct crypto_akcipher *tfm, · 8 unmodified lines
1840 err = -ENOMEM;1849 err = -ENOMEM;
1841 goto free_all;1850 goto free_all;
1842 }1851 }
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);
1844 sg_init_one(&dst, outbuf_dec, out_len_max);1859 sg_init_one(&dst, outbuf_dec, out_len_max);
1845 init_completion(&result.completion);1860 init_completion(&result.completion);
1846 akcipher_request_set_crypt(req, &src, &dst, vecs->c_size, out_len_max);1861 akcipher_request_set_crypt(req, &src, &dst, vecs->c_size, out_len_max);
@@ -1867,6 +1882,8 @@ free_all: · 20 unmodified lines
1867 kfree(outbuf_enc);1882 kfree(outbuf_enc);
1868free_req:1883free_req:
1869 akcipher_request_free(req);1884 akcipher_request_free(req);
1885free_xbuf:
1886 testmgr_free_buf(xbuf);
1870 return err;1887 return err;
1871}1888}
1872 1889

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