Received: by 10.223.185.116 with SMTP id b49csp1104631wrg; Fri, 23 Feb 2018 12:01:45 -0800 (PST) X-Google-Smtp-Source: AH8x225l158FCXGleBESkNmdHnLTLoJ1AaZRTIbI8c1yrOL70vuBZeq8vq5AapXaJcqmxSgRN4uG X-Received: by 2002:a17:902:501:: with SMTP id 1-v6mr2718185plf.283.1519416105856; Fri, 23 Feb 2018 12:01:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519416105; cv=none; d=google.com; s=arc-20160816; b=KRj0eNinPGBB1B8Jpy/YxMuRn0cRHyqymjHmWwOMwIuBr+oYTOU2FCcHgFfdgDXyN1 9VwuUIzwIpO77wa2xFQ9+MvdDHaK0mbWJ6rUYrdwE4bJVxWuL/rCQAulFrLihes3HCWf foOrZ1/9bO1lLphqpSRD7O3qAUp41Qlt3dqHvdejSKK2rsAUvsmy+L9JC0/vqpTlI+MB jPIEt2ddHynTFXPLTdEmfTmnjB8M8jwrfvpm2TfJ5h6B5MOV+pg8QwtKx3dF+syXAjVt s4HuZlYjOwZQX+MtvqwZFb2ACPa8OZWGx3ZtOahZAmHxpXu6zVyRQNT8uTjM49xnDig6 6wCw== 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=4nuGZZ3Rw9BAqghrK3cDjXZvyUu1kPumnq3JXjqhf2I=; b=UNP7vW1Ly8dvrCEEgiXGXY8AthWmhqJjs6l6qjqIeZfsuXZzMG5klGRFGf33j3fabc AqMQIcrWQ5ac3HzrQKLaYhP906VllJ+lb106K/lzY2oIMIj686glP9YOK23NYWUDqPr3 e9qaoJB8WQadf7Ue2mkTidqugNCYbttdxncr4SkqBGLXqziVbMv+51qjdhjVciCbtOcV xhxkEJKIxNMPX3i9KjBkzcUj1YBkvi3gETaMrRpJ0StAkf8RxK8WIdcu6dLAjoHBSzh8 yKq75B1EEQm5y+30OxTfBSu9bN6Tz+NsWbNePcx+Lcc2Uw93j8cTStJhxb3jHStIjvMn r++Q== 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 z16-v6si1201386plo.171.2018.02.23.12.01.29; Fri, 23 Feb 2018 12:01:45 -0800 (PST) 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 S1754954AbeBWT7z (ORCPT + 99 others); Fri, 23 Feb 2018 14:59:55 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:42336 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933386AbeBWSnq (ORCPT ); Fri, 23 Feb 2018 13:43:46 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 0C96010BE; Fri, 23 Feb 2018 18:43:45 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ben Hutchings Subject: [PATCH 4.9 037/145] staging: android: ashmem: Fix a race condition in pin ioctls Date: Fri, 23 Feb 2018 19:25:43 +0100 Message-Id: <20180223170729.749650378@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170724.669759283@linuxfoundation.org> References: <20180223170724.669759283@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.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ben Hutchings commit ce8a3a9e76d0193e2e8d74a06d275b3c324ca652 upstream. ashmem_pin_unpin() reads asma->file and asma->size before taking the ashmem_mutex, so it can race with other operations that modify them. Build-tested only. Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- drivers/staging/android/ashmem.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) --- a/drivers/staging/android/ashmem.c +++ b/drivers/staging/android/ashmem.c @@ -719,30 +719,32 @@ static int ashmem_pin_unpin(struct ashme size_t pgstart, pgend; int ret = -EINVAL; + mutex_lock(&ashmem_mutex); + if (unlikely(!asma->file)) - return -EINVAL; + goto out_unlock; - if (unlikely(copy_from_user(&pin, p, sizeof(pin)))) - return -EFAULT; + if (unlikely(copy_from_user(&pin, p, sizeof(pin)))) { + ret = -EFAULT; + goto out_unlock; + } /* per custom, you can pass zero for len to mean "everything onward" */ if (!pin.len) pin.len = PAGE_ALIGN(asma->size) - pin.offset; if (unlikely((pin.offset | pin.len) & ~PAGE_MASK)) - return -EINVAL; + goto out_unlock; if (unlikely(((__u32)-1) - pin.offset < pin.len)) - return -EINVAL; + goto out_unlock; if (unlikely(PAGE_ALIGN(asma->size) < pin.offset + pin.len)) - return -EINVAL; + goto out_unlock; pgstart = pin.offset / PAGE_SIZE; pgend = pgstart + (pin.len / PAGE_SIZE) - 1; - mutex_lock(&ashmem_mutex); - switch (cmd) { case ASHMEM_PIN: ret = ashmem_pin(asma, pgstart, pgend); @@ -755,6 +757,7 @@ static int ashmem_pin_unpin(struct ashme break; } +out_unlock: mutex_unlock(&ashmem_mutex); return ret;