Return-Path: Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:34753 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751115AbbHAR0Q (ORCPT ); Sat, 1 Aug 2015 13:26:16 -0400 Message-ID: <1438449959.3225.18.camel@decadent.org.uk> Subject: [PATCH 2.6.32-4.0] sg_start_req(): make sure that there's not too many elements in iovec From: Ben Hutchings To: stable@vger.kernel.org Cc: Al Viro Date: Sat, 01 Aug 2015 18:25:59 +0100 Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="=-FHPZ6uNLVFkEQZ0+dTel" Mime-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: --=-FHPZ6uNLVFkEQZ0+dTel Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: Al Viro commit 451a2886b6bf90e2fb378f7c46c655450fb96e81 upstream. unfortunately, allowing an arbitrary 16bit value means a possibility of overflow in the calculation of total number of pages in bio_map_user_iov() = - we rely on there being no more than PAGE_SIZE members of sum in the first loop there. If that sum wraps around, we end up allocating too small array of pointers to pages and it's easy to overflow it in the second loop. X-Coverup: TINC (and there's no lumber cartel either) Signed-off-by: Al Viro [bwh: s/MAX_UIOVEC/UIO_MAXIOV/. This was fixed upstream by commit fdc81f45e9f5 ("sg_start_req(): use import_iovec()"), but we don't have that function.] Signed-off-by: Ben Hutchings --- It looks like this bug was introduced in 2.6.28 by commit 10db10d144c0 ("sg: convert the indirect IO path to use the block layer"), so the fix is needed for all stable branches. Ben. drivers/scsi/sg.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -1687,6 +1687,9 @@ static int sg_start_req(Sg_request *srp, md->from_user =3D 0; } =20 + if (unlikely(iov_count > UIO_MAXIOV)) + return -EINVAL; + if (iov_count) { int len, size =3D sizeof(struct sg_iovec) * iov_count; struct iovec *iov; --=20 Ben Hutchings One of the nice things about standards is that there are so many of them. --=-FHPZ6uNLVFkEQZ0+dTel Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIVAwUAVb0BJ+e/yOyVhhEJAQpdQw/8CBK73mJ7sZm93tiE580KxBOBiW9HocSR CILeclaxsJJA0BDOm0q4ZtOXeH/2aGTU3iU0B9oOnhVtLOIr4GrNPnRq/EDYAKkZ 5ts7ofSnukUDG7+tGT/2OrRxvbUZTEIV+HTAOGhbOxeUd/JJQUNk0HmxZuO6k1nX nF7aSOAqu21ynpxEquYpKrGuY167CpJUCMUjX66MF6Z6XO48NjWc7iblyHyrMaeV 9J7u0h1iyym8DOeCcu1/jSr3DkKz+MBVmiMBvwAKyN2sJX9z3EAYXEDBmbHkOMo6 ph8x1pF8jC0uTajRQN97hyMx4ETR+qchG8bHH/Zuqr3BkNZ5a/0g4KZm/2BVx8ZY C+DpI5KMu5tlaRNKmrHIEzeierqeQgZeeMiGIrw+aUsc8RYKMSl0QSPvWcjzfa5B nzPJODhvPysxYgoBmbsNhD5u9KJGxnoLvJyvYTOkKGTmiZyQNT2ZOhEyP/Mfwmjw sppShEf27t6yciYzMoEwFpToq9HVyULNr2PXUiaS+LVzDapoXZ+/HQ4+ef6va7uV G+93l4y2l5RGY2nDXQQO6hGfL/8sqVQaOBrRHkxt5INXvu2KBWrbRPWGS1EU5ZD7 9Ei2PDokMDMVp6rN5DcSWcShL1SdvxkRvkOuCrmBexbvZ7BNE1NQhJcsESfaPPtT ypaTSrGl5mA= =+k3P -----END PGP SIGNATURE----- --=-FHPZ6uNLVFkEQZ0+dTel--