Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp2968378imm; Sun, 1 Jul 2018 09:21:47 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdsALL/jSm8/izZPreCOdQErDb7tqE6JHvklkKih0GR+dUyUpu8lKDwmMypQx8lL+G4Pv0T X-Received: by 2002:a63:1262:: with SMTP id 34-v6mr15684539pgs.154.1530462107316; Sun, 01 Jul 2018 09:21:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530462107; cv=none; d=google.com; s=arc-20160816; b=OQdCRRESEe+nuyDf8sMmJCEMpziYOWiyqhPZRVcPK+TG00klD4hkkGVVdWZvr67hsQ /AcFbD14DQGz9CU4yJRzK6fbdZpJDbdZwjpCj2HPwcScSauRyM6d6puCEp/4LQBeJpsb VNPpTCe6AfUCb7yHf/QwnwYhCXJ6Zk+WpnfiP4c9gShQk+7pN4oxdGxO2Ro/v/J7TEv3 oJ/i6unPsn7ttZKkG1XeZRXpx25onejm0cvpCvM6W4Ipqq/mSj2oCTOhpY38XOihn/Fb 5Ck3ZXb57Wn4wldu3/WTJpr0a/Fyk7Fzej6iq5Qe7Fvjupyym6Kh/LCZ9IlK/EFcRG4K yKgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=BM9EwycA9m7+AjHkKtK07WLw5rn72AC8kf+bc39dFfg=; b=MXknc+fNObbHGRqU1ZBoATIGOT3RKzICOHgbx8XRj13xU4pgIqIHCLShsOlfRVx2jb gy72bwjg1YOC4i7l+mZfI2A4nn+Kdt6bPEraooztxLZHhR+bROU59aBNz4Kv3SKvQxJj P/vYx7feCKmJlgyiU78F46sGIKyAWkhnFYaBF5Fuqyz3vxn6nWZaMLq2nO5FQ8HGuP8+ mP2V0ZVCS0IZJ7+bQfP485uERnlbsIV+ewJrE79b/Ld5kUPK4zoCn01WQCndOi1jNpnc ovYyq6hsj+EMweIfEmOjBa6JkSYLqoK1WRrfaUZzKgalqrnbGv4TWsnPxMPv9e1gDFho ljcA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c11-v6si12812126pgt.686.2018.07.01.09.21.33; Sun, 01 Jul 2018 09:21:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753478AbeGAQTJ (ORCPT + 99 others); Sun, 1 Jul 2018 12:19:09 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33134 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753217AbeGAQTF (ORCPT ); Sun, 1 Jul 2018 12:19:05 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 0733949B; Sun, 1 Jul 2018 16:19:03 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dave Wysochanski , Stephen Johnston , Trond Myklebust Subject: [PATCH 4.4 091/105] NFSv4: Fix possible 1-byte stack overflow in nfs_idmap_read_and_verify_message Date: Sun, 1 Jul 2018 18:02:41 +0200 Message-Id: <20180701153155.979014291@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180701153149.382300170@linuxfoundation.org> References: <20180701153149.382300170@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dave Wysochanski commit d68894800ec5712d7ddf042356f11e36f87d7f78 upstream. In nfs_idmap_read_and_verify_message there is an incorrect sprintf '%d' that converts the __u32 'im_id' from struct idmap_msg to 'id_str', which is a stack char array variable of length NFS_UINT_MAXLEN == 11. If a uid or gid value is > 2147483647 = 0x7fffffff, the conversion overflows into a negative value, for example: crash> p (unsigned) (0x80000000) $1 = 2147483648 crash> p (signed) (0x80000000) $2 = -2147483648 The '-' sign is written to the buffer and this causes a 1 byte overflow when the NULL byte is written, which corrupts kernel stack memory. If CONFIG_CC_STACKPROTECTOR_STRONG is set we see a stack-protector panic: [11558053.616565] Kernel panic - not syncing: stack-protector: Kernel stack is corrupted in: ffffffffa05b8a8c [11558053.639063] CPU: 6 PID: 9423 Comm: rpc.idmapd Tainted: G W ------------ T 3.10.0-514.el7.x86_64 #1 [11558053.641990] Hardware name: Red Hat OpenStack Compute, BIOS 1.10.2-3.el7_4.1 04/01/2014 [11558053.644462] ffffffff818c7bc0 00000000b1f3aec1 ffff880de0f9bd48 ffffffff81685eac [11558053.646430] ffff880de0f9bdc8 ffffffff8167f2b3 ffffffff00000010 ffff880de0f9bdd8 [11558053.648313] ffff880de0f9bd78 00000000b1f3aec1 ffffffff811dcb03 ffffffffa05b8a8c [11558053.650107] Call Trace: [11558053.651347] [] dump_stack+0x19/0x1b [11558053.653013] [] panic+0xe3/0x1f2 [11558053.666240] [] ? kfree+0x103/0x140 [11558053.682589] [] ? idmap_pipe_downcall+0x1cc/0x1e0 [nfsv4] [11558053.689710] [] __stack_chk_fail+0x1b/0x30 [11558053.691619] [] idmap_pipe_downcall+0x1cc/0x1e0 [nfsv4] [11558053.693867] [] rpc_pipe_write+0x56/0x70 [sunrpc] [11558053.695763] [] vfs_write+0xbd/0x1e0 [11558053.702236] [] ? task_work_run+0xac/0xe0 [11558053.704215] [] SyS_write+0x7f/0xe0 [11558053.709674] [] system_call_fastpath+0x16/0x1b Fix this by calling the internally defined nfs_map_numeric_to_string() function which properly uses '%u' to convert this __u32. For consistency, also replace the one other place where snprintf is called. Signed-off-by: Dave Wysochanski Reported-by: Stephen Johnston Fixes: cf4ab538f1516 ("NFSv4: Fix the string length returned by the idmapper") Cc: stable@vger.kernel.org # v3.4+ Signed-off-by: Trond Myklebust Signed-off-by: Greg Kroah-Hartman --- fs/nfs/nfs4idmap.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/fs/nfs/nfs4idmap.c +++ b/fs/nfs/nfs4idmap.c @@ -343,7 +343,7 @@ static ssize_t nfs_idmap_lookup_name(__u int id_len; ssize_t ret; - id_len = snprintf(id_str, sizeof(id_str), "%u", id); + id_len = nfs_map_numeric_to_string(id, id_str, sizeof(id_str)); ret = nfs_idmap_get_key(id_str, id_len, type, buf, buflen, idmap); if (ret < 0) return -EINVAL; @@ -626,7 +626,8 @@ static int nfs_idmap_read_and_verify_mes if (strcmp(upcall->im_name, im->im_name) != 0) break; /* Note: here we store the NUL terminator too */ - len = sprintf(id_str, "%d", im->im_id) + 1; + len = 1 + nfs_map_numeric_to_string(im->im_id, id_str, + sizeof(id_str)); ret = nfs_idmap_instantiate(key, authkey, id_str, len); break; case IDMAP_CONV_IDTONAME: