From patchwork Thu Jul 12 12:32:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 10521647 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D8F90603D7 for ; Thu, 12 Jul 2018 12:34:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C28032856F for ; Thu, 12 Jul 2018 12:34:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B71FD2941E; Thu, 12 Jul 2018 12:34:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C5CE2856F for ; Thu, 12 Jul 2018 12:34:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727094AbeGLMny (ORCPT ); Thu, 12 Jul 2018 08:43:54 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:51440 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726663AbeGLMny (ORCPT ); Thu, 12 Jul 2018 08:43:54 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w6CCTxIe175059; Thu, 12 Jul 2018 12:33:06 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : mime-version : content-type; s=corp-2018-07-02; bh=OuNh+QSStwJp22tT0ZQ0DWttyDd8mS7/qiGj9b124aA=; b=sBdiwe9Peymst54Wkrlz457UQyoXxh8L/brxTT/eoW8/qUXnBvvzHfmdKFUTxO/Po+Xw o2qY7+xjJooXplDD7+deTL5P2q+2CR8aMUstOx18mGMmLaSy7MUVQG2f03JL5HmQQuNB 1J16CgovHib6dl+syJuWgisjEoQwy8ivedPt4BxB/esiCYXZa2z0HUw+UOitcztHbxWd 82UGPoMLp026LYSp6Y77aMzafSPZkZbarz1KhSJbGqt0FRZQVFYAggxgpwBCpVU3jAGw rxGmqGzhEtfY8RsA8Jc5UUmWIiMGFa+1CsRjN3pG+0dF+Pkoh9fLNYjmtpRz6B/0S0hZ 5Q== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2k2p76bfhv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 12 Jul 2018 12:33:05 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w6CCX4qH011947 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 12 Jul 2018 12:33:05 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w6CCX3pn017187; Thu, 12 Jul 2018 12:33:04 GMT Received: from kili.mountain (/41.202.241.62) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 12 Jul 2018 12:33:03 +0000 Date: Thu, 12 Jul 2018 15:32:56 +0300 From: Dan Carpenter To: Jan Harkes Cc: coda@cs.cmu.edu, codalist@telemann.coda.cs.cmu.edu, linux-fsdevel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH] fs/coda: potential buffer overflow in coda_psdev_write() Message-ID: <20180712123255.rkcszmwdmrloxaki@kili.mountain> MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding User-Agent: NeoMutt/20170113 (1.7.2) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8951 signatures=668706 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=869 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1807120131 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP "dcbuf" is a union that is "size" bytes large. We ensure that "nbytes" is large enough to hold the smallest member of the union, but if we require a larger union member then then we could access beyond the end of the allocated memory in coda_downcall(). The union is quite small so we can allocate enough space so everything fits. The CODA_ALLOC() macro calls kzalloc() which means the extra memory is just zeroed and it's fine. Signed-off-by: Dan Carpenter diff --git a/fs/coda/psdev.c b/fs/coda/psdev.c index c5234c21b539..910d57e576e2 100644 --- a/fs/coda/psdev.c +++ b/fs/coda/psdev.c @@ -124,7 +124,7 @@ static ssize_t coda_psdev_write(struct file *file, const char __user *buf, hdr.opcode, hdr.unique); nbytes = size; } - CODA_ALLOC(dcbuf, union outputArgs *, nbytes); + CODA_ALLOC(dcbuf, union outputArgs *, size); if (copy_from_user(dcbuf, buf, nbytes)) { CODA_FREE(dcbuf, nbytes); retval = -EFAULT;