From patchwork Mon Jan 22 01:17:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Qi X-Patchwork-Id: 10177183 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 BEA0E601D5 for ; Mon, 22 Jan 2018 01:17:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FC8620223 for ; Mon, 22 Jan 2018 01:17:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9270A205AF; Mon, 22 Jan 2018 01:17:26 +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, UNPARSEABLE_RELAY 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 7079A20223 for ; Mon, 22 Jan 2018 01:17:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751036AbeAVBRY (ORCPT ); Sun, 21 Jan 2018 20:17:24 -0500 Received: from out30-130.freemail.mail.aliyun.com ([115.124.30.130]:32867 "EHLO out30-130.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751002AbeAVBRX (ORCPT ); Sun, 21 Jan 2018 20:17:23 -0500 X-Alimail-AntiSpam: AC=CONTINUE; BC=0.3118166|-1; CH=green; FP=0|0|0|0|0|-1|-1|-1; HT=e01e07487; MF=joseph.qi@linux.alibaba.com; NM=1; PH=DS; RN=5; RT=5; SR=0; TI=SMTPD_---0Swxs1UU_1516583840; Received: from JosephdeMacBook-Pro.local(mailfrom:joseph.qi@linux.alibaba.com fp:42.120.74.105) by smtp.aliyun-inc.com(127.0.0.1); Mon, 22 Jan 2018 09:17:20 +0800 From: Joseph Qi Subject: [PATCH RESEND 1/3] blk-throttle: fix NULL pointer dereference risk in throtl_select_dispatch To: Jens Axboe , Shaohua Li Cc: linux-block , jiufei.xue@linux.alibaba.com, caspar@linux.alibaba.com Message-ID: <5d2c2323-058d-7008-85b5-4a353418a341@linux.alibaba.com> Date: Mon, 22 Jan 2018 09:17:21 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 Content-Language: en-US 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 tg in throtl_select_dispatch is used first and then do check. Since tg may be NULL, it has potential NULL pointer dereference risk. So fix it. Signed-off-by: Joseph Qi Reviewed-by: Jiufei Xue --- block/blk-throttle.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/blk-throttle.c b/block/blk-throttle.c index 9052f4e..a0bae2c 100644 --- a/block/blk-throttle.c +++ b/block/blk-throttle.c @@ -1228,7 +1228,7 @@ static int throtl_select_dispatch(struct throtl_service_queue *parent_sq) while (1) { struct throtl_grp *tg = throtl_rb_first(parent_sq); - struct throtl_service_queue *sq = &tg->service_queue; + struct throtl_service_queue *sq; if (!tg) break; @@ -1240,6 +1240,7 @@ static int throtl_select_dispatch(struct throtl_service_queue *parent_sq) nr_disp += throtl_dispatch_tg(tg); + sq = &tg->service_queue; if (sq->nr_queued[0] || sq->nr_queued[1]) tg_update_disptime(tg);