Received: by 10.213.65.68 with SMTP id h4csp651368imn; Fri, 6 Apr 2018 06:47:40 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+ApnibU94D4+JR5WoSq59+S4W89Fygt0mFaASAqt9Qw3yvGs64Z81rHo8DOv7D6YzJCGs7 X-Received: by 10.99.96.79 with SMTP id u76mr17244635pgb.199.1523022460752; Fri, 06 Apr 2018 06:47:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523022460; cv=none; d=google.com; s=arc-20160816; b=0r5+Vb4QWSvWJlOgyMjhDN1zxmNY5E9OV4rJ6dmK1lJAO7KFJqkZkCYKQHTS1PtaIf r3xYMw+k8Af0a0vu2JpfwhECviAQz3zR8ZtUe1rEB2I0Lg0CD5pk7TGvF27s/gx5bEYE 6kUZ8IdEjn8nXy7VVOL/MZuoUKTWrAtpGCWKLLkPc+YdfNkFS2o3+u86HciaOZrAT0Ui /eTNu9BbSabaH6/62o85boNAu2FlMAhnzzgI1kV7cB+VhyvNAMidf71CLkeKJ7razEoP 97aTobuNqG4RZ7+/i4TtWRS/DTeRmzUSN5IZ/kPaNRXGR+uo9ga3KPtvUHca3vxpvMsr LG+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=q6kIA7RPosejz6vP+5pFwGfBXP7fPxbzJVfe4kunqYk=; b=EvKoIUaHNLUBRtRrWUw8GdW7VlrdxeZdOAoI+Pore/vCuIpcPDcxqieES7htccuR4k 3PcRbFQ3O//U0gizs79WhPer12dhawmOTbvvWhplRbRz59MEUCIDarnQA+TOSP8itN2o cehK73d0mzM+7HZ/Udoj1eWlcS6AwhVjRZvwi0EX8mNM8d1DANWqskrhTBBB3HuWR0Le T8IpoRJ0hBWl4WoyIbh8pBrGrATZF8NfoLXEbZ4f0VeYFNpfkH1S+x++fayNv+OJWx5g UfDFyrIPs2pcJ3j481qVOlYcS/UvD5I+h7cDQczEz8D0S8t0XaLhxbNxJItCDd5/O+3/ o2pw== 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 2si7892760pfk.291.2018.04.06.06.47.26; Fri, 06 Apr 2018 06:47:40 -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 S933107AbeDFNpj (ORCPT + 99 others); Fri, 6 Apr 2018 09:45:39 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:38126 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933065AbeDFNpb (ORCPT ); Fri, 6 Apr 2018 09:45:31 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 3C0C3E23; Fri, 6 Apr 2018 13:45:31 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Brad Spengler , Kees Cook Subject: [PATCH 4.16 07/31] /dev/mem: Avoid overwriting "err" in read_mem() Date: Fri, 6 Apr 2018 15:24:32 +0200 Message-Id: <20180406084342.044553170@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180406084340.999820380@linuxfoundation.org> References: <20180406084340.999820380@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kees Cook commit b5b38200ebe54879a7264cb6f33821f61c586a7e upstream. Successes in probe_kernel_read() would mask failures in copy_to_user() during read_mem(). Reported-by: Brad Spengler Fixes: 22ec1a2aea73 ("/dev/mem: Add bounce buffer for copy-out") Cc: stable@vger.kernel.org Signed-off-by: Kees Cook Signed-off-by: Greg Kroah-Hartman --- drivers/char/mem.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/char/mem.c +++ b/drivers/char/mem.c @@ -137,7 +137,7 @@ static ssize_t read_mem(struct file *fil while (count > 0) { unsigned long remaining; - int allowed; + int allowed, probe; sz = size_inside_page(p, count); @@ -160,9 +160,9 @@ static ssize_t read_mem(struct file *fil if (!ptr) goto failed; - err = probe_kernel_read(bounce, ptr, sz); + probe = probe_kernel_read(bounce, ptr, sz); unxlate_dev_mem_ptr(p, ptr); - if (err) + if (probe) goto failed; remaining = copy_to_user(buf, bounce, sz);