From 8eda94bde4ff004a942ed95e6348de711b0e6da9 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 2 Jul 2020 22:05:36 +0200 Subject: Replace HTTP links with HTTPS ones: vsprintf Rationale: Reduces attack surface on kernel devs opening the links for MITM as HTTPS traffic is much harder to manipulate. Deterministic algorithm: For each file: If not .svg: For each line: If doesn't contain `\bxmlns\b`: For each link, `\bhttp://[^# \t\r\n]*(?:\w|/)`: If both the HTTP and HTTPS versions return 200 OK and serve the same content: Replace HTTP with HTTPS. Signed-off-by: Alexander A. Klimov Reviewed-by: Petr Mladek Reviewed-by: Sergey Senozhatsky Signed-off-by: Petr Mladek Link: https://lore.kernel.org/r/20200702200536.13389-1-grandmaster@al2klimov.de --- lib/vsprintf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 259e55895933..31a674dd2674 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -2134,7 +2134,7 @@ char *fwnode_string(char *buf, char *end, struct fwnode_handle *fwnode, * [4] or [6] and is able to print port [p], flowinfo [f], scope [s] * - '[Ii][4S][hnbl]' IPv4 addresses in host, network, big or little endian order * - 'I[6S]c' for IPv6 addresses printed as specified by - * http://tools.ietf.org/html/rfc5952 + * https://tools.ietf.org/html/rfc5952 * - 'E[achnops]' For an escaped buffer, where rules are defined by combination * of the following flags (see string_escape_mem() for the * details): -- cgit v1.2.3 From b886690d1bf050525367f552842e3c89567c8ec6 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Fri, 31 Jul 2020 21:08:22 +0300 Subject: lib/vsprintf: Replace hidden BUILD_BUG_ON() with static_assert() First of all, there is no compile time check for the SMALL to be ' ' (0x20, i.e. space). Second, for ZEROPAD the check is hidden in the code. For better maintenance replace BUILD_BUG_ON() with static_assert() for ZEROPAD and move it closer to the definition. While at it, introduce check for SMALL. Signed-off-by: Andy Shevchenko Reviewed-by: Steven Rostedt (VMware) Reviewed-by: Sergey Senozhatsky Link: https://lore.kernel.org/r/20200731180825.30575-1-andriy.shevchenko@linux.intel.com Signed-off-by: Sergey Senozhatsky --- lib/vsprintf.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 31a674dd2674..f90f09682977 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -381,6 +381,9 @@ int num_to_str(char *buf, int size, unsigned long long num, unsigned int width) #define SMALL 32 /* use lowercase in hex (must be 32 == 0x20) */ #define SPECIAL 64 /* prefix hex with "0x", octal with "0" */ +static_assert(ZEROPAD == ('0' - ' ')); +static_assert(SMALL == ' '); + enum format_type { FORMAT_TYPE_NONE, /* Just a string part */ FORMAT_TYPE_WIDTH, @@ -507,7 +510,7 @@ char *number(char *buf, char *end, unsigned long long num, /* zero or space padding */ if (!(spec.flags & LEFT)) { char c = ' ' + (spec.flags & ZEROPAD); - BUILD_BUG_ON(' ' + ZEROPAD != '0'); + while (--field_width >= 0) { if (buf < end) *buf = c; -- cgit v1.2.3 From 09ceb8d76e6fa2c6a5bfc22eabd0cebe599e1690 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Fri, 31 Jul 2020 21:08:23 +0300 Subject: lib/vsprintf: Replace custom spec to print decimals with generic one When printing phandle via %pOFp the custom spec is used. First of all, it has a SMALL flag which makes no sense for decimal numbers. Second, we have already default spec for decimal numbers. Use the latter in the %pOFp case as well. Signed-off-by: Andy Shevchenko Reviewed-by: Steven Rostedt (VMware) Reviewed-by: Sergey Senozhatsky Cc: Pantelis Antoniou Cc: Rob Herring Cc: Joe Perches Cc: Grant Likely Link: https://lore.kernel.org/r/20200731180825.30575-2-andriy.shevchenko@linux.intel.com Signed-off-by: Sergey Senozhatsky --- lib/vsprintf.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/vsprintf.c b/lib/vsprintf.c index f90f09682977..182a3e2e1629 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -1979,12 +1979,6 @@ char *device_node_string(char *buf, char *end, struct device_node *dn, char *buf_start = buf; struct property *prop; bool has_mult, pass; - static const struct printf_spec num_spec = { - .flags = SMALL, - .field_width = -1, - .precision = -1, - .base = 10, - }; struct printf_spec str_spec = spec; str_spec.field_width = -1; @@ -2024,7 +2018,7 @@ char *device_node_string(char *buf, char *end, struct device_node *dn, str_spec.precision = precision; break; case 'p': /* phandle */ - buf = number(buf, end, (unsigned int)dn->phandle, num_spec); + buf = number(buf, end, (unsigned int)dn->phandle, default_dec_spec); break; case 'P': /* path-spec */ p = fwnode_get_name(of_fwnode_handle(dn)); -- cgit v1.2.3 From 30d497a0e1aadd904867081246c310dd0284eb41 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Fri, 31 Jul 2020 21:08:24 +0300 Subject: lib/vsprintf: Force type of flags value for gfp_t Sparse is not happy about restricted type being assigned: lib/vsprintf.c:1940:23: warning: incorrect type in assignment (different base types) lib/vsprintf.c:1940:23: expected unsigned long [assigned] flags lib/vsprintf.c:1940:23: got restricted gfp_t [usertype] Force type of flags value to make sparse happy. Signed-off-by: Andy Shevchenko Reviewed-by: Steven Rostedt (VMware) Link: https://lore.kernel.org/r/20200731180825.30575-3-andriy.shevchenko@linux.intel.com Signed-off-by: Sergey Senozhatsky --- lib/vsprintf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 182a3e2e1629..c155769559ab 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -1937,7 +1937,7 @@ char *flags_string(char *buf, char *end, void *flags_ptr, names = vmaflag_names; break; case 'g': - flags = *(gfp_t *)flags_ptr; + flags = (__force unsigned long)(*(gfp_t *)flags_ptr); names = gfpflag_names; break; default: -- cgit v1.2.3