Skip to content

Commit 110d693

Browse files
Alessandro ZummoLinus Torvalds
authored andcommitted
[PATCH] rtc subsystem: add capability checks
Centralize CAP_SYS_XXX checks to avoid duplicate code and missing checks in the drivers. Signed-off-by: Alessandro Zummo <a.zummo@towertech.it> Cc: Richard Purdie <rpurdie@rpsys.net> Cc: Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 56f10c6 commit 110d693

5 files changed

Lines changed: 24 additions & 19 deletions

File tree

‎drivers/rtc/class.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev,
6969
rtc->id = id;
7070
rtc->ops = ops;
7171
rtc->owner = owner;
72+
rtc->max_user_freq = 64;
7273
rtc->class_dev.dev = dev;
7374
rtc->class_dev.class = rtc_class;
7475
rtc->class_dev.release = rtc_device_release;

‎drivers/rtc/rtc-dev.c‎

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,28 @@ static int rtc_dev_ioctl(struct inode *inode, struct file *file,
214214
struct rtc_wkalrm alarm;
215215
void __user *uarg = (void __user *) arg;
216216

217+
/* check that the calles has appropriate permissions
218+
* for certain ioctls. doing this check here is useful
219+
* to avoid duplicate code in each driver.
220+
*/
221+
switch (cmd) {
222+
case RTC_EPOCH_SET:
223+
case RTC_SET_TIME:
224+
if (!capable(CAP_SYS_TIME))
225+
return -EACCES;
226+
break;
227+
228+
case RTC_IRQP_SET:
229+
if (arg > rtc->max_user_freq && !capable(CAP_SYS_RESOURCE))
230+
return -EACCES;
231+
break;
232+
233+
case RTC_PIE_ON:
234+
if (!capable(CAP_SYS_RESOURCE))
235+
return -EACCES;
236+
break;
237+
}
238+
217239
/* avoid conflicting IRQ users */
218240
if (cmd == RTC_PIE_ON || cmd == RTC_PIE_OFF || cmd == RTC_IRQP_SET) {
219241
spin_lock(&rtc->irq_task_lock);
@@ -272,9 +294,6 @@ static int rtc_dev_ioctl(struct inode *inode, struct file *file,
272294
break;
273295

274296
case RTC_SET_TIME:
275-
if (!capable(CAP_SYS_TIME))
276-
return -EACCES;
277-
278297
if (copy_from_user(&tm, uarg, sizeof(tm)))
279298
return -EFAULT;
280299

@@ -290,10 +309,6 @@ static int rtc_dev_ioctl(struct inode *inode, struct file *file,
290309
err = -EINVAL;
291310
break;
292311
}
293-
if (!capable(CAP_SYS_TIME)) {
294-
err = -EACCES;
295-
break;
296-
}
297312
rtc_epoch = arg;
298313
err = 0;
299314
#endif

‎drivers/rtc/rtc-sa1100.c‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,6 @@ static int sa1100_rtc_ioctl(struct device *dev, unsigned int cmd,
229229
spin_unlock_irq(&sa1100_rtc_lock);
230230
return 0;
231231
case RTC_PIE_ON:
232-
if ((rtc_freq > 64) && !capable(CAP_SYS_RESOURCE))
233-
return -EACCES;
234232
spin_lock_irq(&sa1100_rtc_lock);
235233
OSMR1 = TIMER_FREQ/rtc_freq + OSCR;
236234
OIER |= OIER_E1;
@@ -242,8 +240,6 @@ static int sa1100_rtc_ioctl(struct device *dev, unsigned int cmd,
242240
case RTC_IRQP_SET:
243241
if (arg < 1 || arg > TIMER_FREQ)
244242
return -EINVAL;
245-
if ((arg > 64) && (!capable(CAP_SYS_RESOURCE)))
246-
return -EACCES;
247243
rtc_freq = arg;
248244
return 0;
249245
}

‎drivers/rtc/rtc-vr41xx.c‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ MODULE_LICENSE("GPL");
8181

8282
#define RTC_FREQUENCY 32768
8383
#define MAX_PERIODIC_RATE 6553
84-
#define MAX_USER_PERIODIC_RATE 64
8584

8685
static void __iomem *rtc1_base;
8786
static void __iomem *rtc2_base;
@@ -240,9 +239,6 @@ static int vr41xx_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long
240239
if (arg > MAX_PERIODIC_RATE)
241240
return -EINVAL;
242241

243-
if (arg > MAX_USER_PERIODIC_RATE && capable(CAP_SYS_RESOURCE) == 0)
244-
return -EACCES;
245-
246242
periodic_frequency = arg;
247243

248244
count = RTC_FREQUENCY;
@@ -263,10 +259,6 @@ static int vr41xx_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long
263259
/* Doesn't support before 1900 */
264260
if (arg < 1900)
265261
return -EINVAL;
266-
267-
if (capable(CAP_SYS_TIME) == 0)
268-
return -EACCES;
269-
270262
epoch = arg;
271263
break;
272264
default:

‎include/linux/rtc.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ struct rtc_device
155155
struct rtc_task *irq_task;
156156
spinlock_t irq_task_lock;
157157
int irq_freq;
158+
int max_user_freq;
158159
#ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
159160
struct work_struct uie_task;
160161
struct timer_list uie_timer;

0 commit comments

Comments
 (0)