From patchwork Sat Sep 10 11:50:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephan Mueller X-Patchwork-Id: 9324941 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0332060231 for ; Sat, 10 Sep 2016 11:50:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E4EAC29799 for ; Sat, 10 Sep 2016 11:50:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D89EE297D1; Sat, 10 Sep 2016 11:50:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2EF5D29799 for ; Sat, 10 Sep 2016 11:50:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751722AbcIJLuU (ORCPT ); Sat, 10 Sep 2016 07:50:20 -0400 Received: from mail.eperm.de ([89.247.134.16]:47918 "EHLO mail.eperm.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751287AbcIJLuU (ORCPT ); Sat, 10 Sep 2016 07:50:20 -0400 Received: from positron.chronox.de (rrcs-97-79-174-130.sw.biz.rr.com [97.79.174.130]) by mail.eperm.de (Postfix) with ESMTPA id E3C1218149CA; Sat, 10 Sep 2016 13:50:15 +0200 (CEST) From: Stephan Mueller To: herbert@gondor.apana.org.au Cc: linux-crypto@vger.kernel.org Subject: [PATCH] crypto: call put_page on used pages only Date: Sat, 10 Sep 2016 13:50:09 +0200 Message-ID: <49118797.WdfLSz7urc@positron.chronox.de> User-Agent: KMail/5.2.3 (Linux/4.7.2-201.fc24.x86_64; KDE/5.25.0; x86_64; ; ) In-Reply-To: <8008966.Q0OrxOpoA1@positron.chronox.de> References: <8008966.Q0OrxOpoA1@positron.chronox.de> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Herbert, This patch fixes the reported BUG reliably that I was able to create with my (faulty) libkcapi test code. However, I am yet unable to pinpoint the code that allocates an SG without an associated page that would trigger the BUG. In any case, if you approve, I would recommend that this patch should go to 4.8 and to stable as well. ---8<--- Ensure that put_page is only invoked on pages that were used by algif_skcipher. Signed-off-by: Stephan Mueller --- crypto/algif_skcipher.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c index d7acb73..bc36a9a 100644 --- a/crypto/algif_skcipher.c +++ b/crypto/algif_skcipher.c @@ -179,7 +179,7 @@ static void skcipher_pull_sgl(struct sock *sk, size_t used, int put) if (sg[i].length) return; - if (put) + if (put && page_ref_count(sg_page(sg + i))) put_page(sg_page(sg + i)); sg_assign_page(sg + i, NULL); }