From: Dan Carpenter Subject: [patch] vfs: check for integer overflows in posix_acl_alloc() Date: Mon, 24 Jun 2013 19:27:19 +0300 Message-ID: <20130624162719.GB32503@elgon.mountain> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org To: Alexander Viro Return-path: Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org We've seen cases where people passed negative numbers to posix_acl_alloc() and we fixed the caller. For example 093019cf1b "xfs: fix acl count validation in xfs_acl_from_disk()". But there are other places which might be affected like ext4_acl_from_disk() which checks for negative but doesn't check an upper limit. Signed-off-by: Dan Carpenter diff --git a/fs/posix_acl.c b/fs/posix_acl.c index cea4623..cd7fd2f 100644 --- a/fs/posix_acl.c +++ b/fs/posix_acl.c @@ -46,7 +46,12 @@ posix_acl_alloc(int count, gfp_t flags) { const size_t size = sizeof(struct posix_acl) + count * sizeof(struct posix_acl_entry); - struct posix_acl *acl = kmalloc(size, flags); + struct posix_acl *acl; + + if (count < 0 || count > (SIZE_MAX - sizeof(struct posix_acl) / + sizeof(struct posix_acl_entry))) + return NULL; + acl = kmalloc(size, flags); if (acl) posix_acl_init(acl, count); return acl;