Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3751505rwd; Sat, 10 Jun 2023 14:08:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6m/eaGaRMslbKQV3pQQLBdtjyoCDLWf0Us3v2OMNyNsQM2Za2KfChhQl4FpOZ8R7f4EHVX X-Received: by 2002:a17:907:6d24:b0:97d:cda7:f09c with SMTP id sa36-20020a1709076d2400b0097dcda7f09cmr2947946ejc.16.1686431322871; Sat, 10 Jun 2023 14:08:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686431322; cv=none; d=google.com; s=arc-20160816; b=VWeqpz6dTmOMJJ5fZsfll7biIcZFJ+//4WMnxSs/Vz/OlDccpGZPUqr/1Xpos/UqR9 XOgJAhscifFAsRALEnYrUgmXw96FFsZazuuWrMyndoU5D/prpPsmt6oPxs00mXeH9seV dZYKyItSnmpz/dExEGjWmP/Qc3QHt+yolaGh6xVuCoNCGlGloTwOhL1D7y2dZAxt1Ooj /fAUDwnEgoDZDJJKu1mkHES7FDusQUISstFg2k5t3oUHgT4wzB5ZYFK4jal2X2Xh5ku0 TgJOFUIEDNsqxEfKZBMU10h9DpLnpsxj656raiTDmx2RpAeSlitS62LGB9Eqdih+xe2x Q+jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=1qqdCLnk8XZZUpiOqZUTKehWt/5RjR4FGu3vEMkB/ek=; b=i3oZBZ6vTXywHggTMEtiDbxBK+jS+IsyUCLVmYHMQqMmxh6i/RnwWvbCNNQaP6RjXu vdDSblsrjmQXEFJp7jKCjphSHs/3B8A9GeAOIEEAkVUdY9eSk5Xf1d4nYHOkx7ZxLreY DnEVaYV6MOMiOdkb4uMF9FlGGkNubVlO4MlL8LeZWPbwyNuMd50cC63AIl1gz0PrgMqS W2FhfYGzihILVG+FjK4KWZsfEtilq/lgVgWGSNe5ZkGWJ27NytM53mVM42aPRouOjEXF T6bNcMSQ301ZX0PqX0mBFn3OncgM6GOzHCbLq9zRljGljQk9b86voRu+Cb1tMh174d3x clYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@invisiblethingslab.com header.s=fm1 header.b=RNwmi56t; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=e1mOAh0x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u15-20020a170906950f00b00978acf8b44esi3088116ejx.707.2023.06.10.14.08.17; Sat, 10 Jun 2023 14:08:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@invisiblethingslab.com header.s=fm1 header.b=RNwmi56t; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=e1mOAh0x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230515AbjFJUlr (ORCPT + 99 others); Sat, 10 Jun 2023 16:41:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231156AbjFJUll (ORCPT ); Sat, 10 Jun 2023 16:41:41 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A77F33A9E; Sat, 10 Jun 2023 13:41:25 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id BC3FA32003F4; Sat, 10 Jun 2023 16:41:23 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Sat, 10 Jun 2023 16:41:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm1; t=1686429683; x=1686516083; bh=1qqdCLnk8X ZZUpiOqZUTKehWt/5RjR4FGu3vEMkB/ek=; b=RNwmi56tXuI4aB88VxWVJYjN5P Hw7IIvlioRJaQi72PlbFI1iAp/W+LJONn/SSjyoyfgXBQxQ0KA7W7Mc/KqThl2zb af8HmrPGpQtGd5GC+cOL3ZZ1SK6m5ZrWdVG8ihyzvV6gblHO/C7ZBXhAWREuWsck P/g4bx+3HxvTx6+/yDS2c5DBMMQFrL8GiOJhY5YudZtIlNTDo5KOoDHvYPEDONHZ F88JNfxJWhVbTrlVR/L2/pabGG7mxCdMlpxtpJBG+2Us+QaQYXB33WJPfePwC5GE HYQ82LY3dbImVJt0Rzh8ItSiO2PaLZocQKmv0t91vqNopAb+hirVaAjqVSxw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1686429683; x= 1686516083; bh=1qqdCLnk8XZZUpiOqZUTKehWt/5RjR4FGu3vEMkB/ek=; b=e 1mOAh0xXnK84ZU62LsR9vciVBb905DBIyIteDQ5rBbSwWerkYe1jAZAYBdrFYzWh m2vltF2suhspVwl1kvNwOYOEmLgTez3EoBzzaEzy0NDKiAnhO2dG/n16qg+LfJE3 Ft668WUWrvb/WZI83UP9j76y7XZbSFj6XDjsD02ZW+CmT65nGehwF0TIXGAI/WLs BiUNxC5ohQYin08dwphHgImXf+s6laXlgOPZWB5Mzs482WbPW4ilyswaqrDY2cXe 0IlaI2nVmKDzFENJfYkN6yLiJRrt2qq1DqnduA9nMIAk3AMNfUvmJruejW8eVrds /H3018pqeMwbr9tpnAUEg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgedutddgudehhecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeffvghm ihcuofgrrhhivgcuqfgsvghnohhurhcuoeguvghmihesihhnvhhishhisghlvghthhhinh hgshhlrggsrdgtohhmqeenucggtffrrghtthgvrhhnpeejffejgffgueegudevvdejkefg hefghffhffejteekleeufeffteffhfdtudehteenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpeguvghmihesihhnvhhishhisghlvghthhhinhhg shhlrggsrdgtohhm X-ME-Proxy: Feedback-ID: iac594737:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 10 Jun 2023 16:41:22 -0400 (EDT) From: Demi Marie Obenour To: Hans de Goede , Mauro Carvalho Chehab , Sakari Ailus , Greg Kroah-Hartman , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Lee Jones , Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Rasmus Villemoes Cc: Demi Marie Obenour , linux-media@vger.kernel.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Subject: [PATCH v3 4/4] Reject NUL bytes in xenstore nodes Date: Sat, 10 Jun 2023 16:40:44 -0400 Message-Id: <20230610204044.3653-5-demi@invisiblethingslab.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230610204044.3653-1-demi@invisiblethingslab.com> References: <20230610204044.3653-1-demi@invisiblethingslab.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This rejects bogus xenstore node values that include interior NUL bytes. These would be truncated by functions that expect NUL-terminated strings. Signed-off-by: Demi Marie Obenour --- drivers/xen/xenbus/xenbus_xs.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/xen/xenbus/xenbus_xs.c b/drivers/xen/xenbus/xenbus_xs.c index 12e02eb01f5991b31db451cc57037205359b347f..7cb2a22a7698ac40c81add23476594d9f27de8d0 100644 --- a/drivers/xen/xenbus/xenbus_xs.c +++ b/drivers/xen/xenbus/xenbus_xs.c @@ -569,16 +569,20 @@ int xenbus_scanf(struct xenbus_transaction t, const char *dir, const char *node, const char *fmt, ...) { va_list ap; - int ret; + int ret = 0; + unsigned int len; char *val; - val = xenbus_read(t, dir, node, NULL); + val = xenbus_read(t, dir, node, &len); if (IS_ERR(val)) return PTR_ERR(val); + if (strlen(val) != len) + goto bad; va_start(ap, fmt); ret = vsscanf(val, fmt, ap); va_end(ap); +bad: kfree(val); /* Distinctive errno. */ if (ret == 0) @@ -636,15 +640,18 @@ int xenbus_gather(struct xenbus_transaction t, const char *dir, ...) while (ret == 0 && (name = va_arg(ap, char *)) != NULL) { const char *fmt = va_arg(ap, char *); void *result = va_arg(ap, void *); + unsigned len; char *p; - p = xenbus_read(t, dir, name, NULL); + p = xenbus_read(t, dir, name, &len); if (IS_ERR(p)) { ret = PTR_ERR(p); break; } - if (fmt) { - if (sscanf(p, fmt, result) == 0) + if (strlen(p) != len) + ret = -EINVAL; + else if (fmt) { + if (sscanf(p, fmt, result) <= 0) ret = -EINVAL; kfree(p); } else -- Sincerely, Demi Marie Obenour (she/her/hers) Invisible Things Lab