From patchwork Mon Sep 19 17:03:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 9339921 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 451B7607D0 for ; Mon, 19 Sep 2016 17:03:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3329E295C9 for ; Mon, 19 Sep 2016 17:03:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 279C2295DD; Mon, 19 Sep 2016 17:03:55 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 CE310295C9 for ; Mon, 19 Sep 2016 17:03:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752594AbcISRDx (ORCPT ); Mon, 19 Sep 2016 13:03:53 -0400 Received: from mail-yw0-f195.google.com ([209.85.161.195]:36312 "EHLO mail-yw0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752436AbcISRDw (ORCPT ); Mon, 19 Sep 2016 13:03:52 -0400 Received: by mail-yw0-f195.google.com with SMTP id v2so8594844ywg.3 for ; Mon, 19 Sep 2016 10:03:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8t/hO3V2DIAuubvzhiqOUipuslVSswyWLrZ/oXa8rzA=; b=a0SYTHlS7J6naZa0FW+cgEH0PPLr3vTT450Q+wfkxMTf8iHjHxSkaIMeZeMPx2u1Kb 45ncrrL5V2pTH4KDCch0/2cc/zTN0fmQ+rd+FRVf1ZYAOeGbtoPwNG5fHDBwAJ1G65ZJ /Kn/axiHclydVM5Z0U2Z+/MZTAoWiH1y+cpMpqo+diKQ9zdMhAhXo9kOYrlcN6PgeGdG F0Xfs2S0XxXWH8uH8EfeVImOpzNv0CRDaVs1tAa6Amej0gXfLin/IA16tl5VYG5PtPEH rM/A3mzDmMugzag5JGu6yuv8w1bttF3Ncxq2eLtNpp1h6Mi57/JRHrYqRNWCTA/HXGJp eaqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8t/hO3V2DIAuubvzhiqOUipuslVSswyWLrZ/oXa8rzA=; b=ED70LksrxAXVmMTG8DfbVa1+ma1FDxW97uIj+n1P9p8o5ohS77+X/u8/nP/dgvkVPA N0X9HbhQMjRBpMSGS2f57Ll5D5t3DVfQ76IijamhXEW+vuDy+693XA0MWyInRVysHhK6 m4LRuxjFJqpnWqTOcRHRZ1rtzSO+gdusAjSqYRtNtlNepSIFesjqXaXu7f0uZO39moeo YFK7oSRKmIWlM/kFT3dZpgMHhZEtjzT5pudM4MVmHSuWICrJ9IMSsn79zN6C0OdfJoDW 7hyY4Geb42e1JslhsCm1rRBBGdv3hN8GzzRggOaTfn5bxlZQ6w4BCVcmEgYp87qj58yH datg== X-Gm-Message-State: AE9vXwN1YyT09Tml7d44sHyGQ9Ts0UD2EWKHw6pD6u1spt8AAW1WhC11PwmTeRVG2+SLtQ== X-Received: by 10.129.112.68 with SMTP id l65mr24629582ywc.222.1474304631704; Mon, 19 Sep 2016 10:03:51 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id o14sm9773905ywd.3.2016.09.19.10.03.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Sep 2016 10:03:51 -0700 (PDT) From: Ilya Dryomov To: ceph-devel@vger.kernel.org Cc: Alex Elder Subject: [PATCH 8/8] rbd: img_data requests don't own their page array Date: Mon, 19 Sep 2016 19:03:28 +0200 Message-Id: <1474304608-17958-9-git-send-email-idryomov@gmail.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1474304608-17958-1-git-send-email-idryomov@gmail.com> References: <1474304608-17958-1-git-send-email-idryomov@gmail.com> Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Move the check into rbd_obj_request_destroy(), to avoid use-after-free on errors in rbd_img_request_fill(). Signed-off-by: Ilya Dryomov Reviewed-by: Alex Elder Reviewed-by: David Disseldorp --- drivers/block/rbd.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 8907ee6342ac..d305b9ebe2cf 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -2139,7 +2139,9 @@ static void rbd_obj_request_destroy(struct kref *kref) bio_chain_put(obj_request->bio_list); break; case OBJ_REQUEST_PAGES: - if (obj_request->pages) + /* img_data requests don't own their page array */ + if (obj_request->pages && + !obj_request_img_data_test(obj_request)) ceph_release_page_vector(obj_request->pages, obj_request->page_count); break; @@ -2360,13 +2362,6 @@ static bool rbd_img_obj_end_request(struct rbd_obj_request *obj_request) xferred = obj_request->length; } - /* Image object requests don't own their page array */ - - if (obj_request->type == OBJ_REQUEST_PAGES) { - obj_request->pages = NULL; - obj_request->page_count = 0; - } - if (img_request_child_test(img_request)) { rbd_assert(img_request->obj_request != NULL); more = obj_request->which < img_request->obj_request_count - 1;