From owner-dev-commits-src-main@freebsd.org Sun May 16 17:27:57 2021 Return-Path: Delivered-To: dev-commits-src-main@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 43AAB629B55 for ; Sun, 16 May 2021 17:27:57 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [IPv6:2607:f8b0:4864:20::82d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Fjq3K0wJyz4s27 for ; Sun, 16 May 2021 17:27:56 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: by mail-qt1-x82d.google.com with SMTP id j11so3297867qtn.12 for ; Sun, 16 May 2021 10:27:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Vq3Su//bgkIJZX5L6/plp06s8ZYj72lwnbBMdimOgmk=; b=BkFQh9dFjSXNoe64TOHag0i+9LcvAbjV7+LB7575mowd90hjsQmmNiRXNAcTrgfsEL XP0A71kihfn3Zyt5/99sANQgDd3KZqbSeV7hFr2DXv/z4eW4WRuQi94xYVYD90gqilXL XXiZxiHV1kok4TMdAUJAAcYvvqcxTylpxo0gr34nqfLf9Wk7T0OT9Lfjr0eoh6KaJytp qQmbCS7Oy7N1s7Z6Qw/svHO75e3x0IIBGXdCU4u/l5/TXOXVgpIKTabmfY8RJWhGmsLG VXT1n5snkbm1o9xgnKKbs5qInGsd/h5k6kPfn1IREa5HNjUNnAxpL8jK2lgbpGfXVEwa 5w2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Vq3Su//bgkIJZX5L6/plp06s8ZYj72lwnbBMdimOgmk=; b=GLtge5glE7JkzodIXHWj6wZhaStPv7K5TriBzf+dRA7C7v0lEkc6r7oimUtGWY7Leh y1OLqp/i4qArRH6OrBHj4Tl9fujf0VvfjDN+/2AulXjdQL03i2QmHahhVA/AZw2z/26y DVwzoNRHTJVJspRWoLAwuWNYCwqmtaOE8T0B4AQVX40YbcevuPYQAfYC5U6uZ3tAJJFg e9tmPGI5rOUog+Rszsf53Wh3dbBU0Hcbd7zuGmXnPO4W0pHUf9zvqph2zkW+7/2xIQpm oPj8m62YrkDQX1s7Xt4U3kHQRQayvYkSXLgI7MgmAwroC2pdbss3DvdPh5tO04LjX0Z6 A/ow== X-Gm-Message-State: AOAM533Bf4Kr5wThxD+vBnJhDFHYTeaX5difpNwPa8npjkLKYUwf2Y56 lf49bTln7cuxLb3LOkngXQsdfTIY7U8jSIoQcrQYuw== X-Google-Smtp-Source: ABdhPJydZS6wTHdOJZWQYbmMK32O9TYOIk54C4VDXfuLltbd3NI+GQRTzh+zzruiWUDXpFwhglWbRclf0Px5XSaaaYU= X-Received: by 2002:a05:622a:588:: with SMTP id c8mr42429415qtb.49.1621186075894; Sun, 16 May 2021 10:27:55 -0700 (PDT) MIME-Version: 1.0 References: <202105161045.14GAjZIL093217@gitrepo.freebsd.org> In-Reply-To: From: Warner Losh Date: Sun, 16 May 2021 12:27:44 -0500 Message-ID: Subject: Re: git: 0f206cc91279 - main - cam: add missing zeroing of a stack-allocated CCB. To: Mark Johnston Cc: Edward Tomasz Napierala , src-committers , "" , dev-commits-src-main@freebsd.org X-Rspamd-Queue-Id: 4Fjq3K0wJyz4s27 X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.34 X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 16 May 2021 17:27:57 -0000 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? > If we did, we could set a flag we could assert on, and/or do static analysis to find any others... Warner diff --git a/sys/dev/virtio/scsi/virtio_scsi.c > b/sys/dev/virtio/scsi/virtio_scsi.c > index 51d9e5f532f7..adf4fd17fc5b 100644 > --- a/sys/dev/virtio/scsi/virtio_scsi.c > +++ b/sys/dev/virtio/scsi/virtio_scsi.c > @@ -700,6 +700,7 @@ vtscsi_register_async(struct vtscsi_softc *sc) > { > struct ccb_setasync csa; > > + memset(&csa, 0, sizeof(csa)); > xpt_setup_ccb(&csa.ccb_h, sc->vtscsi_path, 5); > csa.ccb_h.func_code = XPT_SASYNC_CB; > csa.event_enable = AC_LOST_DEVICE | AC_FOUND_DEVICE; > @@ -716,6 +717,7 @@ vtscsi_deregister_async(struct vtscsi_softc *sc) > { > struct ccb_setasync csa; > > + memset(&csa, 0, sizeof(csa)); > xpt_setup_ccb(&csa.ccb_h, sc->vtscsi_path, 5); > csa.ccb_h.func_code = XPT_SASYNC_CB; > csa.event_enable = 0; >