From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55484C282DD for ; Mon, 10 Jun 2019 08:21:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 244F12082E for ; Mon, 10 Jun 2019 08:21:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387862AbfFJIVQ (ORCPT ); Mon, 10 Jun 2019 04:21:16 -0400 Received: from atrey.karlin.mff.cuni.cz ([195.113.26.193]:53535 "EHLO atrey.karlin.mff.cuni.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387825AbfFJIVQ (ORCPT ); Mon, 10 Jun 2019 04:21:16 -0400 Received: by atrey.karlin.mff.cuni.cz (Postfix, from userid 512) id CD59080266; Mon, 10 Jun 2019 10:21:02 +0200 (CEST) Date: Mon, 10 Jun 2019 10:21:12 +0200 From: Pavel Machek To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, Vivien Didelot , Michal Kubecek , "David S. Miller" Subject: Re: [PATCH 4.19 01/51] ethtool: fix potential userspace buffer overflow Message-ID: <20190610082112.GA8783@amd> References: <20190609164127.123076536@linuxfoundation.org> <20190609164127.215699992@linuxfoundation.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="C7zPtVaVf+AK4Oqc" Content-Disposition: inline In-Reply-To: <20190609164127.215699992@linuxfoundation.org> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org --C7zPtVaVf+AK4Oqc Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi! > From: Vivien Didelot >=20 > [ Upstream commit 0ee4e76937d69128a6a66861ba393ebdc2ffc8a2 ] >=20 > ethtool_get_regs() allocates a buffer of size ops->get_regs_len(), > and pass it to the kernel driver via ops->get_regs() for filling. >=20 > There is no restriction about what the kernel drivers can or cannot do > with the open ethtool_regs structure. They usually set regs->version > and ignore regs->len or set it to the same size as ops->get_regs_len(). >=20 > But if userspace allocates a smaller buffer for the registers dump, > we would cause a userspace buffer overflow in the final copy_to_user() > call, which uses the regs.len value potentially reset by the driver. >=20 > To fix this, make this case obvious and store regs.len before calling > ops->get_regs(), to only copy as much data as requested by userspace, > up to the value returned by ops->get_regs_len(). >=20 > While at it, remove the redundant check for non-null regbuf. Mainline differs from 4.19-stable here, and while the non-null check is redundant in -mainline, it does not seem to be redundant in -stable. In stable, if get_regs_len() returns < 0, we'll pass it to vzalloc. Pavel --=20 (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blo= g.html --C7zPtVaVf+AK4Oqc Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAlz+EvgACgkQMOfwapXb+vLYDwCgpANVlxjsNizDo5i0pIDWsa3G eWMAn04kn8dXdTe1HBOZbl9QHOw8fKHg =3qAG -----END PGP SIGNATURE----- --C7zPtVaVf+AK4Oqc--