From patchwork Thu Jun 29 18:54:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaohua Li X-Patchwork-Id: 9817741 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 9772C6035F for ; Thu, 29 Jun 2017 18:54:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8917220564 for ; Thu, 29 Jun 2017 18:54:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C04D27F90; Thu, 29 Jun 2017 18:54:21 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, 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 19A8620564 for ; Thu, 29 Jun 2017 18:54:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753107AbdF2SyU (ORCPT ); Thu, 29 Jun 2017 14:54:20 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:38804 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752506AbdF2SyU (ORCPT ); Thu, 29 Jun 2017 14:54:20 -0400 Received: from pps.filterd (m0109331.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v5TIqeWE025926 for ; Thu, 29 Jun 2017 11:54:19 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=facebook; bh=RP0XTu8rZCJnHW8+oppykouHutHarnLGFiTj48rA0sk=; b=kw25mWyePSXZ/dkF1PZRtggtqaPV1eN32I5zkjAGP1C9dZ/TMUZb0UINxbw1WixvmMqN ctxK+dKdzeVHLb7rlZR6ZM39aoS4vq5kzsV/G087zfsY1AD0lBfiAwTmRvDMn49VwlAH Lv59zvMoWLiOiZZNhMIoPS/9geZGYn2wZsU= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2bd6qsg3ke-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Thu, 29 Jun 2017 11:54:19 -0700 Received: from mx-out.facebook.com (192.168.52.123) by PRN-CHUB01.TheFacebook.com (192.168.16.11) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 29 Jun 2017 11:54:18 -0700 Received: from facebook.com (2401:db00:21:603d:face:0:19:0) by mx-out.facebook.com (10.102.107.97) with ESMTP id 5aa31e385cfc11e791870002c99331b0-81d398f0 for ; Thu, 29 Jun 2017 11:54:18 -0700 Received: by devbig638.prn2.facebook.com (Postfix, from userid 11222) id E2D8C4A444F5; Thu, 29 Jun 2017 11:54:17 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Shaohua Li Smtp-Origin-Hostname: devbig638.prn2.facebook.com To: CC: , , Smtp-Origin-Cluster: prn2c22 Subject: [PATCH] block: call __bio_free in bio_endio Date: Thu, 29 Jun 2017 11:54:17 -0700 Message-ID: X-Mailer: git-send-email 2.9.3 X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-06-29_13:, , signatures=0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP bio_free isn't a good place to free cgroup info. There are a lot of cases bio is allocated in special way (for example, in stack) and never gets called by bio_put hence bio_free, we are leaking memory. This patch moves the free to bio endio, which should be called anyway. The __bio_free call in bio_free is kept, in case the bio never gets called bio endio. This assumes ->bi_end_io() doesn't access cgroup info, which seems true in my audit. This along with Christoph's integrity patch should fix the memory leak issue. Signed-off-by: Shaohua Li --- block/bio.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/block/bio.c b/block/bio.c index 9cf98b2..e8cda9c 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1828,6 +1828,8 @@ void bio_endio(struct bio *bio) } blk_throtl_bio_endio(bio); + /* release cgroup info */ + __bio_free(bio); if (bio->bi_end_io) bio->bi_end_io(bio); }