Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2949803ybi; Mon, 10 Jun 2019 01:21:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqwp82kjbB27lChq8XijKFFkripE+Lu6/2CiuO2y5QTPTxDnNPeZSVavDXi13wMhE5BaRuPC X-Received: by 2002:a17:90a:bc0c:: with SMTP id w12mr19059324pjr.111.1560154907996; Mon, 10 Jun 2019 01:21:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560154907; cv=none; d=google.com; s=arc-20160816; b=C0/nHeA0jhtaHxdFJJ+fTZvnRtNGNptUutcXPysWb6rEHKeuGE5XUURbDckBUJlyxB dkmb5ZVIPgi0OfQhNUf6XcSGp0vjhRbKSdoglEZI49geLI76I3fJoR4Y+0auUNpJ29r/ lNzPwA5ql181TuLUHEI2z0xooOj/2adFzp//KOvPsP2gcgi5WMbmhZ/OCAhHbdCLLYQ+ SUZqJdweY13PoLqgFnFMliyTU5ZWGH0b3SIxUVAAIeWQHPjCMs/22gzSNNRDaGxmJNuT JZhNxIj8ZOWOC5HLB6cWcDAJiIOvwVURL/gbefHpcRDEYR4qT5WRdzK6YuAX2ctPxbuE MWUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=f9BBqzh5IsWFwP8Mwu327xdI3BdhSgWuyr/J3YskNbU=; b=HqlOu1LYou5DWykFn9NSXt67v4dAOr550OcTHG+zgnwz4Agj+wlkZe3qTvtXBS9ORt 2RkPBb0jVSDP6+On9aOvFX28VU+AWh6U6cOSQ0qz1p8zF/1ctkyTDviqYHCVrNSZD0bR kSglCw9ZTAiZDqTWuQDeR2bT1p2sK0x8Izr/MBL5SAUe0+ArFi5nbwoVsQtJv8moPj8Q lvyilJGRCT1SE6wK6ax8k9h43Ia8LsC7lvpoYdQ1bgYaXexoxFev6c/vXify4hWCXodJ qKCLJFGYksRav0GM0qi91YtYd5azH0bKo4BctVEoP3jyv/S3kYRCiBVLX8GT5rOfFS8Q 1xYA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q203si9066374pgq.384.2019.06.10.01.21.33; Mon, 10 Jun 2019 01:21:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388284AbfFJIVQ (ORCPT + 99 others); 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: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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--