From patchwork Fri Dec 13 22:24:01 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 22392 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vb0-f72.google.com (mail-vb0-f72.google.com [209.85.212.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 775F423FBA for ; Fri, 13 Dec 2013 22:26:50 +0000 (UTC) Received: by mail-vb0-f72.google.com with SMTP id x8sf4314231vbf.3 for ; Fri, 13 Dec 2013 14:26:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=+hs/JnTxztHpaQNt2aPfQQNP/Ns/yumYMuypfbe0pas=; b=RZRO89mGzp2UikWCH/cEQRnplmNaroVkAi2lF9oYTTxcxCbdev1gl2pAlVD1gY4iWo D086SCSkbYzj6ZodZfscssuk9aHYgzcSO+nmqntAjq6q+akEGLDpVlBg4DUZVYmmNTsh 4M7h2ZDO+5jlhdifMzjU9BolD7xBLYPHP+REJPHELZNjYqjiRFWiKydxBisRTwtva6g9 koAR3hIbryLEOSYi2/daAlvjb9Vxa0LtzSrVgOo6nFCDtrAWp/cL+zYiXZe6suiNi9Ru 2xafb7AOK0cgSJ6VsHLf+H5p+satMWBiCCTcPweZkLXaU4WI6HbqubTWLRVVSxfuPKwz GhwQ== X-Gm-Message-State: ALoCoQnJni4gZzZKjnNgOYXYstGkZbVunTZpbt1iRPI+puK6iuTpCSwuLg/weBHWuyhJCtDmVysD X-Received: by 10.58.107.198 with SMTP id he6mr1821949veb.2.1386973610278; Fri, 13 Dec 2013 14:26:50 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.121.98 with SMTP id lj2ls1195849qeb.45.gmail; Fri, 13 Dec 2013 14:26:50 -0800 (PST) X-Received: by 10.220.159.4 with SMTP id h4mr2238220vcx.1.1386973610091; Fri, 13 Dec 2013 14:26:50 -0800 (PST) Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com [209.85.220.181]) by mx.google.com with ESMTPS id dp7si1187220ved.149.2013.12.13.14.26.50 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:26:50 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.181 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.181; Received: by mail-vc0-f181.google.com with SMTP id ks9so1714477vcb.40 for ; Fri, 13 Dec 2013 14:26:50 -0800 (PST) X-Received: by 10.52.230.102 with SMTP id sx6mr1847990vdc.15.1386973609963; Fri, 13 Dec 2013 14:26:49 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp73494vcz; Fri, 13 Dec 2013 14:26:49 -0800 (PST) X-Received: by 10.68.190.169 with SMTP id gr9mr6134819pbc.30.1386973609162; Fri, 13 Dec 2013 14:26:49 -0800 (PST) Received: from mail-pd0-f181.google.com (mail-pd0-f181.google.com [209.85.192.181]) by mx.google.com with ESMTPS id vb7si2512941pbc.92.2013.12.13.14.26.48 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:26:49 -0800 (PST) Received-SPF: neutral (google.com: 209.85.192.181 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.192.181; Received: by mail-pd0-f181.google.com with SMTP id p10so3028594pdj.12 for ; Fri, 13 Dec 2013 14:26:48 -0800 (PST) X-Received: by 10.68.231.105 with SMTP id tf9mr6145403pbc.4.1386973608741; Fri, 13 Dec 2013 14:26:48 -0800 (PST) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id qz9sm7457908pbc.3.2013.12.13.14.26.45 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:26:46 -0800 (PST) From: John Stultz To: LKML Cc: Greg KH , Android Kernel Team , Sumit Semwal , Jesse Barker , Colin Cross , Rebecca Schultz Zavin , John Stultz Subject: [PATCH 027/115] gpu: ion: Fix race between ion_import and ion_free Date: Fri, 13 Dec 2013 14:24:01 -0800 Message-Id: <1386973529-4884-28-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1386973529-4884-1-git-send-email-john.stultz@linaro.org> References: <1386973529-4884-1-git-send-email-john.stultz@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.181 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Rebecca Schultz Zavin If preemted during ion_free after the refcount is updated but before the handle can be removed from the rb_tree, import might find that handle in the tree and try to reuse it when execution returns to free, the handle will be cleaned up leaving the caller of import with a corrupt handle. This patch modifies the locking to protect agains this race. Signed-off-by: Rebecca Schultz Zavin [jstultz: modified patch to apply to staging directory] Signed-off-by: John Stultz --- drivers/staging/android/ion/ion.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index 84229bd..f7dc821 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -253,8 +253,6 @@ static void ion_handle_destroy(struct kref *kref) struct ion_client *client = handle->client; struct ion_buffer *buffer = handle->buffer; - mutex_lock(&client->lock); - mutex_lock(&buffer->lock); while (handle->kmap_cnt) ion_handle_kmap_put(handle); @@ -262,7 +260,6 @@ static void ion_handle_destroy(struct kref *kref) if (!RB_EMPTY_NODE(&handle->node)) rb_erase(&handle->node, &client->handles); - mutex_unlock(&client->lock); ion_buffer_put(buffer); kfree(handle); @@ -406,13 +403,13 @@ void ion_free(struct ion_client *client, struct ion_handle *handle) mutex_lock(&client->lock); valid_handle = ion_handle_validate(client, handle); - mutex_unlock(&client->lock); if (!valid_handle) { WARN(1, "%s: invalid handle passed to free.\n", __func__); return; } ion_handle_put(handle); + mutex_unlock(&client->lock); } EXPORT_SYMBOL(ion_free);