From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756739AbbEUWO2 (ORCPT ); Thu, 21 May 2015 18:14:28 -0400 Received: from mail-qg0-f54.google.com ([209.85.192.54]:33522 "EHLO mail-qg0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754866AbbEUWO0 (ORCPT ); Thu, 21 May 2015 18:14:26 -0400 Date: Thu, 21 May 2015 18:14:23 -0400 From: Tejun Heo To: Vladimir Zapolskiy Cc: Greg Kroah-Hartman , linux-kernel@vger.kernel.org Subject: Re: [PATCH] fs: sysfs: don't pass count == 0 to bin file readers Message-ID: <20150521221423.GK4914@htj.duckdns.org> References: <1432243276-27733-1-git-send-email-vz@mleia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1432243276-27733-1-git-send-email-vz@mleia.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Fri, May 22, 2015 at 12:21:16AM +0300, Vladimir Zapolskiy wrote: > If count == 0 bytes are requested by a reader, sysfs_kf_bin_read() > deliberately returns 0 without passing a potentially harmful value to > some externally defined underlying battr->read() function. > > However in case of (pos == size && count) the next clause always sets > count to 0 and this value is handed over to battr->read(). > > The change intends to make obsolete (and remove later) a redundant > sanity check in battr->read(), if it is present, or add more > protection to struct bin_attribute users, who does not care about > input arguments. > > Signed-off-by: Vladimir Zapolskiy > --- > fs/sysfs/file.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c > index 7c2867b..6c95628 100644 > --- a/fs/sysfs/file.c > +++ b/fs/sysfs/file.c > @@ -90,7 +90,7 @@ static ssize_t sysfs_kf_bin_read(struct kernfs_open_file *of, char *buf, > return 0; > > if (size) { > - if (pos > size) > + if (pos >= size) > return 0; > if (pos + count > size) > count = size - pos; Hmmm... maybe just move that test upwards? if (!count || pos >= size) return 0; count = min(count, size - pos); -- tejun