Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp806992imm; Mon, 21 May 2018 14:52:20 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrP6jdq5OtypyhCiaIeq4cdSxhsJLL55yKK5MGs/TvOL/d7h/8WMpAiSUjp8c/vK+eBN216 X-Received: by 2002:a17:902:2826:: with SMTP id e35-v6mr32618plb.348.1526939539955; Mon, 21 May 2018 14:52:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526939539; cv=none; d=google.com; s=arc-20160816; b=tuOVO8ux2v5WmMKj4lfsrG46GtOrJb2GGAKNK5GDVcQYfOXq5VP5a7OVK8tcz28Hpf laCnXACESduM8BO4+FRBaaioeiJ6nYSK7hcgqZDr2dI2pV0RbpMmQlvFzxRym5mdF+0b /tr3Mx8alsJpHO3NDTRHJxGZ5BjRtR/ehFu+pJ/RaAIRNAoPMh0NBJ+rHZnoe6IlsKOP gGnEbKGVmFzLNhI8sRkMsQWg2aMqddIf9D/7njqLSjzsuEFxQvsEK1NeGSD61VtLB+kg 6cxyuACviMTAmWM0ZPqNFMCV2P9tuIdscOT73MJmpu7GnUQ1B/Ju/HszP0r13yrOaly9 xNgg== 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=PvLBWf0xdKI2JohKWJZgTukFy14ovpJT7RXSIPzd2Vc=; b=ympOkipIoC2+oKjZhJpjvVtFuzxi9r4Gb+kxpZYXRkbkqg1hG0wkqij7/qXwcWCDnX UzaoBaje/ZiQz5FCqAT0VxamOYaINEP7C4BhV0gZZHoh502a37SuxNOrHanqrcb6nZAX TamP5sRJ6cFsty12K9KeZVwteRORYhKTGmHHxrAiX/0JEaV/+kCdVYaIa7rgjkEYV4CH L8MmP2vau65491oJPo3AX9SJ6FNOCALuahry8CD+j+VdSqeyAdrIsG5S3efbX/mSluzt gPrXvoFtDQHkbnmZKfQndVVB2BaDgIMKxTvzdCiu2dGhVK4nXMgsnuipBa3ZlpmhZMpB xTmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0+NcutDf; 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 v2-v6si2640457plo.577.2018.05.21.14.52.05; Mon, 21 May 2018 14:52:19 -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=0+NcutDf; 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 S932204AbeEUVuL (ORCPT + 99 others); Mon, 21 May 2018 17:50:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:37982 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932112AbeEUVXH (ORCPT ); Mon, 21 May 2018 17:23:07 -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 46C8C20871; Mon, 21 May 2018 21:23:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1526937786; bh=e7sgR7VUopDeMn1vY7FxWuX2elbctlEHhoN52YyK03U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0+NcutDfd7XxvTE9dXmIqMw1h/H65WwDPb0TmkLoBHKHZsjneCqekq43p0gGKOiq9 L5K+B5XSY7aZxGP/nyXypBM03FTdlLoPYQwq1Dpg7zqkeYCQZShWQPqqcDtUhPMP8J 1O7gHtWyuiapp/QRi6CCQT581Q5MLuvtmwe+uhIE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jann Horn , Jens Wiklander Subject: [PATCH 4.16 025/110] tee: shm: fix use-after-free via temporarily dropped reference Date: Mon, 21 May 2018 23:11:22 +0200 Message-Id: <20180521210506.066487309@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180521210503.823249477@linuxfoundation.org> References: <20180521210503.823249477@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.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jann Horn commit bb765d1c331f62b59049d35607ed2e365802bef9 upstream. Bump the file's refcount before moving the reference into the fd table, not afterwards. The old code could drop the file's refcount to zero for a short moment before calling get_file() via get_dma_buf(). This code can only be triggered on ARM systems that use Linaro's OP-TEE. Fixes: 967c9cca2cc5 ("tee: generic TEE subsystem") Signed-off-by: Jann Horn Signed-off-by: Jens Wiklander Signed-off-by: Greg Kroah-Hartman --- drivers/tee/tee_shm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/drivers/tee/tee_shm.c +++ b/drivers/tee/tee_shm.c @@ -360,9 +360,10 @@ int tee_shm_get_fd(struct tee_shm *shm) if (!(shm->flags & TEE_SHM_DMA_BUF)) return -EINVAL; + get_dma_buf(shm->dmabuf); fd = dma_buf_fd(shm->dmabuf, O_CLOEXEC); - if (fd >= 0) - get_dma_buf(shm->dmabuf); + if (fd < 0) + dma_buf_put(shm->dmabuf); return fd; }