From owner-svn-src-head@freebsd.org Fri Dec 6 09:40:43 2019 Return-Path: Delivered-To: svn-src-head@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 A7D391C74AE for ; Fri, 6 Dec 2019 09:40:43 +0000 (UTC) (envelope-from steven@multiplay.co.uk) Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) server-signature RSA-PSS (4096 bits) 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 47TndQ5s7mz4Dly for ; Fri, 6 Dec 2019 09:40:42 +0000 (UTC) (envelope-from steven@multiplay.co.uk) Received: by mail-io1-xd35.google.com with SMTP id u7so6712500iop.5 for ; Fri, 06 Dec 2019 01:40:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=multiplay-co-uk.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=KmALm3fGagqIjHhe215DLoZ5+2NZeaFu7dFRYKUj7xk=; b=zmeJ/URJkipaHCEy7qxLxXu0aC836B/ErA6RMYDX3Spi8pSiduFNgFqwHOiNDb5yPq 99t3tNdXORNPRNsdoetA0N9SbcD7TI9K3mtdap7d2kEaxdz7mGf/YoyhEM8AAPzaYD31 nCAJdGpVE7RvIoa6jdWHpEtbovS5d3EDfc+cDPnBc9RF9jQohpSzzo271PwWhmsGT0zs kkt9ouPdQ/P9VaD1DNE4W8IOZnTMj49Vx9vd7PfCgB/DB7nAv4vH0YRFHvcjs35FLVco qaRP9FhV9qdfBQEUIEk0gcBN77AUHf+CBfUc4ZtWio3Yq/QP8+K/7ydPOhz/zBEAI2YU mJUA== 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=KmALm3fGagqIjHhe215DLoZ5+2NZeaFu7dFRYKUj7xk=; b=Q3pMjSq3GcX8kwlnQ0FHSr8URiTu7UiYv4zLXYQNuznV8BwYX1X81JIe0vvsBcG60s XDsocHoobFhXIx/NpOsFtRX2LXQYVWeR7VeuzkmUziQYSZIJc2ObwlMSMmvR0YtsgWkJ 5LYYjAXAAlR2XH1ApDHndAPFSVmc9+Ogow94a14Cc2FQjeo5fVFgeq5t6I8XFsNRK7VY o7jcRccyGc0oPZLOuRaMJTIXgukSeqxCluGaaN4pZTfqsiuWLkiDgPaZFKkKGS4MGt2p 2+fkN2+yahX+hGxc7AqD/kdG+nAvaxCpAlZ4ilngjObysLqC2MaYUaeQMtelNiUCVg19 SqhQ== X-Gm-Message-State: APjAAAV9Qd+rFyvvIF1oVyK/6cRHGl4NyAnIKEZPDTPM7PF5c33NDEAg nag9vbD1r2Nl5Yx9xb8NXVNsOosdIzNkRLR1KqrcCg== X-Google-Smtp-Source: APXvYqwh9PMcRzby9DEZN35LYY5gZCYo22qLKws3sntaOv7M9cCYH8gne3USEPu2L1h8EhQPjzlcIVapgT8WYsX/TuY= X-Received: by 2002:a5d:88c9:: with SMTP id i9mr10275977iol.225.1575625241109; Fri, 06 Dec 2019 01:40:41 -0800 (PST) MIME-Version: 1.0 References: <201912060006.xB6066qR058963@repo.freebsd.org> In-Reply-To: <201912060006.xB6066qR058963@repo.freebsd.org> From: Steven Hartland Date: Fri, 6 Dec 2019 09:40:29 +0000 Message-ID: Subject: Re: svn commit: r355430 - head/sys/cam/scsi To: Alan Somers Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-Rspamd-Queue-Id: 47TndQ5s7mz4Dly X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=multiplay-co-uk.20150623.gappssmtp.com header.s=20150623 header.b=zmeJ/URJ; dmarc=pass (policy=none) header.from=multiplay.co.uk; spf=pass (mx1.freebsd.org: domain of steven@multiplay.co.uk designates 2607:f8b0:4864:20::d35 as permitted sender) smtp.mailfrom=steven@multiplay.co.uk X-Spamd-Result: default: False [-3.85 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; R_DKIM_ALLOW(-0.20)[multiplay-co-uk.20150623.gappssmtp.com:s=20150623]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; PREVIOUSLY_DELIVERED(0.00)[svn-src-head@freebsd.org]; TO_DN_SOME(0.00)[]; URI_COUNT_ODD(1.00)[3]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_TRACE(0.00)[multiplay-co-uk.20150623.gappssmtp.com:+]; DMARC_POLICY_ALLOW(-0.50)[multiplay.co.uk,none]; RCVD_IN_DNSWL_NONE(0.00)[5.3.d.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.4.6.8.4.0.b.8.f.7.0.6.2.list.dnswl.org : 127.0.5.0]; FORGED_SENDER(0.30)[steven.hartland@multiplay.co.uk,steven@multiplay.co.uk]; MIME_TRACE(0.00)[0:+,1:+,2:~]; IP_SCORE(-2.15)[ip: (-6.54), ipnet: 2607:f8b0::/32(-2.23), asn: 15169(-1.93), country: US(-0.05)]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; FROM_NEQ_ENVFROM(0.00)[steven.hartland@multiplay.co.uk,steven@multiplay.co.uk]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2] Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Dec 2019 09:40:43 -0000 If the illegal chars where removed or replaced would the result be useful, if so might that be a better approach? On Fri, 6 Dec 2019 at 00:06, Alan Somers wrote: > Author: asomers > Date: Fri Dec 6 00:06:05 2019 > New Revision: 355430 > URL: https://svnweb.freebsd.org/changeset/base/355430 > > Log: > ses: sanitize illegal strings in SES element descriptors > > The SES4r3 standard requires that element descriptors may only contain > ASCII > characters in the range 0x20 to 0x7e. Some SuperMicro expanders violate > that rule. This patch adds a sanity check to ses(4). Descriptors in > violation will be replaced by "". > > This patch fixes "sesutil --libxo xml" on such systems. Previously it > would > generate non-well-formed XML output. > > PR: 241929 > Reviewed by: allanjude > MFC after: 2 weeks > Sponsored by: Axcient > > Modified: > head/sys/cam/scsi/scsi_enc_ses.c > > Modified: head/sys/cam/scsi/scsi_enc_ses.c > > ============================================================================== > --- head/sys/cam/scsi/scsi_enc_ses.c Thu Dec 5 19:39:51 2019 > (r355429) > +++ head/sys/cam/scsi/scsi_enc_ses.c Fri Dec 6 00:06:05 2019 > (r355430) > @@ -110,7 +110,7 @@ typedef struct ses_addl_status { > typedef struct ses_element { > uint8_t eip; /* eip bit is set */ > uint16_t descr_len; /* length of the descriptor */ > - char *descr; /* descriptor for this object */ > + const char *descr; /* descriptor for this object */ > struct ses_addl_status addl; /* additional status info */ > } ses_element_t; > > @@ -1977,6 +1977,35 @@ ses_publish_cache(enc_softc_t *enc, struct > enc_fsm_sta > return (0); > } > > +/* > + * \brief Sanitize an element descriptor > + * > + * The SES4r3 standard, sections 3.1.2 and 6.1.10, specifies that element > + * descriptors may only contain ASCII characters in the range 0x20 to > 0x7e. > + * But some vendors violate that rule. Ensure that we only expose > compliant > + * descriptors to userland. > + * > + * \param desc SES element descriptor as reported by the hardware > + * \param len Length of desc in bytes, not necessarily including > + * trailing NUL. It will be modified if desc is > invalid. > + */ > +static const char* > +ses_sanitize_elm_desc(const char *desc, uint16_t *len) > +{ > + const char *invalid = ""; > + int i; > + > + for (i = 0; i < *len; i++) { > + if (desc[i] < 0x20 || desc[i] > 0x7e) { > + *len = strlen(invalid); > + return (invalid); > + } else if (desc[i] == 0) { > + break; > + } > + } > + return (desc); > +} > + > /** > * \brief Parse the descriptors for each object. > * > @@ -2061,7 +2090,8 @@ ses_process_elm_descs(enc_softc_t *enc, struct > enc_fsm > if (length > 0) { > elmpriv = element->elm_private; > elmpriv->descr_len = length; > - elmpriv->descr = &buf[offset]; > + elmpriv->descr = > ses_sanitize_elm_desc(&buf[offset], > + &elmpriv->descr_len); > } > > /* skip over the descriptor itself */ >