Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2964512ybi; Mon, 10 Jun 2019 01:43:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqw0kQeR8c92Wqda7tjS8HIVhhLcMOus/P6dFmvUtFkb3wPnnoUQ8VYnUmmMD7/H1z2aFMpT X-Received: by 2002:a17:902:d717:: with SMTP id w23mr26240021ply.275.1560156185665; Mon, 10 Jun 2019 01:43:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560156185; cv=none; d=google.com; s=arc-20160816; b=cWT0GXoDAWOLmRV/WlkpD0bj4r7UvqHDOrpz71aRZVt4vfhYaoERSdG58Cx96I6O30 ozwS1X5TxE5khozrCbrlWOmiNgJSfoScREP4YbjRCuCQUXSfhbznmojDTuUekMD+pUuX rZtROdL8WZmmHjrqdl/zMCbld42TR3LdkuHyhgJMzJKW+O05QT6KVfbGU+mUFqvWJvuO FlW8CoOhfg7hvDUlRdJS0LOQVGyvljUCEqzCqok5aRa4uPsV5J5SPqQfcTZWcxvGfTF3 ikxh63G9nHDDwK/Ad//5yeYe5XEB73mO67q21xrVEKDmJhVnurR3xkMTA8gzz7P90680 APUg== 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=iA8Rl673GrNkKfJvf1rC0S82X4LuUaHgoMdijVpMlNU=; b=AsiMEZPulVFHxP6FrBX4IjbAOJGdrFHzuejQB7tbDqnrQ4decAbnpITKzGgZF4JLxT 43PB8ol9PaRqCnOeoFaxQtlb8lhW9y9p7SUYsavGDReJaqVuXtVYbM4oii0hvFqnZwk2 ipWYCE8rDr41J0mqr5DqMqHrcq2+ZNYMCUb59wwOBAT+DpHAH80BPBJJjImVi+k3IH+D z9MGNkg666JyOvDtbxjFOlge0H6JIM8iy6+ulOkvd/DBESBHNip2benL/RP3vspSWcrQ p0k9w70Fo36phxalurLJTFWtfie39kBA6rQeUVZL+iJZPf20vNr8VW1op3Oe45qaBLIg hpWA== 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 d1si131576pjs.107.2019.06.10.01.42.50; Mon, 10 Jun 2019 01:43:05 -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 S2388616AbfFJImd (ORCPT + 99 others); Mon, 10 Jun 2019 04:42:33 -0400 Received: from mx2.suse.de ([195.135.220.15]:40860 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388267AbfFJImb (ORCPT ); Mon, 10 Jun 2019 04:42:31 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 97B14AF6A; Mon, 10 Jun 2019 08:42:30 +0000 (UTC) Received: by unicorn.suse.cz (Postfix, from userid 1000) id E447EE00E3; Mon, 10 Jun 2019 10:42:29 +0200 (CEST) Date: Mon, 10 Jun 2019 10:42:29 +0200 From: Michal Kubecek To: stable@vger.kernel.org Cc: Pavel Machek , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Vivien Didelot , "David S. Miller" Subject: Re: [PATCH 4.19 01/51] ethtool: fix potential userspace buffer overflow Message-ID: <20190610084229.GA31797@unicorn.suse.cz> References: <20190609164127.123076536@linuxfoundation.org> <20190609164127.215699992@linuxfoundation.org> <20190610082112.GA8783@amd> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190610082112.GA8783@amd> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 10, 2019 at 10:21:12AM +0200, Pavel Machek wrote: > Hi! > > > From: Vivien Didelot > > > > [ Upstream commit 0ee4e76937d69128a6a66861ba393ebdc2ffc8a2 ] > > > > 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. > > > > 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(). > > > > 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. > > > > 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(). > > > > 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. Right. :-( I guess we should also pick commit f9fc54d313fa ("ethtool: check the return value of get_regs_len") to stable branches before 5.0. Michal