Received: by 10.213.65.68 with SMTP id h4csp647891imn; Fri, 6 Apr 2018 06:44:09 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/ruBkUYvxwYTmriRSU8XeBYsOzkc05fbxAGqI3Yq7tacY8PyGg+Gwvno+KKGVFTJCkOn4q X-Received: by 2002:a17:902:9349:: with SMTP id g9-v6mr27004116plp.243.1523022249772; Fri, 06 Apr 2018 06:44:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523022249; cv=none; d=google.com; s=arc-20160816; b=Nr07B9T1czF9FjFYEbmi2h1P2rTVxhzsooIYLFm6X63lG//w+IPZTR/d842H2/f0Y9 27eeHJGvzlbuwf1BulQ4qp5nRQnkJKoNUYMZRhGu3aJTuk2M2+FLKotZkUR5zoLgaer8 UnjuZgh6pn4DWuQAldV/I8KwO4guFFIujzTA2F9+1t6NpPHvj4ierRLWKIuovsWgiZ0l vT15MZE0AeOtFnb5KLGxNYkK2RLzgZHYP/13GeOEe0IVgmVOOVCZResrU9wk43xBTlgl ZOFzbcQyxu1+ORfnlcEyP/8anwvp28Uvu7B/4y8kql3nFM1A5W7NK+j0LeuoE2pCfatU UIBQ== 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=XpDSt3CbGPInFfScktXiOSHqNzqYejyq+MJzJLisuBs=; b=AbsAZZ7dapNd2M7/SISKyEHVxQgk8l24NAyg02GHq9ogcj/75uHwsYpLKbVqb5+HYv AtwvPB0Q6Pvw+NsCUzgTU99JckHuO6fxXFioTYYqZcTNZ6TABgjJraEVDChnFLhI1gUR w1QyWX4wJcz/ghJcn0mcpo2E997sM+i85HHmXSAxNq9Tg6mqYkExD2BKt1LVzq2sR1pR 84KvFs8EeOtpQZ9FiRmJWEn0yZbmAWkSBy2D/AUmecsysUuJ6q830PCDKLykczaCDyN0 rjkriWUqs77JHlEnEPBzBKbPv/3ZxeSTcIbVefGEQHvVOK1RBV6zHEc7Bzuo1+W+DsFH d4mQ== 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 p68si7138290pga.751.2018.04.06.06.43.55; Fri, 06 Apr 2018 06:44:09 -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 S1756622AbeDFNmj (ORCPT + 99 others); Fri, 6 Apr 2018 09:42:39 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:37046 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756594AbeDFNmg (ORCPT ); Fri, 6 Apr 2018 09:42:36 -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 66020DB5; Fri, 6 Apr 2018 13:42:35 +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.15 46/72] /dev/mem: Avoid overwriting "err" in read_mem() Date: Fri, 6 Apr 2018 15:24:21 +0200 Message-Id: <20180406084352.803320780@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180406084349.367583460@linuxfoundation.org> References: <20180406084349.367583460@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.15-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);