Received: by 10.223.185.116 with SMTP id b49csp1142089wrg; Fri, 23 Feb 2018 12:41:20 -0800 (PST) X-Google-Smtp-Source: AH8x22755oY2iuldvKiFGy9vuFxdJu2+5AxWxkVxu0/7QpvLvlQlj55YIvo/2VbR1sraUX88Njx0 X-Received: by 10.99.188.2 with SMTP id q2mr2400777pge.101.1519418480166; Fri, 23 Feb 2018 12:41:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519418480; cv=none; d=google.com; s=arc-20160816; b=oLiM6vob9MxtyPWgQXinwzAbN/w8yomV27uPk6bfKab/hYjdlzyxMF3zsroOuvCxo6 PHSsutVsapJmae6m41/zaU93foSlBGwbNCGJ9Pxrdl+rNJB55XrqwD3ZwROXg4J6SHH3 t/y2j+ylkY28YfkPlD7+NteLKRi134sdpHaIqCEbu+S1pqy9l2viLcjkABPgXIfI8X/D t8Mo4eQHDF1wE9g9ILLiGJ4yKDiPd8+ywScV6fgHv/iUgVkflXp//VSHXCfEYawiXrzC ziNSw2gHf8opntunNL7AKA4IYz9Y4V9jsbsfSAC+qZkyhIkwIvd08IoMiiICVb62eLBW vD0w== 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=7QFJC5CwjK6lNl9ZrG70BTt/kPWp8vmFgySjf4DLX90=; b=jUC5zwxx5PWiG8Dzyu+GJ2UBlPTvLpoJNzXFbgKR5UcZGYD8pbiXJBWGVOd5bVt+HJ oKaTEZodttFllSaZGc4yeFQ3u48J4DX4IE0Kjvqrw47ODU+e7ifGZJ9fx2GtPaKIehWq Sg0Em+3ASCE8sqtfX5VNiX+XYBLoycKKWZq5PnEhw6PIwiWO5v3z6+jE8e/VOVdxSdTS V9rR0NxeC+bUHF/of8N3yzcxWG5kRoIolmaKSM8JWXevkvS9ThGON+0JN8odo5GsiQEB 98bATxyxHfhZbv+N+bYVm8A38QLlBix6Ak4hNe0YoaxmVhg3mEuewLqN/ej3iWGhZ7yG O6CQ== 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 g207si2329145pfb.320.2018.02.23.12.41.05; Fri, 23 Feb 2018 12:41:20 -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 S1753345AbeBWSdr (ORCPT + 99 others); Fri, 23 Feb 2018 13:33:47 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:36658 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753321AbeBWSdp (ORCPT ); Fri, 23 Feb 2018 13:33:45 -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 4B7DC1164; Fri, 23 Feb 2018 18:33:44 +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.4 026/193] staging: android: ashmem: Fix a race condition in pin ioctls Date: Fri, 23 Feb 2018 19:24:19 +0100 Message-Id: <20180223170330.172960669@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170325.997716448@linuxfoundation.org> References: <20180223170325.997716448@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: 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 @@ -704,30 +704,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); @@ -740,6 +742,7 @@ static int ashmem_pin_unpin(struct ashme break; } +out_unlock: mutex_unlock(&ashmem_mutex); return ret;