From patchwork Sat Jun 10 20:40:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Demi Marie Obenour X-Patchwork-Id: 106016 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1731830vqr; Sat, 10 Jun 2023 13:53:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ42znGmZnzknp9QZttnIEJrOf6H0izvtA+xadMX3lOfRKzv4fzmP0VhqiBd0aL9EisiH8yl X-Received: by 2002:a17:90a:b902:b0:255:2daa:4796 with SMTP id p2-20020a17090ab90200b002552daa4796mr4576482pjr.44.1686430406143; Sat, 10 Jun 2023 13:53:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686430406; cv=none; d=google.com; s=arc-20160816; b=ZE8Fvr0bQP1/AgofK0of5DFx+8WtBCQ+4AgIRMalkFtBv3kOxcApoMf1P2oe/FurDy 0w52ZM/1TydvyJVSRjsBnLLqLSEC2FhpsNorCn/qIvWijHNLJuA8j0S94vNyuyOhEVzl 63iJsA/khs30o9YvihbKWLDIDXe0T3Q/ZT0sC1AepUDmI4py8h53vjAJMREE3HA4UVvu GkM88h7KQAVH+p+O19en+4OgEgw4AYfD+Y0d1m8O5EOfwGbfe7BEEMhjCirSUPF74iMx O6GThx22ZWBOMUQTXdAbrd0NNHw941jE5KyBKWim6wEW7GLLRyAdaP+EWM0SGROkUnn1 Illg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pf2-20020a17090b1d8200b00244930ffe45si4907091pjb.0.2023.06.10.13.53.14; Sat, 10 Jun 2023 13:53:26 -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 S231698AbjFJUls (ORCPT + 99 others); Sat, 10 Jun 2023 16:41:48 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768350449424528787?= X-GMAIL-MSGID: =?utf-8?q?1768350449424528787?= 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