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 21C0A5A004C for ; Fri, 24 May 2024 19:39:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716572397; 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=1mgu2Y48klNF+izwQDS2qL7WEQQuen8A/8daE2+IFUM=; b=RGjzqvBJunKaY+I1FxZevuCOAOY+xf1lCwhjKKMMr1UNmctx0lixRG9Wgycl7UgA396avp iyALXXFSm3udKgKMRnd3ASdZKvfCGW06Gj6mqZoXD0U4o2u3IpTyppoxM3uXJLsM5KTqlK pd7kZAFnEmYCSNyCf3KexKpyk529Uxg= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-196-AEb-UO9wNai71GSkuAbfiA-1; Fri, 24 May 2024 13:39:55 -0400 X-MC-Unique: AEb-UO9wNai71GSkuAbfiA-1 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a5a812308daso185287466b.0 for ; Fri, 24 May 2024 10:39:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716572393; x=1717177193; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=1mgu2Y48klNF+izwQDS2qL7WEQQuen8A/8daE2+IFUM=; b=LO01uSqa4Q2ilF/FuJgdh+rcw0WEAj/CmvxVWtrtO4b8Noji7l4A03s/lC6u4bHoyO wFQ0ggQ/jS2yBF74WjzgzAZ0D8y/CUlKGH8yZSYnMidW6GsH9wkcY1NkR4/yAmKRlH7a wU+2uuJVQwhxt9vgE8snk2H2SD6GxpnLZeVSlrfmTmdTTn700k5E6HL+lB2nxBu0Mown B9ab9Of9E42GAKxnAWSuGLlwrNInthViX1zPhkxd2BwlPeoocgOrsIYJoWCuOQoPkpEs MB0deJreDjWuBESae4EwTOIJHDEAQksE07enf/Xkldnw4AoERkicfzYo8ruMAxAObMHU aMGw== X-Gm-Message-State: AOJu0YwWNrxu+XZrwLAVCOuuO5ILEyzW4sy9TXy13JDfMN3bRd1zZ4aC vybEWU3xxMknC4Fv1PjFbuMm8OZJHflqFfgd5U3+dB0jWj3ZmL5jJN9KdftPM15QsSHhnYjQAkO 777sDefCtlNMnv/a++r6UATcB1mSOeKLfsySY01rBEDnTtWIF0Zx8bgIOJqcH X-Received: by 2002:a17:907:1303:b0:a59:cdc9:6fd9 with SMTP id a640c23a62f3a-a62641deb6cmr164454566b.21.1716572393494; Fri, 24 May 2024 10:39:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFsKx4KFmBa5jrLRHJvIm2InswFSlhK0DJH7yf1B0a0ukuPFhp9JaCoxFZfMIQ6M5UmtA5yEA== X-Received: by 2002:a17:907:1303:b0:a59:cdc9:6fd9 with SMTP id a640c23a62f3a-a62641deb6cmr164452966b.21.1716572392873; Fri, 24 May 2024 10:39:52 -0700 (PDT) Received: from maya.cloud.tilaa.com (maya.cloud.tilaa.com. [164.138.29.33]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a626c81773bsm158756666b.30.2024.05.24.10.39.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2024 10:39:52 -0700 (PDT) Date: Fri, 24 May 2024 19:39:18 +0200 From: Stefano Brivio To: Danish Prakash Subject: Re: [PATCH] pasta.c: modify hostname when detaching new namespace Message-ID: <20240524193918.151fd2fc@elisabeth> In-Reply-To: <20240524124903.2004-1-contact@danishpraka.sh> References: <20240520083650.12032-1-contact@danishpraka.sh> <20240524124903.2004-1-contact@danishpraka.sh> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.36; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: M6JCXITNBJZ4QM2MWWR7XZEKW3SKW7C5 X-Message-ID-Hash: M6JCXITNBJZ4QM2MWWR7XZEKW3SKW7C5 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: passt-dev@passt.top 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 Fri, 24 May 2024 18:18:53 +0530 Danish Prakash wrote: > When invoking pasta without any arguments, it's difficult > to tell whether we are in the new namespace or not leaving > users a bit confused. This change modifies the host namespace > to add a prefix "pasta-" to make it a bit more obvious. > > Signed-off-by: Danish Prakash > --- > pasta.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/pasta.c b/pasta.c > index 31e1e00..90afd74 100644 > --- a/pasta.c > +++ b/pasta.c > @@ -50,6 +50,8 @@ > #include "netlink.h" > #include "log.h" > > +#define HOSTNAME_PREFIX "pasta-" > + > /* PID of child, in case we created a namespace */ > int pasta_child_pid; > > @@ -178,6 +180,7 @@ struct pasta_spawn_cmd_arg { > */ > static int pasta_spawn_cmd(void *arg) > { > + char hostname[HOST_NAME_MAX + 1] = HOSTNAME_PREFIX; > const struct pasta_spawn_cmd_arg *a; > sigset_t set; > > @@ -188,6 +191,12 @@ static int pasta_spawn_cmd(void *arg) > if (write_file("/proc/sys/net/ipv4/ping_group_range", "0 0")) > warn("Cannot set ping_group_range, ICMP requests might fail"); > > + if (!gethostname(hostname + sizeof(HOSTNAME_PREFIX) - 1, HOST_NAME_MAX + 1 - sizeof(HOSTNAME_PREFIX)) || Following the Linux kernel coding style also means we try to stick into 80 columns where possible: https://www.kernel.org/doc/html/latest/process/coding-style.html#breaking-long-lines-and-strings ...so there was a reason why I proposed this line like I did, with the line splits. These subtleties, I can also fix them up on merge. > + errno == ENAMETOOLONG ) { Excess whitespace between ENAMETOOLONG and ). Same here, I would fix this up on merge. > + if (sethostname(hostname, strlen(hostname))) So, I mentioned before that you don't really need to set a NULL terminating byte for sethostname() itself, because it takes a length. But strlen() needs it. If gethostname() truncated the hostname, according to POSIX, it's unspecified whether we'll have a NULL byte at the end of 'hostname', and strlen() would read out-of-bounds, past the end of 'hostname'. That's not an issue with glibc, but if POSIX says it's not guaranteed, we shouldn't take anything for granted. I would suggest that you simply add a NULL byte at HOST_NAME_MAX, unconditionally, that should cover the normal case as well as the ENAMETOOLONG case. I haven't tested this by the way. > + warn("Unable to set pasta-prefixed hostname"); > + } > + > /* Wait for the parent to be ready: see main() */ > sigemptyset(&set); > sigaddset(&set, SIGUSR1); -- Stefano