Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4100376imm; Mon, 17 Sep 2018 08:11:49 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYqlVu6EZqSRVy4ra4QQeyUAdn6X021/BV8Ge5cMW7kNOCRjzjkGA0zN90ZYbX2Q2devGBt X-Received: by 2002:a63:344b:: with SMTP id b72-v6mr23918846pga.184.1537197109705; Mon, 17 Sep 2018 08:11:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537197109; cv=none; d=google.com; s=arc-20160816; b=yPtpCoJlZmRlFFT4p8/zXYUlWR7YCE+wK/SBrNjJThwocBplYHyD1V59OKuJlw2z9o ou1pVyy6Rzu1QWSGzCO4dbOe0QYYPj9m+23J3mA9hC2L3D8+2xeW1ey2YocKZ4iVBUzB sWZdGPv/1D+LC1ZfeWd/AvUw9Wk0McBjisGI8QjOx/TMCvYs8nvLgPAIesxAnOtNa1zM GzJaUFYcxdGuSIsXGIVsHnMn4wKqtLkwKhKPM3eWLK+hbInkGDo+zgOjKGys8lad50RA NFVv6RW+y9DbKQoKJK/tpTThUqSyr4SaZId6J7DuyhUs/8oNY6VTAnV2BjeeZ8jpAgt9 Oz7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:cms-type:message-id :in-reply-to:date:subject:cc:to:from:dkim-signature:dkim-filter; bh=g3RorNLxXU6pHJrFDZvhtON4nN0xcIymWtdQdIQNHtM=; b=BhUNjzUvYmzFlcwx7FwR/bCxkNITOfDvUqF+H9yDdiQxW11MDY/pE/L+NT7HBFPYYj NIqJ3uRannIb+7S14dUfPxkMlNUorY7M923/thM0zDEqKZc2bMeTFOTS3KxWmTs5Joao ZTOJ+B3453aZWpIowMvgnymQGRKShaT8FMfpIlWzOvJs3dqKId57K/ZG47lJic/jB5Ru RBfNimQ8yEd6nsKq1NfrChq+nWxxr+3LJUktfWj5cdI62qAjJ9J4J+jTpiW0eeUQyWd4 GUvSqg8Zn9ZunBar6jfqRfQz7gVB6W3G0ba9c4ikzC4GO/jHAgLsM4FH7azrhNtaJA/p xusw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=LfU6q1m8; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 64-v6si16093139ply.375.2018.09.17.08.11.34; Mon, 17 Sep 2018 08:11:49 -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=@samsung.com header.s=mail20170921 header.b=LfU6q1m8; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729285AbeIQUhz (ORCPT + 99 others); Mon, 17 Sep 2018 16:37:55 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:54816 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729265AbeIQUhy (ORCPT ); Mon, 17 Sep 2018 16:37:54 -0400 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20180917151008euoutp013e99fd33db2e89b106c9ca3ca77435e8~VOIjMZOQb2472624726euoutp01A for ; Mon, 17 Sep 2018 15:10:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20180917151008euoutp013e99fd33db2e89b106c9ca3ca77435e8~VOIjMZOQb2472624726euoutp01A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1537197008; bh=g3RorNLxXU6pHJrFDZvhtON4nN0xcIymWtdQdIQNHtM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LfU6q1m8ILD6JS3GimkhYqeAPlGarZgvKs6Y1QavX9haf57fUGfAvh2RJPOvGq/eW 3lM9OhcgB6wbF16TynS1TiUx4vI87Y4C0aKPoSGNBhW1SRYVRJffI4d2MiHwc0bbL1 NHdguwvjXd3THnbcxhl55mHe9vqdC0x3SLAAbHto= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20180917151007eucas1p287db2d512a0af558d21176cce16a182b~VOIiQnvyT1112911129eucas1p2r; Mon, 17 Sep 2018 15:10:07 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 78.F7.04806.EC3CF9B5; Mon, 17 Sep 2018 16:10:06 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20180917151006eucas1p2226806b94605b061bc1bc3e9b5a6c495~VOIhXssSK0729007290eucas1p25; Mon, 17 Sep 2018 15:10:06 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20180917151005eusmtrp18cc33922795db87af587619b1d8acd70~VOIhFdGj03069130691eusmtrp1q; Mon, 17 Sep 2018 15:10:05 +0000 (GMT) X-AuditID: cbfec7f5-79db79c0000012c6-ba-5b9fc3ce4acc Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 41.48.04284.DC3CF9B5; Mon, 17 Sep 2018 16:10:05 +0100 (BST) Received: from AMDC2034.DIGITAL.local (unknown [106.120.51.41]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20180917151005eusmtip2bd2888d07a6fb2b4fe73e5decabd865e~VOIglyGLT2368423684eusmtip29; Mon, 17 Sep 2018 15:10:05 +0000 (GMT) From: Christoph Manszewski To: linux-crypto@vger.kernel.org Cc: Christoph Manszewski , Krzysztof Kozlowski , Vladimir Zapolskiy , Kamil Konieczny , Herbert Xu , "David S. Miller" , linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Bartlomiej Zolnierkiewicz Subject: [PATCH v2 1/4] crypto: s5p-sss: Fix race in error handling Date: Mon, 17 Sep 2018 17:09:27 +0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1537196970-5987-1-git-send-email-c.manszewski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprAKsWRmVeSWpSXmKPExsWy7djP87rnDs+PNrj4Uc1i44z1rBbHdy9l tJhzvoXFovuVjEXfvv+MFufPb2C3uH/vJ5PF5V1z2CxmnN/HZPH/VzOzA5fHlpU3mTy2HVD1 2LSqk83j38IpLB4H3+1h8ujbsorR4/MmuQD2KC6blNSczLLUIn27BK6Ml89mMRWcEa743fef pYFxlUAXIyeHhICJxL+uiaxdjFwcQgIrGCWmvf/LDuF8YZR42nuZBcL5zCixZsUsVpiWX7f2 MkEkljNKHN72gA2uZf+XpywgVWwCphK3734CSnBwiAgoSMz7qgMSZhZoYZb4tZoTJCws4Czx eb4jSJhFQFXi3fonjBDz5SRunutkBrE5BTwk3v+ZBXaRhEA/u0TL1VfsIAlegTKJvcvaWUDm SAi4SPz6LwLRKyzx6vgWdghbRuL05B4WiN5mRolbX66xQjgTGCUOru5igaiylth04xUTyCBm AU2J9bv0IWY6SlxproAw+SRuvBWEuJ5PYtK26cwQYV6JjjYhiBlqEq+3bGGD2fri81eoTzwk jp9oggbhbEaJdfOOsk9glJ+FsGsBI+MqRvHU0uLc9NRi47zUcr3ixNzi0rx0veT83E2MwHRy +t/xrzsY9/1JOsQowMGoxM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8S+EzSO+Ud Flyaw1/9VsFz/VXND5kpyxIOb/F5bV6ntvSznBJLcUaioRZzUXEiAJz1/iaGAgAA Message-Id: <20180917151006eucas1p2226806b94605b061bc1bc3e9b5a6c495~VOIhXssSK0729007290eucas1p25@eucas1p2.samsung.com> X-CMS-MailID: 20180917151006eucas1p2226806b94605b061bc1bc3e9b5a6c495 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20180917151006eucas1p2226806b94605b061bc1bc3e9b5a6c495 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180917151006eucas1p2226806b94605b061bc1bc3e9b5a6c495 References: <1537196970-5987-1-git-send-email-c.manszewski@samsung.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Remove a race condition introduced by error path in functions: s5p_aes_interrupt and s5p_aes_crypt_start. Setting the busy field of struct s5p_aes_dev to false made it possible for s5p_tasklet_cb to change the req field, before s5p_aes_complete was called. Change the first parameter of s5p_aes_complete to struct ablkcipher_request. Before spin_unlock, make a copy of the currently handled request, to ensure s5p_aes_complete function call with the correct request. Signed-off-by: Christoph Manszewski --- drivers/crypto/s5p-sss.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/crypto/s5p-sss.c b/drivers/crypto/s5p-sss.c index faa282074e5a..9021ad9df0c4 100644 --- a/drivers/crypto/s5p-sss.c +++ b/drivers/crypto/s5p-sss.c @@ -475,9 +475,9 @@ static void s5p_sg_done(struct s5p_aes_dev *dev) } /* Calls the completion. Cannot be called with dev->lock hold. */ -static void s5p_aes_complete(struct s5p_aes_dev *dev, int err) +static void s5p_aes_complete(struct ablkcipher_request *req, int err) { - dev->req->base.complete(&dev->req->base, err); + req->base.complete(&req->base, err); } static void s5p_unset_outdata(struct s5p_aes_dev *dev) @@ -655,6 +655,7 @@ static irqreturn_t s5p_aes_interrupt(int irq, void *dev_id) { struct platform_device *pdev = dev_id; struct s5p_aes_dev *dev = platform_get_drvdata(pdev); + struct ablkcipher_request *req; int err_dma_tx = 0; int err_dma_rx = 0; int err_dma_hx = 0; @@ -727,7 +728,7 @@ static irqreturn_t s5p_aes_interrupt(int irq, void *dev_id) spin_unlock_irqrestore(&dev->lock, flags); - s5p_aes_complete(dev, 0); + s5p_aes_complete(dev->req, 0); /* Device is still busy */ tasklet_schedule(&dev->tasklet); } else { @@ -752,11 +753,12 @@ static irqreturn_t s5p_aes_interrupt(int irq, void *dev_id) error: s5p_sg_done(dev); dev->busy = false; + req = dev->req; if (err_dma_hx == 1) s5p_set_dma_hashdata(dev, dev->hash_sg_iter); spin_unlock_irqrestore(&dev->lock, flags); - s5p_aes_complete(dev, err); + s5p_aes_complete(req, err); hash_irq_end: /* @@ -1983,7 +1985,7 @@ static void s5p_aes_crypt_start(struct s5p_aes_dev *dev, unsigned long mode) s5p_sg_done(dev); dev->busy = false; spin_unlock_irqrestore(&dev->lock, flags); - s5p_aes_complete(dev, err); + s5p_aes_complete(req, err); } static void s5p_tasklet_cb(unsigned long data) -- 2.7.4