Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp166274ybi; Thu, 1 Aug 2019 16:46:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqy3tknpNz+soHTSXnqD6qp94VT3n4lArDTopvMwCIjQJR3kf9MAk2XiHPxUfSNaPG9lJG7J X-Received: by 2002:a17:902:684f:: with SMTP id f15mr128889895pln.332.1564703183784; Thu, 01 Aug 2019 16:46:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564703183; cv=none; d=google.com; s=arc-20160816; b=t+R8XM6TGgYOlazD+Dl+38dLwvsdqFu86oAa7nrh11pGa7r3i0lmW1wrdKAP6THvEn oQuMKSNxwu1YKiBANMnQrxBFAAvv9HIpJyoqrNemXfd3KNTLfnZVjqcTX+qR6gOCWnMB zKKb1Np8469Zyou2yQLxemoVZ+MwjQs2gVUxo+IWP09UK6T05kYQwuNmVJxDebUZihK+ q/OSVQQ7xXnBhkF5hcVtOEN4X/jWqA+jfK2ZTEEwTd4U+HEjHB4hTBH50GP6hCkTQhcX fZJDnAu+rb8SehI0v+RDPcXMdzixaRIjbpZWlo9SuOYTzNoCcV4Ney8lLsbrzy5KINrL zIhA== 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 :user-agent:organization:references:in-reply-to:date:cc:to:from :subject:message-id; bh=DPKAwzWvLcrDqQn2bM5aemj2Yjbw1ZonsNLzU3/XvAk=; b=P3kO0lX/aLq0O1jhnY1sXUjlBx4EW4JkxcshR562nprjDWb1JtBTCeI4hvLHuFB24M CtkLszYnACJzONGO9QYROM5dBizbNZvu/4NPHrDgZgLbiIuD0+wCoWvLr0PJl8cmxLKd 6HmfRhKzMPxSjTwg1WQXyzD2vl1fYn3iGqis/JLOAg4TQtjSPZ3Xz/irA3/K9uNzBNtw wpZXA4PGkG9UWaiA1P+lmEnhpJl30QAjOC5eoZioH1u35nzzhM67DugbZkV4IxzxMZ/Z L46+t1aDuFYKa25uA1CD/ujicosDGz4u/XlN8J/JvtlrSaMvwhomIs4ey2ral5HmupMg E/6g== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=codethink.co.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h11si33127103plr.34.2019.08.01.16.45.49; Thu, 01 Aug 2019 16:46:23 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=codethink.co.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732277AbfHASvJ (ORCPT + 99 others); Thu, 1 Aug 2019 14:51:09 -0400 Received: from imap1.codethink.co.uk ([176.9.8.82]:55773 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727899AbfHASvJ (ORCPT ); Thu, 1 Aug 2019 14:51:09 -0400 Received: from [167.98.27.226] (helo=xylophone) by imap1.codethink.co.uk with esmtpsa (Exim 4.84_2 #1 (Debian)) id 1htGAI-0003wL-VP; Thu, 01 Aug 2019 19:51:03 +0100 Message-ID: Subject: Re: [cip-dev] phy-rcar-gen3-usb2: wrong parsing of role in role_store? From: Ben Hutchings To: Pavel Machek , yoshihiro.shimoda.uh@renesas.com, kishon@ti.com, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: cip-dev@lists.cip-project.org Date: Thu, 01 Aug 2019 19:51:02 +0100 In-Reply-To: <20190730095140.GA29609@amd> References: <20190730095140.GA29609@amd> Organization: Codethink Ltd. Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.30.5-1.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2019-07-30 at 11:51 +0200, Pavel Machek wrote: > Hi! > > Code does strcmps, but does not actually check count. So AFAICT > writing "host-I-don't-want-I-need-peripheral" into the file will > succeed and turn it into host mode. I suspect the intent is to work without a trailing "\n", but you're right that this parsing is rather lax. > Also data beyond count in buf are going to be accessed. All attribute writes should be going through kernfs_fop_write(), which writes a null terminator at buf[count] before calling the write/store function. (I don't know where that'ss documented though.) So I think this is safe. Ben. > static ssize_t role_store(struct device *dev, struct device_attribute *attr, > const char *buf, size_t count) > { > struct rcar_gen3_chan *ch = dev_get_drvdata(dev); > bool is_b_device; > enum phy_mode cur_mode, new_mode; > > if (!ch->is_otg_channel || !rcar_gen3_is_any_rphy_initialized(ch)) > return -EIO; > > /* FIXME, this is wrong */ > if (!strncmp(buf, "host", strlen("host"))) > new_mode = PHY_MODE_USB_HOST; > else if (!strncmp(buf, "peripheral", strlen("peripheral"))) > new_mode = PHY_MODE_USB_DEVICE; > else > return -EINVAL; > > > _______________________________________________ > cip-dev mailing list > cip-dev@lists.cip-project.org > https://lists.cip-project.org/mailman/listinfo/cip-dev -- Ben Hutchings, Software Developer Codethink Ltd https://www.codethink.co.uk/ Dale House, 35 Dale Street Manchester, M1 2HF, United Kingdom