From owner-dev-commits-src-all@freebsd.org Mon May 17 06:52:55 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 76E8B63E712; Mon, 17 May 2021 06:52:55 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4Fk8w61sSpz4mVj; Mon, 17 May 2021 06:52:53 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.16.1/8.16.1) with ESMTPS id 14H6qj5I043000 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 17 May 2021 09:52:48 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 14H6qj5I043000 Received: (from kostik@localhost) by tom.home (8.16.1/8.16.1/Submit) id 14H6qjS2042999; Mon, 17 May 2021 09:52:45 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 17 May 2021 09:52:45 +0300 From: Konstantin Belousov To: Warner Losh , Mark Johnston , src-committers , "" , dev-commits-src-main@freebsd.org Subject: Re: git: 0f206cc91279 - main - cam: add missing zeroing of a stack-allocated CCB. Message-ID: References: <202105161045.14GAjZIL093217@gitrepo.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on tom.home X-Rspamd-Queue-Id: 4Fk8w61sSpz4mVj X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=gmail.com (policy=none); spf=softfail (mx1.freebsd.org: 2001:470:d5e7:1::1 is neither permitted nor denied by domain of kostikbel@gmail.com) smtp.mailfrom=kostikbel@gmail.com X-Spamd-Result: default: False [-2.93 / 15.00]; ARC_NA(0.00)[]; RBL_DBL_DONT_QUERY_IPS(0.00)[2001:470:d5e7:1::1:from]; DMARC_POLICY_SOFTFAIL(0.10)[gmail.com : No valid SPF, No valid DKIM,none]; RCVD_TLS_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_FROM(0.00)[gmail.com]; NEURAL_HAM_LONG(-0.95)[-0.946]; MIME_GOOD(-0.10)[text/plain]; HAS_XAW(0.00)[]; NEURAL_HAM_MEDIUM(-0.98)[-0.983]; R_SPF_SOFTFAIL(0.00)[~all:c]; RCPT_COUNT_FIVE(0.00)[5]; SPAMHAUS_ZRD(0.00)[2001:470:d5e7:1::1:from:127.0.2.255]; TO_MATCH_ENVRCPT_SOME(0.00)[]; NEURAL_HAM_SHORT(-1.00)[-1.000]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US]; MIME_TRACE(0.00)[0:+]; MAILMAN_DEST(0.00)[dev-commits-src-all,dev-commits-src-main]; RCVD_COUNT_TWO(0.00)[2] X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 May 2021 06:52:55 -0000 On Sun, May 16, 2021 at 07:03:24PM +0100, Edward Tomasz Napierala wrote: > On 0516T1227, Warner Losh wrote: > > On Sun, May 16, 2021, 11:55 AM Mark Johnston wrote: > > > > > On Sun, May 16, 2021 at 10:45:35AM +0000, Edward Tomasz Napierala wrote: > > > > The branch main has been updated by trasz: > > > > > > > > URL: > > > https://cgit.FreeBSD.org/src/commit/?id=0f206cc91279e630ad9e733eb6e330b7dbe6c70e > > > > > > > > commit 0f206cc91279e630ad9e733eb6e330b7dbe6c70e > > > > Author: Edward Tomasz Napierala > > > > AuthorDate: 2021-05-16 09:28:04 +0000 > > > > Commit: Edward Tomasz Napierala > > > > CommitDate: 2021-05-16 10:38:26 +0000 > > > > > > > > cam: add missing zeroing of a stack-allocated CCB. > > > > > > > > This could cause a panic at boot. > > > > > > There are other instances of this, for example syzbot is currently > > > hitting an assertion, seemingly because the alloc_flags field of a > > > stack-allocated CCB was not zeroed: > > > https://syzkaller.appspot.com/bug?extid=2e9ce63919709feb3d1c > > > > > > I think the patch below will fix it, but I did not audit other callers. > > > It feels a bit strange to require all callers of xpt_setup_ccb() to > > > manually zero the structure first, can we provide a single routine to > > > initialize stack-allocated CCBs? > > We definitely could, although in some cases it's a bit more > complicated than that - a function that gets passed a CCB and then > calls xpt_setup_ccb() to fill it shouldn't zero it, as that would > be making assumption on how the CCB passed to it was allocated. > > Now that I look at the code, I can definitely see that I've missed > a couple of places. Perhaps I should replace those two KASSERTs with > diagnostic printfs for now, until I get that sorted out? > > > If we did, we could set a flag we could assert on, and/or do static > > analysis to find any others... > > That sounds promising, except I've never done anything like that; > I don't even know where to start. Are stack-allocated ccbs passed around? In particular, can the thread that allocated the ccb, put to sleep while ccb is processed elsewere? This should break under swapping.