From patchwork Sat Mar 21 16:54:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sanidhya Kashyap X-Patchwork-Id: 6064491 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 076E29F318 for ; Sat, 21 Mar 2015 16:55:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1DF1B20357 for ; Sat, 21 Mar 2015 16:55:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2F04E2034E for ; Sat, 21 Mar 2015 16:55:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751618AbbCUQze (ORCPT ); Sat, 21 Mar 2015 12:55:34 -0400 Received: from mail-yk0-f194.google.com ([209.85.160.194]:33545 "EHLO mail-yk0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751544AbbCUQzd (ORCPT ); Sat, 21 Mar 2015 12:55:33 -0400 Received: by ykbq200 with SMTP id q200so3396606ykb.0; Sat, 21 Mar 2015 09:55:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=LMe9S4EA5tkZpHR5wYQ6ZD+GP87GWslFqEmwk8XIn6I=; b=XiQ+2AGhojLYeGMf8ldyI9qQCC6kmMdZTBpa02nvi0L5MqhLpAIcU31Txazw98LzAr InkZfG3FKBQQ/rJX1QmYN1g0apPLOtnSiG86EJGxDSQFRyXvzSxlAPvgG9YfRwQN0GHW 6fGZpl93S5fZ7uZ2niVH18T9mti8sOhF7W321K6rEsPFLj2tX/jloJ+jtWO+og4/VpKF oWnzAc2Pq8sMzIkrPL2PzKWOZmmx8hFDiBdziPW0gueDqzkTP0qTvKud8uNu7T5kD2dG 25EPl6t/ai48wYib4cHFLzAa7V+oLEUQEsYZycHh03wSGdN6XkRk+yd8epVqsswVaXmh 06pg== X-Received: by 10.236.206.13 with SMTP id k13mr85714344yho.51.1426956932440; Sat, 21 Mar 2015 09:55:32 -0700 (PDT) Received: from headstrong.gtisc (headstrong.gtisc.gatech.edu. [128.61.240.70]) by mx.google.com with ESMTPSA id v69sm6403632yhc.34.2015.03.21.09.55.31 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Mar 2015 09:55:32 -0700 (PDT) From: Sanidhya Kashyap To: zyan@redhat.com, sage@redhat.com, ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: taesoo@gatech.edu, changwoo@gatech.edu, sanidhya@gatech.edu, blee@gatech.edu, Sanidhya Kashyap Subject: [PATCH] ceph: kstrdup() memory handling Date: Sat, 21 Mar 2015 12:54:58 -0400 Message-Id: <1426956898-32132-1-git-send-email-sanidhya.gatech@gmail.com> X-Mailer: git-send-email 2.1.0 Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently, there is no check for the kstrdup() for r_path2, r_path1 and snapdir_name as various locations as there is a possibility of failure during memory pressure. Therefore, returning ENOMEM where the checks have been missed. Signed-off-by: Sanidhya Kashyap --- fs/ceph/dir.c | 11 +++++++++++ fs/ceph/super.c | 8 ++++++++ fs/ceph/xattr.c | 7 +++++++ 3 files changed, 26 insertions(+) diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c index 83e9976..be32703 100644 --- a/fs/ceph/dir.c +++ b/fs/ceph/dir.c @@ -344,6 +344,12 @@ more: req->r_direct_hash = ceph_frag_value(frag); req->r_direct_is_hash = true; req->r_path2 = kstrdup(fi->last_name, GFP_NOFS); + if (!req->r_path2) { + iput(inode); + ceph_mdsc_put_request(req); + return -ENOMEM; + } + req->r_readdir_offset = fi->next_offset; req->r_args.readdir.frag = cpu_to_le32(frag); err = ceph_mdsc_do_request(mdsc, NULL, req); @@ -758,6 +764,11 @@ static int ceph_symlink(struct inode *dir, struct dentry *dentry, req->r_dentry = dget(dentry); req->r_num_caps = 2; req->r_path2 = kstrdup(dest, GFP_NOFS); + if (!req->r_path2) { + err = -ENOMEM; + ceph_mdsc_put_request(req); + goto out; + } req->r_locked_dir = dir; req->r_dentry_drop = CEPH_CAP_FILE_SHARED; req->r_dentry_unless = CEPH_CAP_FILE_EXCL; diff --git a/fs/ceph/super.c b/fs/ceph/super.c index a63997b..8e68f53 100644 --- a/fs/ceph/super.c +++ b/fs/ceph/super.c @@ -345,6 +345,9 @@ static int parse_mount_options(struct ceph_mount_options **pfsopt, fsopt->rsize = CEPH_RSIZE_DEFAULT; fsopt->rasize = CEPH_RASIZE_DEFAULT; fsopt->snapdir_name = kstrdup(CEPH_SNAPDIRNAME_DEFAULT, GFP_KERNEL); + if (!fsopt->snapdir_name) + goto out; + fsopt->caps_wanted_delay_min = CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT; fsopt->caps_wanted_delay_max = CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT; fsopt->cap_release_safety = CEPH_CAP_RELEASE_SAFETY_DEFAULT; @@ -730,6 +733,11 @@ static struct dentry *open_root_dentry(struct ceph_fs_client *fsc, if (IS_ERR(req)) return ERR_CAST(req); req->r_path1 = kstrdup(path, GFP_NOFS); + if (!req->r_path1) { + root = ERR_PTR(-ENOMEM); + goto out; + } + req->r_ino1.ino = CEPH_INO_ROOT; req->r_ino1.snap = CEPH_NOSNAP; req->r_started = started; diff --git a/fs/ceph/xattr.c b/fs/ceph/xattr.c index 5a492ca..299eb83 100644 --- a/fs/ceph/xattr.c +++ b/fs/ceph/xattr.c @@ -883,6 +883,11 @@ static int ceph_sync_setxattr(struct dentry *dentry, const char *name, req->r_num_caps = 1; req->r_args.setxattr.flags = cpu_to_le32(flags); req->r_path2 = kstrdup(name, GFP_NOFS); + if (!req->r_path2) { + ceph_mdsc_put_request(req); + err = -ENOMEM; + goto out; + } req->r_pagelist = pagelist; pagelist = NULL; @@ -1024,6 +1029,8 @@ static int ceph_send_removexattr(struct dentry *dentry, const char *name) req->r_inode_drop = CEPH_CAP_XATTR_SHARED; req->r_num_caps = 1; req->r_path2 = kstrdup(name, GFP_NOFS); + if (!req->r_path2) + return -ENOMEM; err = ceph_mdsc_do_request(mdsc, NULL, req); ceph_mdsc_put_request(req);