Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp7422570ybn; Mon, 30 Sep 2019 13:41:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqwD8n83HoDwDsKOUp3BJcRTk1zPvK9ST8bLdBSLuGfZpzhdqDg73Infs3hUv5AihXbyEmrg X-Received: by 2002:a17:906:fc2:: with SMTP id c2mr20784286ejk.261.1569876105523; Mon, 30 Sep 2019 13:41:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569876105; cv=none; d=google.com; s=arc-20160816; b=XI7F1mt3B4tjASwoB3rdG7/n8TD82oeWHVfEK4DzWVQ8ENn5RvdLqNL+30VZiI4gHG 8rWWa9zV5URfuo/Z7fGemjaFw+NB6dsvyEdrF01ZqESNJ3JMk8RGteV2YRfO1HomNrAz rOlpu9pCB0Koqh1ThUjzNude+OiUktA1ccYCK3XuaFnt5wOsfebzOsCOuTugJliU9WzS fsgA4gUeZxcHKMK0xsPEpWZrJoap5JrALZBeY3kpL1GscGf9g7Zo7RHff+C/n2STSPVu rLRmtfQAN4mxPeiQmP3Pst7bKFcWoepEQZ48hs/buUZ59OpL6QJdo8I8cBvr8/SizB7f fz/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Gek2awizC19DRqdsGkSxiDjzH45dJ2a6h+V1E8hcFPc=; b=Qo2pf01+zO0zofMfGbdDCGQwdR66wV1h3YEGQ0LC4/yH71J2qs9hZAZGgII7crYzIn vsA0GfAR4BPhkxLBch+yESivVHA2Tmxu29YQCblcFGPn+Y4VVUBWpr18/tTGW1FBwv6f cnbHaGHcD8pJqYik5Jog3jimCaxDfy21RXWKuHjRpWYOMyuIJ1sMPMk2qcpIqjlECNJg 1RZvfOiUG3+nYHm8BvR7Y1+5mrRMtYlkY9HfwmLZZjyoyhO12ryMgm8F5fBNZjjOGFiB PMoa5v5tjye2zPB/BbJJNxn8GBsELbIYat0x1w+73RghS20UJ2XoRANTyoUtqGA4Aa9P fA7g== 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 e57si8060771ede.356.2019.09.30.13.41.15; Mon, 30 Sep 2019 13:41:45 -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 S1731071AbfI3UiI (ORCPT + 99 others); Mon, 30 Sep 2019 16:38:08 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:41461 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730105AbfI3UiH (ORCPT ); Mon, 30 Sep 2019 16:38:07 -0400 Received: by mail-lj1-f195.google.com with SMTP id f5so10926716ljg.8; Mon, 30 Sep 2019 13:38:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Gek2awizC19DRqdsGkSxiDjzH45dJ2a6h+V1E8hcFPc=; b=m5DZh/v+bR7He87gdSFPGLVJrrQjpD045RxFCvuUDYQgF1aEnzS+4GHh9Fx6HEG4mh Zh694ML65wXDvqCojVyghpo+7cJJzJ/dFwz1T+vS53V9wxTLZyTLPg6ECSNSyShebO9p SwMtDQ8B9RvJHmLifzOfjbzYUjpunHAF43uBhO4/hKlElXJV4DoacquPRsDa37EvuQd1 HBZamqQUZ3+1o0guEHwwGMiQm2kRZgbd23sCBpxXt7vHIkGN5DiGNt7KLN9pOcgtmA8o Ed1FaVTjFX5CORqe0SI8428h8Oiwn3zgkN8LncGrHIXmEJ9IpQVMFgXtCDhjz3qtPj5m dPZQ== X-Gm-Message-State: APjAAAVNph/TJ5wtEMujXwXIPp/bnlr6iNn58X6MpwOSQa6ODp7IWRaj QcBnZIs+ohTEGsVy2hc21ksVG1Zv X-Received: by 2002:a2e:63da:: with SMTP id s87mr13106787lje.79.1569875513862; Mon, 30 Sep 2019 13:31:53 -0700 (PDT) Received: from localhost.localdomain (broadband-188-32-48-208.ip.moscow.rt.ru. [188.32.48.208]) by smtp.googlemail.com with ESMTPSA id j84sm3548526ljb.91.2019.09.30.13.31.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2019 13:31:53 -0700 (PDT) From: Denis Efremov To: linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Denis Efremov , Pontus Fuchs , Kalle Valo , "David S. Miller" , David Laight , stable@vger.kernel.org Subject: [PATCH v2] ar5523: check NULL before memcpy() in ar5523_cmd() Date: Mon, 30 Sep 2019 23:31:47 +0300 Message-Id: <20190930203147.10140-1-efremov@linux.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190930140207.28638-1-efremov@linux.com> References: <20190930140207.28638-1-efremov@linux.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org memcpy() call with "idata == NULL && ilen == 0" results in undefined behavior in ar5523_cmd(). For example, NULL is passed in callchain "ar5523_stat_work() -> ar5523_cmd_write() -> ar5523_cmd()". This patch adds ilen check before memcpy() call in ar5523_cmd() to prevent an undefined behavior. Cc: Pontus Fuchs Cc: Kalle Valo Cc: "David S. Miller" Cc: David Laight Cc: stable@vger.kernel.org Signed-off-by: Denis Efremov --- V2: check ilen instead of idata as suggested by David Laight. drivers/net/wireless/ath/ar5523/ar5523.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ar5523/ar5523.c b/drivers/net/wireless/ath/ar5523/ar5523.c index b94759daeacc..da2d179430ca 100644 --- a/drivers/net/wireless/ath/ar5523/ar5523.c +++ b/drivers/net/wireless/ath/ar5523/ar5523.c @@ -255,7 +255,8 @@ static int ar5523_cmd(struct ar5523 *ar, u32 code, const void *idata, if (flags & AR5523_CMD_FLAG_MAGIC) hdr->magic = cpu_to_be32(1 << 24); - memcpy(hdr + 1, idata, ilen); + if (ilen) + memcpy(hdr + 1, idata, ilen); cmd->odata = odata; cmd->olen = olen; -- 2.21.0