[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v9 6/6] x86/boot: add cmdline to struct boot_domain


  • To: "Daniel P. Smith" <dpsmith@xxxxxxxxxxxxxxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jason Andryuk <jason.andryuk@xxxxxxx>
  • Date: Wed, 20 Nov 2024 17:32:06 -0500
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.12) smtp.rcpttodomain=apertussolutions.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=p8xm1btvpe9AmkygMgkrN7BtLT7Iickdu4+9Xrkjp0I=; b=bgYS91ljo+NcG/URBnu7Hpm0Qrd1Nb4dTd5wx7sXxihKLedaAqrL+Sl/l8+I1LM7IEMKLw8sb/H2IqqmQqgvG3Fll+5bXpbHhgJ4nj7p7JBw7jGhy0c8P5niNBkiY2yvB3RlrrX1r0rHOCkj4WD13yXnz3IiskkhFFw/XB7YgBzVltKsJTHyxIYNTWniszqnnCDA4hIcDlicuzWOXal4rAJNWBNxjZCXVlJGAa50p9fVhUpZoZTM9hPsmPOshp6Kc3dJai+E4AICZi/icRIjnTPWJ4Me2pULlRthy4iu77Oh0ZmHRxk4Vpf8e/BabWxOL4sKYtSA0Rj9N5vQtUpa9w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=TUSF7zT8VXdkWI5WN6i3dTRyW4jLbOViCPJ+lcHsup7npdEI6unR51Y/6W5Gr4/XUDuUaUZMuvnoxtLfTQFzbhzD6ZVxoXmJZhLtXeI6yoAUgxnj6G9pD8P8utMwcYboyV+kXK49h56VwCINDVRPUgGutXVBdjVl0oIJKUkCfNNrDFhMH+OvItuoQmtxRi5nusbRzUFNO5s7dCNc02yYbwQrxkHPfNHpB4q6+SL8djkZr21BqO6JNxvr1wHUHxQsnYVkzHWUkaaEvwtWM5oD6W4Iz0FDjtDE5JWsXXao3r9f8BfAXBot0IPVlWeBtcZGEieOPddF6r9K9QlHpl4XYQ==
  • Cc: <christopher.w.clark@xxxxxxxxx>, <stefano.stabellini@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Wed, 20 Nov 2024 22:32:32 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 2024-11-20 12:57, Daniel P. Smith wrote:
On 11/15/24 13:20, Jason Andryuk wrote:
On 2024-11-15 08:12, Daniel P. Smith wrote:>>
Just xmalloc_array since it'll be overwritten immediately?

Yes and no, the concern I was worried about is that the allocation may end up being slight bigger than what is copied in to the buffer. If we do not zero the buffer, then those trailing bytes will have random data in them. In a perfect world, nothing should ever reach those bytes based on the current usage of the buffer. But from my perspective, it would be safer to zero the buffer than rely on the world being perfect. I am not fixed on not switching, just providing my 2 cents,

I only looked at the PVH case, but strlen() is used there to obtain the copy length. I think it's unnecessary and the code doesn't require a zeroed buffer. But I also realize it's safer to start from zeroed.

+            panic("Error allocating cmdline buffer for %pd\n", d);
+
          if ( bd->kernel->cmdline_pa )
-            safe_strcpy(cmdline,
-                        cmdline_cook(__va(bd->kernel->cmdline_pa), bi->loader));
+            strlcpy(cmdline,
+                    cmdline_cook(__va(bd->kernel->cmdline_pa),bi- >loader),

Also I just noticed a missing space: "cmdline_pa),bi"

+                    cmdline_size);
          if ( bi->kextra )
              /* kextra always includes exactly one leading space. */
-            safe_strcat(cmdline, bi->kextra);
+            strlcat(cmdline, bi->kextra, cmdline_size);
          /* Append any extra parameters. */
          if ( skip_ioapic_setup && !strstr(cmdline, "noapic") )
-            safe_strcat(cmdline, " noapic");
+            strlcat(cmdline, " noapic", cmdline_size);
          if ( (strlen(acpi_param) == 0) && acpi_disabled )
          {
@@ -1028,17 +1055,21 @@ static struct domain *__init create_dom0(struct boot_info *bi)
          if ( (strlen(acpi_param) != 0) && !strstr(cmdline, "acpi=") )
          {
-            safe_strcat(cmdline, " acpi=");
-            safe_strcat(cmdline, acpi_param);
+            strlcat(cmdline, " acpi=", cmdline_size);
+            strlcat(cmdline, acpi_param, cmdline_size);
          }
-        bd->kernel->cmdline_pa = __pa(cmdline);
+        bd->cmdline = cmdline;
+        bd->kernel->cmdline_pa = __pa(bd->cmdline);

Should cmdline_pa go away if we now have a valid cmdline variable?

In the PVH dom0 case, we are still relying on cmdline_pa as the reference to get at the command line in the function pvh_load_kernel(). With the introduction of cmdline to boot_domain, I could convert the interface of pvh_load_kernel() to take the boot_domain instance, removing the need to update cmdline_pa. Not sure if you were asking this, but as for cmdline_pa going completely away, that is not possible. First the sequence of events do not allow it, and there is an one-off case for PVH dom0 where the cmdline_pa of the initrd module is copied into the domain.

I was thinking from this point forward only boot_domain->cmdline is necessary. Maybe even zero-ing cmdline_pa? With a valid pointer in cmdline, cmdline_pa shouldn't be necessary anymore.

Regards,
Jason



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.