Received: by 10.223.185.116 with SMTP id b49csp1050313wrg; Fri, 23 Feb 2018 11:01:05 -0800 (PST) X-Google-Smtp-Source: AH8x224l+bsfiAgK3dmf92H/upPaplyuGQBBhdgsLUDKPrn9ka2rjjteKtrfs4zk3SLXlaVjFkrQ X-Received: by 10.101.81.12 with SMTP id f12mr2141511pgq.81.1519412465658; Fri, 23 Feb 2018 11:01:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519412465; cv=none; d=google.com; s=arc-20160816; b=sj7liLnSy3YgX7+OTm3kKaVick8yMUahzefJtmzu0B09yYvMOXooITGICPkyoXh0pr poeH3oAnQiIqL98hNaAmUlt+eNGW01021vIhfC73h3ldFzrQLoAIO+wZyqZegeK4g5JR p04VeTwtBtUU/CZCLhllUuFM/cTyaBc/tgjraMbrcV1LD2HYu3g3Mt5EPBXlEdR+cERi UfDf76iq0h21LEoJH0ri6wAyawyC7M1DIq6Z6PU7gOgcneQhD8+DZgTBUaG4YtujIycS G6HhEqYo/tu0ujyItzAd0kXoi0cHM+aoWf8mLw2os3unoZHrsMB2W+o1exFG49ttoy2v TzrA== 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=lDaRuFkwj2F6fnlqI8GKynvYbKS48Xsf9nLYghshU+0=; b=VDuz/UPSmXonNe9rZdszV+fHqhBakLP5arRjyZENYhWV1gZGBkO+iNz3o8K2aPQqUo hjmnzVsZYGJdqh93GcjgUA22P26C3yJKU90vATyTwR31Q5mVto9jDKr2ktoJkRHHqLSt 1A26JxC3LPISNzUJTB9I2KGYA4kaHzJMEEVp5fNEK1eLcWliKClWmpiTCwBrdX20wUZj oTJL+he4Rn8Cz74mjBpJRUJxeyUqaYaBexfNMUB3XGJnsc1f8oxWxCImw8Q2/4bh2g1C K08ZS9Wr6NqVVR2ZaHz4hLeddop/ozg9v4iHoBe+EvZcT3D9BE9UMbcQtIJ3xhfEyKIW PZXA== 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 bg3-v6si2134883plb.28.2018.02.23.11.00.51; Fri, 23 Feb 2018 11:01:05 -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 S935704AbeBWS7P (ORCPT + 99 others); Fri, 23 Feb 2018 13:59:15 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:50832 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935690AbeBWS7N (ORCPT ); Fri, 23 Feb 2018 13:59:13 -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 501F911AC; Fri, 23 Feb 2018 18:59:12 +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.15 31/45] staging: android: ashmem: Fix a race condition in pin ioctls Date: Fri, 23 Feb 2018 19:29:10 +0100 Message-Id: <20180223170720.230960956@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170715.197760019@linuxfoundation.org> References: <20180223170715.197760019@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: 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 @@ -710,30 +710,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); @@ -746,6 +748,7 @@ static int ashmem_pin_unpin(struct ashme break; } +out_unlock: mutex_unlock(&ashmem_mutex); return ret;