From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753224AbbDGIeb (ORCPT ); Tue, 7 Apr 2015 04:34:31 -0400 Received: from mail-wg0-f45.google.com ([74.125.82.45]:34205 "EHLO mail-wg0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752849AbbDGIe0 (ORCPT ); Tue, 7 Apr 2015 04:34:26 -0400 MIME-Version: 1.0 In-Reply-To: <1428394698-16938-1-git-send-email-tomvanbraeckel@gmail.com> References: <20150406121022.GA3867@wfg-t540p.sh.intel.com> <1428394698-16938-1-git-send-email-tomvanbraeckel@gmail.com> Date: Tue, 7 Apr 2015 11:34:25 +0300 X-Google-Sender-Auth: VmThO9KqtU4fVbd-wygJeQn3WfI Message-ID: Subject: Re: [PATCH] lguest: explicitly setup /dev/lguest private_data From: Daniel Baluta To: Tom Van Braeckel Cc: Rusty Russell , lguest , Linux Kernel Mailing List , kbuild test robot , Greg Kroah-Hartman , lkp@01.org Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 7, 2015 at 11:18 AM, Tom Van Braeckel wrote: > The private_data member of the /dev/lguest device file is used to hold > the current struct lguest and needs to be set to NULL to signify that > no initialization has taken place. > > We explicitly set it to NULL to be independent of whatever value the > misc subsystem initializes it to. > > Signed-off-by: Tom Van Braeckel > --- > Backstory: > ========== > The misc subsystem used to initialize a file's private_data to point to > the misc device when a driver had registered a custom open file > operation and initialized it to NULL when a custom open file operation > had *not* been provided. > > This subtle quirk was confusing, to the point where kernel code > registered *empty* file open operations to have private_data point to > the misc device structure. > > And it lead to bugs, where the addition or removal of a custom open > file operation surprisingly changed the initial contents of a file's > private_data structure. > > The misc subsystem is currently underdoing changes to *always* set > private_data to point to the misc device instead of only doing this > when a custom open file operation has been registered. > > Intel's 0day kernel testing robot discovered that the lguest driver > depended on it implicitly being initialized to NULL, as Fengguang Wu > reported. Thanks a lot for all the hard work! > > drivers/lguest/lguest_user.c | 14 +++++++++++++- > 1 file changed, 13 insertions(+), 1 deletion(-) > > diff --git a/drivers/lguest/lguest_user.c b/drivers/lguest/lguest_user.c > index c4c6113..054bf70 100644 > --- a/drivers/lguest/lguest_user.c > +++ b/drivers/lguest/lguest_user.c > @@ -98,6 +98,17 @@ static int trap(struct lg_cpu *cpu, const unsigned long __user *input) > return 0; > } > > +/* > + * Set up the /dev/lguest file structure > + * The file's private_data will hold the "struct lguest" after > + * initialization and is used to check whether it is already initialized. > + */ > +static int open(struct inode *inode, struct file *file) > +{ > + file->private_data = NULL; > + return 0; > +} > + > /*L:040 > * Once our Guest is initialized, the Launcher makes it run by reading > * from /dev/lguest. > @@ -405,10 +416,11 @@ static int close(struct inode *inode, struct file *file) > * > * We begin our understanding with the Host kernel interface which the Launcher > * uses: reading and writing a character device called /dev/lguest. All the > - * work happens in the read(), write() and close() routines: > + * work happens in the open(), read(), write() and close() routines: > */ > static const struct file_operations lguest_fops = { > .owner = THIS_MODULE, > + .open = open, > .release = close, > .write = write, > .read = read, Hmm, isn't this already fixed? https://lkml.org/lkml/2015/3/23/319 thanks, Daniel. From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: multipart/mixed; boundary="===============0519822700711441387==" MIME-Version: 1.0 From: Daniel Baluta To: lkp@lists.01.org Subject: Re: [PATCH] lguest: explicitly setup /dev/lguest private_data Date: Tue, 07 Apr 2015 11:34:25 +0300 Message-ID: In-Reply-To: <1428394698-16938-1-git-send-email-tomvanbraeckel@gmail.com> List-Id: --===============0519822700711441387== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable On Tue, Apr 7, 2015 at 11:18 AM, Tom Van Braeckel wrote: > The private_data member of the /dev/lguest device file is used to hold > the current struct lguest and needs to be set to NULL to signify that > no initialization has taken place. > > We explicitly set it to NULL to be independent of whatever value the > misc subsystem initializes it to. > > Signed-off-by: Tom Van Braeckel > --- > Backstory: > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > The misc subsystem used to initialize a file's private_data to point to > the misc device when a driver had registered a custom open file > operation and initialized it to NULL when a custom open file operation > had *not* been provided. > > This subtle quirk was confusing, to the point where kernel code > registered *empty* file open operations to have private_data point to > the misc device structure. > > And it lead to bugs, where the addition or removal of a custom open > file operation surprisingly changed the initial contents of a file's > private_data structure. > > The misc subsystem is currently underdoing changes to *always* set > private_data to point to the misc device instead of only doing this > when a custom open file operation has been registered. > > Intel's 0day kernel testing robot discovered that the lguest driver > depended on it implicitly being initialized to NULL, as Fengguang Wu > reported. Thanks a lot for all the hard work! > > drivers/lguest/lguest_user.c | 14 +++++++++++++- > 1 file changed, 13 insertions(+), 1 deletion(-) > > diff --git a/drivers/lguest/lguest_user.c b/drivers/lguest/lguest_user.c > index c4c6113..054bf70 100644 > --- a/drivers/lguest/lguest_user.c > +++ b/drivers/lguest/lguest_user.c > @@ -98,6 +98,17 @@ static int trap(struct lg_cpu *cpu, const unsigned lon= g __user *input) > return 0; > } > > +/* > + * Set up the /dev/lguest file structure > + * The file's private_data will hold the "struct lguest" after > + * initialization and is used to check whether it is already initialized. > + */ > +static int open(struct inode *inode, struct file *file) > +{ > + file->private_data =3D NULL; > + return 0; > +} > + > /*L:040 > * Once our Guest is initialized, the Launcher makes it run by reading > * from /dev/lguest. > @@ -405,10 +416,11 @@ static int close(struct inode *inode, struct file *= file) > * > * We begin our understanding with the Host kernel interface which the L= auncher > * uses: reading and writing a character device called /dev/lguest. All= the > - * work happens in the read(), write() and close() routines: > + * work happens in the open(), read(), write() and close() routines: > */ > static const struct file_operations lguest_fops =3D { > .owner =3D THIS_MODULE, > + .open =3D open, > .release =3D close, > .write =3D write, > .read =3D read, Hmm, isn't this already fixed? https://lkml.org/lkml/2015/3/23/319 thanks, Daniel. --===============0519822700711441387==--