Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3752760pxv; Mon, 28 Jun 2021 11:56:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwAoR0X2DkOywXTAIfHaKRasgU+nbbIvXJDKODORcrxz6gJBumhZgLL5Q8JXcu6+XURdMSY X-Received: by 2002:aa7:dccb:: with SMTP id w11mr33823591edu.96.1624906614152; Mon, 28 Jun 2021 11:56:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624906614; cv=none; d=google.com; s=arc-20160816; b=mjXrAFSf38a8CLvHinsiFteHnVVJAfzX2wk4LSGVNxHaC51KEceAJWUbJdZTAnuNwE 17Nda9eUc8VQD/+zhmgcu2fDcvdRk8DJ694hoyFvMoYz6f7t241SNvzWrR4Pzt4e43Em 8w2l9tI6ghX7SPb9BXFDZxCPpnWC38IbCCTZVh89O8PT5O96jemzn9+TU/iB6H1a02i3 VSR2iPzeuXlLzdIYWUCUy1gDvmR3TiCurlMxrCTjiHglRayF63tDhGOlDXPF6NQz7j/C od6n0HfTgrw1bGnxfurwK3If22/jjsfa7qwBbbt/hEWJuAa9FMEp+WOxrftmjQNeN4of fJQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=UfotHoXr1MGRstAAk/SsclnC2qgTL5WZjtgDBeEKZ9Y=; b=T9Z7QAQWH/89EQ9LT0dAr5r4tqFodvt9GWF3zL39bCLYoVslaAb7Nriz1/XhwNz9N4 zWY9Jn4omSvGKuEq642pzpT6SCn1K+O36kvGz0vxkWYtgAgJN63SHOsZ0bgGJKusvQ8w CM1JsrPCSH8d+p+kHn6MCHIoDMWRnWN04Xu7ePm0d79vEFdbx0r7894u+Y2VOu3oEIE5 2OmIWAmdo/Wzv5GC/lJU3AvFdyCzyxqi9Q7JTrgBebMs4jOgoKX0O9wlnMr2mSO8q6By WNGzXEuIwbFfM/rk2xLQA+A/QuUNbL16RzNxs+YD6oqBKg5JQfU1Bc3koamNuOjTVn9F d0MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=H0L8p74b; 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=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id my3si14744083ejc.49.2021.06.28.11.56.25; Mon, 28 Jun 2021 11:56:54 -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=@alien8.de header.s=dkim header.b=H0L8p74b; 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=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233867AbhF1Oat (ORCPT + 99 others); Mon, 28 Jun 2021 10:30:49 -0400 Received: from mail.skyhub.de ([5.9.137.197]:35772 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233920AbhF1O2T (ORCPT ); Mon, 28 Jun 2021 10:28:19 -0400 Received: from zn.tnic (p200300ec2f0ad700491bef6a2c18e575.dip0.t-ipconnect.de [IPv6:2003:ec:2f0a:d700:491b:ef6a:2c18:e575]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id B237F1EC0473; Mon, 28 Jun 2021 16:25:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1624890351; 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:in-reply-to:in-reply-to: references:references; bh=UfotHoXr1MGRstAAk/SsclnC2qgTL5WZjtgDBeEKZ9Y=; b=H0L8p74bADoaFQqh5Bs0Sa9tkPZtGAUt099tGAQKW16jlHCamnoNPTM4QaBGcowNPO408r ZXTvLgJloHkQVZ63hKGd3gLQd10i/TkZpfUOFmNlDZS9VzmMiKhexTTLRAzMpoXIooiN8x Qj/1EFWBumfwusr4xYHdl28RXz6XANc= Date: Mon, 28 Jun 2021 16:25:45 +0200 From: Borislav Petkov To: Greg Kroah-Hartman Cc: "H. Peter Anvin" , x86@kernel.org, Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org Subject: [PATCH] x86/tools/relocs: Mark die() with the printf function attr format Message-ID: References: <1EFF7FE1-D341-41DF-8681-D386A1BD6F7A@zytor.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jun 27, 2021 at 05:01:28PM +0200, Greg Kroah-Hartman wrote: > This works for me! It should fix the static checking tool that keeps > tripping over this pointless warning :) > > Want to turn it into a real patch? How's that? --- From: Borislav Petkov Mark die() as a function which accepts printf-style arguments so that the compiler can typecheck them against the supplied format string. Use the C99 inttypes.h format specifiers as relocs.c gets built for both 32- and 64-bit. Original version of the patch by Greg Kroah-Hartman Signed-off-by: Borislav Petkov --- arch/x86/tools/relocs.c | 37 ++++++++++++++++++++----------------- arch/x86/tools/relocs.h | 1 + 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c index 04c5a44b9682..2582991ba216 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -26,6 +26,9 @@ static struct relocs relocs32; #if ELF_BITS == 64 static struct relocs relocs32neg; static struct relocs relocs64; +#define FMT PRIu64 +#else +#define FMT PRIu32 #endif struct section { @@ -389,7 +392,7 @@ static void read_ehdr(FILE *fp) Elf_Shdr shdr; if (fseek(fp, ehdr.e_shoff, SEEK_SET) < 0) - die("Seek to %d failed: %s\n", ehdr.e_shoff, strerror(errno)); + die("Seek to %" FMT " failed: %s\n", ehdr.e_shoff, strerror(errno)); if (fread(&shdr, sizeof(shdr), 1, fp) != 1) die("Cannot read initial ELF section header: %s\n", strerror(errno)); @@ -412,17 +415,17 @@ static void read_shdrs(FILE *fp) secs = calloc(shnum, sizeof(struct section)); if (!secs) { - die("Unable to allocate %d section headers\n", + die("Unable to allocate %ld section headers\n", shnum); } if (fseek(fp, ehdr.e_shoff, SEEK_SET) < 0) { - die("Seek to %d failed: %s\n", - ehdr.e_shoff, strerror(errno)); + die("Seek to %" FMT " failed: %s\n", + ehdr.e_shoff, strerror(errno)); } for (i = 0; i < shnum; i++) { struct section *sec = &secs[i]; if (fread(&shdr, sizeof(shdr), 1, fp) != 1) - die("Cannot read ELF section headers %d/%d: %s\n", + die("Cannot read ELF section headers %d/%ld: %s\n", i, shnum, strerror(errno)); sec->shdr.sh_name = elf_word_to_cpu(shdr.sh_name); sec->shdr.sh_type = elf_word_to_cpu(shdr.sh_type); @@ -450,12 +453,12 @@ static void read_strtabs(FILE *fp) } sec->strtab = malloc(sec->shdr.sh_size); if (!sec->strtab) { - die("malloc of %d bytes for strtab failed\n", - sec->shdr.sh_size); + die("malloc of %" FMT " bytes for strtab failed\n", + sec->shdr.sh_size); } if (fseek(fp, sec->shdr.sh_offset, SEEK_SET) < 0) { - die("Seek to %d failed: %s\n", - sec->shdr.sh_offset, strerror(errno)); + die("Seek to %" FMT " failed: %s\n", + sec->shdr.sh_offset, strerror(errno)); } if (fread(sec->strtab, 1, sec->shdr.sh_size, fp) != sec->shdr.sh_size) { @@ -475,12 +478,12 @@ static void read_symtabs(FILE *fp) } sec->symtab = malloc(sec->shdr.sh_size); if (!sec->symtab) { - die("malloc of %d bytes for symtab failed\n", - sec->shdr.sh_size); + die("malloc of %" FMT " bytes for symtab failed\n", + sec->shdr.sh_size); } if (fseek(fp, sec->shdr.sh_offset, SEEK_SET) < 0) { - die("Seek to %d failed: %s\n", - sec->shdr.sh_offset, strerror(errno)); + die("Seek to %" FMT " failed: %s\n", + sec->shdr.sh_offset, strerror(errno)); } if (fread(sec->symtab, 1, sec->shdr.sh_size, fp) != sec->shdr.sh_size) { @@ -508,12 +511,12 @@ static void read_relocs(FILE *fp) } sec->reltab = malloc(sec->shdr.sh_size); if (!sec->reltab) { - die("malloc of %d bytes for relocs failed\n", - sec->shdr.sh_size); + die("malloc of %" FMT " bytes for relocs failed\n", + sec->shdr.sh_size); } if (fseek(fp, sec->shdr.sh_offset, SEEK_SET) < 0) { - die("Seek to %d failed: %s\n", - sec->shdr.sh_offset, strerror(errno)); + die("Seek to %" FMT " failed: %s\n", + sec->shdr.sh_offset, strerror(errno)); } if (fread(sec->reltab, 1, sec->shdr.sh_size, fp) != sec->shdr.sh_size) { diff --git a/arch/x86/tools/relocs.h b/arch/x86/tools/relocs.h index 43c83c0fd22c..4c49c82446eb 100644 --- a/arch/x86/tools/relocs.h +++ b/arch/x86/tools/relocs.h @@ -17,6 +17,7 @@ #include #include +__attribute__((__format__(printf, 1, 2))) void die(char *fmt, ...) __attribute__((noreturn)); #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) -- 2.29.2 -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette