From nobody Tue Nov 4 21:57:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530897450311481.4342162589902; Fri, 6 Jul 2018 10:17:30 -0700 (PDT) Received: from localhost ([::1]:59008 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbUML-0002Uc-AX for importer@patchew.org; Fri, 06 Jul 2018 13:17:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51047) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbUK4-0001D4-66 for qemu-devel@nongnu.org; Fri, 06 Jul 2018 13:15:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fbUJz-0000kr-UN for qemu-devel@nongnu.org; Fri, 06 Jul 2018 13:15:08 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:44932) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fbUJz-0000kN-G3 for qemu-devel@nongnu.org; Fri, 06 Jul 2018 13:15:03 -0400 Received: by mail-wr1-x444.google.com with SMTP id r16-v6so4873020wrt.11 for ; Fri, 06 Jul 2018 10:15:03 -0700 (PDT) Received: from 640k.lan ([82.84.124.111]) by smtp.gmail.com with ESMTPSA id h40-v6sm13784683wrf.40.2018.07.06.10.15.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Jul 2018 10:15:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=CrX2pNcywD0kHcAnRUdC4yRQEJhoMKEI9aBJorcN8CM=; b=iEi9p7nD7iKoGCSojXszcDB7JR0ABc209vJo/39WR1LqKFTo38ucgHLJCT5elE8T9A 49pZp+dm8+xmc4EYwljyX/Yk4Li8Sy9jyshaZoppibCIF51aOKcrs078CMZyPR937B8O sAB7eTfaCbXO0sGnN+AxCSW4Sd4S6698vrlZo6Hz0EKGMUIG19EpEOhHG0DfQb6V+2VI jUk/3bzmE18om0VQzkaOBkKjvigqGBZnQUAKv9MPNCwctV0SLzkbaOgR0kfJxPXmTyRW Irp7d5BypToNtTcRMiCoeRnnLOZLEQ+s58rEvJvLMy5tgpnqhQ4eF0cCHNde2mm9ho3R Kmwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=CrX2pNcywD0kHcAnRUdC4yRQEJhoMKEI9aBJorcN8CM=; b=Ha2goKGCKhdosoG4eOznnkMZYHoK7M0I1COUlPnQGHd3hYGvTodQwM83aWkrDSZqhm qUHQ4XGgEhB+cIrtNSZskg765ihzGauIDBKg8l/gVaZq4CIWaPWZkPaIC120xDKEGZxs Q1opLgX1yP7zz/T2I0AZ/DUooYj9VVrmSnVvkAw5T8KBjCdALG6uKqV3rV31dpGOubp8 N6b+cDuv1nUycAZjw76s7wIKJ7/m3rVBtJNxYC/2RqkysL/WANJ7w2FBQOslXKJDCLqp 7oxd4LCmmEal5qj2nzxxZLjS6TE1L6Z9QZmH0B4u6VAWf5Ibd7RVbhLcr1vZ529gVCFQ dB6A== X-Gm-Message-State: APt69E1yWLJ25MawdQsFPsW5NLgO8ocsD1LrycNBizyx6LezJQ6kas7L hmsceTwPJ11/PBH+dKZEsDp5iuHe X-Google-Smtp-Source: AAOMgpdhVlSCDDBh5DdchGyAtccb9aKjIsXQGwDbvg3HbsGIi7jdw/xB7PCK9mh+DOgJyfDHhr6TtA== X-Received: by 2002:adf:9025:: with SMTP id h34-v6mr8816562wrh.123.1530897302264; Fri, 06 Jul 2018 10:15:02 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 6 Jul 2018 19:14:21 +0200 Message-Id: <1530897268-22932-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1530897268-22932-1-git-send-email-pbonzini@redhat.com> References: <1530897268-22932-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 Subject: [Qemu-devel] [PULL 1/8] pr-helper: avoid error on PR IN command with zero request size X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" After reading a PR IN command with zero request size in prh_read_request, the resp->result field will be uninitialized and the resp.sz field will be also uninitialized when returning to prh_co_entry. If resp->result =3D=3D GOOD (from a previous successful reply or just luck), then the assert in prh_write_response might not be triggered and uninitialized response will be sent. The fix is to remove the whole handling of sz =3D=3D 0 in prh_co_entry. Those errors apply only to PR OUT commands and it's perfectly okay to catch them later in do_pr_out and multipath_pr_out; the check for too-short parameters in fact doesn't apply in the easy SG_IO case, as it can be left to the target firmware even. The result is that prh_read_request does not fail requests anymore and prh_co_entry becomes simpler. Reported-by: Dima Stepanov Signed-off-by: Paolo Bonzini --- scsi/qemu-pr-helper.c | 63 ++++++++++++++++++++++++-----------------------= ---- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c index 0218d65..c89a446 100644 --- a/scsi/qemu-pr-helper.c +++ b/scsi/qemu-pr-helper.c @@ -455,6 +455,14 @@ static int multipath_pr_out(int fd, const uint8_t *cdb= , uint8_t *sense, char transportids[PR_HELPER_DATA_SIZE]; int r; =20 + if (sz < PR_OUT_FIXED_PARAM_SIZE) { + /* Illegal request, Parameter list length error. This isn't fatal; + * we have read the data, send an error without closing the socket. + */ + scsi_build_sense(sense, SENSE_CODE(INVALID_PARAM_LEN)); + return CHECK_CONDITION; + } + switch (rq_servact) { case MPATH_PROUT_REG_SA: case MPATH_PROUT_RES_SA: @@ -574,6 +582,12 @@ static int do_pr_out(int fd, const uint8_t *cdb, uint8= _t *sense, const uint8_t *param, int sz) { int resp_sz; + + if ((fcntl(fd, F_GETFL) & O_ACCMODE) =3D=3D O_RDONLY) { + scsi_build_sense(sense, SENSE_CODE(INVALID_OPCODE)); + return CHECK_CONDITION; + } + #ifdef CONFIG_MPATH if (is_mpath(fd)) { return multipath_pr_out(fd, cdb, sense, param, sz); @@ -690,21 +704,6 @@ static int coroutine_fn prh_read_request(PRHelperClien= t *client, errp) < 0) { goto out_close; } - if ((fcntl(client->fd, F_GETFL) & O_ACCMODE) =3D=3D O_RDONLY) { - scsi_build_sense(resp->sense, SENSE_CODE(INVALID_OPCODE)); - sz =3D 0; - } else if (sz < PR_OUT_FIXED_PARAM_SIZE) { - /* Illegal request, Parameter list length error. This isn't f= atal; - * we have read the data, send an error without closing the so= cket. - */ - scsi_build_sense(resp->sense, SENSE_CODE(INVALID_PARAM_LEN)); - sz =3D 0; - } - if (sz =3D=3D 0) { - resp->result =3D CHECK_CONDITION; - close(client->fd); - client->fd =3D -1; - } } =20 req->fd =3D client->fd; @@ -785,25 +784,23 @@ static void coroutine_fn prh_co_entry(void *opaque) break; } =20 - if (sz > 0) { - num_active_sockets++; - if (req.cdb[0] =3D=3D PERSISTENT_RESERVE_OUT) { - r =3D do_pr_out(req.fd, req.cdb, resp.sense, - client->data, sz); - resp.sz =3D 0; - } else { - resp.sz =3D sizeof(client->data); - r =3D do_pr_in(req.fd, req.cdb, resp.sense, - client->data, &resp.sz); - resp.sz =3D MIN(resp.sz, sz); - } - num_active_sockets--; - close(req.fd); - if (r =3D=3D -1) { - break; - } - resp.result =3D r; + num_active_sockets++; + if (req.cdb[0] =3D=3D PERSISTENT_RESERVE_OUT) { + r =3D do_pr_out(req.fd, req.cdb, resp.sense, + client->data, sz); + resp.sz =3D 0; + } else { + resp.sz =3D sizeof(client->data); + r =3D do_pr_in(req.fd, req.cdb, resp.sense, + client->data, &resp.sz); + resp.sz =3D MIN(resp.sz, sz); + } + num_active_sockets--; + close(req.fd); + if (r =3D=3D -1) { + break; } + resp.result =3D r; =20 if (prh_write_response(client, &req, &resp, &local_err) < 0) { break; --=20 1.8.3.1