Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753982AbcDSNoc (ORCPT ); Tue, 19 Apr 2016 09:44:32 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:21054 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752545AbcDSNoa (ORCPT ); Tue, 19 Apr 2016 09:44:30 -0400 X-AuditID: cbfec7f4-f796c6d000001486-7e-5716363a7b21 From: Krzysztof Kozlowski To: Herbert Xu , "David S. Miller" , Krzysztof Kozlowski , Vladimir Zapolskiy , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org Cc: Bartlomiej Zolnierkiewicz Subject: [PATCH 1/2] crypto: s5p-sss - Fix use after free of copied input buffer in error path Date: Tue, 19 Apr 2016 15:44:11 +0200 Message-id: <1461073452-10426-1-git-send-email-k.kozlowski@samsung.com> X-Mailer: git-send-email 1.9.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrLJMWRmVeSWpSXmKPExsVy+t/xK7pWZmLhBjf+a1psnLGe1WLO+RYW i/lHzrFadL+SsXj9wtDi/r2fTBaXd81hs/j/q5nZgcNjy8qbTB7bDqh6/Fs4hcWjb8sqRo/P m+QCWKO4bFJSczLLUov07RK4Mi5v7mMuuMNZcW6idwPjJI4uRk4OCQETiR/rrzNC2GISF+6t ZwOxhQSWMkrceeLRxcgFZDcySUxrXMwEkmATMJbYvHwJG0hCRKCdSWJF2zVmkASzgIXE1q2r 2UFsYYEEieb+TWCTWARUJY5suwFm8wq4S+w6tIsFYpucxMljk1knMHIvYGRYxSiaWppcUJyU nmuoV5yYW1yal66XnJ+7iRESKF92MC4+ZnWIUYCDUYmHN6BANFyINbGsuDL3EKMEB7OSCK+D sVi4EG9KYmVValF+fFFpTmrxIUZpDhYlcd65u96HCAmkJ5akZqemFqQWwWSZODilGhjr/7y8 m1/5rc+iTC6X8dVhli1eOyJ3Fmxde2/rgYesy2JCc2wl1rdmOiQ/NCh2EVx40+Zj+aITfCfY 3J7ysIRY7eI3uCxy5Hng03WMjDNY+dWvzTmUEWMSX7XvFce5jGVr183Yosp6+vyqmZO2Xzod pzd/vpNB7G0Fe478Wb+zp/N5CHmsYbmgxFKckWioxVxUnAgAHivKzRACAAA= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1209 Lines: 33 The driver makes copies of memory (input or output scatterlists) if they are not aligned. In s5p_aes_crypt_start() error path (on unsuccessful initialization of output scatterlist), if input scatterlist was not aligned, the driver first freed copied input memory and then unmapped it from the device, instead of doing otherwise (unmap and then free). This was wrong in two ways: 1. Freed pages were still mapped to the device. 2. The dma_unmap_sg() iterated over freed scatterlist structure. The call to s5p_free_sg_cpy() in this error path is not needed because the copied scatterlists will be freed by s5p_aes_complete(). Fixes: 9e4a1100a445 ("crypto: s5p-sss - Handle unaligned buffers") Signed-off-by: Krzysztof Kozlowski --- drivers/crypto/s5p-sss.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/crypto/s5p-sss.c b/drivers/crypto/s5p-sss.c index 4f6d5b3ec418..b0484d4d68d9 100644 --- a/drivers/crypto/s5p-sss.c +++ b/drivers/crypto/s5p-sss.c @@ -577,7 +577,6 @@ static void s5p_aes_crypt_start(struct s5p_aes_dev *dev, unsigned long mode) return; outdata_error: - s5p_free_sg_cpy(dev, &dev->sg_src_cpy); s5p_unset_indata(dev); indata_error: -- 1.9.1