Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2902232rwd; Fri, 9 Jun 2023 20:21:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Dw3GsAI7sUgdynB33JLQnHDalu4t9qa61AgRCVo8+fzhjulK8lT9ePw/+VXyliTLIPzS6 X-Received: by 2002:a17:90a:5c:b0:259:12b2:84ef with SMTP id 28-20020a17090a005c00b0025912b284efmr4168733pjb.13.1686367314472; Fri, 09 Jun 2023 20:21:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686367314; cv=none; d=google.com; s=arc-20160816; b=UD1Pocq64Equdk2U2bvGXhktgG+HYVqOY7hKDuYnzjW75GpjglfYnlXBnEN3yoXSfc Vy4qmPKfHTiUIRxM2Iq08VAlVplj/FNCb2/WtGUXTd3i7rieTiu73fC9DAz+cwd+mZUF Sl/c9YENXp1/TbQXI+SI6T6RcCaxbT9edCzP6l74p/MX0Mqy5MW8ec/3w+jZZxe32Ean v1pR2IAY+6k9iud3ZrNibTfPN3C8uz4Tt5XBNhuFpcFjE8+/wBrb3e2GH34rcMZ+nh2Z 79D1oYtKA7CQ7+tV86LAGFRA0y33ctHcQrGYIzTrqfo7iQxPIoe5ey6TVMQqHLcLwpdF UDaQ== 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=9jx1BPUbfcVgExhjQbchVzVzEh8/1tbELFoG8PhPivY=; b=uisxLitVmNwzffJ2mrWogjgXHK6BjI3kO4A6a8PyJrDx9jTRApB1Yk2HyxUQ5T97QE +dyqyfAdGQFQrlWPG6ZclPgZiNYjtiqmz44c3FfSQ/qWekcst0XFAAeOHXTvBWJmQmOl Uu8CUA3V7b+HLcriRMo/fq7uR1Bnndlvv+S/f8yFMk3HMwLmv1jN+5q1h3qouDK/LP9x GPMPtNUdYGariFltgC1UlDXsHXsjzEE1mGkDHYLCm5CvATIykCXYM9hV8OcRfdYVOikN WR7Cn/M1M55ZVW2/CRiM/d0pmujm0QKIsE1askGN3hdHJxr9TuIpPUlgZ82ikPsXPD2J qwzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@invisiblethingslab.com header.s=fm1 header.b=KzDj4AYY; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=ZvSpafDB; 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 ng17-20020a17090b1a9100b0025645cd3909si3693272pjb.161.2023.06.09.20.21.42; Fri, 09 Jun 2023 20:21:54 -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=KzDj4AYY; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=ZvSpafDB; 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 S233342AbjFJC7p (ORCPT + 99 others); Fri, 9 Jun 2023 22:59:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233051AbjFJC7m (ORCPT ); Fri, 9 Jun 2023 22:59:42 -0400 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F259830D6; Fri, 9 Jun 2023 19:59:41 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 6E1B05C01A3; Fri, 9 Jun 2023 22:59:41 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Fri, 09 Jun 2023 22:59:41 -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=1686365981; x=1686452381; bh=9jx1BPUbfc VgExhjQbchVzVzEh8/1tbELFoG8PhPivY=; b=KzDj4AYYzePpimX6H5wkYZwkks NHGbQDu8jIRMdcSSSgF3b3PCmK7D2vOotKxA1DfVlTP2e08oG9cNjOaC0kyc2A/A Woeqakefd0epg23qLeX6igy3kxTwzSX6HLFhahqzHc+vqvIKm4sAeWi9aoNSXRR6 wCI5HfGLfst2I2vTH2hIA7ZxZ26JHuWYOCEEPQPqUdH0cH2Rrtx60UFtXGXkXHdo oHHe5NzrKGAz0eOgRzDoxWrkDYMlWiOGDPj/JZbnnXGfaI+2MtyHouaGMcEBMaZV jdSrar5Q0z3nIwuLL3W3Xx2b6XH6XjVb12K0C8yZS0BhFD3XVFZWGvJ79QUg== 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=1686365981; x= 1686452381; bh=9jx1BPUbfcVgExhjQbchVzVzEh8/1tbELFoG8PhPivY=; b=Z vSpafDBLwDL8H2CTo8lfIfv0lBZ6g4SdgNNNWgwt9+71cFO74vFRkfX5OQ0eun+2 V9U7u1FWaanTOidIYHn+FaDRXl+fpQTdsWaByWb8JDChI4RHKW0Er7WreEW70XSH F7ovWDNSgioIcLiDVSE1DlAfe687KvI/kOFQUYI5cJrhQ5FVuqQj+0k+MXIqK2ZF 5YIcEJ5iqfquW6njaZXeLisvjATivHd3InKEgpO6av2xMmSPYJ9xVUx7M/y8yarE v1ZhBTL4ViFGSyXf3rk89tTMCKeP0BpWjJ6L5NGJkGZn6HsrPPsYg/Mr1c8kHU06 REVYBioVQJyWfzr6tnZjw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgedtledgieegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepffgvmhhi ucforghrihgvucfqsggvnhhouhhruceouggvmhhisehinhhvihhsihgslhgvthhhihhngh hslhgrsgdrtghomheqnecuggftrfgrthhtvghrnhepjeffjefggfeugeduvedvjeekgfeh gffhhfffjeetkeelueefffetfffhtdduheetnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepuggvmhhisehinhhvihhsihgslhgvthhhihhnghhs lhgrsgdrtghomh X-ME-Proxy: Feedback-ID: iac594737:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 9 Jun 2023 22:59:40 -0400 (EDT) From: Demi Marie Obenour To: Dwaipayan Ray , Lukas Bulwahn , Joe Perches , Jonathan Corbet , Federico Vaga , 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-doc@vger.kernel.org, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Subject: [PATCH 4/4] Strict XenStore entry parsing Date: Fri, 9 Jun 2023 22:57:59 -0400 Message-Id: <20230610025759.1813-4-demi@invisiblethingslab.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230610025759.1813-1-demi@invisiblethingslab.com> References: <20230610025759.1813-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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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 uses the newly-introduced strict version of sscanf(). Signed-off-by: Demi Marie Obenour --- drivers/xen/xenbus/xenbus_xs.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/xen/xenbus/xenbus_xs.c b/drivers/xen/xenbus/xenbus_xs.c index 12e02eb01f5991b31db451cc57037205359b347f..88e94269c9221d16d1a97e59399058e870675729 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); + ret = vsscanf_strict(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_strict(p, fmt, result) <= 0) ret = -EINVAL; kfree(p); } else -- Sincerely, Demi Marie Obenour (she/her/hers) Invisible Things Lab