From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id 8BBB75A028F for ; Tue, 23 May 2023 16:11:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684851113; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PAUaKLBcrl2+hhEDclOHPzeck7n2nJoghXk5GvZJ+gg=; b=YPclwCNNeo8cR0JwJnQo21yrDprY4qJ+Z9aoWYLOVVtqNot3HN1QAiT9wqTZcaHOq+cN6m gomvWez2vqFRth4eCKKYgFUjQQ338N8xzOxHLfbVumxXzOyleckbYMkMwF0GcBGnafVYB4 1FY5/CSk6ZwpqVORLifM40YfCvEX0Cc= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-272-CPZWv3cXN9mQ47okuIcElQ-1; Tue, 23 May 2023 10:11:51 -0400 X-MC-Unique: CPZWv3cXN9mQ47okuIcElQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5C7B72A59573; Tue, 23 May 2023 14:11:51 +0000 (UTC) Received: from elisabeth (unknown [10.39.208.35]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7624F40CFD47; Tue, 23 May 2023 14:11:50 +0000 (UTC) Date: Tue, 23 May 2023 16:11:48 +0200 From: Stefano Brivio To: passt-dev@passt.top Subject: Re: [PATCH v2 1/3] util, conf: Add and use ns_is_init() helper Message-ID: <20230523161148.0a029260@elisabeth> In-Reply-To: <20230522085205.2803560-2-sbrivio@redhat.com> References: <20230522085205.2803560-1-sbrivio@redhat.com> <20230522085205.2803560-2-sbrivio@redhat.com> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: XSK6P2MO7WV3MBQZYNN3VWLSS4Z4V4OS X-Message-ID-Hash: XSK6P2MO7WV3MBQZYNN3VWLSS4Z4V4OS X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Mon, 22 May 2023 10:52:03 +0200 Stefano Brivio wrote: > +bool ns_is_init(void) > +{ > + const char root_uid_map[] = " 0 0 4294967295\n"; > + char buf[sizeof(root_uid_map)]; > + bool ret = true; > + int fd; > + > + if ((fd = open("/proc/self/uid_map", O_RDONLY | O_CLOEXEC)) < 0) { > + die("Can't determine if we're in init namespace: %s", > + strerror(errno)); > + } > + > + if (read(fd, buf, sizeof(root_uid_map)) != sizeof(root_uid_map) - 1 || > + strncmp(buf, root_uid_map, sizeof(root_uid_map))) Oops, valgrind noticed I didn't actually initialise that extra byte at the end of 'buf'. Fixing this up as well before pushing... -- Stefano