From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965032AbcHaPoK (ORCPT ); Wed, 31 Aug 2016 11:44:10 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:47341 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964800AbcHaPoJ (ORCPT ); Wed, 31 Aug 2016 11:44:09 -0400 X-IBM-Helo: d01dlp03.pok.ibm.com X-IBM-MailFrom: arbab@linux.vnet.ibm.com From: Reza Arbab To: Greg Kroah-Hartman , Andrew Morton , Vlastimil Babka , Vitaly Kuznetsov , David Rientjes , Yaowei Bai , Joonsoo Kim , Dan Williams , Xishi Qiu , David Vrabel , Chen Yucong , Andrew Banman , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RESEND PATCH v2] memory-hotplug: fix store_mem_state() return value Date: Wed, 31 Aug 2016 10:44:01 -0500 X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <20160831150105.GB26702@kroah.com> References: <20160831150105.GB26702@kroah.com> X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16083115-0040-0000-0000-000001341ED5 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00005686; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000184; SDB=6.00752143; UDB=6.00355581; IPR=6.00524953; BA=6.00004683; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00012534; XFM=3.00000011; UTC=2016-08-31 15:44:07 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16083115-0041-0000-0000-0000050F3086 Message-Id: <1472658241-32748-1-git-send-email-arbab@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-08-31_04:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1608310185 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Attempting to online memory which is already online will cause this: 1. store_mem_state() called with buf="online" 2. device_online() returns 1 because device is already online 3. store_mem_state() returns 1 4. calling code interprets this as 1-byte buffer read 5. store_mem_state() called again with buf="nline" 6. store_mem_state() returns -EINVAL Example: $ cat /sys/devices/system/memory/memory0/state online $ echo online > /sys/devices/system/memory/memory0/state -bash: echo: write error: Invalid argument Fix the return value of store_mem_state() so this doesn't happen. Signed-off-by: Reza Arbab --- Andrew et al, Greg asked that this come in through the -mm tree, as you know this code better than him. drivers/base/memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 1cea0ba..8e385ea 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -359,7 +359,7 @@ store_mem_state(struct device *dev, err: unlock_device_hotplug(); - if (ret) + if (ret < 0) return ret; return count; } -- 1.8.3.1