Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3847593pxj; Tue, 15 Jun 2021 09:54:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3AO2ZJuGHL4De23AGVm4mCmhT7Nj/zftqvKY40qvpzZ3coBF/1EZJ34NIsqliaXkWfiBS X-Received: by 2002:a05:6402:11cc:: with SMTP id j12mr556141edw.114.1623776060745; Tue, 15 Jun 2021 09:54:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623776060; cv=none; d=google.com; s=arc-20160816; b=ti5WRKhuv63V57fiwWKdKFmNYTfSYzFW6owKnEQrWDdEH7q+KCDi0G+T8VuqCI/MzW LtkPl1vkTm9YHqDoEgRPPXIIovoyAeqcwy9q7zOjYmLcGAB8wMF7I4+l2NwWB+j4jcTn 3Hd9mcvhXejYSCXWTIk8cPUZRiHMggfPu5pJNh1Vskt4zZ61MYFPrFZK94J5deRSsSC0 Pvt7GIo0GHe59xBPHXQILl+PV+BPP3NEOURJcBpRXMD6V/KqDgZAmhGmuh/ylxY+9lLx 3zZCXu4McjtNO51TSMyZo0XTlFYVeWtXJvVgKRn0pB0WXKUQpEYegiECPy9ubV/T5q4N fVKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=TdsZ4DlmZMWp7IIX24/wJw3Spb9c4r2beuPMEL4JlFA=; b=zA9d79jr2NCu1b9caaqcBAmmPrIQeqbSM7suWhS6xjox4OZy5lUvutFHBKaJcACMdz 8WXjPRdCgj+eFg0CmxD8BvfkAhTYMsBGXzbavr9RpUAgumIgAU2BEwJ+ZCL+b2CIJh5P LSCR2FhkoUv6LJVOQzatxpbEMbInC83aEwAyzfbR4jeS6Hy2L4/011ejrm/0TDDWgTOM CmFUNwewaeoyxxpLFWpSPNVd/AhTT0BjDzss8B/x7PCNCIqyQWAsd8cr+u/DAopYem6w u1ijlT6avqk3IyKdj8JkYkJYTCkOb2dy5JTDIIYYsUQ9So1ufodmvHICy5/7vsgERnLA xWbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chrisdown.name header.s=google header.b=ZbCQEokp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chrisdown.name Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c17si6351385ejc.223.2021.06.15.09.53.57; Tue, 15 Jun 2021 09:54:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chrisdown.name header.s=google header.b=ZbCQEokp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chrisdown.name Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230084AbhFOQyx (ORCPT + 99 others); Tue, 15 Jun 2021 12:54:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229734AbhFOQyw (ORCPT ); Tue, 15 Jun 2021 12:54:52 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39A26C061574 for ; Tue, 15 Jun 2021 09:52:48 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id b205so9836464wmb.3 for ; Tue, 15 Jun 2021 09:52:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=TdsZ4DlmZMWp7IIX24/wJw3Spb9c4r2beuPMEL4JlFA=; b=ZbCQEokp5V6qt+imbaiPM+2G3xigia6lDuXitL+Vh80IWHXNB/FS4cVR4pbP3/eWAU +VwrAXRAsl4vzm0bvBMfgULQAh9KDmVshiYpXW4VpL9bEwSwtMMYs6lB4ekFRPGZ5/TN LBr1EVC+qQ7h2AZEFGqaJmVNOJtsAZDi/86fs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=TdsZ4DlmZMWp7IIX24/wJw3Spb9c4r2beuPMEL4JlFA=; b=VS86QLcABq2ABrWNu/cASLyIik7KvpmYxsJeteKiQrsRGwbwhsGUqc2qXTs/ms4iUO SDhXuNWjnQBfYU5tTNu5qsGq9amYH2bxJj/UClxX3P/XckoIpCTa4M4QYS1zA/G1xaVF w9+06nTU+WVathRBxdEzugaGDkDHJQuZlpF+IlRjzxQAm7/RPxQGvapiaLUkuPbywroj rIJeQN9WsojPsJ6kyLjjd9REHF9wxmfi/RjXeyCwKTzc63A87BIVnzAzp+0iv4ZGUbYk oMkiQ0dhqHLGqZbLkAgiG91gZnUgCnKURYs8HGcyZWYPbZkGDG/4/O04DdjPydgDDLdO 201Q== X-Gm-Message-State: AOAM532puq8eNsoJkHqomrUvAM5+ItZI1C3CZMbtoNdkPpxjQhvNVDwV QcwgUmLU2poAwin3doE+pUmioyv6rZLZP0lUvWw= X-Received: by 2002:a1c:1f54:: with SMTP id f81mr215760wmf.121.1623775966461; Tue, 15 Jun 2021 09:52:46 -0700 (PDT) Received: from localhost ([2a01:4b00:8432:8a00:63de:dd93:20be:f460]) by smtp.gmail.com with ESMTPSA id z10sm13581734wmp.39.2021.06.15.09.52.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 09:52:46 -0700 (PDT) Date: Tue, 15 Jun 2021 17:52:45 +0100 From: Chris Down To: linux-kernel@vger.kernel.org Cc: Petr Mladek , Jessica Yu , Sergey Senozhatsky , John Ogness , Steven Rostedt , Greg Kroah-Hartman , Johannes Weiner , Kees Cook , Andy Shevchenko , Rasmus Villemoes , kernel-team@fb.com Subject: [PATCH v7 1/5] string_helpers: Escape double quotes in escape_special Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.1 (4b100969) (2021-06-12) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From an abstract point of view, escape_special's counterpart, unescape_special, already handles the unescaping of blackslashed double quote sequences. As a more practical example, printk indexing is an example case where this is already practically useful. Compare an example with `ESCAPE_SPECIAL | ESCAPE_SPACE`, with quotes not escaped: [root@ktst ~]# grep drivers/pci/pci-stub.c:69 /sys/kernel/debug/printk/index/vmlinux <4> drivers/pci/pci-stub.c:69 pci_stub_init "pci-stub: invalid ID string "%s"\n" ...and the same after this patch: [root@ktst ~]# grep drivers/pci/pci-stub.c:69 /sys/kernel/debug/printk/index/vmlinux <4> drivers/pci/pci-stub.c:69 pci_stub_init "pci-stub: invalid ID string \"%s\"\n" One can of course, alternatively, use ESCAPE_APPEND with a quote in @only, but without this patch quotes are coerced into hex or octal which can hurt readability quite significantly. I've checked uses of ESCAPE_SPECIAL and %pE across the codebase, and I'm pretty confident that this shouldn't affect any stable interfaces. Signed-off-by: Chris Down Reviewed-by: Andy Shevchenko Reviewed-by: Petr Mladek Cc: Rasmus Villemoes --- lib/string_helpers.c | 4 ++++ lib/test-string_helpers.c | 14 +++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/string_helpers.c b/lib/string_helpers.c index 5a35c7e16e96..3806a52ce697 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c @@ -361,6 +361,9 @@ static bool escape_special(unsigned char c, char **dst, char *end) case '\e': to = 'e'; break; + case '"': + to = '"'; + break; default: return false; } @@ -474,6 +477,7 @@ static bool escape_hex(unsigned char c, char **dst, char *end) * '\t' - horizontal tab * '\v' - vertical tab * %ESCAPE_SPECIAL: + * '\"' - double quote * '\\' - backslash * '\a' - alert (BEL) * '\e' - escape diff --git a/lib/test-string_helpers.c b/lib/test-string_helpers.c index 2185d71704f0..437d8e6b7cb1 100644 --- a/lib/test-string_helpers.c +++ b/lib/test-string_helpers.c @@ -140,13 +140,13 @@ static const struct test_string_2 escape0[] __initconst = {{ },{ .in = "\\h\\\"\a\e\\", .s1 = {{ - .out = "\\\\h\\\\\"\\a\\e\\\\", + .out = "\\\\h\\\\\\\"\\a\\e\\\\", .flags = ESCAPE_SPECIAL, },{ - .out = "\\\\\\150\\\\\\042\\a\\e\\\\", + .out = "\\\\\\150\\\\\\\"\\a\\e\\\\", .flags = ESCAPE_SPECIAL | ESCAPE_OCTAL, },{ - .out = "\\\\\\x68\\\\\\x22\\a\\e\\\\", + .out = "\\\\\\x68\\\\\\\"\\a\\e\\\\", .flags = ESCAPE_SPECIAL | ESCAPE_HEX, },{ /* terminator */ @@ -157,10 +157,10 @@ static const struct test_string_2 escape0[] __initconst = {{ .out = "\eb \\C\007\"\x90\\r]", .flags = ESCAPE_SPACE, },{ - .out = "\\eb \\\\C\\a\"\x90\r]", + .out = "\\eb \\\\C\\a\\\"\x90\r]", .flags = ESCAPE_SPECIAL, },{ - .out = "\\eb \\\\C\\a\"\x90\\r]", + .out = "\\eb \\\\C\\a\\\"\x90\\r]", .flags = ESCAPE_SPACE | ESCAPE_SPECIAL, },{ .out = "\\033\\142\\040\\134\\103\\007\\042\\220\\015\\135", @@ -169,10 +169,10 @@ static const struct test_string_2 escape0[] __initconst = {{ .out = "\\033\\142\\040\\134\\103\\007\\042\\220\\r\\135", .flags = ESCAPE_SPACE | ESCAPE_OCTAL, },{ - .out = "\\e\\142\\040\\\\\\103\\a\\042\\220\\015\\135", + .out = "\\e\\142\\040\\\\\\103\\a\\\"\\220\\015\\135", .flags = ESCAPE_SPECIAL | ESCAPE_OCTAL, },{ - .out = "\\e\\142\\040\\\\\\103\\a\\042\\220\\r\\135", + .out = "\\e\\142\\040\\\\\\103\\a\\\"\\220\\r\\135", .flags = ESCAPE_SPACE | ESCAPE_SPECIAL | ESCAPE_OCTAL, },{ .out = "\eb \\C\007\"\x90\r]", -- 2.31.1