Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752930AbbFATRR (ORCPT ); Mon, 1 Jun 2015 15:17:17 -0400 Received: from mail-by2on0148.outbound.protection.outlook.com ([207.46.100.148]:13376 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753888AbbFATRA (ORCPT ); Mon, 1 Jun 2015 15:17:00 -0400 Authentication-Results: spf=none (sender IP is 165.204.84.222) smtp.mailfrom=amd.com; alien8.de; dkim=none (message not signed) header.d=none; X-WSS-ID: 0NPA5JZ-08-91X-02 X-M-MSG: Message-ID: <556CAF9F.6080008@amd.com> Date: Mon, 1 Jun 2015 14:16:47 -0500 From: Aravind Gopalakrishnan User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Borislav Petkov CC: , , , Subject: Re: [PATCH 3/6] edac, mce_amd_inj: Modify flags attrigute to use string arguments References: <1432753418-2985-1-git-send-email-Aravind.Gopalakrishnan@amd.com> <1432753418-2985-4-git-send-email-Aravind.Gopalakrishnan@amd.com> <20150529134943.GF31435@pd.tnic> In-Reply-To: <20150529134943.GF31435@pd.tnic> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.180.168.240] X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BN1AFFO11FD037;1:I/1jH1yrlP+JAB2u7S58C9UqDXOVkDnS5Eg6bQH8PXgDsCu+IUxdPwgOaqrqvRBg6ENl7IfwwueXiVgQHAKb+mWVxf0EU07fW4/mqe9SA1bXZVXFsg/5nESAxON1Fc9HsNhUMUTtsoWitHF843tlFPH9c2QQv+abGK5m+0brDwwrGGlLuLxp64ZG/sfwoNU9WgjLrOasNzdBXiipcwUFrotc+/nReUWlveX+oanl3m7cNe0f0B/g78j4Y5lNWObAKgnitCvx7rx/X0IcD6wsWQ== X-Forefront-Antispam-Report: CIP:165.204.84.222;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(428002)(51704005)(377454003)(479174004)(164054003)(24454002)(199003)(189002)(87936001)(110136002)(2950100001)(101416001)(92566002)(105586002)(33656002)(86362001)(106466001)(36756003)(64706001)(5001860100001)(62966003)(189998001)(77156002)(97736004)(4001350100001)(4001540100001)(47776003)(77096005)(59896002)(65806001)(65956001)(5001830100001)(23676002)(120886001)(46102003)(87266999)(76176999)(54356999)(65816999)(68736005)(50986999)(80316001)(50466002)(64126003)(83506001);DIR:OUT;SFP:1102;SCL:1;SRVR:BLUPR02MB067;H:atltwp02.amd.com;FPR:;SPF:None;PTR:ErrorRetry;A:3;MX:1;LANG:en; X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR02MB067;UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR02MB1156; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5005006)(520003)(3002001);SRVR:BLUPR02MB067;BCL:0;PCL:0;RULEID:;SRVR:BLUPR02MB067; X-Forefront-PRVS: 05947791E4 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jun 2015 19:16:51.1961 (UTC) X-MS-Exchange-CrossTenant-Id: fde4dada-be84-483f-92cc-e026cbee8e96 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=fde4dada-be84-483f-92cc-e026cbee8e96;Ip=[165.204.84.222];Helo=[atltwp02.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR02MB067 X-OriginatorOrg: amd.com Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2487 Lines: 86 On 5/29/2015 8:49 AM, Borislav Petkov wrote: > On Wed, May 27, 2015 at 02:03:35PM -0500, Aravind Gopalakrishnan wrote: >> >> +#define MAX_FLAG_OPT_SIZE 10 > Why 10? > > This should be 2 and increased when another, longer injection type > string gets introduced. > So I hit an issue when I have this as 2 and moving 'ret = cnt' statement (in flags_write() below) to after the check for MAX_FLAG_OPT_SIZE. The problem was, if I did echo hw > flags; I would get an error on dmesg like so- [ 78.692949] flags_write: Invalid flags value: But the write would have actually gone through. i.e, if we do cat flags, the output was 'hw'. The issue seems to be that 'cnt' of flags_write() is 3 (after accounting for a terminating NULL) when we enter the function (for this case), Since we move 'ret = cnt;' statement to after the check, we end up returning 2. And since it is less than 'cnt', we re-enter flags_write() for the final NULL character. At this point, our comparisons with flags_options[] fail and we end up returning -EINVAL from __set_inj(). Hence the error on dmesg.. The fix to this was simply having MAX_FLAG_OPT_SIZE as 3. In this case, we already account for the NULL and flags_write() returns the correct value upon success. So I shall go ahead and make that change to MAX_FLAG_OPT_SIZE as 3 and increase it in subsequent patch for the apic interrupts. Thanks, -Aravind. >> >> -DEFINE_SIMPLE_ATTRIBUTE(flags_fops, flags_get, flags_set, "%llu\n"); >> +static ssize_t flags_write(struct file *filp, const char __user *ubuf, >> + size_t cnt, loff_t *ppos) >> +{ >> + char buf[MAX_FLAG_OPT_SIZE + 1]; >> + int err; >> + size_t ret; >> + >> + ret = cnt; > You're assigning cnt to ret here... > >> + >> + if (cnt > MAX_FLAG_OPT_SIZE) >> + cnt = MAX_FLAG_OPT_SIZE; > ... but correcting cnt afterwards. The assignment should be *after* that > correction. > >> + >> + if (copy_from_user(&buf, ubuf, cnt)) >> + return -EFAULT; >> + >> + buf[cnt] = 0; >> + >> + /* strip whitespaces.. */ >> + strstrip(buf); >> + >> + err = __set_inj(buf, cnt - 1); >> + if (err) { >> + pr_err("%s: Invalid flags value: %s\n", __func__, buf); >> + return err; >> + } >> + >> + *ppos += ret; >> + >> + return ret; >> +} >> + >> -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/