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
Unified · Split
| @@ -1776,6 +1776,7 @@ static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver, · 1775 unmodified lines | ||
| 1776 | 1776 | static int do_test_rsa(struct crypto_akcipher *tfm, |
| 1777 | 1777 | struct akcipher_testvec *vecs) |
| 1778 | 1778 | { |
| 1779 | + char *xbuf[XBUFSIZE]; | |
| 1779 | 1780 | struct akcipher_request *req; |
| 1780 | 1781 | void *outbuf_enc = NULL; |
| 1781 | 1782 | void *outbuf_dec = NULL; |
| @@ -1784,9 +1785,12 @@ static int do_test_rsa(struct crypto_akcipher *tfm, · 2 unmodified lines | ||
| 1784 | 1785 | int err = -ENOMEM; |
| 1785 | 1786 | struct scatterlist src, dst, src_tab[2]; |
| 1786 | 1787 | |
| 1788 | + if (testmgr_alloc_buf(xbuf)) | |
| 1789 | + return err; | |
| 1790 | + | |
| 1787 | 1791 | req = akcipher_request_alloc(tfm, GFP_KERNEL); |
| 1788 | 1792 | if (!req) |
| 1789 | − return err; | |
| 1793 | + goto free_xbuf; | |
| 1790 | 1794 | |
| 1791 | 1795 | init_completion(&result.completion); |
| 1792 | 1796 | |
| @@ -1804,9 +1808,14 @@ static int do_test_rsa(struct crypto_akcipher *tfm, · 11 unmodified lines | ||
| 1804 | 1808 | if (!outbuf_enc) |
| 1805 | 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 | 1816 | 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); | |
| 1810 | 1819 | sg_init_one(&dst, outbuf_enc, out_len_max); |
| 1811 | 1820 | akcipher_request_set_crypt(req, src_tab, &dst, vecs->m_size, |
| 1812 | 1821 | out_len_max); |
| @@ -1825,7 +1834,7 @@ static int do_test_rsa(struct crypto_akcipher *tfm, · 12 unmodified lines | ||
| 1825 | 1834 | goto free_all; |
| 1826 | 1835 | } |
| 1827 | 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 | 1838 | pr_err("alg: rsa: encrypt test failed. Invalid output\n"); |
| 1830 | 1839 | err = -EINVAL; |
| 1831 | 1840 | goto free_all; |
| @@ -1840,7 +1849,13 @@ static int do_test_rsa(struct crypto_akcipher *tfm, · 8 unmodified lines | ||
| 1840 | 1849 | err = -ENOMEM; |
| 1841 | 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 | 1859 | sg_init_one(&dst, outbuf_dec, out_len_max); |
| 1845 | 1860 | init_completion(&result.completion); |
| 1846 | 1861 | akcipher_request_set_crypt(req, &src, &dst, vecs->c_size, out_len_max); |
| @@ -1867,6 +1882,8 @@ free_all: · 20 unmodified lines | ||
| 1867 | 1882 | kfree(outbuf_enc); |
| 1868 | 1883 | free_req: |
| 1869 | 1884 | akcipher_request_free(req); |
| 1885 | +free_xbuf: | |
| 1886 | + testmgr_free_buf(xbuf); | |
| 1870 | 1887 | return err; |
| 1871 | 1888 | } |
| 1872 | 1889 | |