Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp5233603rdb; Sat, 30 Dec 2023 11:24:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IEWBh7VK10gY7bh6NXfFO8EC68zxNL6zaTYZGyH9+EUKqavG4l1lwSYqrEGh0QDEZ25TQZv X-Received: by 2002:a05:6808:2115:b0:3b9:e600:6de2 with SMTP id r21-20020a056808211500b003b9e6006de2mr16863362oiw.28.1703964266626; Sat, 30 Dec 2023 11:24:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703964266; cv=none; d=google.com; s=arc-20160816; b=pBPUl/2FiMzKEwzCQapWyK3WLht42jCuqgHVMfg4HQHL0vIe4OZrn17LkMrHGr5oLa udJzexV+S6GMqLV7WqjqDvhVd1Q0KB7kdaxDTCeWSe/jggD4ECxvrybG6Ep4UiewGx20 rrm9gZHMiThzcBV+l1PZX8UFjO/zrVlGDxGH0WoeGtoIR10mRqUWJZacG5/EzCRH1SGb +G1q2QWykggGOAEtrnSCbm3LOnsvi624jGAhgs69yZ8alTEX1+PYEc5UMeL6VxW6jZxm rTf+iE7P90ML+S+jgOtMOBBWHvXSKvMpMF8k+M3tWUV3UyGJ8LfT8uXaagojSeG/EXDx w/oQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:dkim-signature:date; bh=PvM8Sn8DH7rCqnf+LkHgkFYPn3ooypFdz/LllQI5VSg=; fh=2h7mtSTI8A3PQ9bXyg3YuJsb796zJygFcs4ZX01wbeQ=; b=q1pC9jZX3B8ZJHeA0yHewzFt4po8Gxdrkx4Moj7e5nt4MbFWGgQ6ndjlLJyiWIbHlD RCnWk4VvetG7YFO3X3HZ1nCI97c1TZWVoIYeso7n3ldfch59SogcIqBv/6pWaadwEQAs kYPHv/ysfsIKC6+xcJNdPaq7tXcJ2w8xgMTUnzIZdcz/h+u2O4qqbEpmv5agtkukzkiJ uK5fbqA+vrekhuSksOcGJbJetIYn3MS2n8/n9O5ksV+9XzsgfgPAEP/hkmwMu9JGt1m5 ez6x6e9/vLuA90DNBmdJo4XlCn0wVNth0S+xADhCSJiXpR6KTlZJoL7Np0BTbbzPxRRT 0bqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=vLj1KmNw; spf=pass (google.com: domain of linux-kernel+bounces-13575-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-13575-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id o2-20020a62cd02000000b006d52b0c27c2si13174349pfg.373.2023.12.30.11.24.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Dec 2023 11:24:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-13575-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=vLj1KmNw; spf=pass (google.com: domain of linux-kernel+bounces-13575-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-13575-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 420D6283F41 for ; Sat, 30 Dec 2023 19:24:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4449ABE6B; Sat, 30 Dec 2023 19:24:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="vLj1KmNw" X-Original-To: linux-kernel@vger.kernel.org Received: from out-176.mta1.migadu.com (out-176.mta1.migadu.com [95.215.58.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B459BE58 for ; Sat, 30 Dec 2023 19:24:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Date: Sat, 30 Dec 2023 14:24:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1703964253; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=PvM8Sn8DH7rCqnf+LkHgkFYPn3ooypFdz/LllQI5VSg=; b=vLj1KmNw8I72SVlvdc4NNNGDiYm6uOrZRw4nlTAdA/ejGfKPCu23SfDiPmwP4fZvvccDDg PDP22YFXAv1AJwKqQy6GKRDOVpICVX0ebgq6Cv1Fsnvc62dJ1ZFwNlLf0QzhNIkTLXka0i AizSQMPdNC4LICel5EAZfnf6Ca/oB44= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: Daniel J Blueman Cc: linux-bcachefs@vger.kernel.org, Linux Kernel Subject: Re: Stack corruption in bch2_nocow_write Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT On Sat, Dec 30, 2023 at 04:34:39PM +0800, Daniel J Blueman wrote: > On Sat, 30 Dec 2023 at 02:54, Kent Overstreet wrote: > > > > On Fri, Dec 29, 2023 at 07:43:13PM +0800, Daniel J Blueman wrote: > > > Hi Kent et al, > > > > > > On Linux 6.7-rc7 from bcachefs master SHA f3608cbdfd built with UBSAN > > > [1], with a crafted workload [2] I'm able to trigger stack corruption > > > in bch2_nocow_write [3]. > > > > > > Let me know if you can't reproduce it and I'll check reproducibility > > > on another platform, and let me know for any patch testing. > > > > this should be fixed in the testing branch: > > > > commit ab35f724070ccdaa31f6376a1890473e7d031ed0 > > Author: Kent Overstreet > > Date: Fri Dec 29 13:54:00 2023 -0500 > > > > bcachefs: fix nocow write path when writing to multiple extents > > > > Signed-off-by: Kent Overstreet > > > > diff --git a/fs/bcachefs/io_write.c b/fs/bcachefs/io_write.c > > index c5961bac19f0..7c5963cd0b85 100644 > > --- a/fs/bcachefs/io_write.c > > +++ b/fs/bcachefs/io_write.c > > @@ -1316,6 +1316,7 @@ static void bch2_nocow_write(struct bch_write_op *op) > > closure_get(&op->cl); > > bch2_submit_wbio_replicas(to_wbio(bio), c, BCH_DATA_user, > > op->insert_keys.top, true); > > + nr_buckets = 0; > > > > bch2_keylist_push(&op->insert_keys); > > if (op->flags & BCH_WRITE_DONE) > > Thanks for the quick update, Kent. > > With this change and a few runs of the reproducer, I still hit this > stack corruption with the same backtrace. Reprod it - my first fix was bogus. Turns out I didn't consider cached extents; those can exceed the BCH_REPLICAS_MAX limit, and there's another issue I just spotted - the bucket invalidate path doesn't respect nocow locking. And I'm wondering if there's a lock inversion between nocow locks and btree locks as well; need to add lockdep support for that.