Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1239797pxk; Fri, 18 Sep 2020 07:28:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyjdvjxTp7c3FxZsw5UEBZeRvuWVeJb8Pgj9IUQDszdBC+YVae15wc+2v5DHttERbjbZ8mJ X-Received: by 2002:a17:906:e4f:: with SMTP id q15mr38053137eji.155.1600439328250; Fri, 18 Sep 2020 07:28:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600439328; cv=none; d=google.com; s=arc-20160816; b=HkuHcMg4SzDdUQ2vK9tPlBJDTt0FicsT70wRY4rT66HZn+fgJw8zwjWFYBJKioo3s6 TS1W7SgTPC1irlEm+S9BKyhKbIBSWtoe8haPAwPMAYobfCVYzec7/lJszQMEN73hzHrd 1VFycb0+Y73UP6CG5PwViJfxoL9oSTjvVkUWqCB8wN9S6apX30H+4WkqeKTxSP9+1cQf KRSDTEjbmnPJZan9XuJxIoH+oQOJj9KqGvu9C0HpoHsVuw21UutPksqHjH4+m/gW7nLV ZyTAbzZ+6Ve7NcKaz46Kl9UOBk+ZKtQZQL6Lw1OD7xqTUjzUZvk7bzwpEUKjbWdTc8rd Q1Vg== 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=HhTTG3AAgrCpwmciInJaUJL+OcbiXHiDYJ/Fm1dkKoI=; b=ffqLdXkF5mTMDuofouv5itzDLjw5k872mPySl05toQHszcARLLDXKqfFUpZ3MUmZLk k+9M6grwf5T82+7vROO4+JSBDtfQnFLavpGJsKizuSygOZKmtI4aeZVmOzeQWJE4nAed KLHJYHeUBUcHE4B3u/xaeJ65uhIoRaI3WUTXwpfUdg7Ru+dPu9ivwk9Tr46BgifeiD7+ I99QIuNqNnkV5TKDGS0Dx/EEBJBHJKLkKIbyGPW5k4gUxOKP5c+M3dA7X37xvR9XfgIr RLreUB9e8ryQQmfyK12RcQQZgeUPGSL7Bm9fVTD+piVMcaIKFDUOQXrwLMAEvtsR9Vqu O3DA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=DvWFXDWL; 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=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q16si2153730edr.453.2020.09.18.07.28.24; Fri, 18 Sep 2020 07:28:48 -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=@suse.com header.s=susede1 header.b=DvWFXDWL; 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=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726301AbgIROYx (ORCPT + 99 others); Fri, 18 Sep 2020 10:24:53 -0400 Received: from mx2.suse.de ([195.135.220.15]:40524 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726126AbgIROYx (ORCPT ); Fri, 18 Sep 2020 10:24:53 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1600439091; 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: in-reply-to:in-reply-to:references:references; bh=HhTTG3AAgrCpwmciInJaUJL+OcbiXHiDYJ/Fm1dkKoI=; b=DvWFXDWLV4VPEdcu0TOFnLUeO8eYuWPT7mjavXlRAQhJFko7NnR0XfEzT3rXnAkrXZP3P9 ErFOJ75tFuOD0S27Aft4wKW885ROW8po1xK4h0sJN/Swnu0U88CcW0Q5llpc6MFEApXwWa uoJ1Qi8bVnUdsoTjA01KLjd94JL2z7Q= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 945F1AB91; Fri, 18 Sep 2020 14:25:25 +0000 (UTC) Date: Fri, 18 Sep 2020 16:24:50 +0200 From: Petr Mladek To: Rasmus Villemoes Cc: John Ogness , Sergey Senozhatsky , Sergey Senozhatsky , Steven Rostedt , Linus Torvalds , Greg Kroah-Hartman , Thomas Gleixner , kexec@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH printk 2/3] printk: move dictionary keys to dev_printk_info Message-ID: <20200918142450.GE14605@alley> References: <20200917131644.25838-1-john.ogness@linutronix.de> <20200917131644.25838-3-john.ogness@linutronix.de> <316cf147-0ae2-1c88-7375-07aedc58bd15@rasmusvillemoes.dk> <20200918121342.GD14605@alley> <3123b0b5-ca4f-e964-ecc7-95fe8409f1d2@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3123b0b5-ca4f-e964-ecc7-95fe8409f1d2@rasmusvillemoes.dk> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri 2020-09-18 14:32:41, Rasmus Villemoes wrote: > On 18/09/2020 14.13, Petr Mladek wrote: > > On Fri 2020-09-18 08:16:37, Rasmus Villemoes wrote: > >> On 17/09/2020 15.16, John Ogness wrote: > >> > >>> if (dev->class) > >>> subsys = dev->class->name; > >>> else if (dev->bus) > >>> subsys = dev->bus->name; > >>> else > >>> - return 0; > >>> + return; > >>> > >>> - pos += snprintf(hdr + pos, hdrlen - pos, "SUBSYSTEM=%s", subsys); > >>> - if (pos >= hdrlen) > >>> - goto overflow; > >>> + snprintf(dev_info->subsystem, sizeof(dev_info->subsystem), subsys); > >> > >> It's unlikely that subsys would contain a %, but this will be yet > >> another place to spend brain cycles ignoring if doing static analysis. > >> So can we not do this. Either of strXcpy() for X=s,l will do the same > >> thing, and likely faster. > > > > Good point! Better be on the safe size in a generic printk() API. > > > > Well, I am afraid that this would be only small drop in a huge lake. > > class->name and bus->name seems to be passed to %s in so many > > *print*() calls all over the kernel code. > > So what? printf("%s", some_string_that_might_contain_percent_chars) is > not a problem. Grr, shame on me. I have completely messed this. The combination of Friday afternoon and noisy kids did not help me much to get it right. > printf(some_string_that_might_contain_percent_chars) is. I fully agree that passing unknown string as "fmt" is dangerous and must be used carefully. It is not needed here. > And yes, one could do > > snprintf(dev_info->subsystem, sizeof(dev_info->subsystem), "%s", subsys); > > but one might as well avoid the snprintf overhead and use one of the > strX functions that have the exact same semantics (copy as much as > there's room for, ensure nul-termination). Yes, we should use either snprinf() with %s or strXcpy(). Best Regards, Petr