From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751526AbeCOH6t (ORCPT ); Thu, 15 Mar 2018 03:58:49 -0400 Received: from mail-pg0-f48.google.com ([74.125.83.48]:45079 "EHLO mail-pg0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751314AbeCOH6s (ORCPT ); Thu, 15 Mar 2018 03:58:48 -0400 X-Google-Smtp-Source: AG47ELswPf+Z3heyUoUI5frKPA6IWkql2TJYViLrSbHeVSucM5nr4XBoHTyJv6PllapGWEQhEcikqg== Date: Thu, 15 Mar 2018 16:58:42 +0900 From: Sergey Senozhatsky To: Petr Mladek Cc: Linus Torvalds , Andy Shevchenko , Rasmus Villemoes , "Tobin C . Harding" , Joe Perches , Linux Kernel Mailing List , Andrew Morton , Michal Hocko , Sergey Senozhatsky , Steven Rostedt , Sergey Senozhatsky Subject: Re: [PATCH v3] vsprintf: Prevent crash when dereferencing invalid pointers Message-ID: <20180315075842.GD3628@jagdpanzerIV> References: <20180306092513.ibodfsnv4xrxdlub@pathway.suse.cz> <1520330185.10722.401.camel@linux.intel.com> <20180307155244.b45c3fb5vcxb4q2l@pathway.suse.cz> <20180308141824.bfk2pr6wmjh4ytdi@pathway.suse.cz> <20180309150153.3sxbbpd6jdn2d5yy@pathway.suse.cz> <20180314140947.rs3b6i5gguzzu5wi@pathway.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180314140947.rs3b6i5gguzzu5wi@pathway.suse.cz> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On (03/14/18 15:09), Petr Mladek wrote: [..] > +static const char *check_pointer_access(const void *ptr) > +{ > + unsigned char byte; > + > + if (!ptr) > + return "(null)"; > + > + if (probe_kernel_read(&byte, ptr, 1)) ^^^^^ Why one byte? sizeof(ptr)? [..] > char *pointer(const char *fmt, char *buf, char *end, void *ptr, > struct printf_spec spec) > { > + static const char data_access_fmt[] = "RrhbMmIiEUVNadCDgGO"; > const int default_width = 2 * sizeof(void *); > + const char *err_msg = NULL; > + > + /* Prevent silent crash when this is called under logbuf_lock. */ > + if (*fmt && strchr(data_access_fmt, *fmt) != NULL) > + err_msg = check_pointer_access(ptr); Agree with Rasmus, I think switch() is easier. -ss