Received: by 10.223.185.116 with SMTP id b49csp2617684wrg; Mon, 12 Feb 2018 12:43:29 -0800 (PST) X-Google-Smtp-Source: AH8x224pjcmjsAz+WL5z2KQsmjZ2ySngMOZqQPaKeW9elibBq1vaxTluCigAArBTV8Sy74J0tgI0 X-Received: by 2002:a17:902:6908:: with SMTP id j8-v6mr11660699plk.211.1518468209228; Mon, 12 Feb 2018 12:43:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518468209; cv=none; d=google.com; s=arc-20160816; b=jlDr3mw8CrTsfQ3zQcrAXonpTn3bAMSn8hax0DWSlIh78z4p49iHVazOzLRTGKyset HqMAAl07zaIv6yATNi+XP9SpF1S1V1GA5l9FFYcrP5ATtHVwQWOE7Pz4IwRUkb39raIO LMYWJ9XoIiILJD/3f7pBoW0MOeom2b7MVgv2lY+t4jKH1Zu6At/Zv3bv68TwGQecxiD7 GhBZByKRfsnzC+p0Q7TqvjbqMfjTV7ahAWbxOKX/OLRaCLHOTYyzCJok64Vz9N+8byvn +zaz0csbmvkbewGJXNWSo7xBJqACHALjTM5IOom1V8pXbo6/a1xxwvCQBymzygUZzDIb U5xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=PUM8dcBdB5RdSQCvTyKcQbPKCYMwGoYW+tLnnX7bY98=; b=p1Ke5ufFfPJSDuLQZRF8a4djPv+wQ5Ej6uA/5GieQ4EO6afWrl/134N+j3+qxPhjvF xcZhsDhxfMSPR7OIbHUZ1aZee8k8qBHxv/p6uiaahHJapHhfnWdwJVfTAwV550gNsFcK Pjwfk4+In0JDj/yToiulaPi4FxYPmkWMCH65RkvoBXNqVR5mpo/LsNhwq2ST9MdRgwku b4Lh3UFJqpoNR5fspb+kXtxeOI6ocb+nuVkzBZ9R3ReO0aI+WtOsuAaVMRXWsWHbre8L FAl062yVYFZMbcofmDvoZIFgAUpKlIwC2I4yuLk8LJ0sLTPHS0nb8R+fDWPbKc7lD5Cm PPgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Y1/OVUUx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e192si112801pfc.292.2018.02.12.12.43.13; Mon, 12 Feb 2018 12:43:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Y1/OVUUx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753639AbeBLUm0 (ORCPT + 99 others); Mon, 12 Feb 2018 15:42:26 -0500 Received: from mail-qt0-f196.google.com ([209.85.216.196]:42455 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751441AbeBLUmZ (ORCPT ); Mon, 12 Feb 2018 15:42:25 -0500 Received: by mail-qt0-f196.google.com with SMTP id l9so909207qtj.9 for ; Mon, 12 Feb 2018 12:42:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=PUM8dcBdB5RdSQCvTyKcQbPKCYMwGoYW+tLnnX7bY98=; b=Y1/OVUUxwqoezDRnQiNybwAvh/hTDIvBbskM5RpYcihAOztdU3iN5FeUZTOUGHnEIx 8/zyUnp/KGkygh+ziAYy6Z9pJc2fwT0DoxKoj3JqmsynMFDDUacVbKy85UxwRFBEfIdD DW7GWwUQIjwr1exv8kZiOvg7zL+Tl+4GZSSMDjaDCOlOLPZIZnNthilNGNCrSVyBgShd NOlWekawHy0s6BYbVGagGM2Q6xHDEP7LyN/1D9v8/DJk29wE8PcUL5rhOkE0NvKW0/cJ y7HywJQhedCK23zPeFHfs/oxuQzZWvrwbWeaws8jvthslZoL+xIRuDNYs3Kgfr1bMFz0 KrGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=PUM8dcBdB5RdSQCvTyKcQbPKCYMwGoYW+tLnnX7bY98=; b=GWmyRS3wMBZgw3KjQbhVjNFemu8J0GNxrBsqmQMQ+X+eu0/QRqZh3wmqPYrZqHfs6s sWqK2VVe9FuVbO3F5wlmd1NKowPPytgxM4pj73VWgWc+sKW0uJBuCpXoYwkQGfMe23tH t2Lw5WfZduTHu2124x0eFgf21Iw257vnntNiM06ZLCCJhPwkpOXGu5YTD0mKZgDK45RO ywVsYRiY4GmXTPooCGeeLuTIYEuJvpmVKBbu3j0iI3o1SGKvrkUwHvZU0NdMfxgZt+cz pX6veFIlOK6N+JYQE6PKj0ITChkmMuovpyJ2RF+LS8JRAqTovFyJ+NdA19tCeKfZzhwV ahig== X-Gm-Message-State: APf1xPAkXUeW4iwGUXWENQ4FmGe0nE8+PelrIvIT54S5/JoYENJIXE0X qwFGe4tPHUI2BC7PhMLtSc/i6VR4ak1JpUId1yuvrxdc87o= X-Received: by 10.237.40.34 with SMTP id r31mr7415543qtd.330.1518468144574; Mon, 12 Feb 2018 12:42:24 -0800 (PST) MIME-Version: 1.0 Received: by 10.200.52.247 with HTTP; Mon, 12 Feb 2018 12:42:23 -0800 (PST) In-Reply-To: <20180212171137.GA31601@1wt.eu> References: <1516095490-83827-1-git-send-email-wangxiongfeng2@huawei.com> <20180212171137.GA31601@1wt.eu> From: Miguel Ojeda Date: Mon, 12 Feb 2018 21:42:23 +0100 Message-ID: Subject: Re: [PATCH V2] auxdisplay: use correct string length To: Willy Tarreau , Linus Torvalds , Greg KH , Andrew Morton Cc: Xiongfeng Wang , Dan , Arnd Bergmann , linux-kernel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 12, 2018 at 6:11 PM, Willy Tarreau wrote: > On Mon, Feb 12, 2018 at 01:53:57PM +0100, Miguel Ojeda wrote: >> > diff --git a/drivers/auxdisplay/panel.c b/drivers/auxdisplay/panel.c >> > index ea7869c..d288900 100644 >> > --- a/drivers/auxdisplay/panel.c >> > +++ b/drivers/auxdisplay/panel.c >> > @@ -1506,10 +1506,10 @@ static struct logical_input *panel_bind_key(const char *name, const char *press, >> > key->rise_time = 1; >> > key->fall_time = 1; >> > >> > - strncpy(key->u.kbd.press_str, press, sizeof(key->u.kbd.press_str)); >> > - strncpy(key->u.kbd.repeat_str, repeat, sizeof(key->u.kbd.repeat_str)); >> > + strncpy(key->u.kbd.press_str, press, sizeof(key->u.kbd.press_str) - 1); >> > + strncpy(key->u.kbd.repeat_str, repeat, sizeof(key->u.kbd.repeat_str) - 1); >> > strncpy(key->u.kbd.release_str, release, >> > - sizeof(key->u.kbd.release_str)); >> > + sizeof(key->u.kbd.release_str) - 1); >> >> Are you sure about this patch? `kbd` says "strings can be non null-terminated". >> >> Willy, maybe those should just be memcpy()s? (unless the remaining >> bytes, if any, must be 0). > > For me this seems to be the result of yet another very stupid gcc warning > trying to dissuade us from using well defined fonctions... it's unimaginable > how gcc warnings have become stupid and irrelevant since its developers > stopped using C to write it :-( > > If you want to work around this wrong warning, probably that increasing the > destination storage size by one and adding -1 to strncpy() would shut it up It does indeed. > but that really becomes quite annoying to have to modify code and storage > just to shut down a dumbass compiler trying to be smart. > I have looked a bit deeper at this new warning. It comes with -Wall, and to trigger it the compiler needs to have some optimization passes enabled (-O2 works). See https://godbolt.org/g/dydPah to play with it in action. Assuming gcc 8 comes out with this warning implemented as of today (likely), we have several options then: a) -Wno-stringop-truncation for gcc >= 8. Note: the warning checks for several kinds of potential issues, some might be useful. b) Use the new __attribute__((nonstring)) for gcc >= 8. For instance, the kbd strings are anyhow marked with the /* strings can be non null-terminated */ comment, so we might just as well replace the comment with the attribute. c) For this case: +1 the array length, -1 the sizeof; as Willy suggested; or similar workarounds. d) For this case: try to make gcc see that the source is a small enough array. Unlikely, due to the keypad_profile indirection and the loop in keypad_init. Since anyway we will be hit by this warning in N places in the kernel now or in the future, let's ask Linus et. al. about what should be the policy to follow :) Miguel > Willy