Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760805AbcDFAaT (ORCPT ); Tue, 5 Apr 2016 20:30:19 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:16967 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753639AbcDFAaR (ORCPT ); Tue, 5 Apr 2016 20:30:17 -0400 Date: Tue, 5 Apr 2016 20:30:03 -0400 From: Chris Mason To: Lars Ellenberg CC: Neil Brown , Jens Axboe , Josef Bacik , David Sterba , , , Subject: Re: [PATCH] [RFC] fix potential access after free: return value of blk_check_plugged() must be used schedule() safe Message-ID: <20160406003003.GA57524@clm-mbp.masoncoding.com> Mail-Followup-To: Chris Mason , Lars Ellenberg , Neil Brown , Jens Axboe , Josef Bacik , David Sterba , linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, linux-btrfs@vger.kernel.org References: <20160405133657.GA3078@soda.linbit> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20160405133657.GA3078@soda.linbit> User-Agent: Mutt/1.5.24 (2015-08-30) X-Originating-IP: [192.168.54.13] X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-04-06_02:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1045 Lines: 27 On Tue, Apr 05, 2016 at 03:36:57PM +0200, Lars Ellenberg wrote: > blk_check_plugged() will return a pointer > to an object linked on current->plug->cb_list. > > That list may "at any time" be implicitly cleared by > blk_flush_plug_list() > flush_plug_callbacks() > either as a result of blk_finish_plug(), > or implicitly by schedule() [and maybe other implicit mechanisms?] > > If there is no protection against an implicit unplug > between the call to blk_check_plug() and using its return value, > that implicit unplug may have already happened, > even before the plug is actually initialized or populated, > and we may be using a pointer to already free()d data. > > I suggest that both raid1 and raid10 can easily be fixed > by moving the call to blk_check_plugged() inside the spinlock. > > For md/raid5 and btrfs/raid56, > I'm unsure how (if) this needs to be fixed. I think you're right, digging in to see if there's something I missed. But as Neil said, it looks like we just got saved by preemption being off by default. -chris