Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2042372imm; Thu, 24 May 2018 05:01:00 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpD5I08gihts70WpclYUEqQFMCc0HsgZkZWHcN2DxiKTapzUDJnS1fsvm+ZkZKM11YwdwUV X-Received: by 2002:a63:7553:: with SMTP id f19-v6mr1998564pgn.314.1527163260524; Thu, 24 May 2018 05:01:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527163260; cv=none; d=google.com; s=arc-20160816; b=ocyDkpkYD0fQ5PP1JdUNuD0LnNWT/z23KtntR2oDIIiqan3QkNg09BFjmwYWxq3LTy OZZv2fYtkifyURKj2v86pYqCLZ49SYBs+PbLCc05dBSQP+EjdCmTr0xcZVTBcf3ahNvA GiUI6X3o4JEkv11pBZArbFKwX6gPlVj6QlPF3EYTUEyA6A+s4VppXdgl3iFslI/2N1BD 4cpuyNHCxpyr41134lHqZQim44Tkdl3QHS50mCkFX1Rr9snoQ+r4kqGJElp7I8eJR7Ia /nKvuuiRTVgDMi9Ts6B3+Q60I0QipfIrowE4XdToxSU8qllCky4Y1PeooJHyKZ5iemRH 63tw== 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:dkim-signature :arc-authentication-results; bh=H0KecsFixEuuy8g66jq7ky7CWSNoP4uTtGWGmpPoeJU=; b=dtKmIvbUsXcmiTF8bdTkr1SXT0+nZ2Cy1cN9CtZ6QsEgiwoTIoKEEZA+GDghHmoj/G jUISrv9fFQffVVyyjETW7sdHhzReD+wUMemv1xUdRe6Vrh8ygzKrD7KGiqLkbutF/XwB Wbp7kALyfsYszuP8laKr/mfgUaiYmNvNoU2vtBch8Oqrq9sRVF6okGF8CJOQyzIblit5 +49XFE7x9vL6h5/2KIyXAGGlaztoaYCBmEhOruUunJLFU2OkEJMIoiD944rLAhsL1+9V EoBhPkgW06GiIycZFVcxs4PBhMoVwHCTYdMfDSviwfMuv1ZrGJFy9ZG25G82aPzeMjxm TM+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=t0kp39hI; 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 v15-v6si16654421pgq.292.2018.05.24.05.00.45; Thu, 24 May 2018 05:01:00 -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; dkim=pass header.i=@kernel.org header.s=default header.b=t0kp39hI; 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 S966738AbeEXJpI (ORCPT + 99 others); Thu, 24 May 2018 05:45:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:56130 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966727AbeEXJo5 (ORCPT ); Thu, 24 May 2018 05:44:57 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 067E5208C3; Thu, 24 May 2018 09:44:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155096; bh=eXTAnYqzmDiH8rzVkECqaeJEMs1nMXSmHtXBEXLVPCE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t0kp39hITI6XE6mBstRgfQALzXX8PwNrYDhvlV3WFEiRZHPDt7w4XqbZrufblgqPl eEdCmuueXm/G1FZBjS2OElpGFFOxxQyCwqdUdRrF/dcSoyUxb0zJwI63IseaXE/0np R4uX6sTX4dKTv3N/uA7TcCZMcJNXdDVKpfNsOrLU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mateusz Guzik , Cyrill Gorcunov , Alexey Dobriyan , Jarod Wilson , Jan Stancek , Al Viro , Anshuman Khandual , Andrew Morton , Linus Torvalds Subject: [PATCH 4.4 54/92] proc read mms {arg,env}_{start,end} with mmap semaphore taken. Date: Thu, 24 May 2018 11:38:31 +0200 Message-Id: <20180524093204.534521242@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093159.286472249@linuxfoundation.org> References: <20180524093159.286472249@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.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mateusz Guzik commit a3b609ef9f8b1dbfe97034ccad6cd3fe71fbe7ab upstream. Only functions doing more than one read are modified. Consumeres happened to deal with possibly changing data, but it does not seem like a good thing to rely on. Signed-off-by: Mateusz Guzik Acked-by: Cyrill Gorcunov Cc: Alexey Dobriyan Cc: Jarod Wilson Cc: Jan Stancek Cc: Al Viro Cc: Anshuman Khandual Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/proc/base.c | 13 ++++++++++--- mm/util.c | 16 ++++++++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -953,6 +953,7 @@ static ssize_t environ_read(struct file unsigned long src = *ppos; int ret = 0; struct mm_struct *mm = file->private_data; + unsigned long env_start, env_end; /* Ensure the process spawned far enough to have an environment. */ if (!mm || !mm->env_end) @@ -965,19 +966,25 @@ static ssize_t environ_read(struct file ret = 0; if (!atomic_inc_not_zero(&mm->mm_users)) goto free; + + down_read(&mm->mmap_sem); + env_start = mm->env_start; + env_end = mm->env_end; + up_read(&mm->mmap_sem); + while (count > 0) { size_t this_len, max_len; int retval; - if (src >= (mm->env_end - mm->env_start)) + if (src >= (env_end - env_start)) break; - this_len = mm->env_end - (mm->env_start + src); + this_len = env_end - (env_start + src); max_len = min_t(size_t, PAGE_SIZE, count); this_len = min(max_len, this_len); - retval = access_remote_vm(mm, (mm->env_start + src), + retval = access_remote_vm(mm, (env_start + src), page, this_len, 0); if (retval <= 0) { --- a/mm/util.c +++ b/mm/util.c @@ -428,17 +428,25 @@ int get_cmdline(struct task_struct *task int res = 0; unsigned int len; struct mm_struct *mm = get_task_mm(task); + unsigned long arg_start, arg_end, env_start, env_end; if (!mm) goto out; if (!mm->arg_end) goto out_mm; /* Shh! No looking before we're done */ - len = mm->arg_end - mm->arg_start; + down_read(&mm->mmap_sem); + arg_start = mm->arg_start; + arg_end = mm->arg_end; + env_start = mm->env_start; + env_end = mm->env_end; + up_read(&mm->mmap_sem); + + len = arg_end - arg_start; if (len > buflen) len = buflen; - res = access_process_vm(task, mm->arg_start, buffer, len, 0); + res = access_process_vm(task, arg_start, buffer, len, 0); /* * If the nul at the end of args has been overwritten, then @@ -449,10 +457,10 @@ int get_cmdline(struct task_struct *task if (len < res) { res = len; } else { - len = mm->env_end - mm->env_start; + len = env_end - env_start; if (len > buflen - res) len = buflen - res; - res += access_process_vm(task, mm->env_start, + res += access_process_vm(task, env_start, buffer+res, len, 0); res = strnlen(buffer, res); }