lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 11 Nov 2014 16:21:46 -0800
From:	Andrew Morton <akpm@...ux-foundation.org>
To:	Steven Stewart-Gallus <sstewartgallus00@...angara.bc.ca>
Cc:	linux-kernel@...r.kernel.org, Davidlohr Bueso <davidlohr@...com>,
	Manfred Spraul <manfred@...orfullife.com>,
	"J. Bruce Fields" <bfields@...hat.com>,
	Doug Ledford <dledford@...hat.com>,
	linux-newbie@...r.kernel.org
Subject: Re: [PATCH 1/1] ipc/mqueue.c: Drag unneeded code out of locks

On Fri, 07 Nov 2014 05:40:37 +0000 (GMT) Steven Stewart-Gallus <sstewartgallus00@...angara.bc.ca> wrote:

> This shouldn't be too controversial. I simply looked for where there
> was a tiny bit of waste in the message queue code.
> 

It's probably better to do this as three or four separate patches.

> --- a/ipc/mqueue.c
> +++ b/ipc/mqueue.c
> @@ -278,16 +278,29 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
>  		mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
>  					  info->attr.mq_msgsize);
>  
> -		spin_lock(&mq_lock);
> -		if (u->mq_bytes + mq_bytes < u->mq_bytes ||
> -		    u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
> +		{
> +			bool too_many_open_files;

Well yes, that's what EMFILE means but "too_many_open_files" doesn't
make sense in this context!


> +			long msgqueue_lim;
> +			unsigned long u_bytes;
> +
> +			msgqueue_lim = rlimit(RLIMIT_MSGQUEUE);
> +
> +			spin_lock(&mq_lock);
> +
> +			u_bytes = u->mq_bytes;
> +			too_many_open_files = u_bytes + mq_bytes < u_bytes ||
> +				u_bytes + mq_bytes > msgqueue_lim;
> +			if (!too_many_open_files)

This test isn't really needed.

> +				u->mq_bytes += mq_bytes;
> +
>  			spin_unlock(&mq_lock);
> +
>  			/* mqueue_evict_inode() releases info->messages */
> -			ret = -EMFILE;
> -			goto out_inode;
> +			if (too_many_open_files) {
> +				ret = -EMFILE;
> +				goto out_inode;
> +			}
>  		}
> -		u->mq_bytes += mq_bytes;
> -		spin_unlock(&mq_lock);
>  
>  		/* all is ok */
>  		info->user = get_uid(u);
> @@ -423,44 +436,60 @@ static int mqueue_create(struct inode *dir, struct dentry
> *dentry,
>  				umode_t mode, bool excl)
>  {
>  	struct inode *inode;
> -	struct mq_attr *attr = dentry->d_fsdata;
> -	int error;
> +	struct mq_attr *attr;
>  	struct ipc_namespace *ipc_ns;
> +	int error = 0;
> +
> +	if (!capable(CAP_SYS_RESOURCE)) {
> +		error = -ENOSPC;
> +		goto finish;
> +	}

Thatsabug.  It only requires CAP_SYS_RESOURCE if we're trying with
queues_count >= queues_max.


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ