From nobody Mon Apr 29 18:22:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1627556831; cv=none; d=zohomail.com; s=zohoarc; b=nVZE2yjN/O0rm0LWj4yYvjSr1OlsJlmEboxQ0fsildxF1udFFQIL7BhvSu1bp1Z67eg78itIeGJrt1Btg1xJ4h2XZuqn7/iuvHFvBSCiaw13S9y+CCPDwtWGAgQ8uM90j2hDz/4JbfTv3XKFfISnN2+2CEJjWSokuBVwJ7TWVcY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1627556831; h=Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To; bh=9cjgZZnC+CjNZwAhAzGV3zUaO4AAHfmbwNPumDCV3o4=; b=ablq0Nx3gfRWw+QPJrqjWzdgrK9a5L2C69NWkZ41BoLucPxWFCH+4UzBa8kgK8HfaTqIy1rjG5HU3BhsCmxDWkggXuBLdO8yx1v2QjGFSJKCnsFsZiO/FqsgV83i1o2ODtnEjbs680ZYnEkux9kzQG0uqdincb1XLIRgti5xqA8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1627556831956850.7951334858894; Thu, 29 Jul 2021 04:07:11 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.161903.297094 (Exim 4.92) (envelope-from ) id 1m93sP-00029A-8P; Thu, 29 Jul 2021 11:06:57 +0000 Received: by outflank-mailman (output) from mailman id 161903.297094; Thu, 29 Jul 2021 11:06:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1m93sP-000293-54; Thu, 29 Jul 2021 11:06:57 +0000 Received: by outflank-mailman (input) for mailman id 161903; Thu, 29 Jul 2021 11:06:55 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1m93sN-00028t-Cu for xen-devel@lists.xenproject.org; Thu, 29 Jul 2021 11:06:55 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1m93sM-0004vm-OW; Thu, 29 Jul 2021 11:06:54 +0000 Received: from 54-240-197-235.amazon.com ([54.240.197.235] helo=ufe34d9ed68d054.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m93sM-0006OX-FT; Thu, 29 Jul 2021 11:06:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Message-Id:Date:Subject:Cc:To:From; bh=9cjgZZnC+CjNZwAhAzGV3zUaO4AAHfmbwNPumDCV3o4=; b=j6Dgly8XOB/Pf8F23GKD7B3X/p XvW8vrQhnShAqewJk7w84qdrAzhBXXWIlA1h2fyHS+vssbDs1xGhYFt+CVebPBDXXLowa6ynrVAky KKlfMLWqv5p3xqfgxd8lS09A+kHsTS1ie03qDE1I9J2XMeJsLrUVQNqrU17PzvGvmhQU=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Ian Jackson , Wei Liu , Juergen Gross Subject: [PATCH] tools/xenstored: Don't assume errno will not be overwritten in lu_arch() Date: Thu, 29 Jul 2021 12:06:47 +0100 Message-Id: <20210729110647.25500-1-julien@xen.org> X-Mailer: git-send-email 2.17.1 X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1627556833576100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Julien Grall At the moment, do_control_lu() will set errno to 0 before calling lu_arch() and then check errno. The expectation is nothing in lu_arch() will change the value unless there is an error. However, per errno(3), a function that succeeds is allowed to change errno. In fact, syslog() will overwrite errno if the logs are rotated at the time it is called. To prevent any further issue, errno is now always set before returning NULL. Additionally, errno is only checked when returning NULL so the client can see the error message if there is any. Reported-by: Michael Kurth Signed-off-by: Julien Grall Reviewed-by: Juergen Gross --- tools/xenstore/xenstored_control.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_= control.c index 6b68b79faac7..6fcb42095b59 100644 --- a/tools/xenstore/xenstored_control.c +++ b/tools/xenstore/xenstored_control.c @@ -324,6 +324,7 @@ static const char *lu_binary_alloc(const void *ctx, str= uct connection *conn, lu_status->kernel_size =3D size; lu_status->kernel_off =3D 0; =20 + errno =3D 0; return NULL; } =20 @@ -339,6 +340,7 @@ static const char *lu_binary_save(const void *ctx, stru= ct connection *conn, memcpy(lu_status->kernel + lu_status->kernel_off, data, size); lu_status->kernel_off +=3D size; =20 + errno =3D 0; return NULL; } =20 @@ -798,9 +800,8 @@ static int do_control_lu(void *ctx, struct connection *= conn, if (!ret) return errno; } else { - errno =3D 0; ret =3D lu_arch(ctx, conn, vec, num); - if (errno) + if (!ret && errno) return errno; } =20 --=20 2.17.1