Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3009317ybi; Mon, 17 Jun 2019 14:35:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqxJvthkVKz4dNKOqYmbe3iPuqaYHEAkFU7fx72Ey97QGotmyKvXOSWj/7jo/ea2ZJkOxYPF X-Received: by 2002:a17:902:830c:: with SMTP id bd12mr32641409plb.237.1560807342511; Mon, 17 Jun 2019 14:35:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560807342; cv=none; d=google.com; s=arc-20160816; b=kVma9qgJrTwrdWBk/KmBlTWJINqZrTh55f/L6Vws+/uoHc0YsDVa9SNlqFsPvKMvBW 3+9WG0XUMms5erVq9E1fPYPsZf8iD9RGUA/pSpzZBl/pKDb0UcIuEYc9Jv+LbxUj29jH 5GlltiW09Bhaw/XFmSj2plHe4BPICciAIDbSIv995GHJGvSgCInPBEDFMazDDT94aUcl N82Aup/c/XarmKdTKMyi/dc1xi4cSkY8QuCkfsxbaXikZjGf86qOYmAbe69rK9de/S6C jjf3atrOlP1PRlbzX9Jrn01W8sY3pnasF8CmoRASiYJ6KingFPIlZTaxQtcdgM+Nysfo ZIJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Jn45Hj8hc7c1ztQhwpzfAnR6i3OuYSQTAHu3tPLaTpY=; b=rApc4zq05MLDQ3dtZczitL53T74yDzbLklyBmM2bFT07qV34WBgC4eJyO2rQZaNnQP mY9pY0FScU3AfNPDr9zIsz/NJrK2vNGaPAs1SKik9k6nTKhWlqd598D4lEdBNS5h/EM7 6jWjos7SlYNk0vjlfrv1mfSGW9QPo7ysJjgmwfSm3lGrY7jdchAEG106WxDa6ZcvGnwO 5ApWL0v5dTTIo9EL13mu1nF2PUGOSvAPoChrCi9v30VN02GhHYPwLrF2ZGTC61VNt39T riS4M841PbowLqmQ1bLN9VNIIRRJwbzMeEZEFsuVBJJJwXXBVaF7+dxbmppnmziVn1+s 3jlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cxt9Xi6i; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s37si316953pjb.16.2019.06.17.14.35.27; Mon, 17 Jun 2019 14:35:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cxt9Xi6i; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729397AbfFQVYx (ORCPT + 99 others); Mon, 17 Jun 2019 17:24:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:50576 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729592AbfFQVYr (ORCPT ); Mon, 17 Jun 2019 17:24:47 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 43C602063F; Mon, 17 Jun 2019 21:24:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560806686; bh=8AZXDN5az/P3ZHNDwkQykMB35CKW4NUB8QoKxRQ8Qrk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cxt9Xi6iiWiK+GB04B0uN/gXEFcef2DVe8aCEnL+9/NjrXBozsPE0vVcmBFOTQHNR CNf2F9ZdHYZNP+9wHU4YMkmimX12t2twD5JRizsWcyTmaMRzFyStIcNkmgg1cLSqNf Ho161SJEx8zYRI7ufpgsIcq+WJTbQEAJfWsgmwJ0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Bj=C3=B8rn=20Forsman?= , Coly Li , Jens Axboe Subject: [PATCH 4.19 22/75] bcache: only set BCACHE_DEV_WB_RUNNING when cached device attached Date: Mon, 17 Jun 2019 23:09:33 +0200 Message-Id: <20190617210753.709500958@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190617210752.799453599@linuxfoundation.org> References: <20190617210752.799453599@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Coly Li commit 1f0ffa67349c56ea54c03ccfd1e073c990e7411e upstream. When people set a writeback percent via sysfs file, /sys/block/bcache/bcache/writeback_percent current code directly sets BCACHE_DEV_WB_RUNNING to dc->disk.flags and schedules kworker dc->writeback_rate_update. If there is no cache set attached to, the writeback kernel thread is not running indeed, running dc->writeback_rate_update does not make sense and may cause NULL pointer deference when reference cache set pointer inside update_writeback_rate(). This patch checks whether the cache set point (dc->disk.c) is NULL in sysfs interface handler, and only set BCACHE_DEV_WB_RUNNING and schedule dc->writeback_rate_update when dc->disk.c is not NULL (it means the cache device is attached to a cache set). This problem might be introduced from initial bcache commit, but commit 3fd47bfe55b0 ("bcache: stop dc->writeback_rate_update properly") changes part of the original code piece, so I add 'Fixes: 3fd47bfe55b0' to indicate from which commit this patch can be applied. Fixes: 3fd47bfe55b0 ("bcache: stop dc->writeback_rate_update properly") Reported-by: Bjørn Forsman Signed-off-by: Coly Li Reviewed-by: Bjørn Forsman Cc: stable@vger.kernel.org Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- drivers/md/bcache/sysfs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/drivers/md/bcache/sysfs.c +++ b/drivers/md/bcache/sysfs.c @@ -393,8 +393,13 @@ STORE(bch_cached_dev) if (attr == &sysfs_writeback_running) bch_writeback_queue(dc); + /* + * Only set BCACHE_DEV_WB_RUNNING when cached device attached to + * a cache set, otherwise it doesn't make sense. + */ if (attr == &sysfs_writeback_percent) - if (!test_and_set_bit(BCACHE_DEV_WB_RUNNING, &dc->disk.flags)) + if ((dc->disk.c != NULL) && + (!test_and_set_bit(BCACHE_DEV_WB_RUNNING, &dc->disk.flags))) schedule_delayed_work(&dc->writeback_rate_update, dc->writeback_rate_update_seconds * HZ);