Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp1592084imd; Sun, 4 Nov 2018 05:59:55 -0800 (PST) X-Google-Smtp-Source: AJdET5eJL0loxUulECndB3eIzmpVuk9HNpwRPmJ0K7+RMeQx8EKRyT8MrWVWYV+OiwssFmb0n0Mz X-Received: by 2002:a62:4e01:: with SMTP id c1-v6mr18435469pfb.141.1541339995584; Sun, 04 Nov 2018 05:59:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541339995; cv=none; d=google.com; s=arc-20160816; b=Yt8/Hl4azGZ0RVPay9xcAg2b5O/iSmACR5YU1vbZlVIU1ioj80VAxwRnNpAEXxwY+m LZZSBMlN8muLx6kEZGD49EGvxALJD0bUKMY7FcTVFODzG0jFopwnwpDUhxgwiD5nRPtX JVgzMygJYdngiu68K3r+NLoNSfyuhJOa8C8j9FOzewfTpfduT5m9if/gH1Mpa/OHa6dQ zykMfBrJ8/xk8FRXiTlM3oBdCFAyRlW93mL/3xqNWhEYwX/JwLsSpCAgK5TM8VmnJHz1 1pndMZoJxbPs8RePhyTzffZhZQ9xgtoqfZZgpNcyKNYJqUe/7FvJTm+kNtz2qFmAk6+9 X0tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=sGbSkCx8kTU1KQc1gBSA41MAGRPcqt1d3WMLi63o+kI=; b=ZWOGTFglpQF9uHYbp/ax1G251rz/ZKf3OFXTDfDp2ilOFKTfz2KIRgo1NXlUOaQm0I oVr5tflxoe5WHCOKFdSU9+ubN/Ck318/XTUcya/N9hNqIem/8cTYKox8HRszq3kqebdL bez3NLu6x8JODqzbqsYIKFyE0le7mNNIYo8ar2r9a/8P5PL0L/dvb8+Jj5OH/PAdKkQ9 2hd7GiIPA1UZqkoapo4jRY18fuzfAJ0GXA6pOLagdmIA3vYmsk9V82MY1761bngjgtYT csHkBcOLXmio7kyaL9b5Y8Am8GjXz6DMOgPZlCQhswrEUKXzU4tGs5/5tLBPDKsV8wZf q3rA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ixTC4pzS; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o131-v6si39882064pgo.591.2018.11.04.05.59.41; Sun, 04 Nov 2018 05:59:55 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=ixTC4pzS; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731444AbeKDXJC (ORCPT + 99 others); Sun, 4 Nov 2018 18:09:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:48272 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731412AbeKDXI7 (ORCPT ); Sun, 4 Nov 2018 18:08:59 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D7CA52085B; Sun, 4 Nov 2018 13:53:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541339635; bh=96bxXHluvXFbK4ksvmyj8/sPd3+N8gUickML/WDueFA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ixTC4pzSY65iEDMOuyvjnWuy1BpZn6lz/AKJzaTcpvv+I49ZjEgAayt/gkwx2gqGQ 6isq4DEuB2o3zzFMXVTZthCgGw08eNpn6e00aH9i1lKK0l/bw92g3CQTxoWGCEpM3Q BD0zfP4OcZaHDLWiDP/TLkwPwRaELLOo0t3Fm7cI= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Dominique Martinet , Sasha Levin Subject: [PATCH AUTOSEL 4.14 30/30] 9p: clear dangling pointers in p9stat_free Date: Sun, 4 Nov 2018 08:53:25 -0500 Message-Id: <20181104135325.88524-30-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181104135325.88524-1-sashal@kernel.org> References: <20181104135325.88524-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dominique Martinet [ Upstream commit 62e3941776fea8678bb8120607039410b1b61a65 ] p9stat_free is more of a cleanup function than a 'free' function as it only frees the content of the struct; there are chances of use-after-free if it is improperly used (e.g. p9stat_free called twice as it used to be possible to) Clearing dangling pointers makes the function idempotent and safer to use. Link: http://lkml.kernel.org/r/1535410108-20650-2-git-send-email-asmadeus@codewreck.org Signed-off-by: Dominique Martinet Reported-by: syzbot+d4252148d198410b864f@syzkaller.appspotmail.com Signed-off-by: Sasha Levin --- net/9p/protocol.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/9p/protocol.c b/net/9p/protocol.c index 16e10680518c..9743837aebc6 100644 --- a/net/9p/protocol.c +++ b/net/9p/protocol.c @@ -46,10 +46,15 @@ p9pdu_writef(struct p9_fcall *pdu, int proto_version, const char *fmt, ...); void p9stat_free(struct p9_wstat *stbuf) { kfree(stbuf->name); + stbuf->name = NULL; kfree(stbuf->uid); + stbuf->uid = NULL; kfree(stbuf->gid); + stbuf->gid = NULL; kfree(stbuf->muid); + stbuf->muid = NULL; kfree(stbuf->extension); + stbuf->extension = NULL; } EXPORT_SYMBOL(p9stat_free); -- 2.17.1